| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ | 5 #ifndef COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ |
| 6 #define COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ | 6 #define COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 17 #include "components/gcm_driver/gcm_client.h" | 18 #include "components/gcm_driver/gcm_client.h" |
| 18 #include "components/gcm_driver/gcm_stats_recorder_impl.h" | 19 #include "components/gcm_driver/gcm_stats_recorder_impl.h" |
| 19 #include "google_apis/gcm/base/mcs_message.h" | 20 #include "google_apis/gcm/base/mcs_message.h" |
| 20 #include "google_apis/gcm/engine/gcm_store.h" | 21 #include "google_apis/gcm/engine/gcm_store.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 void Initialize( | 105 void Initialize( |
| 105 const ChromeBuildInfo& chrome_build_info, | 106 const ChromeBuildInfo& chrome_build_info, |
| 106 const base::FilePath& store_path, | 107 const base::FilePath& store_path, |
| 107 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, | 108 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, |
| 108 const scoped_refptr<net::URLRequestContextGetter>& | 109 const scoped_refptr<net::URLRequestContextGetter>& |
| 109 url_request_context_getter, | 110 url_request_context_getter, |
| 110 scoped_ptr<Encryptor> encryptor, | 111 scoped_ptr<Encryptor> encryptor, |
| 111 GCMClient::Delegate* delegate) override; | 112 GCMClient::Delegate* delegate) override; |
| 112 void Start(StartMode start_mode) override; | 113 void Start(StartMode start_mode) override; |
| 113 void Stop() override; | 114 void Stop() override; |
| 114 void Register(const std::string& app_id, | 115 void Register(const linked_ptr<RegistrationInfo>& registration_info) override; |
| 115 const std::vector<std::string>& sender_ids) override; | 116 void Unregister( |
| 116 void Unregister(const std::string& app_id) override; | 117 const linked_ptr<RegistrationInfo>& registration_info) override; |
| 117 void Send(const std::string& app_id, | 118 void Send(const std::string& app_id, |
| 118 const std::string& receiver_id, | 119 const std::string& receiver_id, |
| 119 const OutgoingMessage& message) override; | 120 const OutgoingMessage& message) override; |
| 120 void SetRecording(bool recording) override; | 121 void SetRecording(bool recording) override; |
| 121 void ClearActivityLogs() override; | 122 void ClearActivityLogs() override; |
| 122 GCMStatistics GetStatistics() const override; | 123 GCMStatistics GetStatistics() const override; |
| 123 void SetAccountTokens( | 124 void SetAccountTokens( |
| 124 const std::vector<AccountTokenInfo>& account_tokens) override; | 125 const std::vector<AccountTokenInfo>& account_tokens) override; |
| 125 void UpdateAccountMapping(const AccountMapping& account_mapping) override; | 126 void UpdateAccountMapping(const AccountMapping& account_mapping) override; |
| 126 void RemoveAccountMapping(const std::string& account_id) override; | 127 void RemoveAccountMapping(const std::string& account_id) override; |
| 127 void SetLastTokenFetchTime(const base::Time& time) override; | 128 void SetLastTokenFetchTime(const base::Time& time) override; |
| 128 void UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) override; | 129 void UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) override; |
| 129 void AddInstanceIDData(const std::string& app_id, | 130 void AddInstanceIDData(const std::string& app_id, |
| 130 const std::string& instance_id_data) override; | 131 const std::string& instance_id, |
| 132 const std::string& extra_data) override; |
| 131 void RemoveInstanceIDData(const std::string& app_id) override; | 133 void RemoveInstanceIDData(const std::string& app_id) override; |
| 132 std::string GetInstanceIDData(const std::string& app_id) override; | 134 void GetInstanceIDData(const std::string& app_id, |
| 135 std::string* instance_id, |
| 136 std::string* extra_data) override; |
| 133 | 137 |
| 134 // GCMStatsRecorder::Delegate implemenation. | 138 // GCMStatsRecorder::Delegate implemenation. |
| 135 void OnActivityRecorded() override; | 139 void OnActivityRecorded() override; |
| 136 | 140 |
| 137 // ConnectionFactory::ConnectionListener implementation. | 141 // ConnectionFactory::ConnectionListener implementation. |
| 138 void OnConnected(const GURL& current_server, | 142 void OnConnected(const GURL& current_server, |
| 139 const net::IPEndPoint& ip_endpoint) override; | 143 const net::IPEndPoint& ip_endpoint) override; |
| 140 void OnDisconnected() override; | 144 void OnDisconnected() override; |
| 141 | 145 |
| 142 private: | 146 private: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 156 // True if accounts were already provided through SetAccountsForCheckin(), | 160 // True if accounts were already provided through SetAccountsForCheckin(), |
| 157 // or when |last_checkin_accounts| was loaded as empty. | 161 // or when |last_checkin_accounts| was loaded as empty. |
| 158 bool accounts_set; | 162 bool accounts_set; |
| 159 // Map of account email addresses and OAuth2 tokens that will be sent to the | 163 // Map of account email addresses and OAuth2 tokens that will be sent to the |
| 160 // checkin server on a next checkin. | 164 // checkin server on a next checkin. |
| 161 std::map<std::string, std::string> account_tokens; | 165 std::map<std::string, std::string> account_tokens; |
| 162 // As set of accounts last checkin was completed with. | 166 // As set of accounts last checkin was completed with. |
| 163 std::set<std::string> last_checkin_accounts; | 167 std::set<std::string> last_checkin_accounts; |
| 164 }; | 168 }; |
| 165 | 169 |
| 166 // Collection of pending registration requests. Keys are app IDs, while values | 170 // Collection of pending registration requests. Keys are RegistrationInfo |
| 167 // are pending registration requests to obtain a registration ID for | 171 // instance, while values are pending registration requests to obtain a |
| 168 // requesting application. | 172 // registration ID for requesting application. |
| 169 typedef std::map<std::string, RegistrationRequest*> | 173 typedef std::map<linked_ptr<RegistrationInfo>, |
| 170 PendingRegistrationRequests; | 174 RegistrationRequest*, |
| 175 RegistrationInfoComparer> PendingRegistrationRequests; |
| 171 | 176 |
| 172 // Collection of pending unregistration requests. Keys are app IDs, while | 177 // Collection of pending unregistration requests. Keys are RegistrationInfo |
| 173 // values are pending unregistration requests to disable the registration ID | 178 // instance, while values are pending unregistration requests to disable the |
| 174 // currently assigned to the application. | 179 // registration ID currently assigned to the application. |
| 175 typedef std::map<std::string, UnregistrationRequest*> | 180 typedef std::map<linked_ptr<RegistrationInfo>, |
| 176 PendingUnregistrationRequests; | 181 UnregistrationRequest*, |
| 182 RegistrationInfoComparer> PendingUnregistrationRequests; |
| 177 | 183 |
| 178 friend class GCMClientImplTest; | 184 friend class GCMClientImplTest; |
| 179 | 185 |
| 180 // Returns text representation of the enum State. | 186 // Returns text representation of the enum State. |
| 181 std::string GetStateString() const; | 187 std::string GetStateString() const; |
| 182 | 188 |
| 189 // Builds RequestInfo that is passed to registration/unregistration requests. |
| 190 scoped_ptr<RegistrationRequest::RequestInfo> |
| 191 BuildRegistrationRequestInfo( |
| 192 const RegistrationInfo& registration_info) const; |
| 193 scoped_ptr<UnregistrationRequest::RequestInfo> |
| 194 BuildUnregistrationRequestInfo( |
| 195 const RegistrationInfo& registration_info) const; |
| 196 |
| 183 // Callbacks for the MCSClient. | 197 // Callbacks for the MCSClient. |
| 184 // Receives messages and dispatches them to relevant user delegates. | 198 // Receives messages and dispatches them to relevant user delegates. |
| 185 void OnMessageReceivedFromMCS(const gcm::MCSMessage& message); | 199 void OnMessageReceivedFromMCS(const gcm::MCSMessage& message); |
| 186 // Receives confirmation of sent messages or information about errors. | 200 // Receives confirmation of sent messages or information about errors. |
| 187 void OnMessageSentToMCS(int64 user_serial_number, | 201 void OnMessageSentToMCS(int64 user_serial_number, |
| 188 const std::string& app_id, | 202 const std::string& app_id, |
| 189 const std::string& message_id, | 203 const std::string& message_id, |
| 190 MCSClient::MessageSendStatus status); | 204 MCSClient::MessageSendStatus status); |
| 191 // Receives information about mcs_client_ errors. | 205 // Receives information about mcs_client_ errors. |
| 192 void OnMCSError(); | 206 void OnMCSError(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // |gcm_store_| fails. | 252 // |gcm_store_| fails. |
| 239 void DefaultStoreCallback(bool success); | 253 void DefaultStoreCallback(bool success); |
| 240 | 254 |
| 241 // Callback for store operation where result does not matter. | 255 // Callback for store operation where result does not matter. |
| 242 void IgnoreWriteResultCallback(bool success); | 256 void IgnoreWriteResultCallback(bool success); |
| 243 | 257 |
| 244 // Callback for resetting the GCM store. | 258 // Callback for resetting the GCM store. |
| 245 void ResetStoreCallback(bool success); | 259 void ResetStoreCallback(bool success); |
| 246 | 260 |
| 247 // Completes the registration request. | 261 // Completes the registration request. |
| 248 void OnRegisterCompleted(const std::string& app_id, | 262 void OnRegisterCompleted( |
| 249 const std::vector<std::string>& sender_ids, | 263 const linked_ptr<RegistrationInfo>& registration_info, |
| 250 RegistrationRequest::Status status, | 264 RegistrationRequest::Status status, |
| 251 const std::string& registration_id); | 265 const std::string& registration_id); |
| 252 | 266 |
| 253 // Completes the unregistration request. | 267 // Completes the unregistration request. |
| 254 void OnUnregisterCompleted(const std::string& app_id, | 268 void OnUnregisterCompleted( |
| 255 UnregistrationRequest::Status status); | 269 const linked_ptr<RegistrationInfo>& registration_info, |
| 270 UnregistrationRequest::Status status); |
| 256 | 271 |
| 257 // Completes the GCM store destroy request. | 272 // Completes the GCM store destroy request. |
| 258 void OnGCMStoreDestroyed(bool success); | 273 void OnGCMStoreDestroyed(bool success); |
| 259 | 274 |
| 260 // Handles incoming data message and dispatches it the delegate of this class. | 275 // Handles incoming data message and dispatches it the delegate of this class. |
| 261 void HandleIncomingMessage(const gcm::MCSMessage& message); | 276 void HandleIncomingMessage(const gcm::MCSMessage& message); |
| 262 | 277 |
| 263 // Fires OnMessageReceived event on the delegate of this class, based on the | 278 // Fires OnMessageReceived event on the delegate of this class, based on the |
| 264 // details in |data_message_stanza| and |message_data|. | 279 // details in |data_message_stanza| and |message_data|. |
| 265 void HandleIncomingDataMessage( | 280 void HandleIncomingDataMessage( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 PendingUnregistrationRequests pending_unregistration_requests_; | 353 PendingUnregistrationRequests pending_unregistration_requests_; |
| 339 STLValueDeleter<PendingUnregistrationRequests> | 354 STLValueDeleter<PendingUnregistrationRequests> |
| 340 pending_unregistration_requests_deleter_; | 355 pending_unregistration_requests_deleter_; |
| 341 | 356 |
| 342 // G-services settings that were provided by MCS. | 357 // G-services settings that were provided by MCS. |
| 343 GServicesSettings gservices_settings_; | 358 GServicesSettings gservices_settings_; |
| 344 | 359 |
| 345 // Time of the last successful checkin. | 360 // Time of the last successful checkin. |
| 346 base::Time last_checkin_time_; | 361 base::Time last_checkin_time_; |
| 347 | 362 |
| 348 // Cached instance ID data, key is app id. | 363 // Cached instance ID data, key is app ID and value is pair of instance ID |
| 349 std::map<std::string, std::string> instance_id_data_; | 364 // and extra data. |
| 365 std::map<std::string, std::pair<std::string, std::string>> instance_id_data_; |
| 350 | 366 |
| 351 // Factory for creating references when scheduling periodic checkin. | 367 // Factory for creating references when scheduling periodic checkin. |
| 352 base::WeakPtrFactory<GCMClientImpl> periodic_checkin_ptr_factory_; | 368 base::WeakPtrFactory<GCMClientImpl> periodic_checkin_ptr_factory_; |
| 353 | 369 |
| 354 // Factory for creating references in callbacks. | 370 // Factory for creating references in callbacks. |
| 355 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; | 371 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; |
| 356 | 372 |
| 357 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); | 373 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); |
| 358 }; | 374 }; |
| 359 | 375 |
| 360 } // namespace gcm | 376 } // namespace gcm |
| 361 | 377 |
| 362 #endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ | 378 #endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ |
| OLD | NEW |