[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 5 | #ifndef COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ |
| 6 | #define COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 7 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 8 | #include <map> |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 9 | #include <set> |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 10 | #include <string> |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 11 | #include <vector> |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 12 | |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 13 | #include "base/compiler_specific.h" |
[email protected] | 79994f4 | 2014-01-16 16:05:36 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
[email protected] | 955e0ff | 2014-01-31 20:42:12 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 16 | #include "base/stl_util.h" |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 17 | #include "components/gcm_driver/gcm_client.h" |
| 18 | #include "components/gcm_driver/gcm_stats_recorder_impl.h" |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 19 | #include "google_apis/gcm/base/mcs_message.h" |
| 20 | #include "google_apis/gcm/engine/gcm_store.h" |
[email protected] | 06e4527 | 2014-05-06 03:41:34 | [diff] [blame] | 21 | #include "google_apis/gcm/engine/gservices_settings.h" |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 22 | #include "google_apis/gcm/engine/mcs_client.h" |
[email protected] | b4dd023 | 2014-02-08 02:37:31 | [diff] [blame] | 23 | #include "google_apis/gcm/engine/registration_request.h" |
[email protected] | 0e88e1d1 | 2014-03-19 06:53:08 | [diff] [blame] | 24 | #include "google_apis/gcm/engine/unregistration_request.h" |
[email protected] | 436bcb8 | 2014-04-18 00:40:57 | [diff] [blame] | 25 | #include "google_apis/gcm/protocol/android_checkin.pb.h" |
[email protected] | 2c4d4cd | 2014-04-10 21:10:22 | [diff] [blame] | 26 | #include "google_apis/gcm/protocol/checkin.pb.h" |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 27 | #include "net/base/net_log.h" |
| 28 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 29 | |
[email protected] | 2bbe0a68 | 2014-03-26 00:08:31 | [diff] [blame] | 30 | class GURL; |
| 31 | |
[email protected] | 79994f4 | 2014-01-16 16:05:36 | [diff] [blame] | 32 | namespace base { |
[email protected] | 955e0ff | 2014-01-31 20:42:12 | [diff] [blame] | 33 | class Clock; |
[email protected] | 764c044 | 2014-05-01 04:30:55 | [diff] [blame] | 34 | class Time; |
[email protected] | 79994f4 | 2014-01-16 16:05:36 | [diff] [blame] | 35 | } // namespace base |
| 36 | |
[email protected] | 436bcb8 | 2014-04-18 00:40:57 | [diff] [blame] | 37 | namespace mcs_proto { |
| 38 | class DataMessageStanza; |
| 39 | } // namespace mcs_proto |
| 40 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 41 | namespace net { |
| 42 | class HttpNetworkSession; |
[email protected] | 955e0ff | 2014-01-31 20:42:12 | [diff] [blame] | 43 | } // namespace net |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 44 | |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 45 | namespace gcm { |
| 46 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 47 | class CheckinRequest; |
| 48 | class ConnectionFactory; |
| 49 | class GCMClientImplTest; |
[email protected] | 79994f4 | 2014-01-16 16:05:36 | [diff] [blame] | 50 | |
[email protected] | 2bbe0a68 | 2014-03-26 00:08:31 | [diff] [blame] | 51 | // Helper class for building GCM internals. Allows tests to inject fake versions |
| 52 | // as necessary. |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 53 | class GCMInternalsBuilder { |
[email protected] | 2bbe0a68 | 2014-03-26 00:08:31 | [diff] [blame] | 54 | public: |
| 55 | GCMInternalsBuilder(); |
| 56 | virtual ~GCMInternalsBuilder(); |
| 57 | |
| 58 | virtual scoped_ptr<base::Clock> BuildClock(); |
| 59 | virtual scoped_ptr<MCSClient> BuildMCSClient( |
| 60 | const std::string& version, |
| 61 | base::Clock* clock, |
| 62 | ConnectionFactory* connection_factory, |
[email protected] | 436bcb8 | 2014-04-18 00:40:57 | [diff] [blame] | 63 | GCMStore* gcm_store, |
| 64 | GCMStatsRecorder* recorder); |
[email protected] | 2bbe0a68 | 2014-03-26 00:08:31 | [diff] [blame] | 65 | virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory( |
| 66 | const std::vector<GURL>& endpoints, |
| 67 | const net::BackoffEntry::Policy& backoff_policy, |
[email protected] | 6f63606a | 2014-07-18 02:18:55 | [diff] [blame] | 68 | const scoped_refptr<net::HttpNetworkSession>& gcm_network_session, |
| 69 | const scoped_refptr<net::HttpNetworkSession>& http_network_session, |
[email protected] | 9df5b93 | 2014-04-30 00:39:06 | [diff] [blame] | 70 | net::NetLog* net_log, |
| 71 | GCMStatsRecorder* recorder); |
[email protected] | 2bbe0a68 | 2014-03-26 00:08:31 | [diff] [blame] | 72 | }; |
| 73 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 74 | // Implements the GCM Client. It is used to coordinate MCS Client (communication |
| 75 | // with MCS) and other pieces of GCM infrastructure like Registration and |
| 76 | // Checkins. It also allows for registering user delegates that host |
| 77 | // applications that send and receive messages. |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 78 | class GCMClientImpl |
[email protected] | c31e1b5 | 2014-06-12 21:00:47 | [diff] [blame] | 79 | : public GCMClient, public GCMStatsRecorder::Delegate, |
| 80 | public ConnectionFactory::ConnectionListener { |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 81 | public: |
[email protected] | 2bbe0a68 | 2014-03-26 00:08:31 | [diff] [blame] | 82 | explicit GCMClientImpl(scoped_ptr<GCMInternalsBuilder> internals_builder); |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 83 | ~GCMClientImpl() override; |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 84 | |
[email protected] | c31e1b5 | 2014-06-12 21:00:47 | [diff] [blame] | 85 | // GCMClient implementation. |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 86 | void Initialize( |
[email protected] | 8ad8051 | 2014-05-23 09:40:47 | [diff] [blame] | 87 | const ChromeBuildInfo& chrome_build_info, |
[email protected] | e2a4a801 | 2014-02-07 22:32:52 | [diff] [blame] | 88 | const base::FilePath& store_path, |
| 89 | const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, |
| 90 | const scoped_refptr<net::URLRequestContextGetter>& |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 91 | url_request_context_getter, |
[email protected] | 446f73c2 | 2014-05-14 20:47:18 | [diff] [blame] | 92 | scoped_ptr<Encryptor> encryptor, |
mostynb | fe59f48 | 2014-10-06 15:04:46 | [diff] [blame] | 93 | GCMClient::Delegate* delegate) override; |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 94 | void Start() override; |
| 95 | void Stop() override; |
| 96 | void CheckOut() override; |
| 97 | void Register(const std::string& app_id, |
| 98 | const std::vector<std::string>& sender_ids) override; |
| 99 | void Unregister(const std::string& app_id) override; |
| 100 | void Send(const std::string& app_id, |
| 101 | const std::string& receiver_id, |
| 102 | const OutgoingMessage& message) override; |
| 103 | void SetRecording(bool recording) override; |
| 104 | void ClearActivityLogs() override; |
| 105 | GCMStatistics GetStatistics() const override; |
| 106 | void SetAccountTokens( |
mostynb | fe59f48 | 2014-10-06 15:04:46 | [diff] [blame] | 107 | const std::vector<AccountTokenInfo>& account_tokens) override; |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 108 | void UpdateAccountMapping(const AccountMapping& account_mapping) override; |
| 109 | void RemoveAccountMapping(const std::string& account_id) override; |
fgorski | 5df10170 | 2014-10-28 02:09:31 | [diff] [blame] | 110 | void SetLastTokenFetchTime(const base::Time& time) override; |
[email protected] | c31e1b5 | 2014-06-12 21:00:47 | [diff] [blame] | 111 | |
| 112 | // GCMStatsRecorder::Delegate implemenation. |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 113 | void OnActivityRecorded() override; |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 114 | |
[email protected] | c31e1b5 | 2014-06-12 21:00:47 | [diff] [blame] | 115 | // ConnectionFactory::ConnectionListener implementation. |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 116 | void OnConnected(const GURL& current_server, |
| 117 | const net::IPEndPoint& ip_endpoint) override; |
| 118 | void OnDisconnected() override; |
[email protected] | c31e1b5 | 2014-06-12 21:00:47 | [diff] [blame] | 119 | |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 120 | private: |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 121 | // State representation of the GCMClient. |
[email protected] | 3560181 | 2014-03-07 19:52:43 | [diff] [blame] | 122 | // Any change made to this enum should have corresponding change in the |
| 123 | // GetStateString(...) function. |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 124 | enum State { |
| 125 | // Uninitialized. |
| 126 | UNINITIALIZED, |
[email protected] | d3a4b2e | 2014-02-27 13:46:54 | [diff] [blame] | 127 | // Initialized, |
| 128 | INITIALIZED, |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 129 | // GCM store loading is in progress. |
| 130 | LOADING, |
| 131 | // Initial device checkin is in progress. |
| 132 | INITIAL_DEVICE_CHECKIN, |
| 133 | // Ready to accept requests. |
| 134 | READY, |
| 135 | }; |
| 136 | |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 137 | // The check-in info for the device. |
| 138 | // TODO(fgorski): Convert to a class with explicit getters/setters. |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 139 | struct CheckinInfo { |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 140 | CheckinInfo(); |
| 141 | ~CheckinInfo(); |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 142 | bool IsValid() const { return android_id != 0 && secret != 0; } |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 143 | void SnapshotCheckinAccounts(); |
| 144 | void Reset(); |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 145 | |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 146 | // Android ID of the device as assigned by the server. |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 147 | uint64 android_id; |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 148 | // Security token of the device as assigned by the server. |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 149 | uint64 secret; |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 150 | // True if accounts were already provided through SetAccountsForCheckin(), |
| 151 | // or when |last_checkin_accounts| was loaded as empty. |
| 152 | bool accounts_set; |
| 153 | // Map of account email addresses and OAuth2 tokens that will be sent to the |
| 154 | // checkin server on a next checkin. |
| 155 | std::map<std::string, std::string> account_tokens; |
| 156 | // As set of accounts last checkin was completed with. |
| 157 | std::set<std::string> last_checkin_accounts; |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 158 | }; |
| 159 | |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 160 | // Collection of pending registration requests. Keys are app IDs, while values |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 161 | // are pending registration requests to obtain a registration ID for |
| 162 | // requesting application. |
| 163 | typedef std::map<std::string, RegistrationRequest*> |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 164 | PendingRegistrationRequests; |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 165 | |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 166 | // Collection of pending unregistration requests. Keys are app IDs, while |
| 167 | // values are pending unregistration requests to disable the registration ID |
| 168 | // currently assigned to the application. |
| 169 | typedef std::map<std::string, UnregistrationRequest*> |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 170 | PendingUnregistrationRequests; |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 171 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 172 | friend class GCMClientImplTest; |
| 173 | |
[email protected] | 3560181 | 2014-03-07 19:52:43 | [diff] [blame] | 174 | // Returns text representation of the enum State. |
| 175 | std::string GetStateString() const; |
| 176 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 177 | // Callbacks for the MCSClient. |
| 178 | // Receives messages and dispatches them to relevant user delegates. |
| 179 | void OnMessageReceivedFromMCS(const gcm::MCSMessage& message); |
| 180 | // Receives confirmation of sent messages or information about errors. |
| 181 | void OnMessageSentToMCS(int64 user_serial_number, |
| 182 | const std::string& app_id, |
| 183 | const std::string& message_id, |
| 184 | MCSClient::MessageSendStatus status); |
| 185 | // Receives information about mcs_client_ errors. |
| 186 | void OnMCSError(); |
| 187 | |
| 188 | // Runs after GCM Store load is done to trigger continuation of the |
| 189 | // initialization. |
[email protected] | 2809af7 | 2014-01-25 09:23:57 | [diff] [blame] | 190 | void OnLoadCompleted(scoped_ptr<GCMStore::LoadResult> result); |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 191 | // Initializes mcs_client_, which handles the connection to MCS. |
[email protected] | 2809af7 | 2014-01-25 09:23:57 | [diff] [blame] | 192 | void InitializeMCSClient(scoped_ptr<GCMStore::LoadResult> result); |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 193 | // Complets the first time device checkin. |
| 194 | void OnFirstTimeDeviceCheckinCompleted(const CheckinInfo& checkin_info); |
| 195 | // Starts a login on mcs_client_. |
| 196 | void StartMCSLogin(); |
| 197 | // Resets state to before initialization. |
| 198 | void ResetState(); |
[email protected] | 86625df | 2014-01-31 03:47:58 | [diff] [blame] | 199 | // Sets state to ready. This will initiate the MCS login and notify the |
| 200 | // delegates. |
fgorski | 5df10170 | 2014-10-28 02:09:31 | [diff] [blame] | 201 | void OnReady(const std::vector<AccountMapping>& account_mappings, |
| 202 | const base::Time& last_token_fetch_time); |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 203 | |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 204 | // Starts a first time device checkin. |
[email protected] | 25b5f50e | 2014-04-03 08:27:23 | [diff] [blame] | 205 | void StartCheckin(); |
[email protected] | 2c4d4cd | 2014-04-10 21:10:22 | [diff] [blame] | 206 | // Completes the device checkin request by parsing the |checkin_response|. |
| 207 | // Function also cleans up the pending checkin. |
| 208 | void OnCheckinCompleted( |
| 209 | const checkin_proto::AndroidCheckinResponse& checkin_response); |
[email protected] | 06e4527 | 2014-05-06 03:41:34 | [diff] [blame] | 210 | |
| 211 | // Callback passed to GCMStore::SetGServicesSettings. |
| 212 | void SetGServicesSettingsCallback(bool success); |
| 213 | |
[email protected] | 764c044 | 2014-05-01 04:30:55 | [diff] [blame] | 214 | // Schedules next periodic device checkin and makes sure there is at most one |
| 215 | // pending checkin at a time. This function is meant to be called after a |
| 216 | // successful checkin. |
| 217 | void SchedulePeriodicCheckin(); |
| 218 | // Gets the time until next checkin. |
| 219 | base::TimeDelta GetTimeToNextCheckin() const; |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 220 | // Callback for setting last checkin information in the |gcm_store_|. |
| 221 | void SetLastCheckinInfoCallback(bool success); |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 222 | |
| 223 | // Callback for persisting device credentials in the |gcm_store_|. |
| 224 | void SetDeviceCredentialsCallback(bool success); |
| 225 | |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 226 | // Callback for persisting registration info in the |gcm_store_|. |
| 227 | void UpdateRegistrationCallback(bool success); |
| 228 | |
[email protected] | 72d4f25 | 2014-08-20 22:34:28 | [diff] [blame] | 229 | // Callback for all store operations that do not try to recover, if write in |
| 230 | // |gcm_store_| fails. |
| 231 | void DefaultStoreCallback(bool success); |
| 232 | |
fgorski | 9a40510 | 2014-11-19 01:25:16 | [diff] [blame] | 233 | // Callback for store operation where result does not matter. |
| 234 | void IgnoreWriteResultCallback(bool success); |
| 235 | |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 236 | // Completes the registration request. |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 237 | void OnRegisterCompleted(const std::string& app_id, |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 238 | const std::vector<std::string>& sender_ids, |
[email protected] | b4dd023 | 2014-02-08 02:37:31 | [diff] [blame] | 239 | RegistrationRequest::Status status, |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 240 | const std::string& registration_id); |
| 241 | |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 242 | // Completes the unregistration request. |
[email protected] | 0e88e1d1 | 2014-03-19 06:53:08 | [diff] [blame] | 243 | void OnUnregisterCompleted(const std::string& app_id, |
| 244 | UnregistrationRequest::Status status); |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 245 | |
[email protected] | d3a4b2e | 2014-02-27 13:46:54 | [diff] [blame] | 246 | // Completes the GCM store destroy request. |
| 247 | void OnGCMStoreDestroyed(bool success); |
| 248 | |
[email protected] | c6fe36b | 2014-03-11 10:58:12 | [diff] [blame] | 249 | // Handles incoming data message and dispatches it the delegate of this class. |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 250 | void HandleIncomingMessage(const gcm::MCSMessage& message); |
| 251 | |
[email protected] | c6fe36b | 2014-03-11 10:58:12 | [diff] [blame] | 252 | // Fires OnMessageReceived event on the delegate of this class, based on the |
| 253 | // details in |data_message_stanza| and |message_data|. |
| 254 | void HandleIncomingDataMessage( |
| 255 | const mcs_proto::DataMessageStanza& data_message_stanza, |
| 256 | MessageData& message_data); |
| 257 | |
| 258 | // Fires OnMessageSendError event on the delegate of this calss, based on the |
| 259 | // details in |data_message_stanza| and |message_data|. |
| 260 | void HandleIncomingSendError( |
| 261 | const mcs_proto::DataMessageStanza& data_message_stanza, |
| 262 | MessageData& message_data); |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 263 | |
[email protected] | 2bbe0a68 | 2014-03-26 00:08:31 | [diff] [blame] | 264 | // Builder for the GCM internals (mcs client, etc.). |
| 265 | scoped_ptr<GCMInternalsBuilder> internals_builder_; |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 266 | |
[email protected] | 436bcb8 | 2014-04-18 00:40:57 | [diff] [blame] | 267 | // Recorder that logs GCM activities. |
[email protected] | 025adfa | 2014-06-03 21:51:12 | [diff] [blame] | 268 | GCMStatsRecorderImpl recorder_; |
[email protected] | 436bcb8 | 2014-04-18 00:40:57 | [diff] [blame] | 269 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 270 | // State of the GCM Client Implementation. |
| 271 | State state_; |
| 272 | |
[email protected] | 7de7880 | 2014-05-10 19:49:40 | [diff] [blame] | 273 | GCMClient::Delegate* delegate_; |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 274 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 275 | // Device checkin info (android ID and security token used by device). |
| 276 | CheckinInfo device_checkin_info_; |
| 277 | |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 278 | // Clock used for timing of retry logic. Passed in for testing. Owned by |
| 279 | // GCMClientImpl. |
| 280 | scoped_ptr<base::Clock> clock_; |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 281 | |
| 282 | // Information about the chrome build. |
| 283 | // TODO(fgorski): Check if it can be passed in constructor and made const. |
[email protected] | 8ad8051 | 2014-05-23 09:40:47 | [diff] [blame] | 284 | ChromeBuildInfo chrome_build_info_; |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 285 | |
| 286 | // Persistent data store for keeping device credentials, messages and user to |
| 287 | // serial number mappings. |
[email protected] | 79994f4 | 2014-01-16 16:05:36 | [diff] [blame] | 288 | scoped_ptr<GCMStore> gcm_store_; |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 289 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 290 | scoped_refptr<net::HttpNetworkSession> network_session_; |
| 291 | net::BoundNetLog net_log_; |
| 292 | scoped_ptr<ConnectionFactory> connection_factory_; |
| 293 | scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 294 | |
| 295 | // Controls receiving and sending of packets and reliable message queueing. |
| 296 | scoped_ptr<MCSClient> mcs_client_; |
| 297 | |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 298 | scoped_ptr<CheckinRequest> checkin_request_; |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 299 | |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 300 | // Cached registration info. |
| 301 | RegistrationInfoMap registrations_; |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 302 | |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 303 | // Currently pending registration requests. GCMClientImpl owns the |
| 304 | // RegistrationRequests. |
| 305 | PendingRegistrationRequests pending_registration_requests_; |
| 306 | STLValueDeleter<PendingRegistrationRequests> |
| 307 | pending_registration_requests_deleter_; |
| 308 | |
| 309 | // Currently pending unregistration requests. GCMClientImpl owns the |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 310 | // UnregistrationRequests. |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 311 | PendingUnregistrationRequests pending_unregistration_requests_; |
| 312 | STLValueDeleter<PendingUnregistrationRequests> |
| 313 | pending_unregistration_requests_deleter_; |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 314 | |
[email protected] | 764c044 | 2014-05-01 04:30:55 | [diff] [blame] | 315 | // G-services settings that were provided by MCS. |
[email protected] | 06e4527 | 2014-05-06 03:41:34 | [diff] [blame] | 316 | GServicesSettings gservices_settings_; |
[email protected] | 764c044 | 2014-05-01 04:30:55 | [diff] [blame] | 317 | |
| 318 | // Time of the last successful checkin. |
| 319 | base::Time last_checkin_time_; |
| 320 | |
| 321 | // Factory for creating references when scheduling periodic checkin. |
| 322 | base::WeakPtrFactory<GCMClientImpl> periodic_checkin_ptr_factory_; |
| 323 | |
[email protected] | 955e0ff | 2014-01-31 20:42:12 | [diff] [blame] | 324 | // Factory for creating references in callbacks. |
| 325 | base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; |
| 326 | |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 327 | DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); |
| 328 | }; |
| 329 | |
| 330 | } // namespace gcm |
| 331 | |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 332 | #endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ |