[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" |
eroman | 58e913a | 2015-04-02 17:23:31 | [diff] [blame] | 27 | #include "net/log/net_log.h" |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 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: |
jianli | f3e52af4 | 2015-01-21 23:18:47 | [diff] [blame] | 82 | // State representation of the GCMClient. |
| 83 | // Any change made to this enum should have corresponding change in the |
| 84 | // GetStateString(...) function. |
| 85 | enum State { |
| 86 | // Uninitialized. |
| 87 | UNINITIALIZED, |
| 88 | // Initialized, |
| 89 | INITIALIZED, |
| 90 | // GCM store loading is in progress. |
| 91 | LOADING, |
| 92 | // GCM store is loaded. |
| 93 | LOADED, |
| 94 | // Initial device checkin is in progress. |
| 95 | INITIAL_DEVICE_CHECKIN, |
| 96 | // Ready to accept requests. |
| 97 | READY, |
| 98 | }; |
| 99 | |
[email protected] | 2bbe0a68 | 2014-03-26 00:08:31 | [diff] [blame] | 100 | explicit GCMClientImpl(scoped_ptr<GCMInternalsBuilder> internals_builder); |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 101 | ~GCMClientImpl() override; |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 102 | |
[email protected] | c31e1b5 | 2014-06-12 21:00:47 | [diff] [blame] | 103 | // GCMClient implementation. |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 104 | void Initialize( |
[email protected] | 8ad8051 | 2014-05-23 09:40:47 | [diff] [blame] | 105 | const ChromeBuildInfo& chrome_build_info, |
[email protected] | e2a4a801 | 2014-02-07 22:32:52 | [diff] [blame] | 106 | const base::FilePath& store_path, |
| 107 | const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, |
| 108 | const scoped_refptr<net::URLRequestContextGetter>& |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 109 | url_request_context_getter, |
[email protected] | 446f73c2 | 2014-05-14 20:47:18 | [diff] [blame] | 110 | scoped_ptr<Encryptor> encryptor, |
mostynb | fe59f48 | 2014-10-06 15:04:46 | [diff] [blame] | 111 | GCMClient::Delegate* delegate) override; |
jianli | f3e52af4 | 2015-01-21 23:18:47 | [diff] [blame] | 112 | void Start(StartMode start_mode) override; |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 113 | void Stop() override; |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 114 | void Register(const std::string& app_id, |
| 115 | const std::vector<std::string>& sender_ids) override; |
| 116 | void Unregister(const std::string& app_id) override; |
| 117 | void Send(const std::string& app_id, |
| 118 | const std::string& receiver_id, |
| 119 | const OutgoingMessage& message) override; |
| 120 | void SetRecording(bool recording) override; |
| 121 | void ClearActivityLogs() override; |
| 122 | GCMStatistics GetStatistics() const override; |
| 123 | void SetAccountTokens( |
mostynb | fe59f48 | 2014-10-06 15:04:46 | [diff] [blame] | 124 | const std::vector<AccountTokenInfo>& account_tokens) override; |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 125 | void UpdateAccountMapping(const AccountMapping& account_mapping) override; |
| 126 | void RemoveAccountMapping(const std::string& account_id) override; |
fgorski | 5df10170 | 2014-10-28 02:09:31 | [diff] [blame] | 127 | void SetLastTokenFetchTime(const base::Time& time) override; |
chirantan | 192a921 | 2014-12-06 03:30:45 | [diff] [blame] | 128 | void UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) override; |
jianli | 10018b2d | 2015-05-11 21:14:13 | [diff] [blame] | 129 | void AddInstanceIDData(const std::string& app_id, |
| 130 | const std::string& instance_id_data) override; |
| 131 | void RemoveInstanceIDData(const std::string& app_id) override; |
| 132 | std::string GetInstanceIDData(const std::string& app_id) override; |
fgorski | 2275446 | 2015-05-14 00:05:22 | [diff] [blame^] | 133 | void AddHeartbeatInterval(const std::string& scope, int interval_ms) override; |
| 134 | void RemoveHeartbeatInterval(const std::string& scope) override; |
[email protected] | c31e1b5 | 2014-06-12 21:00:47 | [diff] [blame] | 135 | |
| 136 | // GCMStatsRecorder::Delegate implemenation. |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 137 | void OnActivityRecorded() override; |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 138 | |
[email protected] | c31e1b5 | 2014-06-12 21:00:47 | [diff] [blame] | 139 | // ConnectionFactory::ConnectionListener implementation. |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 140 | void OnConnected(const GURL& current_server, |
| 141 | const net::IPEndPoint& ip_endpoint) override; |
| 142 | void OnDisconnected() override; |
[email protected] | c31e1b5 | 2014-06-12 21:00:47 | [diff] [blame] | 143 | |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 144 | private: |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 145 | // The check-in info for the device. |
| 146 | // TODO(fgorski): Convert to a class with explicit getters/setters. |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 147 | struct CheckinInfo { |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 148 | CheckinInfo(); |
| 149 | ~CheckinInfo(); |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 150 | bool IsValid() const { return android_id != 0 && secret != 0; } |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 151 | void SnapshotCheckinAccounts(); |
| 152 | void Reset(); |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 153 | |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 154 | // Android ID of the device as assigned by the server. |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 155 | uint64 android_id; |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 156 | // Security token of the device as assigned by the server. |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 157 | uint64 secret; |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 158 | // True if accounts were already provided through SetAccountsForCheckin(), |
| 159 | // or when |last_checkin_accounts| was loaded as empty. |
| 160 | bool accounts_set; |
| 161 | // Map of account email addresses and OAuth2 tokens that will be sent to the |
| 162 | // checkin server on a next checkin. |
| 163 | std::map<std::string, std::string> account_tokens; |
| 164 | // As set of accounts last checkin was completed with. |
| 165 | std::set<std::string> last_checkin_accounts; |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 166 | }; |
| 167 | |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 168 | // Collection of pending registration requests. Keys are app IDs, while values |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 169 | // are pending registration requests to obtain a registration ID for |
| 170 | // requesting application. |
| 171 | typedef std::map<std::string, RegistrationRequest*> |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 172 | PendingRegistrationRequests; |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 173 | |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 174 | // Collection of pending unregistration requests. Keys are app IDs, while |
| 175 | // values are pending unregistration requests to disable the registration ID |
| 176 | // currently assigned to the application. |
| 177 | typedef std::map<std::string, UnregistrationRequest*> |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 178 | PendingUnregistrationRequests; |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 179 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 180 | friend class GCMClientImplTest; |
| 181 | |
[email protected] | 3560181 | 2014-03-07 19:52:43 | [diff] [blame] | 182 | // Returns text representation of the enum State. |
| 183 | std::string GetStateString() const; |
| 184 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 185 | // Callbacks for the MCSClient. |
| 186 | // Receives messages and dispatches them to relevant user delegates. |
| 187 | void OnMessageReceivedFromMCS(const gcm::MCSMessage& message); |
| 188 | // Receives confirmation of sent messages or information about errors. |
| 189 | void OnMessageSentToMCS(int64 user_serial_number, |
| 190 | const std::string& app_id, |
| 191 | const std::string& message_id, |
| 192 | MCSClient::MessageSendStatus status); |
| 193 | // Receives information about mcs_client_ errors. |
| 194 | void OnMCSError(); |
| 195 | |
| 196 | // Runs after GCM Store load is done to trigger continuation of the |
| 197 | // initialization. |
[email protected] | 2809af7 | 2014-01-25 09:23:57 | [diff] [blame] | 198 | void OnLoadCompleted(scoped_ptr<GCMStore::LoadResult> result); |
jianli | f3e52af4 | 2015-01-21 23:18:47 | [diff] [blame] | 199 | // Starts the GCM. |
| 200 | void StartGCM(); |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 201 | // Initializes mcs_client_, which handles the connection to MCS. |
jianli | f3e52af4 | 2015-01-21 23:18:47 | [diff] [blame] | 202 | void InitializeMCSClient(); |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 203 | // Complets the first time device checkin. |
| 204 | void OnFirstTimeDeviceCheckinCompleted(const CheckinInfo& checkin_info); |
| 205 | // Starts a login on mcs_client_. |
| 206 | void StartMCSLogin(); |
jianli | 00b4600f | 2015-02-10 23:32:49 | [diff] [blame] | 207 | // Resets the GCM store when it is corrupted. |
| 208 | void ResetStore(); |
[email protected] | 86625df | 2014-01-31 03:47:58 | [diff] [blame] | 209 | // Sets state to ready. This will initiate the MCS login and notify the |
| 210 | // delegates. |
fgorski | 5df10170 | 2014-10-28 02:09:31 | [diff] [blame] | 211 | void OnReady(const std::vector<AccountMapping>& account_mappings, |
| 212 | const base::Time& last_token_fetch_time); |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 213 | |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 214 | // Starts a first time device checkin. |
[email protected] | 25b5f50e | 2014-04-03 08:27:23 | [diff] [blame] | 215 | void StartCheckin(); |
[email protected] | 2c4d4cd | 2014-04-10 21:10:22 | [diff] [blame] | 216 | // Completes the device checkin request by parsing the |checkin_response|. |
| 217 | // Function also cleans up the pending checkin. |
| 218 | void OnCheckinCompleted( |
| 219 | const checkin_proto::AndroidCheckinResponse& checkin_response); |
[email protected] | 06e4527 | 2014-05-06 03:41:34 | [diff] [blame] | 220 | |
| 221 | // Callback passed to GCMStore::SetGServicesSettings. |
| 222 | void SetGServicesSettingsCallback(bool success); |
| 223 | |
[email protected] | 764c044 | 2014-05-01 04:30:55 | [diff] [blame] | 224 | // Schedules next periodic device checkin and makes sure there is at most one |
| 225 | // pending checkin at a time. This function is meant to be called after a |
| 226 | // successful checkin. |
| 227 | void SchedulePeriodicCheckin(); |
| 228 | // Gets the time until next checkin. |
| 229 | base::TimeDelta GetTimeToNextCheckin() const; |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 230 | // Callback for setting last checkin information in the |gcm_store_|. |
| 231 | void SetLastCheckinInfoCallback(bool success); |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 232 | |
| 233 | // Callback for persisting device credentials in the |gcm_store_|. |
| 234 | void SetDeviceCredentialsCallback(bool success); |
| 235 | |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 236 | // Callback for persisting registration info in the |gcm_store_|. |
| 237 | void UpdateRegistrationCallback(bool success); |
| 238 | |
[email protected] | 72d4f25 | 2014-08-20 22:34:28 | [diff] [blame] | 239 | // Callback for all store operations that do not try to recover, if write in |
| 240 | // |gcm_store_| fails. |
| 241 | void DefaultStoreCallback(bool success); |
| 242 | |
fgorski | 9a40510 | 2014-11-19 01:25:16 | [diff] [blame] | 243 | // Callback for store operation where result does not matter. |
| 244 | void IgnoreWriteResultCallback(bool success); |
| 245 | |
jianli | 00b4600f | 2015-02-10 23:32:49 | [diff] [blame] | 246 | // Callback for resetting the GCM store. |
| 247 | void ResetStoreCallback(bool success); |
| 248 | |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 249 | // Completes the registration request. |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 250 | void OnRegisterCompleted(const std::string& app_id, |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 251 | const std::vector<std::string>& sender_ids, |
[email protected] | b4dd023 | 2014-02-08 02:37:31 | [diff] [blame] | 252 | RegistrationRequest::Status status, |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 253 | const std::string& registration_id); |
| 254 | |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 255 | // Completes the unregistration request. |
[email protected] | 0e88e1d1 | 2014-03-19 06:53:08 | [diff] [blame] | 256 | void OnUnregisterCompleted(const std::string& app_id, |
| 257 | UnregistrationRequest::Status status); |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 258 | |
[email protected] | d3a4b2e | 2014-02-27 13:46:54 | [diff] [blame] | 259 | // Completes the GCM store destroy request. |
| 260 | void OnGCMStoreDestroyed(bool success); |
| 261 | |
[email protected] | c6fe36b | 2014-03-11 10:58:12 | [diff] [blame] | 262 | // Handles incoming data message and dispatches it the delegate of this class. |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 263 | void HandleIncomingMessage(const gcm::MCSMessage& message); |
| 264 | |
[email protected] | c6fe36b | 2014-03-11 10:58:12 | [diff] [blame] | 265 | // Fires OnMessageReceived event on the delegate of this class, based on the |
| 266 | // details in |data_message_stanza| and |message_data|. |
| 267 | void HandleIncomingDataMessage( |
| 268 | const mcs_proto::DataMessageStanza& data_message_stanza, |
| 269 | MessageData& message_data); |
| 270 | |
| 271 | // Fires OnMessageSendError event on the delegate of this calss, based on the |
| 272 | // details in |data_message_stanza| and |message_data|. |
| 273 | void HandleIncomingSendError( |
| 274 | const mcs_proto::DataMessageStanza& data_message_stanza, |
| 275 | MessageData& message_data); |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 276 | |
jianli | f3e52af4 | 2015-01-21 23:18:47 | [diff] [blame] | 277 | // Is there any standalone app being registered for GCM? |
| 278 | bool HasStandaloneRegisteredApp() const; |
| 279 | |
[email protected] | 2bbe0a68 | 2014-03-26 00:08:31 | [diff] [blame] | 280 | // Builder for the GCM internals (mcs client, etc.). |
| 281 | scoped_ptr<GCMInternalsBuilder> internals_builder_; |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 282 | |
[email protected] | 436bcb8 | 2014-04-18 00:40:57 | [diff] [blame] | 283 | // Recorder that logs GCM activities. |
[email protected] | 025adfa | 2014-06-03 21:51:12 | [diff] [blame] | 284 | GCMStatsRecorderImpl recorder_; |
[email protected] | 436bcb8 | 2014-04-18 00:40:57 | [diff] [blame] | 285 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 286 | // State of the GCM Client Implementation. |
| 287 | State state_; |
| 288 | |
[email protected] | 7de7880 | 2014-05-10 19:49:40 | [diff] [blame] | 289 | GCMClient::Delegate* delegate_; |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 290 | |
jianli | f3e52af4 | 2015-01-21 23:18:47 | [diff] [blame] | 291 | // Flag to indicate if the GCM should be delay started until it is actually |
| 292 | // used in either of the following cases: |
| 293 | // 1) The GCM store contains the registration records. |
| 294 | // 2) GCM functionailities are explicitly called. |
| 295 | StartMode start_mode_; |
| 296 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 297 | // Device checkin info (android ID and security token used by device). |
| 298 | CheckinInfo device_checkin_info_; |
| 299 | |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 300 | // Clock used for timing of retry logic. Passed in for testing. Owned by |
| 301 | // GCMClientImpl. |
| 302 | scoped_ptr<base::Clock> clock_; |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 303 | |
| 304 | // Information about the chrome build. |
| 305 | // TODO(fgorski): Check if it can be passed in constructor and made const. |
[email protected] | 8ad8051 | 2014-05-23 09:40:47 | [diff] [blame] | 306 | ChromeBuildInfo chrome_build_info_; |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 307 | |
| 308 | // Persistent data store for keeping device credentials, messages and user to |
| 309 | // serial number mappings. |
[email protected] | 79994f4 | 2014-01-16 16:05:36 | [diff] [blame] | 310 | scoped_ptr<GCMStore> gcm_store_; |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 311 | |
jianli | f3e52af4 | 2015-01-21 23:18:47 | [diff] [blame] | 312 | // Data loaded from the GCM store. |
| 313 | scoped_ptr<GCMStore::LoadResult> load_result_; |
| 314 | |
jianli | 00b4600f | 2015-02-10 23:32:49 | [diff] [blame] | 315 | // Tracks if the GCM store has been reset. This is used to prevent from |
| 316 | // resetting and loading from the store again and again. |
| 317 | bool gcm_store_reset_; |
| 318 | |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 319 | scoped_refptr<net::HttpNetworkSession> network_session_; |
| 320 | net::BoundNetLog net_log_; |
| 321 | scoped_ptr<ConnectionFactory> connection_factory_; |
| 322 | scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 323 | |
| 324 | // Controls receiving and sending of packets and reliable message queueing. |
| 325 | scoped_ptr<MCSClient> mcs_client_; |
| 326 | |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 327 | scoped_ptr<CheckinRequest> checkin_request_; |
[email protected] | b83122a9 | 2014-01-22 21:29:29 | [diff] [blame] | 328 | |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 329 | // Cached registration info. |
| 330 | RegistrationInfoMap registrations_; |
[email protected] | 848b1b6 | 2014-01-30 23:51:04 | [diff] [blame] | 331 | |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 332 | // Currently pending registration requests. GCMClientImpl owns the |
| 333 | // RegistrationRequests. |
| 334 | PendingRegistrationRequests pending_registration_requests_; |
| 335 | STLValueDeleter<PendingRegistrationRequests> |
| 336 | pending_registration_requests_deleter_; |
| 337 | |
| 338 | // Currently pending unregistration requests. GCMClientImpl owns the |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 339 | // UnregistrationRequests. |
[email protected] | 3a20a4d | 2014-03-21 22:54:21 | [diff] [blame] | 340 | PendingUnregistrationRequests pending_unregistration_requests_; |
| 341 | STLValueDeleter<PendingUnregistrationRequests> |
| 342 | pending_unregistration_requests_deleter_; |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 343 | |
[email protected] | 764c044 | 2014-05-01 04:30:55 | [diff] [blame] | 344 | // G-services settings that were provided by MCS. |
[email protected] | 06e4527 | 2014-05-06 03:41:34 | [diff] [blame] | 345 | GServicesSettings gservices_settings_; |
[email protected] | 764c044 | 2014-05-01 04:30:55 | [diff] [blame] | 346 | |
| 347 | // Time of the last successful checkin. |
| 348 | base::Time last_checkin_time_; |
| 349 | |
jianli | 10018b2d | 2015-05-11 21:14:13 | [diff] [blame] | 350 | // Cached instance ID data, key is app id. |
| 351 | std::map<std::string, std::string> instance_id_data_; |
| 352 | |
[email protected] | 764c044 | 2014-05-01 04:30:55 | [diff] [blame] | 353 | // Factory for creating references when scheduling periodic checkin. |
| 354 | base::WeakPtrFactory<GCMClientImpl> periodic_checkin_ptr_factory_; |
| 355 | |
[email protected] | 955e0ff | 2014-01-31 20:42:12 | [diff] [blame] | 356 | // Factory for creating references in callbacks. |
| 357 | base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; |
| 358 | |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 359 | DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); |
| 360 | }; |
| 361 | |
| 362 | } // namespace gcm |
| 363 | |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 364 | #endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ |