blob: ebd48e894f4eaf8e414b4e5f4d6e4b3fa827efb4 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2014 The Chromium Authors
[email protected]e4097c82013-11-08 00:16:122// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]cd57f372014-06-09 17:13:065#ifndef COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_
6#define COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_
[email protected]e4097c82013-11-08 00:16:127
avi26062922015-12-26 00:14:188#include <stdint.h>
9
[email protected]b83122a92014-01-22 21:29:2910#include <map>
dchenga77e28eb2016-04-21 21:34:3711#include <memory>
[email protected]7df5ef22014-07-17 07:35:5812#include <set>
[email protected]b83122a92014-01-22 21:29:2913#include <string>
jianli7a0c9b62015-05-26 23:24:4714#include <utility>
[email protected]848b1b62014-01-30 23:51:0415#include <vector>
[email protected]b83122a92014-01-22 21:29:2916
[email protected]e4097c82013-11-08 00:16:1217#include "base/compiler_specific.h"
Keishi Hattori0e45c022021-11-27 09:25:5218#include "base/memory/raw_ptr.h"
[email protected]79994f42014-01-16 16:05:3619#include "base/memory/ref_counted.h"
[email protected]955e0ff2014-01-31 20:42:1220#include "base/memory/weak_ptr.h"
Sean Mahere672a662023-01-09 21:42:2821#include "base/task/sequenced_task_runner.h"
Gabriel Charetted87f10f2022-03-31 00:44:2222#include "base/time/time.h"
Sebastien Marchandefda77e532019-01-25 22:53:5223#include "base/timer/timer.h"
[email protected]cd57f372014-06-09 17:13:0624#include "components/gcm_driver/gcm_client.h"
25#include "components/gcm_driver/gcm_stats_recorder_impl.h"
[email protected]b83122a92014-01-22 21:29:2926#include "google_apis/gcm/base/mcs_message.h"
27#include "google_apis/gcm/engine/gcm_store.h"
[email protected]06e45272014-05-06 03:41:3428#include "google_apis/gcm/engine/gservices_settings.h"
[email protected]b83122a92014-01-22 21:29:2929#include "google_apis/gcm/engine/mcs_client.h"
[email protected]b4dd0232014-02-08 02:37:3130#include "google_apis/gcm/engine/registration_request.h"
[email protected]0e88e1d12014-03-19 06:53:0831#include "google_apis/gcm/engine/unregistration_request.h"
[email protected]436bcb82014-04-18 00:40:5732#include "google_apis/gcm/protocol/android_checkin.pb.h"
[email protected]2c4d4cd2014-04-10 21:10:2233#include "google_apis/gcm/protocol/checkin.pb.h"
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4834#include "mojo/public/cpp/bindings/pending_receiver.h"
zea76342abf2016-11-01 17:26:0435#include "net/http/http_status_code.h"
Helen Li5f3d96a2018-08-10 20:37:2436#include "services/network/public/mojom/proxy_resolving_socket.mojom.h"
[email protected]e4097c82013-11-08 00:16:1237
[email protected]2bbe0a682014-03-26 00:08:3138class GURL;
39
[email protected]79994f42014-01-16 16:05:3640namespace base {
[email protected]955e0ff2014-01-31 20:42:1241class Clock;
[email protected]764c0442014-05-01 04:30:5542class Time;
[email protected]79994f42014-01-16 16:05:3643} // namespace base
44
[email protected]436bcb82014-04-18 00:40:5745namespace mcs_proto {
46class DataMessageStanza;
47} // namespace mcs_proto
48
Maks Orlovichc70c93c2018-07-12 02:45:4449namespace network {
Robbie McElrathb01499332018-09-25 00:53:1350class NetworkConnectionTracker;
Maks Orlovichc70c93c2018-07-12 02:45:4451class SharedURLLoaderFactory;
52} // namespace network
53
[email protected]e4097c82013-11-08 00:16:1254namespace gcm {
55
[email protected]b83122a92014-01-22 21:29:2956class CheckinRequest;
57class ConnectionFactory;
58class GCMClientImplTest;
[email protected]79994f42014-01-16 16:05:3659
[email protected]2bbe0a682014-03-26 00:08:3160// Helper class for building GCM internals. Allows tests to inject fake versions
61// as necessary.
[email protected]cd57f372014-06-09 17:13:0662class GCMInternalsBuilder {
[email protected]2bbe0a682014-03-26 00:08:3163 public:
64 GCMInternalsBuilder();
65 virtual ~GCMInternalsBuilder();
66
tzik48479d92018-03-20 15:20:4267 virtual base::Clock* GetClock();
dchenga77e28eb2016-04-21 21:34:3768 virtual std::unique_ptr<MCSClient> BuildMCSClient(
[email protected]2bbe0a682014-03-26 00:08:3169 const std::string& version,
70 base::Clock* clock,
71 ConnectionFactory* connection_factory,
[email protected]436bcb82014-04-18 00:40:5772 GCMStore* gcm_store,
Steven Zhub36394c2019-06-04 16:10:4673 scoped_refptr<base::SequencedTaskRunner> io_task_runner,
[email protected]436bcb82014-04-18 00:40:5774 GCMStatsRecorder* recorder);
dchenga77e28eb2016-04-21 21:34:3775 virtual std::unique_ptr<ConnectionFactory> BuildConnectionFactory(
[email protected]2bbe0a682014-03-26 00:08:3176 const std::vector<GURL>& endpoints,
77 const net::BackoffEntry::Policy& backoff_policy,
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4878 base::RepeatingCallback<void(
79 mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
Helen Li5f3d96a2018-08-10 20:37:2480 get_socket_factory_callback,
Steven Zhub36394c2019-06-04 16:10:4681 scoped_refptr<base::SequencedTaskRunner> io_task_runner,
Robbie McElrathb01499332018-09-25 00:53:1382 GCMStatsRecorder* recorder,
83 network::NetworkConnectionTracker* network_connection_tracker);
[email protected]2bbe0a682014-03-26 00:08:3184};
85
[email protected]b83122a92014-01-22 21:29:2986// Implements the GCM Client. It is used to coordinate MCS Client (communication
87// with MCS) and other pieces of GCM infrastructure like Registration and
88// Checkins. It also allows for registering user delegates that host
89// applications that send and receive messages.
[email protected]cd57f372014-06-09 17:13:0690class GCMClientImpl
[email protected]c31e1b52014-06-12 21:00:4791 : public GCMClient, public GCMStatsRecorder::Delegate,
92 public ConnectionFactory::ConnectionListener {
[email protected]e4097c82013-11-08 00:16:1293 public:
jianlif3e52af42015-01-21 23:18:4794 // State representation of the GCMClient.
95 // Any change made to this enum should have corresponding change in the
96 // GetStateString(...) function.
97 enum State {
98 // Uninitialized.
99 UNINITIALIZED,
100 // Initialized,
101 INITIALIZED,
102 // GCM store loading is in progress.
103 LOADING,
104 // GCM store is loaded.
105 LOADED,
106 // Initial device checkin is in progress.
107 INITIAL_DEVICE_CHECKIN,
108 // Ready to accept requests.
109 READY,
110 };
111
dchenga77e28eb2016-04-21 21:34:37112 explicit GCMClientImpl(
113 std::unique_ptr<GCMInternalsBuilder> internals_builder);
Peter Boström09c01822021-09-20 22:43:27114
115 GCMClientImpl(const GCMClientImpl&) = delete;
116 GCMClientImpl& operator=(const GCMClientImpl&) = delete;
117
dcheng00ea022b2014-10-21 11:24:56118 ~GCMClientImpl() override;
[email protected]e4097c82013-11-08 00:16:12119
[email protected]c31e1b52014-06-12 21:00:47120 // GCMClient implementation.
dcheng00ea022b2014-10-21 11:24:56121 void Initialize(
[email protected]8ad80512014-05-23 09:40:47122 const ChromeBuildInfo& chrome_build_info,
[email protected]e2a4a8012014-02-07 22:32:52123 const base::FilePath& store_path,
124 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
Steven Zhub36394c2019-06-04 16:10:46125 scoped_refptr<base::SequencedTaskRunner> io_task_runner,
Julie Jeongeun Kim17b2adf12019-10-29 10:24:48126 base::RepeatingCallback<void(
127 mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
Helen Li5f3d96a2018-08-10 20:37:24128 get_socket_factory_callback,
Maks Orlovichc70c93c2018-07-12 02:45:44129 const scoped_refptr<network::SharedURLLoaderFactory>& url_loader_factory,
Robbie McElrathb01499332018-09-25 00:53:13130 network::NetworkConnectionTracker* network_connection_tracker,
dchenga77e28eb2016-04-21 21:34:37131 std::unique_ptr<Encryptor> encryptor,
mostynbfe59f482014-10-06 15:04:46132 GCMClient::Delegate* delegate) override;
jianlif3e52af42015-01-21 23:18:47133 void Start(StartMode start_mode) override;
dcheng00ea022b2014-10-21 11:24:56134 void Stop() override;
Rayan Kanso3da434f2018-12-19 17:09:39135 void Register(scoped_refptr<RegistrationInfo> registration_info) override;
136 bool ValidateRegistration(scoped_refptr<RegistrationInfo> registration_info,
137 const std::string& registration_id) override;
138 void Unregister(scoped_refptr<RegistrationInfo> registration_info) override;
dcheng00ea022b2014-10-21 11:24:56139 void Send(const std::string& app_id,
140 const std::string& receiver_id,
141 const OutgoingMessage& message) override;
peteree284ba52016-02-01 11:53:28142 void RecordDecryptionFailure(const std::string& app_id,
Peter Beverlooa376e98c2017-06-27 15:55:37143 GCMDecryptionResult result) override;
dcheng00ea022b2014-10-21 11:24:56144 void SetRecording(bool recording) override;
145 void ClearActivityLogs() override;
146 GCMStatistics GetStatistics() const override;
147 void SetAccountTokens(
mostynbfe59f482014-10-06 15:04:46148 const std::vector<AccountTokenInfo>& account_tokens) override;
dcheng00ea022b2014-10-21 11:24:56149 void UpdateAccountMapping(const AccountMapping& account_mapping) override;
Tanmoy Mollikf6ec6b92019-08-12 16:19:55150 void RemoveAccountMapping(const CoreAccountId& account_id) override;
fgorski5df101702014-10-28 02:09:31151 void SetLastTokenFetchTime(const base::Time& time) override;
tzikb6c66b22018-07-06 12:14:16152 void UpdateHeartbeatTimer(
153 std::unique_ptr<base::RetainingOneShotTimer> timer) override;
jianli10018b2d2015-05-11 21:14:13154 void AddInstanceIDData(const std::string& app_id,
jianli7a0c9b62015-05-26 23:24:47155 const std::string& instance_id,
156 const std::string& extra_data) override;
jianli10018b2d2015-05-11 21:14:13157 void RemoveInstanceIDData(const std::string& app_id) override;
jianli7a0c9b62015-05-26 23:24:47158 void GetInstanceIDData(const std::string& app_id,
159 std::string* instance_id,
160 std::string* extra_data) override;
fgorski22754462015-05-14 00:05:22161 void AddHeartbeatInterval(const std::string& scope, int interval_ms) override;
162 void RemoveHeartbeatInterval(const std::string& scope) override;
[email protected]c31e1b52014-06-12 21:00:47163
164 // GCMStatsRecorder::Delegate implemenation.
dcheng00ea022b2014-10-21 11:24:56165 void OnActivityRecorded() override;
[email protected]e4097c82013-11-08 00:16:12166
[email protected]c31e1b52014-06-12 21:00:47167 // ConnectionFactory::ConnectionListener implementation.
dcheng00ea022b2014-10-21 11:24:56168 void OnConnected(const GURL& current_server,
169 const net::IPEndPoint& ip_endpoint) override;
170 void OnDisconnected() override;
[email protected]c31e1b52014-06-12 21:00:47171
[email protected]e4097c82013-11-08 00:16:12172 private:
[email protected]7df5ef22014-07-17 07:35:58173 // The check-in info for the device.
174 // TODO(fgorski): Convert to a class with explicit getters/setters.
[email protected]cd57f372014-06-09 17:13:06175 struct CheckinInfo {
[email protected]7df5ef22014-07-17 07:35:58176 CheckinInfo();
177 ~CheckinInfo();
[email protected]5799d052014-02-12 20:47:39178 bool IsValid() const { return android_id != 0 && secret != 0; }
[email protected]7df5ef22014-07-17 07:35:58179 void Reset();
[email protected]b83122a92014-01-22 21:29:29180
[email protected]7df5ef22014-07-17 07:35:58181 // Android ID of the device as assigned by the server.
avi26062922015-12-26 00:14:18182 uint64_t android_id;
[email protected]7df5ef22014-07-17 07:35:58183 // Security token of the device as assigned by the server.
avi26062922015-12-26 00:14:18184 uint64_t secret;
[email protected]7df5ef22014-07-17 07:35:58185 // True if accounts were already provided through SetAccountsForCheckin(),
186 // or when |last_checkin_accounts| was loaded as empty.
187 bool accounts_set;
[email protected]848b1b62014-01-30 23:51:04188 };
189
zeae6e404182016-11-04 23:05:45190 // Reasons for resetting the GCM Store.
191 // Note: this enum is recorded into a histogram. Do not change enum value
192 // or order.
193 enum ResetReason {
194 LOAD_FAILURE, // GCM store failed to load, but the store exists.
195 CHECKIN_REJECTED, // Checkin was rejected by server.
196
197 RESET_REASON_COUNT,
198 };
199
jianli7a0c9b62015-05-26 23:24:47200 // Collection of pending registration requests. Keys are RegistrationInfo
201 // instance, while values are pending registration requests to obtain a
202 // registration ID for requesting application.
dchenga77e28eb2016-04-21 21:34:37203 using PendingRegistrationRequests =
Rayan Kanso3da434f2018-12-19 17:09:39204 std::map<scoped_refptr<RegistrationInfo>,
dchenga77e28eb2016-04-21 21:34:37205 std::unique_ptr<RegistrationRequest>,
206 RegistrationInfoComparer>;
[email protected]848b1b62014-01-30 23:51:04207
jianli7a0c9b62015-05-26 23:24:47208 // Collection of pending unregistration requests. Keys are RegistrationInfo
209 // instance, while values are pending unregistration requests to disable the
210 // registration ID currently assigned to the application.
limasdf20c5d7a2015-12-01 01:16:19211 using PendingUnregistrationRequests =
Rayan Kanso3da434f2018-12-19 17:09:39212 std::map<scoped_refptr<RegistrationInfo>,
dchenga77e28eb2016-04-21 21:34:37213 std::unique_ptr<UnregistrationRequest>,
limasdf20c5d7a2015-12-01 01:16:19214 RegistrationInfoComparer>;
[email protected]e4007042014-02-15 20:34:28215
[email protected]b83122a92014-01-22 21:29:29216 friend class GCMClientImplTest;
jianlic02d25e2015-05-27 22:24:31217 friend class GCMClientInstanceIDTest;
[email protected]b83122a92014-01-22 21:29:29218
[email protected]35601812014-03-07 19:52:43219 // Returns text representation of the enum State.
220 std::string GetStateString() const;
221
[email protected]b83122a92014-01-22 21:29:29222 // Callbacks for the MCSClient.
223 // Receives messages and dispatches them to relevant user delegates.
224 void OnMessageReceivedFromMCS(const gcm::MCSMessage& message);
225 // Receives confirmation of sent messages or information about errors.
avi26062922015-12-26 00:14:18226 void OnMessageSentToMCS(int64_t user_serial_number,
[email protected]b83122a92014-01-22 21:29:29227 const std::string& app_id,
228 const std::string& message_id,
229 MCSClient::MessageSendStatus status);
230 // Receives information about mcs_client_ errors.
231 void OnMCSError();
232
233 // Runs after GCM Store load is done to trigger continuation of the
234 // initialization.
dchenga77e28eb2016-04-21 21:34:37235 void OnLoadCompleted(std::unique_ptr<GCMStore::LoadResult> result);
jianlif3e52af42015-01-21 23:18:47236 // Starts the GCM.
237 void StartGCM();
[email protected]b83122a92014-01-22 21:29:29238 // Initializes mcs_client_, which handles the connection to MCS.
jianlif3e52af42015-01-21 23:18:47239 void InitializeMCSClient();
[email protected]b83122a92014-01-22 21:29:29240 // Complets the first time device checkin.
241 void OnFirstTimeDeviceCheckinCompleted(const CheckinInfo& checkin_info);
242 // Starts a login on mcs_client_.
243 void StartMCSLogin();
jianli00b4600f2015-02-10 23:32:49244 // Resets the GCM store when it is corrupted.
245 void ResetStore();
[email protected]86625df2014-01-31 03:47:58246 // Sets state to ready. This will initiate the MCS login and notify the
247 // delegates.
fgorski5df101702014-10-28 02:09:31248 void OnReady(const std::vector<AccountMapping>& account_mappings,
249 const base::Time& last_token_fetch_time);
[email protected]b83122a92014-01-22 21:29:29250
[email protected]5799d052014-02-12 20:47:39251 // Starts a first time device checkin.
[email protected]25b5f50e2014-04-03 08:27:23252 void StartCheckin();
[email protected]2c4d4cd2014-04-10 21:10:22253 // Completes the device checkin request by parsing the |checkin_response|.
254 // Function also cleans up the pending checkin.
255 void OnCheckinCompleted(
zea76342abf2016-11-01 17:26:04256 net::HttpStatusCode response_code,
[email protected]2c4d4cd2014-04-10 21:10:22257 const checkin_proto::AndroidCheckinResponse& checkin_response);
[email protected]06e45272014-05-06 03:41:34258
259 // Callback passed to GCMStore::SetGServicesSettings.
260 void SetGServicesSettingsCallback(bool success);
261
[email protected]764c0442014-05-01 04:30:55262 // Schedules next periodic device checkin and makes sure there is at most one
263 // pending checkin at a time. This function is meant to be called after a
264 // successful checkin.
265 void SchedulePeriodicCheckin();
266 // Gets the time until next checkin.
267 base::TimeDelta GetTimeToNextCheckin() const;
[email protected]7df5ef22014-07-17 07:35:58268 // Callback for setting last checkin information in the |gcm_store_|.
269 void SetLastCheckinInfoCallback(bool success);
[email protected]b83122a92014-01-22 21:29:29270
271 // Callback for persisting device credentials in the |gcm_store_|.
272 void SetDeviceCredentialsCallback(bool success);
273
[email protected]3a20a4d2014-03-21 22:54:21274 // Callback for persisting registration info in the |gcm_store_|.
275 void UpdateRegistrationCallback(bool success);
276
[email protected]72d4f252014-08-20 22:34:28277 // Callback for all store operations that do not try to recover, if write in
278 // |gcm_store_| fails.
279 void DefaultStoreCallback(bool success);
280
fgorski9a405102014-11-19 01:25:16281 // Callback for store operation where result does not matter.
Tim Schumannfe839832019-11-27 12:17:31282 void IgnoreWriteResultCallback(const std::string& operation_suffix_for_uma,
283 bool success);
fgorski9a405102014-11-19 01:25:16284
jianli78b56042015-06-17 01:21:22285 // Callback for destroying the GCM store.
286 void DestroyStoreCallback(bool success);
287
288 // Callback for resetting the GCM store. The store will be reloaded.
jianli00b4600f2015-02-10 23:32:49289 void ResetStoreCallback(bool success);
290
[email protected]848b1b62014-01-30 23:51:04291 // Completes the registration request.
Rayan Kanso3da434f2018-12-19 17:09:39292 void OnRegisterCompleted(scoped_refptr<RegistrationInfo> registration_info,
293 RegistrationRequest::Status status,
294 const std::string& registration_id);
[email protected]848b1b62014-01-30 23:51:04295
[email protected]e4007042014-02-15 20:34:28296 // Completes the unregistration request.
Rayan Kanso3da434f2018-12-19 17:09:39297 void OnUnregisterCompleted(scoped_refptr<RegistrationInfo> registration_info,
298 UnregistrationRequest::Status status);
[email protected]e4007042014-02-15 20:34:28299
[email protected]d3a4b2e2014-02-27 13:46:54300 // Completes the GCM store destroy request.
301 void OnGCMStoreDestroyed(bool success);
302
[email protected]c6fe36b2014-03-11 10:58:12303 // Handles incoming data message and dispatches it the delegate of this class.
[email protected]b83122a92014-01-22 21:29:29304 void HandleIncomingMessage(const gcm::MCSMessage& message);
305
[email protected]c6fe36b2014-03-11 10:58:12306 // Fires OnMessageReceived event on the delegate of this class, based on the
307 // details in |data_message_stanza| and |message_data|.
308 void HandleIncomingDataMessage(
johnme627dc8c72016-08-19 21:49:39309 const std::string& app_id,
310 bool was_subtype,
[email protected]c6fe36b2014-03-11 10:58:12311 const mcs_proto::DataMessageStanza& data_message_stanza,
312 MessageData& message_data);
313
johnme409dc532016-12-13 23:43:42314 // Fires OnMessagesDeleted event on the delegate of this class, based on the
315 // details in |data_message_stanza| and |message_data|.
316 void HandleIncomingDeletedMessages(
317 const std::string& app_id,
318 const mcs_proto::DataMessageStanza& data_message_stanza,
319 MessageData& message_data);
320
johnme627dc8c72016-08-19 21:49:39321 // Fires OnMessageSendError event on the delegate of this class, based on the
[email protected]c6fe36b2014-03-11 10:58:12322 // details in |data_message_stanza| and |message_data|.
323 void HandleIncomingSendError(
johnme627dc8c72016-08-19 21:49:39324 const std::string& app_id,
[email protected]c6fe36b2014-03-11 10:58:12325 const mcs_proto::DataMessageStanza& data_message_stanza,
326 MessageData& message_data);
[email protected]848b1b62014-01-30 23:51:04327
jianlif3e52af42015-01-21 23:18:47328 // Is there any standalone app being registered for GCM?
329 bool HasStandaloneRegisteredApp() const;
330
jianli78b56042015-06-17 01:21:22331 // Destroys the store when it is not needed.
332 void DestroyStoreWhenNotNeeded();
333
334 // Reset all cahced values.
335 void ResetCache();
336
[email protected]2bbe0a682014-03-26 00:08:31337 // Builder for the GCM internals (mcs client, etc.).
dchenga77e28eb2016-04-21 21:34:37338 std::unique_ptr<GCMInternalsBuilder> internals_builder_;
[email protected]b83122a92014-01-22 21:29:29339
[email protected]436bcb82014-04-18 00:40:57340 // Recorder that logs GCM activities.
[email protected]025adfa2014-06-03 21:51:12341 GCMStatsRecorderImpl recorder_;
[email protected]436bcb82014-04-18 00:40:57342
[email protected]b83122a92014-01-22 21:29:29343 // State of the GCM Client Implementation.
344 State state_;
345
Keishi Hattori0e45c022021-11-27 09:25:52346 raw_ptr<GCMClient::Delegate> delegate_;
[email protected]5799d052014-02-12 20:47:39347
jianlif3e52af42015-01-21 23:18:47348 // Flag to indicate if the GCM should be delay started until it is actually
349 // used in either of the following cases:
350 // 1) The GCM store contains the registration records.
351 // 2) GCM functionailities are explicitly called.
352 StartMode start_mode_;
353
[email protected]b83122a92014-01-22 21:29:29354 // Device checkin info (android ID and security token used by device).
355 CheckinInfo device_checkin_info_;
356
tzik48479d92018-03-20 15:20:42357 // Clock used for timing of retry logic. Passed in for testing.
Keishi Hattori0e45c022021-11-27 09:25:52358 raw_ptr<base::Clock> clock_;
[email protected]b83122a92014-01-22 21:29:29359
360 // Information about the chrome build.
361 // TODO(fgorski): Check if it can be passed in constructor and made const.
[email protected]8ad80512014-05-23 09:40:47362 ChromeBuildInfo chrome_build_info_;
[email protected]b83122a92014-01-22 21:29:29363
364 // Persistent data store for keeping device credentials, messages and user to
365 // serial number mappings.
dchenga77e28eb2016-04-21 21:34:37366 std::unique_ptr<GCMStore> gcm_store_;
[email protected]b83122a92014-01-22 21:29:29367
jianlif3e52af42015-01-21 23:18:47368 // Data loaded from the GCM store.
dchenga77e28eb2016-04-21 21:34:37369 std::unique_ptr<GCMStore::LoadResult> load_result_;
jianlif3e52af42015-01-21 23:18:47370
jianli00b4600f2015-02-10 23:32:49371 // Tracks if the GCM store has been reset. This is used to prevent from
372 // resetting and loading from the store again and again.
373 bool gcm_store_reset_;
374
dchenga77e28eb2016-04-21 21:34:37375 std::unique_ptr<ConnectionFactory> connection_factory_;
Helen Li5f3d96a2018-08-10 20:37:24376 base::RepeatingCallback<void(
Julie Jeongeun Kim17b2adf12019-10-29 10:24:48377 mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
Helen Li5f3d96a2018-08-10 20:37:24378 get_socket_factory_callback_;
379
Maks Orlovichc70c93c2018-07-12 02:45:44380 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
[email protected]b83122a92014-01-22 21:29:29381
Keishi Hattori0e45c022021-11-27 09:25:52382 raw_ptr<network::NetworkConnectionTracker> network_connection_tracker_;
Robbie McElrathb01499332018-09-25 00:53:13383
Steven Zhub36394c2019-06-04 16:10:46384 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
385
[email protected]b83122a92014-01-22 21:29:29386 // Controls receiving and sending of packets and reliable message queueing.
mmenkee65e7af2015-10-13 17:16:42387 // Must be destroyed before |network_session_|.
dchenga77e28eb2016-04-21 21:34:37388 std::unique_ptr<MCSClient> mcs_client_;
[email protected]b83122a92014-01-22 21:29:29389
dchenga77e28eb2016-04-21 21:34:37390 std::unique_ptr<CheckinRequest> checkin_request_;
[email protected]b83122a92014-01-22 21:29:29391
[email protected]3a20a4d2014-03-21 22:54:21392 // Cached registration info.
393 RegistrationInfoMap registrations_;
[email protected]848b1b62014-01-30 23:51:04394
[email protected]3a20a4d2014-03-21 22:54:21395 // Currently pending registration requests. GCMClientImpl owns the
396 // RegistrationRequests.
397 PendingRegistrationRequests pending_registration_requests_;
[email protected]3a20a4d2014-03-21 22:54:21398
399 // Currently pending unregistration requests. GCMClientImpl owns the
[email protected]e4007042014-02-15 20:34:28400 // UnregistrationRequests.
[email protected]3a20a4d2014-03-21 22:54:21401 PendingUnregistrationRequests pending_unregistration_requests_;
[email protected]e4007042014-02-15 20:34:28402
[email protected]764c0442014-05-01 04:30:55403 // G-services settings that were provided by MCS.
[email protected]06e45272014-05-06 03:41:34404 GServicesSettings gservices_settings_;
[email protected]764c0442014-05-01 04:30:55405
406 // Time of the last successful checkin.
407 base::Time last_checkin_time_;
408
jianli7a0c9b62015-05-26 23:24:47409 // Cached instance ID data, key is app ID and value is pair of instance ID
410 // and extra data.
411 std::map<std::string, std::pair<std::string, std::string>> instance_id_data_;
jianli10018b2d2015-05-11 21:14:13412
[email protected]764c0442014-05-01 04:30:55413 // Factory for creating references when scheduling periodic checkin.
Jeremy Roman5c341f6d2019-07-15 15:56:10414 base::WeakPtrFactory<GCMClientImpl> periodic_checkin_ptr_factory_{this};
[email protected]764c0442014-05-01 04:30:55415
jianli78b56042015-06-17 01:21:22416 // Factory for wiping out GCM store.
Jeremy Roman5c341f6d2019-07-15 15:56:10417 base::WeakPtrFactory<GCMClientImpl> destroying_gcm_store_ptr_factory_{this};
jianli78b56042015-06-17 01:21:22418
[email protected]955e0ff2014-01-31 20:42:12419 // Factory for creating references in callbacks.
Jeremy Roman5c341f6d2019-07-15 15:56:10420 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_{this};
[email protected]e4097c82013-11-08 00:16:12421};
422
423} // namespace gcm
424
[email protected]cd57f372014-06-09 17:13:06425#endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_