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