[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_H_ |
| 6 | #define COMPONENTS_GCM_DRIVER_GCM_CLIENT_H_ |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 7 | |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 10 | #include <map> |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 11 | #include <memory> |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
Rayan Kanso | 3da434f | 2018-12-19 17:09:39 | [diff] [blame] | 15 | #include "base/memory/scoped_refptr.h" |
Rayan Kanso | 7b3b5ea | 2019-05-08 18:15:00 | [diff] [blame] | 16 | #include "components/gcm_driver/common/gcm_message.h" |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 17 | #include "components/gcm_driver/gcm_activity.h" |
jianli | 7a0c9b6 | 2015-05-26 23:24:47 | [diff] [blame] | 18 | #include "components/gcm_driver/registration_info.h" |
Tanmoy Mollik | f6ec6b9 | 2019-08-12 16:19:55 | [diff] [blame] | 19 | #include "google_apis/gaia/core_account_id.h" |
Julie Jeongeun Kim | 17b2adf1 | 2019-10-29 10:24:48 | [diff] [blame] | 20 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
Takuto Ikuta | aa3b796c | 2019-02-06 02:54:56 | [diff] [blame] | 21 | #include "services/network/public/mojom/proxy_resolving_socket.mojom-forward.h" |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 22 | |
[email protected] | e2a4a801 | 2014-02-07 22:32:52 | [diff] [blame] | 23 | namespace base { |
| 24 | class FilePath; |
tzik | b6c66b2 | 2018-07-06 12:14:16 | [diff] [blame] | 25 | class RetainingOneShotTimer; |
[email protected] | e2a4a801 | 2014-02-07 22:32:52 | [diff] [blame] | 26 | class SequencedTaskRunner; |
Rayan Kanso | 3da434f | 2018-12-19 17:09:39 | [diff] [blame] | 27 | } // namespace base |
[email protected] | e2a4a801 | 2014-02-07 22:32:52 | [diff] [blame] | 28 | |
[email protected] | e2a4a801 | 2014-02-07 22:32:52 | [diff] [blame] | 29 | namespace net { |
[email protected] | fc6078a | 2014-06-14 08:28:43 | [diff] [blame] | 30 | class IPEndPoint; |
Rayan Kanso | 3da434f | 2018-12-19 17:09:39 | [diff] [blame] | 31 | } // namespace net |
[email protected] | e2a4a801 | 2014-02-07 22:32:52 | [diff] [blame] | 32 | |
Maks Orlovich | c70c93c | 2018-07-12 02:45:44 | [diff] [blame] | 33 | namespace network { |
Robbie McElrath | b0149933 | 2018-09-25 00:53:13 | [diff] [blame] | 34 | class NetworkConnectionTracker; |
Maks Orlovich | c70c93c | 2018-07-12 02:45:44 | [diff] [blame] | 35 | class SharedURLLoaderFactory; |
Rayan Kanso | 3da434f | 2018-12-19 17:09:39 | [diff] [blame] | 36 | } // namespace network |
Maks Orlovich | c70c93c | 2018-07-12 02:45:44 | [diff] [blame] | 37 | |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 38 | namespace gcm { |
| 39 | |
[email protected] | 72d4f25 | 2014-08-20 22:34:28 | [diff] [blame] | 40 | struct AccountMapping; |
Peter Beverloo | a376e98c | 2017-06-27 15:55:37 | [diff] [blame] | 41 | class Encryptor; |
| 42 | enum class GCMDecryptionResult; |
[email protected] | 446f73c2 | 2014-05-14 20:47:18 | [diff] [blame] | 43 | |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 44 | // Interface that encapsulates the network communications with the Google Cloud |
| 45 | // Messaging server. This interface is not supposed to be thread-safe. |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 46 | class GCMClient { |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 47 | public: |
jianli | f3e52af4 | 2015-01-21 23:18:47 | [diff] [blame] | 48 | // Controls how GCM is being started. At first, GCMClient will be initialized |
| 49 | // and GCM store will be loaded. Then GCM connection may or may not be |
| 50 | // initiated depending on this enum value. |
| 51 | enum StartMode { |
| 52 | // GCM should be started only when it is being actually used. If no |
| 53 | // registration record is found, GCM will not kick off. |
| 54 | DELAYED_START, |
| 55 | // GCM should be started immediately. |
| 56 | IMMEDIATE_START |
| 57 | }; |
| 58 | |
johnme | ef71bd0 | 2017-02-09 17:45:56 | [diff] [blame] | 59 | // Used for UMA. Can add enum values, but never renumber or delete and reuse. |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 60 | enum Result { |
| 61 | // Successful operation. |
| 62 | SUCCESS, |
[email protected] | b16a7c5 | 2013-11-20 01:18:59 | [diff] [blame] | 63 | // Invalid parameter. |
| 64 | INVALID_PARAMETER, |
[email protected] | 9d7e5c0 | 2014-05-21 03:09:03 | [diff] [blame] | 65 | // GCM is disabled. |
| 66 | GCM_DISABLED, |
[email protected] | b16a7c5 | 2013-11-20 01:18:59 | [diff] [blame] | 67 | // Previous asynchronous operation is still pending to finish. Certain |
| 68 | // operation, like register, is only allowed one at a time. |
| 69 | ASYNC_OPERATION_PENDING, |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 70 | // Network socket error. |
| 71 | NETWORK_ERROR, |
| 72 | // Problem at the server. |
| 73 | SERVER_ERROR, |
| 74 | // Exceeded the specified TTL during message sending. |
| 75 | TTL_EXCEEDED, |
| 76 | // Other errors. |
johnme | ef71bd0 | 2017-02-09 17:45:56 | [diff] [blame] | 77 | UNKNOWN_ERROR, |
| 78 | |
| 79 | // Used for UMA. Keep LAST_RESULT up to date and sync with histograms.xml. |
| 80 | LAST_RESULT = UNKNOWN_ERROR |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 81 | }; |
| 82 | |
[email protected] | 8ad8051 | 2014-05-23 09:40:47 | [diff] [blame] | 83 | enum ChromePlatform { |
| 84 | PLATFORM_WIN, |
| 85 | PLATFORM_MAC, |
| 86 | PLATFORM_LINUX, |
| 87 | PLATFORM_CROS, |
| 88 | PLATFORM_IOS, |
| 89 | PLATFORM_ANDROID, |
Daniel Bratell | e3c10f3 | 2018-02-05 15:03:38 | [diff] [blame] | 90 | PLATFORM_UNSPECIFIED |
[email protected] | 8ad8051 | 2014-05-23 09:40:47 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | enum ChromeChannel { |
| 94 | CHANNEL_STABLE, |
| 95 | CHANNEL_BETA, |
| 96 | CHANNEL_DEV, |
| 97 | CHANNEL_CANARY, |
| 98 | CHANNEL_UNKNOWN |
| 99 | }; |
| 100 | |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 101 | struct ChromeBuildInfo { |
[email protected] | 8ad8051 | 2014-05-23 09:40:47 | [diff] [blame] | 102 | ChromeBuildInfo(); |
| 103 | ~ChromeBuildInfo(); |
| 104 | |
| 105 | ChromePlatform platform; |
| 106 | ChromeChannel channel; |
| 107 | std::string version; |
johnme | 627dc8c7 | 2016-08-19 21:49:39 | [diff] [blame] | 108 | std::string product_category_for_subtypes; |
[email protected] | 8ad8051 | 2014-05-23 09:40:47 | [diff] [blame] | 109 | }; |
| 110 | |
[email protected] | c6fe36b | 2014-03-11 10:58:12 | [diff] [blame] | 111 | // Detailed information of the Send Error event. |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 112 | struct SendErrorDetails { |
[email protected] | c6fe36b | 2014-03-11 10:58:12 | [diff] [blame] | 113 | SendErrorDetails(); |
vmpstr | b6449d51 | 2016-02-25 23:55:40 | [diff] [blame] | 114 | SendErrorDetails(const SendErrorDetails& other); |
[email protected] | c6fe36b | 2014-03-11 10:58:12 | [diff] [blame] | 115 | ~SendErrorDetails(); |
| 116 | |
| 117 | std::string message_id; |
| 118 | MessageData additional_data; |
| 119 | Result result; |
| 120 | }; |
| 121 | |
[email protected] | 3560181 | 2014-03-07 19:52:43 | [diff] [blame] | 122 | // Internal states and activity statistics of a GCM client. |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 123 | struct GCMStatistics { |
[email protected] | 3560181 | 2014-03-07 19:52:43 | [diff] [blame] | 124 | public: |
| 125 | GCMStatistics(); |
vmpstr | b6449d51 | 2016-02-25 23:55:40 | [diff] [blame] | 126 | GCMStatistics(const GCMStatistics& other); |
[email protected] | 3560181 | 2014-03-07 19:52:43 | [diff] [blame] | 127 | ~GCMStatistics(); |
| 128 | |
[email protected] | 436bcb8 | 2014-04-18 00:40:57 | [diff] [blame] | 129 | bool is_recording; |
[email protected] | 3560181 | 2014-03-07 19:52:43 | [diff] [blame] | 130 | bool gcm_client_created; |
| 131 | std::string gcm_client_state; |
| 132 | bool connection_client_created; |
| 133 | std::string connection_state; |
zea | 76342abf | 2016-11-01 17:26:04 | [diff] [blame] | 134 | base::Time last_checkin; |
| 135 | base::Time next_checkin; |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 136 | uint64_t android_id; |
Peter Beverloo | f946918 | 2018-05-03 20:46:52 | [diff] [blame] | 137 | uint64_t android_secret; |
[email protected] | 436bcb8 | 2014-04-18 00:40:57 | [diff] [blame] | 138 | std::vector<std::string> registered_app_ids; |
| 139 | int send_queue_size; |
| 140 | int resend_queue_size; |
| 141 | |
[email protected] | 5da9380 | 2014-05-24 01:35:01 | [diff] [blame] | 142 | RecordedActivities recorded_activities; |
[email protected] | 3560181 | 2014-03-07 19:52:43 | [diff] [blame] | 143 | }; |
| 144 | |
fgorski | c104731 | 2014-09-04 16:48:54 | [diff] [blame] | 145 | // Information about account. |
| 146 | struct AccountTokenInfo { |
Tanmoy Mollik | f6ec6b9 | 2019-08-12 16:19:55 | [diff] [blame] | 147 | CoreAccountId account_id; |
fgorski | c104731 | 2014-09-04 16:48:54 | [diff] [blame] | 148 | std::string email; |
| 149 | std::string access_token; |
| 150 | }; |
| 151 | |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 152 | // A delegate interface that allows the GCMClient instance to interact with |
| 153 | // its caller, i.e. notifying asynchronous event. |
| 154 | class Delegate { |
| 155 | public: |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 156 | // Called when the registration completed successfully or an error occurs. |
jianli | 7a0c9b6 | 2015-05-26 23:24:47 | [diff] [blame] | 157 | // |registration_info|: the specific information required for the |
| 158 | // registration. |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 159 | // |registration_id|: non-empty if the registration completed successfully. |
| 160 | // |result|: the type of the error if an error occured, success otherwise. |
jianli | 7a0c9b6 | 2015-05-26 23:24:47 | [diff] [blame] | 161 | virtual void OnRegisterFinished( |
Rayan Kanso | 3da434f | 2018-12-19 17:09:39 | [diff] [blame] | 162 | scoped_refptr<RegistrationInfo> registration_info, |
jianli | 7a0c9b6 | 2015-05-26 23:24:47 | [diff] [blame] | 163 | const std::string& registration_id, |
| 164 | Result result) = 0; |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 165 | |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 166 | // Called when the unregistration completed. |
jianli | 7a0c9b6 | 2015-05-26 23:24:47 | [diff] [blame] | 167 | // |registration_info|: the specific information required for the |
| 168 | // registration. |
[email protected] | 0e88e1d1 | 2014-03-19 06:53:08 | [diff] [blame] | 169 | // |result|: result of the unregistration. |
jianli | 7a0c9b6 | 2015-05-26 23:24:47 | [diff] [blame] | 170 | virtual void OnUnregisterFinished( |
Rayan Kanso | 3da434f | 2018-12-19 17:09:39 | [diff] [blame] | 171 | scoped_refptr<RegistrationInfo> registration_info, |
jianli | 7a0c9b6 | 2015-05-26 23:24:47 | [diff] [blame] | 172 | GCMClient::Result result) = 0; |
[email protected] | e400704 | 2014-02-15 20:34:28 | [diff] [blame] | 173 | |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 174 | // Called when the message is scheduled to send successfully or an error |
| 175 | // occurs. |
| 176 | // |app_id|: application ID. |
| 177 | // |message_id|: ID of the message being sent. |
| 178 | // |result|: the type of the error if an error occured, success otherwise. |
| 179 | virtual void OnSendFinished(const std::string& app_id, |
| 180 | const std::string& message_id, |
| 181 | Result result) = 0; |
| 182 | |
| 183 | // Called when a message has been received. |
| 184 | // |app_id|: application ID. |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 185 | // |message|: message received. |
| 186 | virtual void OnMessageReceived(const std::string& app_id, |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 187 | const IncomingMessage& message) = 0; |
| 188 | |
| 189 | // Called when some messages have been deleted from the server. |
| 190 | // |app_id|: application ID. |
| 191 | virtual void OnMessagesDeleted(const std::string& app_id) = 0; |
| 192 | |
| 193 | // Called when a message failed to send to the server. |
| 194 | // |app_id|: application ID. |
[email protected] | c6fe36b | 2014-03-11 10:58:12 | [diff] [blame] | 195 | // |send_error_detials|: Details of the send error event, like mesasge ID. |
| 196 | virtual void OnMessageSendError( |
| 197 | const std::string& app_id, |
| 198 | const SendErrorDetails& send_error_details) = 0; |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 199 | |
[email protected] | 292af2b2 | 2014-08-06 19:42:45 | [diff] [blame] | 200 | // Called when a message was acknowledged by the GCM server. |
| 201 | // |app_id|: application ID. |
| 202 | // |message_id|: ID of the acknowledged message. |
| 203 | virtual void OnSendAcknowledged(const std::string& app_id, |
| 204 | const std::string& message_id) = 0; |
| 205 | |
[email protected] | 86625df | 2014-01-31 03:47:58 | [diff] [blame] | 206 | // Called when the GCM becomes ready. To get to this state, GCMClient |
| 207 | // finished loading from the GCM store and retrieved the device check-in |
| 208 | // from the server if it hadn't yet. |
fgorski | d578c18b | 2014-09-24 23:40:17 | [diff] [blame] | 209 | // |account_mappings|: a persisted list of accounts mapped to this GCM |
| 210 | // client. |
fgorski | 5df10170 | 2014-10-28 02:09:31 | [diff] [blame] | 211 | // |last_token_fetch_time|: time of a last successful token fetch. |
| 212 | virtual void OnGCMReady(const std::vector<AccountMapping>& account_mappings, |
| 213 | const base::Time& last_token_fetch_time) = 0; |
[email protected] | 7de7880 | 2014-05-10 19:49:40 | [diff] [blame] | 214 | |
| 215 | // Called when activities are being recorded and a new activity has just |
| 216 | // been recorded. |
| 217 | virtual void OnActivityRecorded() = 0; |
[email protected] | fc6078a | 2014-06-14 08:28:43 | [diff] [blame] | 218 | |
| 219 | // Called when a new connection is established and a successful handshake |
| 220 | // has been performed. |
| 221 | virtual void OnConnected(const net::IPEndPoint& ip_endpoint) = 0; |
| 222 | |
| 223 | // Called when the connection is interrupted. |
| 224 | virtual void OnDisconnected() = 0; |
johnme | 93ec793 | 2016-11-17 14:26:58 | [diff] [blame] | 225 | |
| 226 | // Called when the GCM store is reset (e.g. due to corruption), which |
| 227 | // changes the device ID, invalidating all prior registrations. |
| 228 | virtual void OnStoreReset() = 0; |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 229 | }; |
| 230 | |
[email protected] | 0db11822 | 2014-01-22 01:37:59 | [diff] [blame] | 231 | GCMClient(); |
| 232 | virtual ~GCMClient(); |
[email protected] | 1b1c3cd | 2013-12-17 18:40:04 | [diff] [blame] | 233 | |
[email protected] | d3a4b2e | 2014-02-27 13:46:54 | [diff] [blame] | 234 | // Begins initialization of the GCM Client. This will not trigger a |
Steven Zhu | b36394c | 2019-06-04 16:10:46 | [diff] [blame] | 235 | // connection. Must be called on |io_task_runner|. |
[email protected] | 8ad8051 | 2014-05-23 09:40:47 | [diff] [blame] | 236 | // |chrome_build_info|: chrome info, i.e., version, channel and etc. |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 237 | // |store_path|: path to the GCM store. |
| 238 | // |blocking_task_runner|: for running blocking file tasks. |
Steven Zhu | b36394c | 2019-06-04 16:10:46 | [diff] [blame] | 239 | // |io_task_runner|: for running IO tasks. When provided, it could be a |
| 240 | // wrapper on top of base::ThreadTaskRunnerHandle::Get() to provide power |
| 241 | // management featueres so that a delayed task posted to it can wake the |
| 242 | // system up from sleep to perform the task. |
Julie Jeongeun Kim | 17b2adf1 | 2019-10-29 10:24:48 | [diff] [blame] | 243 | // |get_socket_factory_callback|: a callback that can accept a receiver for a |
Julie Jeongeun Kim | 5eb197a9 | 2019-11-01 02:02:06 | [diff] [blame] | 244 | // network::mojom::ProxyResolvingSocketFactory. It needs to be safe to |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 245 | // run on any thread. |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 246 | // |delegate|: the delegate whose methods will be called asynchronously in |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 247 | // response to events and messages. |
[email protected] | e2a4a801 | 2014-02-07 22:32:52 | [diff] [blame] | 248 | virtual void Initialize( |
[email protected] | 8ad8051 | 2014-05-23 09:40:47 | [diff] [blame] | 249 | const ChromeBuildInfo& chrome_build_info, |
[email protected] | e2a4a801 | 2014-02-07 22:32:52 | [diff] [blame] | 250 | const base::FilePath& store_path, |
| 251 | const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, |
Steven Zhu | b36394c | 2019-06-04 16:10:46 | [diff] [blame] | 252 | scoped_refptr<base::SequencedTaskRunner> io_task_runner, |
Julie Jeongeun Kim | 17b2adf1 | 2019-10-29 10:24:48 | [diff] [blame] | 253 | base::RepeatingCallback<void( |
| 254 | mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)> |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 255 | get_socket_factory_callback, |
Maks Orlovich | c70c93c | 2018-07-12 02:45:44 | [diff] [blame] | 256 | const scoped_refptr<network::SharedURLLoaderFactory>& url_loader_factory, |
Robbie McElrath | b0149933 | 2018-09-25 00:53:13 | [diff] [blame] | 257 | network::NetworkConnectionTracker* network_connection_tracker_, |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 258 | std::unique_ptr<Encryptor> encryptor, |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 259 | Delegate* delegate) = 0; |
[email protected] | e2a4a801 | 2014-02-07 22:32:52 | [diff] [blame] | 260 | |
jianli | f3e52af4 | 2015-01-21 23:18:47 | [diff] [blame] | 261 | // This will initiate the GCM connection only if |start_mode| means to start |
| 262 | // the GCM immediately or the GCM registration records are found in the store. |
| 263 | // Note that it is OK to call Start multiple times and the implementation |
| 264 | // should handle it gracefully. |
| 265 | virtual void Start(StartMode start_mode) = 0; |
[email protected] | d3a4b2e | 2014-02-27 13:46:54 | [diff] [blame] | 266 | |
[email protected] | 21fee548 | 2014-03-05 00:57:15 | [diff] [blame] | 267 | // Stops using the GCM service. This will not erase the persisted data. |
| 268 | virtual void Stop() = 0; |
| 269 | |
jianli | 7a0c9b6 | 2015-05-26 23:24:47 | [diff] [blame] | 270 | // Registers with the server to access the provided service. |
| 271 | // Delegate::OnRegisterFinished will be called asynchronously upon completion. |
| 272 | // |registration_info|: the specific information required for the |
| 273 | // registration. For GCM, it will contain app id and |
| 274 | // sender IDs. For InstanceID, it will contain app_id, |
| 275 | // authorized entity and scope. |
Rayan Kanso | 3da434f | 2018-12-19 17:09:39 | [diff] [blame] | 276 | virtual void Register(scoped_refptr<RegistrationInfo> registration_info) = 0; |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 277 | |
johnme | 6576ecf | 2017-04-03 19:26:28 | [diff] [blame] | 278 | // Checks that the provided |registration_id| (aka token for Instance ID |
| 279 | // registrations) matches the stored registration info. Also checks sender IDs |
| 280 | // match for GCM registrations. |
| 281 | virtual bool ValidateRegistration( |
Rayan Kanso | 3da434f | 2018-12-19 17:09:39 | [diff] [blame] | 282 | scoped_refptr<RegistrationInfo> registration_info, |
johnme | 6576ecf | 2017-04-03 19:26:28 | [diff] [blame] | 283 | const std::string& registration_id) = 0; |
| 284 | |
jianli | 7a0c9b6 | 2015-05-26 23:24:47 | [diff] [blame] | 285 | // Unregisters from the server to stop accessing the provided service. |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 286 | // Delegate::OnUnregisterFinished will be called asynchronously upon |
| 287 | // completion. |
jianli | 7a0c9b6 | 2015-05-26 23:24:47 | [diff] [blame] | 288 | // |registration_info|: the specific information required for the |
| 289 | // registration. For GCM, it will contain app id (sender |
| 290 | // IDs can be ingored). For InstanceID, it will contain |
| 291 | // app id, authorized entity and scope. |
| 292 | virtual void Unregister( |
Rayan Kanso | 3da434f | 2018-12-19 17:09:39 | [diff] [blame] | 293 | scoped_refptr<RegistrationInfo> registration_info) = 0; |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 294 | |
| 295 | // Sends a message to a given receiver. Delegate::OnSendFinished will be |
| 296 | // called asynchronously upon completion. |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 297 | // |app_id|: application ID. |
| 298 | // |receiver_id|: registration ID of the receiver party. |
| 299 | // |message|: message to be sent. |
[email protected] | 5799d05 | 2014-02-12 20:47:39 | [diff] [blame] | 300 | virtual void Send(const std::string& app_id, |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 301 | const std::string& receiver_id, |
| 302 | const OutgoingMessage& message) = 0; |
[email protected] | 3560181 | 2014-03-07 19:52:43 | [diff] [blame] | 303 | |
peter | 266a2aa4 | 2016-02-19 18:51:39 | [diff] [blame] | 304 | // Records a decryption failure due to |result| for the |app_id|. |
Peter Beverloo | a376e98c | 2017-06-27 15:55:37 | [diff] [blame] | 305 | virtual void RecordDecryptionFailure(const std::string& app_id, |
| 306 | GCMDecryptionResult result) = 0; |
peter | ee284ba5 | 2016-02-01 11:53:28 | [diff] [blame] | 307 | |
[email protected] | 436bcb8 | 2014-04-18 00:40:57 | [diff] [blame] | 308 | // Enables or disables internal activity recording. |
| 309 | virtual void SetRecording(bool recording) = 0; |
| 310 | |
| 311 | // Clear all recorded GCM activity logs. |
| 312 | virtual void ClearActivityLogs() = 0; |
| 313 | |
[email protected] | 3560181 | 2014-03-07 19:52:43 | [diff] [blame] | 314 | // Gets internal states and statistics. |
| 315 | virtual GCMStatistics GetStatistics() const = 0; |
[email protected] | 7df5ef2 | 2014-07-17 07:35:58 | [diff] [blame] | 316 | |
| 317 | // Sets a list of accounts with OAuth2 tokens for the next checkin. |
fgorski | 58b9dfc | 2014-09-29 16:46:18 | [diff] [blame] | 318 | // |account_tokens|: list of email addresses, account IDs and OAuth2 access |
| 319 | // tokens. |
| 320 | virtual void SetAccountTokens( |
| 321 | const std::vector<AccountTokenInfo>& account_tokens) = 0; |
[email protected] | 72d4f25 | 2014-08-20 22:34:28 | [diff] [blame] | 322 | |
| 323 | // Persists the |account_mapping| in the store. |
| 324 | virtual void UpdateAccountMapping(const AccountMapping& account_mapping) = 0; |
| 325 | |
| 326 | // Removes the account mapping related to |account_id| from the persistent |
| 327 | // store. |
Tanmoy Mollik | f6ec6b9 | 2019-08-12 16:19:55 | [diff] [blame] | 328 | virtual void RemoveAccountMapping(const CoreAccountId& account_id) = 0; |
fgorski | 5df10170 | 2014-10-28 02:09:31 | [diff] [blame] | 329 | |
| 330 | // Sets last token fetch time in persistent store. |
| 331 | virtual void SetLastTokenFetchTime(const base::Time& time) = 0; |
chirantan | 192a921 | 2014-12-06 03:30:45 | [diff] [blame] | 332 | |
| 333 | // Updates the timer used by the HeartbeatManager for sending heartbeats. |
tzik | b6c66b2 | 2018-07-06 12:14:16 | [diff] [blame] | 334 | virtual void UpdateHeartbeatTimer( |
| 335 | std::unique_ptr<base::RetainingOneShotTimer> timer) = 0; |
jianli | 10018b2d | 2015-05-11 21:14:13 | [diff] [blame] | 336 | |
| 337 | // Adds the Instance ID data for a specific app to the persistent store. |
| 338 | virtual void AddInstanceIDData(const std::string& app_id, |
jianli | 7a0c9b6 | 2015-05-26 23:24:47 | [diff] [blame] | 339 | const std::string& instance_id, |
| 340 | const std::string& extra_data) = 0; |
jianli | 10018b2d | 2015-05-11 21:14:13 | [diff] [blame] | 341 | |
| 342 | // Removes the Instance ID data for a specific app from the persistent store. |
| 343 | virtual void RemoveInstanceIDData(const std::string& app_id) = 0; |
| 344 | |
| 345 | // Retrieves the Instance ID data for a specific app from the persistent |
| 346 | // store. |
jianli | 7a0c9b6 | 2015-05-26 23:24:47 | [diff] [blame] | 347 | virtual void GetInstanceIDData(const std::string& app_id, |
| 348 | std::string* instance_id, |
| 349 | std::string* extra_data) = 0; |
fgorski | 2275446 | 2015-05-14 00:05:22 | [diff] [blame] | 350 | |
| 351 | // Gets and sets custom heartbeat interval for the MCS connection. |
| 352 | // |scope| is used to identify the component that requests a custom interval |
| 353 | // to be set, and allows that component to later revoke the setting. It should |
| 354 | // be unique. |
| 355 | virtual void AddHeartbeatInterval(const std::string& scope, |
| 356 | int interval_ms) = 0; |
| 357 | virtual void RemoveHeartbeatInterval(const std::string& scope) = 0; |
[email protected] | e4097c8 | 2013-11-08 00:16:12 | [diff] [blame] | 358 | }; |
| 359 | |
| 360 | } // namespace gcm |
| 361 | |
[email protected] | cd57f37 | 2014-06-09 17:13:06 | [diff] [blame] | 362 | #endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_H_ |