blob: f670b683eb9e14a28ee7e2100a87a18db432a359 [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 Vakulenko3cb466c2014-04-15 11:36:32 -070048// The DeviceRegistrationInfo class represents device registration information.
Vitaly Bukac3c6dab2015-10-01 19:41:02 -070049class DeviceRegistrationInfo : public NotificationDelegate,
Alex Vakulenkofe53f612015-06-26 09:05:15 -070050 public CloudCommandUpdateInterface {
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070051 public:
Vitaly Buka74763422015-10-11 00:39:52 -070052 using CloudRequestDoneCallback =
53 base::Callback<void(const base::DictionaryValue& response,
54 ErrorPtr error)>;
Christopher Wileye0fdeee2015-02-07 18:29:32 -080055
Vitaly Buka666b43e2015-12-08 16:35:47 -080056 DeviceRegistrationInfo(Config* config,
57 ComponentManager* component_manager,
Vitaly Buka3d851b42015-12-08 16:17:01 -080058 provider::TaskRunner* task_runner,
59 provider::HttpClient* http_client,
60 provider::Network* network,
61 privet::AuthManager* auth_manager);
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070062
Alex Vakulenko534a3122015-05-22 15:48:53 -070063 ~DeviceRegistrationInfo() override;
Anton Muhin332df192014-11-22 05:59:14 +040064
Vitaly Bukac3c6dab2015-10-01 19:41:02 -070065 void AddGcdStateChangedCallback(
66 const Device::GcdStateChangedCallback& callback);
Vitaly Buka12870bd2015-10-08 23:49:39 -070067 void RegisterDevice(const std::string& ticket_id,
Vitaly Buka74763422015-10-11 00:39:52 -070068 const DoneCallback& callback);
Vitaly Buka9aa15c72015-10-01 19:14:44 -070069
Vitaly Bukab624bc42015-09-29 19:13:55 -070070 void UpdateDeviceInfo(const std::string& name,
Vitaly Buka8b4ab962015-07-14 19:19:39 -070071 const std::string& description,
Vitaly Buka9aa15c72015-10-01 19:14:44 -070072 const std::string& location);
Vitaly Bukab624bc42015-09-29 19:13:55 -070073 void UpdateBaseConfig(AuthScope anonymous_access_role,
Vitaly Buka8b4ab962015-07-14 19:19:39 -070074 bool local_discovery_enabled,
Vitaly Buka9aa15c72015-10-01 19:14:44 -070075 bool local_pairing_enabled);
Vitaly Buka8b4ab962015-07-14 19:19:39 -070076 bool UpdateServiceConfig(const std::string& client_id,
77 const std::string& client_secret,
78 const std::string& api_key,
79 const std::string& oauth_url,
80 const std::string& service_url,
Vitaly Buka9aa15c72015-10-01 19:14:44 -070081 ErrorPtr* error);
Christopher Wileyc900e482015-02-15 15:42:04 -080082
Vitaly Buka74763422015-10-11 00:39:52 -070083 void GetDeviceInfo(const CloudRequestDoneCallback& callback);
Vitaly Bukaee3e36d2015-10-01 18:18:58 -070084
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070085 // Returns the GCD service request URL. If |subpath| is specified, it is
86 // appended to the base URL which is normally
Vitaly Buka88272d52015-11-17 17:04:01 -080087 // https://www.googleapis.com/weave/v1/".
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070088 // If |params| are specified, each key-value pair is formatted using
Vitaly Buka7d556392015-08-13 20:06:48 -070089 // WebParamsEncode() and appended to URL as a query
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070090 // string.
91 // So, calling:
92 // GetServiceURL("ticket", {{"key","apiKey"}})
93 // will return something like:
Vitaly Buka88272d52015-11-17 17:04:01 -080094 // https://www.googleapis.com/weave/v1/ticket?key=apiKey
Vitaly Buka7d556392015-08-13 20:06:48 -070095 std::string GetServiceURL(const std::string& subpath = {},
96 const WebParamList& params = {}) const;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070097
98 // Returns a service URL to access the registered device on GCD server.
99 // The base URL used to construct the full URL looks like this:
Vitaly Buka88272d52015-11-17 17:04:01 -0800100 // https://www.googleapis.com/weave/v1/devices/<cloud_id>/
Vitaly Buka7d556392015-08-13 20:06:48 -0700101 std::string GetDeviceURL(const std::string& subpath = {},
102 const WebParamList& params = {}) const;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700103
104 // Similar to GetServiceURL, GetOAuthURL() returns a URL of OAuth 2.0 server.
105 // The base URL used is https://accounts.google.com/o/oauth2/.
Vitaly Buka7d556392015-08-13 20:06:48 -0700106 std::string GetOAuthURL(const std::string& subpath = {},
107 const WebParamList& params = {}) const;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700108
Alex Vakulenko6e3c30e2015-05-21 17:39:25 -0700109 // Starts GCD device if credentials available.
Vitaly Bukaee7a3af2015-05-14 16:57:23 -0700110 void Start();
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700111
Vitaly Bukab6f015a2015-07-09 14:59:23 -0700112 // Updates a command (override from CloudCommandUpdateInterface).
Anton Muhin59755522014-11-05 21:30:12 +0400113 void UpdateCommand(const std::string& command_id,
Alex Vakulenkob211c102015-04-21 11:43:23 -0700114 const base::DictionaryValue& command_patch,
Vitaly Buka74763422015-10-11 00:39:52 -0700115 const DoneCallback& callback) override;
Anton Muhin59755522014-11-05 21:30:12 +0400116
Vitaly Bukab56872f2015-06-21 18:39:34 -0700117 // TODO(vitalybuka): remove getters and pass config to dependent code.
Vitaly Buka238db692015-09-29 16:58:39 -0700118 const Config::Settings& GetSettings() const { return config_->GetSettings(); }
Vitaly Buka666b43e2015-12-08 16:35:47 -0800119 Config* GetMutableConfig() { return config_; }
Vitaly Buka72410b22015-05-13 13:48:59 -0700120
Vitaly Bukac3c6dab2015-10-01 19:41:02 -0700121 GcdState GetGcdState() const { return gcd_state_; }
122
Vitaly Buka4c808b22015-08-02 13:44:52 -0700123 private:
124 friend class DeviceRegistrationInfoTest;
125
Vitaly Buka72410b22015-05-13 13:48:59 -0700126 base::WeakPtr<DeviceRegistrationInfo> AsWeakPtr() {
127 return weak_factory_.GetWeakPtr();
128 }
129
Vitaly Buka672634b2015-11-20 09:49:30 -0800130 // Checks whether we have credentials generated during registration.
131 bool HaveRegistrationCredentials() const;
132 // Calls HaveRegistrationCredentials() and logs an error if no credentials
133 // are available.
134 bool VerifyRegistrationCredentials(ErrorPtr* error) const;
135
Alex Vakulenkofb331ac2015-07-22 15:10:11 -0700136 // Cause DeviceRegistrationInfo to attempt to connect to cloud server on
137 // its own later.
138 void ScheduleCloudConnection(const base::TimeDelta& delay);
Christopher Wileyba983c82015-03-05 16:32:23 -0800139
Alex Vakulenkofb331ac2015-07-22 15:10:11 -0700140 // Initiates the connection to the cloud server.
Christopher Wileyba983c82015-03-05 16:32:23 -0800141 // Device will do required start up chores and then start to listen
142 // to new commands.
Vitaly Buka74763422015-10-11 00:39:52 -0700143 void ConnectToCloud(ErrorPtr error);
Alex Vakulenkofb331ac2015-07-22 15:10:11 -0700144 // Notification called when ConnectToCloud() succeeds.
Vitaly Buka74763422015-10-11 00:39:52 -0700145 void OnConnectedToCloud(ErrorPtr error);
Christopher Wileyba983c82015-03-05 16:32:23 -0800146
David Zeuthen390d1912015-03-03 14:54:48 -0500147 // Forcibly refreshes the access token.
Vitaly Buka74763422015-10-11 00:39:52 -0700148 void RefreshAccessToken(const DoneCallback& callback);
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700149
Alex Vakulenko0f91be82015-07-27 10:11:53 -0700150 // Callbacks for RefreshAccessToken().
Vitaly Buka74763422015-10-11 00:39:52 -0700151 void OnRefreshAccessTokenDone(
152 const DoneCallback& callback,
153 std::unique_ptr<provider::HttpClient::Response> response,
Vitaly Bukaf7f52d42015-10-10 22:43:55 -0700154 ErrorPtr error);
Alex Vakulenko6b028ae2015-05-29 09:38:59 -0700155
Nathan Bullock24d189f2015-02-26 13:09:18 -0500156 // Parse the OAuth response, and sets registration status to
157 // kInvalidCredentials if our registration is no longer valid.
158 std::unique_ptr<base::DictionaryValue> ParseOAuthResponse(
Vitaly Buka1e363672015-09-25 14:01:16 -0700159 const provider::HttpClient::Response& response,
Vitaly Buka0801a1f2015-08-14 10:03:46 -0700160 ErrorPtr* error);
Nathan Bullock24d189f2015-02-26 13:09:18 -0500161
Alex Vakulenkoeedf3be2015-05-13 17:52:02 -0700162 // This attempts to open a notification channel. The channel needs to be
Nathan Bullockbea91132015-02-19 09:13:33 -0500163 // restarted anytime the access_token is refreshed.
Alex Vakulenkoeedf3be2015-05-13 17:52:02 -0700164 void StartNotificationChannel();
Nathan Bullockbea91132015-02-19 09:13:33 -0500165
Anton Muhinac661ab2014-10-03 20:29:48 +0400166 // Do a HTTPS request to cloud services.
167 // Handles many cases like reauthorization, 5xx HTTP response codes
168 // and device removal. It is a recommended way to do cloud API
169 // requests.
170 // TODO(antonm): Consider moving into some other class.
Vitaly Buka1a42e142015-10-10 18:15:15 -0700171 void DoCloudRequest(provider::HttpClient::Method method,
Vitaly Bukaa647c852015-07-06 14:51:01 -0700172 const std::string& url,
173 const base::DictionaryValue* body,
Vitaly Buka74763422015-10-11 00:39:52 -0700174 const CloudRequestDoneCallback& callback);
Anton Muhinac661ab2014-10-03 20:29:48 +0400175
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700176 // Helper for DoCloudRequest().
177 struct CloudRequestData {
Vitaly Buka1a42e142015-10-10 18:15:15 -0700178 provider::HttpClient::Method method;
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700179 std::string url;
180 std::string body;
Vitaly Buka74763422015-10-11 00:39:52 -0700181 CloudRequestDoneCallback callback;
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700182 };
183 void SendCloudRequest(const std::shared_ptr<const CloudRequestData>& data);
Vitaly Buka74763422015-10-11 00:39:52 -0700184 void OnCloudRequestDone(
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700185 const std::shared_ptr<const CloudRequestData>& data,
Vitaly Buka74763422015-10-11 00:39:52 -0700186 std::unique_ptr<provider::HttpClient::Response> response,
187 ErrorPtr error);
Vitaly Bukaa647c852015-07-06 14:51:01 -0700188 void RetryCloudRequest(const std::shared_ptr<const CloudRequestData>& data);
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700189 void OnAccessTokenRefreshed(
Vitaly Buka74763422015-10-11 00:39:52 -0700190 const std::shared_ptr<const CloudRequestData>& data,
191 ErrorPtr error);
Vitaly Bukaf7f52d42015-10-10 22:43:55 -0700192 void CheckAccessTokenError(ErrorPtr error);
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700193
Vitaly Buka74763422015-10-11 00:39:52 -0700194 void UpdateDeviceResource(const DoneCallback& callback);
Alex Vakulenkof3a95bf2015-07-01 07:52:13 -0700195 void StartQueuedUpdateDeviceResource();
Vitaly Buka74763422015-10-11 00:39:52 -0700196 void OnUpdateDeviceResourceDone(const base::DictionaryValue& device_info,
197 ErrorPtr error);
Vitaly Bukaf7f52d42015-10-10 22:43:55 -0700198 void OnUpdateDeviceResourceError(ErrorPtr error);
Anton Muhinc635c592014-10-28 21:48:08 +0400199
Vitaly Buka72d8d162015-12-09 18:39:36 -0800200 void SendAuthInfo();
Vitaly Buka0c190b32015-12-14 15:22:10 -0800201 void OnSendAuthInfoDone(const std::vector<uint8_t>& token,
202 const base::DictionaryValue& body,
203 ErrorPtr error);
Vitaly Buka72d8d162015-12-09 18:39:36 -0800204
Alex Vakulenkofb331ac2015-07-22 15:10:11 -0700205 // Callback from GetDeviceInfo() to retrieve the device resource timestamp
206 // and retry UpdateDeviceResource() call.
Vitaly Buka74763422015-10-11 00:39:52 -0700207 void OnDeviceInfoRetrieved(const base::DictionaryValue& device_info,
208 ErrorPtr error);
Alex Vakulenkofb331ac2015-07-22 15:10:11 -0700209
210 // Extracts the timestamp from the device resource and sets it to
211 // |last_device_resource_updated_timestamp_|.
212 // Returns false if the "lastUpdateTimeMs" field is not found in the device
213 // resource or it is invalid.
214 bool UpdateDeviceInfoTimestamp(const base::DictionaryValue& device_info);
215
Christopher Wileyba983c82015-03-05 16:32:23 -0800216 void FetchCommands(
Alex Vakulenkoe07c29d2015-10-22 10:31:12 -0700217 const base::Callback<void(const base::ListValue&, ErrorPtr)>& callback,
218 const std::string& reason);
Vitaly Buka74763422015-10-11 00:39:52 -0700219 void OnFetchCommandsDone(
220 const base::Callback<void(const base::ListValue&, ErrorPtr)>& callback,
221 const base::DictionaryValue& json,
222 ErrorPtr);
Alex Vakulenko64bc9ea2015-09-14 09:24:58 -0700223 // Called when FetchCommands completes (with either success or error).
224 // This method reschedules any pending/queued fetch requests.
225 void OnFetchCommandsReturned();
Anton Muhinc635c592014-10-28 21:48:08 +0400226
Alex Vakulenkod05725f2015-05-27 15:48:19 -0700227 // Processes the command list that is fetched from the server on connection.
228 // Aborts commands which are in transitional states and publishes queued
229 // commands which are queued.
Vitaly Buka74763422015-10-11 00:39:52 -0700230 void ProcessInitialCommandList(const base::ListValue& commands,
231 ErrorPtr error);
Anton Muhinc635c592014-10-28 21:48:08 +0400232
Vitaly Buka74763422015-10-11 00:39:52 -0700233 void PublishCommands(const base::ListValue& commands, ErrorPtr error);
Alex Vakulenko6e3c30e2015-05-21 17:39:25 -0700234 void PublishCommand(const base::DictionaryValue& command);
Anton Muhind07e2062014-10-27 10:53:29 +0400235
Alex Vakulenko1038ec12015-07-15 14:36:13 -0700236 // Helper function to pull the pending command list from the server using
237 // FetchCommands() and make them available on D-Bus with PublishCommands().
Alex Vakulenkoe07c29d2015-10-22 10:31:12 -0700238 // |backup_fetch| is set to true when performing backup ("just-in-case")
239 // command fetch while XMPP channel is up and running.
240 void FetchAndPublishCommands(const std::string& reason);
Alex Vakulenko1038ec12015-07-15 14:36:13 -0700241
Anton Muhinb8315622014-11-20 03:17:05 +0400242 void PublishStateUpdates();
Alex Vakulenkod91d6252015-12-05 17:14:39 -0800243 void OnPublishStateDone(ComponentManager::UpdateID update_id,
Vitaly Buka74763422015-10-11 00:39:52 -0700244 const base::DictionaryValue& reply,
245 ErrorPtr error);
Vitaly Bukaf7f52d42015-10-10 22:43:55 -0700246 void OnPublishStateError(ErrorPtr error);
Anton Muhinb8315622014-11-20 03:17:05 +0400247
Alex Vakulenkod1978d32015-04-29 17:33:26 -0700248 // If unrecoverable error occurred (e.g. error parsing command instance),
249 // notify the server that the command is aborted by the device.
Vitaly Buka0801a1f2015-08-14 10:03:46 -0700250 void NotifyCommandAborted(const std::string& command_id, ErrorPtr error);
Alex Vakulenkod1978d32015-04-29 17:33:26 -0700251
Alex Vakulenko9ea5a322015-04-17 15:35:34 -0700252 // Builds Cloud API devices collection REST resource which matches
Anton Muhind8d32162014-10-02 20:37:00 +0400253 // current state of the device including command definitions
254 // for all supported commands and current device state.
Vitaly Buka1a108712015-12-06 17:41:07 -0800255 std::unique_ptr<base::DictionaryValue> BuildDeviceResource() const;
Anton Muhind8d32162014-10-02 20:37:00 +0400256
Vitaly Bukac3c6dab2015-10-01 19:41:02 -0700257 void SetGcdState(GcdState new_state);
Johan Euphrosine312c2f52015-09-29 00:04:29 -0700258 void SetDeviceId(const std::string& cloud_id);
Christopher Wileyc900e482015-02-15 15:42:04 -0800259
Alex Vakulenko9ea5a322015-04-17 15:35:34 -0700260 // Callback called when command definitions are changed to re-publish new CDD.
Alex Vakulenkod91d6252015-12-05 17:14:39 -0800261 void OnTraitDefsChanged();
262 void OnComponentTreeChanged();
Vitaly Bukac903d282015-05-26 17:03:08 -0700263 void OnStateChanged();
Alex Vakulenko9ea5a322015-04-17 15:35:34 -0700264
Alex Vakulenko6b40d8f2015-06-24 11:44:22 -0700265 // Overrides from NotificationDelegate.
Alex Vakulenkoeedf3be2015-05-13 17:52:02 -0700266 void OnConnected(const std::string& channel_name) override;
267 void OnDisconnected() override;
268 void OnPermanentFailure() override;
Alex Vakulenkoe07c29d2015-10-22 10:31:12 -0700269 void OnCommandCreated(const base::DictionaryValue& command,
270 const std::string& channel_name) override;
Johan Euphrosine312c2f52015-09-29 00:04:29 -0700271 void OnDeviceDeleted(const std::string& cloud_id) override;
Alex Vakulenkoeedf3be2015-05-13 17:52:02 -0700272
Alex Vakulenko3fa42ae2015-06-23 15:12:22 -0700273 // Wipes out the device registration information and stops server connections.
Vitaly Buka672634b2015-11-20 09:49:30 -0800274 void RemoveCredentials();
Alex Vakulenko3fa42ae2015-06-23 15:12:22 -0700275
Vitaly Buka74763422015-10-11 00:39:52 -0700276 void RegisterDeviceError(const DoneCallback& callback, ErrorPtr error);
Vitaly Buka4774df22015-10-09 12:36:22 -0700277 void RegisterDeviceOnTicketSent(
278 const std::string& ticket_id,
Vitaly Buka74763422015-10-11 00:39:52 -0700279 const DoneCallback& callback,
280 std::unique_ptr<provider::HttpClient::Response> response,
281 ErrorPtr error);
Vitaly Buka4774df22015-10-09 12:36:22 -0700282 void RegisterDeviceOnTicketFinalized(
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 RegisterDeviceOnAuthCodeSent(
287 const std::string& cloud_id,
288 const std::string& robot_account,
Vitaly Buka74763422015-10-11 00:39:52 -0700289 const DoneCallback& callback,
290 std::unique_ptr<provider::HttpClient::Response> response,
291 ErrorPtr error);
Vitaly Buka4774df22015-10-09 12:36:22 -0700292
Nathan Bullockd9e0bcd2015-02-11 11:36:39 -0500293 // Transient data
294 std::string access_token_;
295 base::Time access_token_expiration_;
Alex Vakulenkofb331ac2015-07-22 15:10:11 -0700296 // The time stamp of last device resource update on the server.
297 std::string last_device_resource_updated_timestamp_;
298 // Set to true if the device has connected to the cloud server correctly.
299 // At this point, normal state and command updates can be dispatched to the
300 // server.
301 bool connected_to_cloud_{false};
Nathan Bullockd9e0bcd2015-02-11 11:36:39 -0500302
Alex Vakulenkoa3062c52014-04-21 17:05:51 -0700303 // HTTP transport used for communications.
Vitaly Buka1e363672015-09-25 14:01:16 -0700304 provider::HttpClient* http_client_{nullptr};
Vitaly Buka6da94252015-08-04 15:45:14 -0700305
Vitaly Buka1e363672015-09-25 14:01:16 -0700306 provider::TaskRunner* task_runner_{nullptr};
Vitaly Buka666b43e2015-12-08 16:35:47 -0800307
308 Config* config_{nullptr};
309
Alex Vakulenkod91d6252015-12-05 17:14:39 -0800310 // Global component manager.
311 ComponentManager* component_manager_{nullptr};
Alex Vakulenkoa3062c52014-04-21 17:05:51 -0700312
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700313 // Backoff manager for DoCloudRequest() method.
Vitaly Buka0f80f7c2015-08-13 00:57:25 -0700314 std::unique_ptr<BackoffEntry::Policy> cloud_backoff_policy_;
315 std::unique_ptr<BackoffEntry> cloud_backoff_entry_;
316 std::unique_ptr<BackoffEntry> oauth2_backoff_entry_;
Alex Vakulenko266b2b12015-06-19 11:01:42 -0700317
Alex Vakulenko93ba0bd2015-06-19 14:06:46 -0700318 // Flag set to true while a device state update patch request is in flight
319 // to the cloud server.
320 bool device_state_update_pending_{false};
321
Alex Vakulenko64bc9ea2015-09-14 09:24:58 -0700322 // Set to true when command queue fetch request is in flight to the server.
323 bool fetch_commands_request_sent_{false};
324 // Set to true when another command queue fetch request is queued while
325 // another one was in flight.
326 bool fetch_commands_request_queued_{false};
Alex Vakulenkoe07c29d2015-10-22 10:31:12 -0700327 // Specifies the reason for queued command fetch request.
328 std::string queued_fetch_reason_;
Alex Vakulenko64bc9ea2015-09-14 09:24:58 -0700329
Vitaly Buka74763422015-10-11 00:39:52 -0700330 using ResourceUpdateCallbackList = std::vector<DoneCallback>;
331 // Callbacks for device resource update request currently in flight to the
332 // cloud server.
Alex Vakulenkof3a95bf2015-07-01 07:52:13 -0700333 ResourceUpdateCallbackList in_progress_resource_update_callbacks_;
Vitaly Buka74763422015-10-11 00:39:52 -0700334 // Callbacks for device resource update requests queued while another request
335 // is in flight to the cloud server.
Alex Vakulenkof3a95bf2015-07-01 07:52:13 -0700336 ResourceUpdateCallbackList queued_resource_update_callbacks_;
337
Vitaly Buka72d8d162015-12-09 18:39:36 -0800338 bool auth_info_update_inprogress_{false};
339
Alex Vakulenkoeedf3be2015-05-13 17:52:02 -0700340 std::unique_ptr<NotificationChannel> primary_notification_channel_;
Alex Vakulenkod05725f2015-05-27 15:48:19 -0700341 std::unique_ptr<PullChannel> pull_channel_;
342 NotificationChannel* current_notification_channel_{nullptr};
Alex Vakulenko6b028ae2015-05-29 09:38:59 -0700343 bool notification_channel_starting_{false};
Christopher Wileyd732bd02015-04-07 11:11:18 -0700344
Vitaly Buka1e363672015-09-25 14:01:16 -0700345 provider::Network* network_{nullptr};
Vitaly Buka3d851b42015-12-08 16:17:01 -0800346 privet::AuthManager* auth_manager_{nullptr};
Vitaly Buka63cc3d22015-06-23 20:11:36 -0700347
Vitaly Bukac3c6dab2015-10-01 19:41:02 -0700348 // Tracks our GCD state.
349 GcdState gcd_state_{GcdState::kUnconfigured};
Christopher Wileyc900e482015-02-15 15:42:04 -0800350
Vitaly Bukac3c6dab2015-10-01 19:41:02 -0700351 std::vector<Device::GcdStateChangedCallback> gcd_state_changed_callbacks_;
Vitaly Bukaee7a3af2015-05-14 16:57:23 -0700352
Christopher Wileycd419662015-02-06 17:51:43 -0800353 base::WeakPtrFactory<DeviceRegistrationInfo> weak_factory_{this};
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700354 DISALLOW_COPY_AND_ASSIGN(DeviceRegistrationInfo);
355};
356
Vitaly Bukab6f015a2015-07-09 14:59:23 -0700357} // namespace weave
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700358
Vitaly Buka912b6982015-07-06 11:13:03 -0700359#endif // LIBWEAVE_SRC_DEVICE_REGISTRATION_INFO_H_