blob: 4a1c925b38787fd4d0f762fbdb27aa608c59f44e [file] [log] [blame]
Vitaly Buka4615e0d2015-10-14 15:35:12 -07001// Copyright 2015 The Weave Authors. All rights reserved.
Alex Vakulenko3cb466c2014-04-15 11:36:32 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Vitaly Buka912b6982015-07-06 11:13:03 -07005#ifndef LIBWEAVE_SRC_DEVICE_REGISTRATION_INFO_H_
6#define LIBWEAVE_SRC_DEVICE_REGISTRATION_INFO_H_
Alex Vakulenko3cb466c2014-04-15 11:36:32 -07007
Alex Vakulenko3cb466c2014-04-15 11:36:32 -07008#include <map>
9#include <memory>
Alex Vakulenko5841c302014-07-23 10:49:49 -070010#include <string>
Alex Vakulenkob3aac252014-05-07 17:35:24 -070011#include <utility>
Vitaly Bukaee7a3af2015-05-14 16:57:23 -070012#include <vector>
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070013
Alex Vakulenko266b2b12015-06-19 11:01:42 -070014#include <base/callback.h>
Alex Vakulenko132617a2014-09-04 08:59:43 -070015#include <base/macros.h>
Christopher Wileycd419662015-02-06 17:51:43 -080016#include <base/memory/weak_ptr.h>
Alex Vakulenkoa3062c52014-04-21 17:05:51 -070017#include <base/time/time.h>
Vitaly Bukac3c6dab2015-10-01 19:41:02 -070018#include <weave/device.h>
Vitaly Buka0801a1f2015-08-14 10:03:46 -070019#include <weave/error.h>
Vitaly Buka1e363672015-09-25 14:01:16 -070020#include <weave/provider/http_client.h>
Alex Vakulenkoa3062c52014-04-21 17:05:51 -070021
Stefan Sauer2d16dfa2015-09-25 17:08:35 +020022#include "src/backoff_entry.h"
23#include "src/commands/cloud_command_update_interface.h"
Alex Vakulenkod91d6252015-12-05 17:14:39 -080024#include "src/component_manager.h"
Stefan Sauer2d16dfa2015-09-25 17:08:35 +020025#include "src/config.h"
26#include "src/data_encoding.h"
27#include "src/notification/notification_channel.h"
28#include "src/notification/notification_delegate.h"
29#include "src/notification/pull_channel.h"
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070030
31namespace base {
Vitaly Buka6ca3ad62015-03-11 17:03:23 -070032class DictionaryValue;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070033} // namespace base
34
Vitaly Bukab6f015a2015-07-09 14:59:23 -070035namespace weave {
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070036
Vitaly Buka6da94252015-08-04 15:45:14 -070037class StateManager;
Vitaly Buka1e363672015-09-25 14:01:16 -070038
39namespace provider {
40class Network;
Vitaly Buka823fdda2015-08-13 00:33:00 -070041class TaskRunner;
Vitaly Buka1e363672015-09-25 14:01:16 -070042}
Vitaly Bukab6f015a2015-07-09 14:59:23 -070043
Vitaly Buka3d851b42015-12-08 16:17:01 -080044namespace privet {
45class AuthManager;
46}
47
Alex Vakulenkob3aac252014-05-07 17:35:24 -070048extern const char kErrorDomainOAuth2[];
49extern const char kErrorDomainGCD[];
50extern const char kErrorDomainGCDServer[];
Alex Vakulenkob3aac252014-05-07 17:35:24 -070051
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070052// The DeviceRegistrationInfo class represents device registration information.
Vitaly Bukac3c6dab2015-10-01 19:41:02 -070053class DeviceRegistrationInfo : public NotificationDelegate,
Alex Vakulenkofe53f612015-06-26 09:05:15 -070054 public CloudCommandUpdateInterface {
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070055 public:
Vitaly Buka74763422015-10-11 00:39:52 -070056 using CloudRequestDoneCallback =
57 base::Callback<void(const base::DictionaryValue& response,
58 ErrorPtr error)>;
Christopher Wileye0fdeee2015-02-07 18:29:32 -080059
Vitaly Buka666b43e2015-12-08 16:35:47 -080060 DeviceRegistrationInfo(Config* config,
61 ComponentManager* component_manager,
Vitaly Buka3d851b42015-12-08 16:17:01 -080062 provider::TaskRunner* task_runner,
63 provider::HttpClient* http_client,
64 provider::Network* network,
65 privet::AuthManager* auth_manager);
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070066
Alex Vakulenko534a3122015-05-22 15:48:53 -070067 ~DeviceRegistrationInfo() override;
Anton Muhin332df192014-11-22 05:59:14 +040068
Vitaly Bukac3c6dab2015-10-01 19:41:02 -070069 void AddGcdStateChangedCallback(
70 const Device::GcdStateChangedCallback& callback);
Vitaly Buka12870bd2015-10-08 23:49:39 -070071 void RegisterDevice(const std::string& ticket_id,
Vitaly Buka74763422015-10-11 00:39:52 -070072 const DoneCallback& callback);
Vitaly Buka9aa15c72015-10-01 19:14:44 -070073
Vitaly Bukab624bc42015-09-29 19:13:55 -070074 void UpdateDeviceInfo(const std::string& name,
Vitaly Buka8b4ab962015-07-14 19:19:39 -070075 const std::string& description,
Vitaly Buka9aa15c72015-10-01 19:14:44 -070076 const std::string& location);
Vitaly Bukab624bc42015-09-29 19:13:55 -070077 void UpdateBaseConfig(AuthScope anonymous_access_role,
Vitaly Buka8b4ab962015-07-14 19:19:39 -070078 bool local_discovery_enabled,
Vitaly Buka9aa15c72015-10-01 19:14:44 -070079 bool local_pairing_enabled);
Vitaly Buka8b4ab962015-07-14 19:19:39 -070080 bool UpdateServiceConfig(const std::string& client_id,
81 const std::string& client_secret,
82 const std::string& api_key,
83 const std::string& oauth_url,
84 const std::string& service_url,
Vitaly Buka9aa15c72015-10-01 19:14:44 -070085 ErrorPtr* error);
Christopher Wileyc900e482015-02-15 15:42:04 -080086
Vitaly Buka74763422015-10-11 00:39:52 -070087 void GetDeviceInfo(const CloudRequestDoneCallback& callback);
Vitaly Bukaee3e36d2015-10-01 18:18:58 -070088
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070089 // Returns the GCD service request URL. If |subpath| is specified, it is
90 // appended to the base URL which is normally
Vitaly Buka88272d52015-11-17 17:04:01 -080091 // https://www.googleapis.com/weave/v1/".
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070092 // If |params| are specified, each key-value pair is formatted using
Vitaly Buka7d556392015-08-13 20:06:48 -070093 // WebParamsEncode() and appended to URL as a query
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070094 // string.
95 // So, calling:
96 // GetServiceURL("ticket", {{"key","apiKey"}})
97 // will return something like:
Vitaly Buka88272d52015-11-17 17:04:01 -080098 // https://www.googleapis.com/weave/v1/ticket?key=apiKey
Vitaly Buka7d556392015-08-13 20:06:48 -070099 std::string GetServiceURL(const std::string& subpath = {},
100 const WebParamList& params = {}) const;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700101
102 // Returns a service URL to access the registered device on GCD server.
103 // The base URL used to construct the full URL looks like this:
Vitaly Buka88272d52015-11-17 17:04:01 -0800104 // https://www.googleapis.com/weave/v1/devices/<cloud_id>/
Vitaly Buka7d556392015-08-13 20:06:48 -0700105 std::string GetDeviceURL(const std::string& subpath = {},
106 const WebParamList& params = {}) const;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700107
108 // Similar to GetServiceURL, GetOAuthURL() returns a URL of OAuth 2.0 server.
109 // The base URL used is https://accounts.google.com/o/oauth2/.
Vitaly Buka7d556392015-08-13 20:06:48 -0700110 std::string GetOAuthURL(const std::string& subpath = {},
111 const WebParamList& params = {}) const;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700112
Alex Vakulenko6e3c30e2015-05-21 17:39:25 -0700113 // Starts GCD device if credentials available.
Vitaly Bukaee7a3af2015-05-14 16:57:23 -0700114 void Start();
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700115
Vitaly Bukab6f015a2015-07-09 14:59:23 -0700116 // Updates a command (override from CloudCommandUpdateInterface).
Anton Muhin59755522014-11-05 21:30:12 +0400117 void UpdateCommand(const std::string& command_id,
Alex Vakulenkob211c102015-04-21 11:43:23 -0700118 const base::DictionaryValue& command_patch,
Vitaly Buka74763422015-10-11 00:39:52 -0700119 const DoneCallback& callback) override;
Anton Muhin59755522014-11-05 21:30:12 +0400120
Vitaly Bukab56872f2015-06-21 18:39:34 -0700121 // TODO(vitalybuka): remove getters and pass config to dependent code.
Vitaly Buka238db692015-09-29 16:58:39 -0700122 const Config::Settings& GetSettings() const { return config_->GetSettings(); }
Vitaly Buka666b43e2015-12-08 16:35:47 -0800123 Config* GetMutableConfig() { return config_; }
Vitaly Buka72410b22015-05-13 13:48:59 -0700124
Vitaly Bukac3c6dab2015-10-01 19:41:02 -0700125 GcdState GetGcdState() const { return gcd_state_; }
126
Vitaly Buka4c808b22015-08-02 13:44:52 -0700127 private:
128 friend class DeviceRegistrationInfoTest;
129
Vitaly Buka72410b22015-05-13 13:48:59 -0700130 base::WeakPtr<DeviceRegistrationInfo> AsWeakPtr() {
131 return weak_factory_.GetWeakPtr();
132 }
133
Vitaly Buka672634b2015-11-20 09:49:30 -0800134 // Checks whether we have credentials generated during registration.
135 bool HaveRegistrationCredentials() const;
136 // Calls HaveRegistrationCredentials() and logs an error if no credentials
137 // are available.
138 bool VerifyRegistrationCredentials(ErrorPtr* error) const;
139
Alex Vakulenkofb331ac2015-07-22 15:10:11 -0700140 // Cause DeviceRegistrationInfo to attempt to connect to cloud server on
141 // its own later.
142 void ScheduleCloudConnection(const base::TimeDelta& delay);
Christopher Wileyba983c82015-03-05 16:32:23 -0800143
Alex Vakulenkofb331ac2015-07-22 15:10:11 -0700144 // Initiates the connection to the cloud server.
Christopher Wileyba983c82015-03-05 16:32:23 -0800145 // Device will do required start up chores and then start to listen
146 // to new commands.
Vitaly Buka74763422015-10-11 00:39:52 -0700147 void ConnectToCloud(ErrorPtr error);
Alex Vakulenkofb331ac2015-07-22 15:10:11 -0700148 // Notification called when ConnectToCloud() succeeds.
Vitaly Buka74763422015-10-11 00:39:52 -0700149 void OnConnectedToCloud(ErrorPtr error);
Christopher Wileyba983c82015-03-05 16:32:23 -0800150
David Zeuthen390d1912015-03-03 14:54:48 -0500151 // Forcibly refreshes the access token.
Vitaly Buka74763422015-10-11 00:39:52 -0700152 void RefreshAccessToken(const DoneCallback& callback);
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700153
Alex Vakulenko0f91be82015-07-27 10:11:53 -0700154 // Callbacks for RefreshAccessToken().
Vitaly Buka74763422015-10-11 00:39:52 -0700155 void OnRefreshAccessTokenDone(
156 const DoneCallback& callback,
157 std::unique_ptr<provider::HttpClient::Response> response,
Vitaly Bukaf7f52d42015-10-10 22:43:55 -0700158 ErrorPtr error);
Alex Vakulenko6b028ae2015-05-29 09:38:59 -0700159
Nathan Bullock24d189f2015-02-26 13:09:18 -0500160 // Parse the OAuth response, and sets registration status to
161 // kInvalidCredentials if our registration is no longer valid.
162 std::unique_ptr<base::DictionaryValue> ParseOAuthResponse(
Vitaly Buka1e363672015-09-25 14:01:16 -0700163 const provider::HttpClient::Response& response,
Vitaly Buka0801a1f2015-08-14 10:03:46 -0700164 ErrorPtr* error);
Nathan Bullock24d189f2015-02-26 13:09:18 -0500165
Alex Vakulenkoeedf3be2015-05-13 17:52:02 -0700166 // This attempts to open a notification channel. The channel needs to be
Nathan Bullockbea91132015-02-19 09:13:33 -0500167 // restarted anytime the access_token is refreshed.
Alex Vakulenkoeedf3be2015-05-13 17:52:02 -0700168 void StartNotificationChannel();
Nathan Bullockbea91132015-02-19 09:13:33 -0500169
Anton Muhinac661ab2014-10-03 20:29:48 +0400170 // Do a HTTPS request to cloud services.
171 // Handles many cases like reauthorization, 5xx HTTP response codes
172 // and device removal. It is a recommended way to do cloud API
173 // requests.
174 // TODO(antonm): Consider moving into some other class.
Vitaly Buka1a42e142015-10-10 18:15:15 -0700175 void DoCloudRequest(provider::HttpClient::Method method,
Vitaly Bukaa647c852015-07-06 14:51:01 -0700176 const std::string& url,
177 const base::DictionaryValue* body,
Vitaly Buka74763422015-10-11 00:39:52 -0700178 const CloudRequestDoneCallback& callback);
Anton Muhinac661ab2014-10-03 20:29:48 +0400179
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700180 // Helper for DoCloudRequest().
181 struct CloudRequestData {
Vitaly Buka1a42e142015-10-10 18:15:15 -0700182 provider::HttpClient::Method method;
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700183 std::string url;
184 std::string body;
Vitaly Buka74763422015-10-11 00:39:52 -0700185 CloudRequestDoneCallback callback;
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700186 };
187 void SendCloudRequest(const std::shared_ptr<const CloudRequestData>& data);
Vitaly Buka74763422015-10-11 00:39:52 -0700188 void OnCloudRequestDone(
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700189 const std::shared_ptr<const CloudRequestData>& data,
Vitaly Buka74763422015-10-11 00:39:52 -0700190 std::unique_ptr<provider::HttpClient::Response> response,
191 ErrorPtr error);
Vitaly Bukaa647c852015-07-06 14:51:01 -0700192 void RetryCloudRequest(const std::shared_ptr<const CloudRequestData>& data);
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700193 void OnAccessTokenRefreshed(
Vitaly Buka74763422015-10-11 00:39:52 -0700194 const std::shared_ptr<const CloudRequestData>& data,
195 ErrorPtr error);
Vitaly Bukaf7f52d42015-10-10 22:43:55 -0700196 void CheckAccessTokenError(ErrorPtr error);
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700197
Vitaly Buka74763422015-10-11 00:39:52 -0700198 void UpdateDeviceResource(const DoneCallback& callback);
Alex Vakulenkof3a95bf2015-07-01 07:52:13 -0700199 void StartQueuedUpdateDeviceResource();
Vitaly Buka74763422015-10-11 00:39:52 -0700200 void OnUpdateDeviceResourceDone(const base::DictionaryValue& device_info,
201 ErrorPtr error);
Vitaly Bukaf7f52d42015-10-10 22:43:55 -0700202 void OnUpdateDeviceResourceError(ErrorPtr error);
Anton Muhinc635c592014-10-28 21:48:08 +0400203
Vitaly Buka72d8d162015-12-09 18:39:36 -0800204 void SendAuthInfo();
Vitaly Buka0c190b32015-12-14 15:22:10 -0800205 void OnSendAuthInfoDone(const std::vector<uint8_t>& token,
206 const base::DictionaryValue& body,
207 ErrorPtr error);
Vitaly Buka72d8d162015-12-09 18:39:36 -0800208
Alex Vakulenkofb331ac2015-07-22 15:10:11 -0700209 // Callback from GetDeviceInfo() to retrieve the device resource timestamp
210 // and retry UpdateDeviceResource() call.
Vitaly Buka74763422015-10-11 00:39:52 -0700211 void OnDeviceInfoRetrieved(const base::DictionaryValue& device_info,
212 ErrorPtr error);
Alex Vakulenkofb331ac2015-07-22 15:10:11 -0700213
214 // Extracts the timestamp from the device resource and sets it to
215 // |last_device_resource_updated_timestamp_|.
216 // Returns false if the "lastUpdateTimeMs" field is not found in the device
217 // resource or it is invalid.
218 bool UpdateDeviceInfoTimestamp(const base::DictionaryValue& device_info);
219
Christopher Wileyba983c82015-03-05 16:32:23 -0800220 void FetchCommands(
Alex Vakulenkoe07c29d2015-10-22 10:31:12 -0700221 const base::Callback<void(const base::ListValue&, ErrorPtr)>& callback,
222 const std::string& reason);
Vitaly Buka74763422015-10-11 00:39:52 -0700223 void OnFetchCommandsDone(
224 const base::Callback<void(const base::ListValue&, ErrorPtr)>& callback,
225 const base::DictionaryValue& json,
226 ErrorPtr);
Alex Vakulenko64bc9ea2015-09-14 09:24:58 -0700227 // Called when FetchCommands completes (with either success or error).
228 // This method reschedules any pending/queued fetch requests.
229 void OnFetchCommandsReturned();
Anton Muhinc635c592014-10-28 21:48:08 +0400230
Alex Vakulenkod05725f2015-05-27 15:48:19 -0700231 // Processes the command list that is fetched from the server on connection.
232 // Aborts commands which are in transitional states and publishes queued
233 // commands which are queued.
Vitaly Buka74763422015-10-11 00:39:52 -0700234 void ProcessInitialCommandList(const base::ListValue& commands,
235 ErrorPtr error);
Anton Muhinc635c592014-10-28 21:48:08 +0400236
Vitaly Buka74763422015-10-11 00:39:52 -0700237 void PublishCommands(const base::ListValue& commands, ErrorPtr error);
Alex Vakulenko6e3c30e2015-05-21 17:39:25 -0700238 void PublishCommand(const base::DictionaryValue& command);
Anton Muhind07e2062014-10-27 10:53:29 +0400239
Alex Vakulenko1038ec12015-07-15 14:36:13 -0700240 // Helper function to pull the pending command list from the server using
241 // FetchCommands() and make them available on D-Bus with PublishCommands().
Alex Vakulenkoe07c29d2015-10-22 10:31:12 -0700242 // |backup_fetch| is set to true when performing backup ("just-in-case")
243 // command fetch while XMPP channel is up and running.
244 void FetchAndPublishCommands(const std::string& reason);
Alex Vakulenko1038ec12015-07-15 14:36:13 -0700245
Anton Muhinb8315622014-11-20 03:17:05 +0400246 void PublishStateUpdates();
Alex Vakulenkod91d6252015-12-05 17:14:39 -0800247 void OnPublishStateDone(ComponentManager::UpdateID update_id,
Vitaly Buka74763422015-10-11 00:39:52 -0700248 const base::DictionaryValue& reply,
249 ErrorPtr error);
Vitaly Bukaf7f52d42015-10-10 22:43:55 -0700250 void OnPublishStateError(ErrorPtr error);
Anton Muhinb8315622014-11-20 03:17:05 +0400251
Alex Vakulenkod1978d32015-04-29 17:33:26 -0700252 // If unrecoverable error occurred (e.g. error parsing command instance),
253 // notify the server that the command is aborted by the device.
Vitaly Buka0801a1f2015-08-14 10:03:46 -0700254 void NotifyCommandAborted(const std::string& command_id, ErrorPtr error);
Alex Vakulenkod1978d32015-04-29 17:33:26 -0700255
Alex Vakulenko9ea5a322015-04-17 15:35:34 -0700256 // Builds Cloud API devices collection REST resource which matches
Anton Muhind8d32162014-10-02 20:37:00 +0400257 // current state of the device including command definitions
258 // for all supported commands and current device state.
Vitaly Buka1a108712015-12-06 17:41:07 -0800259 std::unique_ptr<base::DictionaryValue> BuildDeviceResource() const;
Anton Muhind8d32162014-10-02 20:37:00 +0400260
Vitaly Bukac3c6dab2015-10-01 19:41:02 -0700261 void SetGcdState(GcdState new_state);
Johan Euphrosine312c2f52015-09-29 00:04:29 -0700262 void SetDeviceId(const std::string& cloud_id);
Christopher Wileyc900e482015-02-15 15:42:04 -0800263
Alex Vakulenko9ea5a322015-04-17 15:35:34 -0700264 // Callback called when command definitions are changed to re-publish new CDD.
Alex Vakulenkod91d6252015-12-05 17:14:39 -0800265 void OnTraitDefsChanged();
266 void OnComponentTreeChanged();
Vitaly Bukac903d282015-05-26 17:03:08 -0700267 void OnStateChanged();
Alex Vakulenko9ea5a322015-04-17 15:35:34 -0700268
Alex Vakulenko6b40d8f2015-06-24 11:44:22 -0700269 // Overrides from NotificationDelegate.
Alex Vakulenkoeedf3be2015-05-13 17:52:02 -0700270 void OnConnected(const std::string& channel_name) override;
271 void OnDisconnected() override;
272 void OnPermanentFailure() override;
Alex Vakulenkoe07c29d2015-10-22 10:31:12 -0700273 void OnCommandCreated(const base::DictionaryValue& command,
274 const std::string& channel_name) override;
Johan Euphrosine312c2f52015-09-29 00:04:29 -0700275 void OnDeviceDeleted(const std::string& cloud_id) override;
Alex Vakulenkoeedf3be2015-05-13 17:52:02 -0700276
Alex Vakulenko3fa42ae2015-06-23 15:12:22 -0700277 // Wipes out the device registration information and stops server connections.
Vitaly Buka672634b2015-11-20 09:49:30 -0800278 void RemoveCredentials();
Alex Vakulenko3fa42ae2015-06-23 15:12:22 -0700279
Vitaly Buka74763422015-10-11 00:39:52 -0700280 void RegisterDeviceError(const DoneCallback& callback, ErrorPtr error);
Vitaly Buka4774df22015-10-09 12:36:22 -0700281 void RegisterDeviceOnTicketSent(
282 const std::string& ticket_id,
Vitaly Buka74763422015-10-11 00:39:52 -0700283 const DoneCallback& callback,
284 std::unique_ptr<provider::HttpClient::Response> response,
285 ErrorPtr error);
Vitaly Buka4774df22015-10-09 12:36:22 -0700286 void RegisterDeviceOnTicketFinalized(
Vitaly Buka74763422015-10-11 00:39:52 -0700287 const DoneCallback& callback,
288 std::unique_ptr<provider::HttpClient::Response> response,
289 ErrorPtr error);
Vitaly Buka4774df22015-10-09 12:36:22 -0700290 void RegisterDeviceOnAuthCodeSent(
291 const std::string& cloud_id,
292 const std::string& robot_account,
Vitaly Buka74763422015-10-11 00:39:52 -0700293 const DoneCallback& callback,
294 std::unique_ptr<provider::HttpClient::Response> response,
295 ErrorPtr error);
Vitaly Buka4774df22015-10-09 12:36:22 -0700296
Nathan Bullockd9e0bcd2015-02-11 11:36:39 -0500297 // Transient data
298 std::string access_token_;
299 base::Time access_token_expiration_;
Alex Vakulenkofb331ac2015-07-22 15:10:11 -0700300 // The time stamp of last device resource update on the server.
301 std::string last_device_resource_updated_timestamp_;
302 // Set to true if the device has connected to the cloud server correctly.
303 // At this point, normal state and command updates can be dispatched to the
304 // server.
305 bool connected_to_cloud_{false};
Nathan Bullockd9e0bcd2015-02-11 11:36:39 -0500306
Alex Vakulenkoa3062c52014-04-21 17:05:51 -0700307 // HTTP transport used for communications.
Vitaly Buka1e363672015-09-25 14:01:16 -0700308 provider::HttpClient* http_client_{nullptr};
Vitaly Buka6da94252015-08-04 15:45:14 -0700309
Vitaly Buka1e363672015-09-25 14:01:16 -0700310 provider::TaskRunner* task_runner_{nullptr};
Vitaly Buka666b43e2015-12-08 16:35:47 -0800311
312 Config* config_{nullptr};
313
Alex Vakulenkod91d6252015-12-05 17:14:39 -0800314 // Global component manager.
315 ComponentManager* component_manager_{nullptr};
Alex Vakulenkoa3062c52014-04-21 17:05:51 -0700316
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700317 // Backoff manager for DoCloudRequest() method.
Vitaly Buka0f80f7c2015-08-13 00:57:25 -0700318 std::unique_ptr<BackoffEntry::Policy> cloud_backoff_policy_;
319 std::unique_ptr<BackoffEntry> cloud_backoff_entry_;
320 std::unique_ptr<BackoffEntry> oauth2_backoff_entry_;
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700321
Alex Vakulenko93ba0bd2015-06-19 14:06:46 -0700322 // Flag set to true while a device state update patch request is in flight
323 // to the cloud server.
324 bool device_state_update_pending_{false};
325
Alex Vakulenko64bc9ea2015-09-14 09:24:58 -0700326 // Set to true when command queue fetch request is in flight to the server.
327 bool fetch_commands_request_sent_{false};
328 // Set to true when another command queue fetch request is queued while
329 // another one was in flight.
330 bool fetch_commands_request_queued_{false};
Alex Vakulenkoe07c29d2015-10-22 10:31:12 -0700331 // Specifies the reason for queued command fetch request.
332 std::string queued_fetch_reason_;
Alex Vakulenko64bc9ea2015-09-14 09:24:58 -0700333
Vitaly Buka74763422015-10-11 00:39:52 -0700334 using ResourceUpdateCallbackList = std::vector<DoneCallback>;
335 // Callbacks for device resource update request currently in flight to the
336 // cloud server.
Alex Vakulenkof3a95bf2015-07-01 07:52:13 -0700337 ResourceUpdateCallbackList in_progress_resource_update_callbacks_;
Vitaly Buka74763422015-10-11 00:39:52 -0700338 // Callbacks for device resource update requests queued while another request
339 // is in flight to the cloud server.
Alex Vakulenkof3a95bf2015-07-01 07:52:13 -0700340 ResourceUpdateCallbackList queued_resource_update_callbacks_;
341
Vitaly Buka72d8d162015-12-09 18:39:36 -0800342 bool auth_info_update_inprogress_{false};
343
Alex Vakulenkoeedf3be2015-05-13 17:52:02 -0700344 std::unique_ptr<NotificationChannel> primary_notification_channel_;
Alex Vakulenkod05725f2015-05-27 15:48:19 -0700345 std::unique_ptr<PullChannel> pull_channel_;
346 NotificationChannel* current_notification_channel_{nullptr};
Alex Vakulenko6b028ae2015-05-29 09:38:59 -0700347 bool notification_channel_starting_{false};
Christopher Wileyd732bd02015-04-07 11:11:18 -0700348
Vitaly Buka1e363672015-09-25 14:01:16 -0700349 provider::Network* network_{nullptr};
Vitaly Buka3d851b42015-12-08 16:17:01 -0800350 privet::AuthManager* auth_manager_{nullptr};
Vitaly Buka63cc3d22015-06-23 20:11:36 -0700351
Vitaly Bukac3c6dab2015-10-01 19:41:02 -0700352 // Tracks our GCD state.
353 GcdState gcd_state_{GcdState::kUnconfigured};
Christopher Wileyc900e482015-02-15 15:42:04 -0800354
Vitaly Bukac3c6dab2015-10-01 19:41:02 -0700355 std::vector<Device::GcdStateChangedCallback> gcd_state_changed_callbacks_;
Vitaly Bukaee7a3af2015-05-14 16:57:23 -0700356
Christopher Wileycd419662015-02-06 17:51:43 -0800357 base::WeakPtrFactory<DeviceRegistrationInfo> weak_factory_{this};
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700358 DISALLOW_COPY_AND_ASSIGN(DeviceRegistrationInfo);
359};
360
Vitaly Bukab6f015a2015-07-09 14:59:23 -0700361} // namespace weave
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700362
Vitaly Buka912b6982015-07-06 11:13:03 -0700363#endif // LIBWEAVE_SRC_DEVICE_REGISTRATION_INFO_H_