| 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 void AddHeartbeatInterval(const std::string& scope, int interval_ms) override; | 137 void AddHeartbeatInterval(const std::string& scope, int interval_ms) override; |
| 134 void RemoveHeartbeatInterval(const std::string& scope) override; | 138 void RemoveHeartbeatInterval(const std::string& scope) override; |
| 135 | 139 |
| 136 // GCMStatsRecorder::Delegate implemenation. | 140 // GCMStatsRecorder::Delegate implemenation. |
| 137 void OnActivityRecorded() override; | 141 void OnActivityRecorded() override; |
| 138 | 142 |
| 139 // ConnectionFactory::ConnectionListener implementation. | 143 // ConnectionFactory::ConnectionListener implementation. |
| 140 void OnConnected(const GURL& current_server, | 144 void OnConnected(const GURL& current_server, |
| 141 const net::IPEndPoint& ip_endpoint) override; | 145 const net::IPEndPoint& ip_endpoint) override; |
| 142 void OnDisconnected() override; | 146 void OnDisconnected() override; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 158 // True if accounts were already provided through SetAccountsForCheckin(), | 162 // True if accounts were already provided through SetAccountsForCheckin(), |
| 159 // or when |last_checkin_accounts| was loaded as empty. | 163 // or when |last_checkin_accounts| was loaded as empty. |
| 160 bool accounts_set; | 164 bool accounts_set; |
| 161 // Map of account email addresses and OAuth2 tokens that will be sent to the | 165 // Map of account email addresses and OAuth2 tokens that will be sent to the |
| 162 // checkin server on a next checkin. | 166 // checkin server on a next checkin. |
| 163 std::map<std::string, std::string> account_tokens; | 167 std::map<std::string, std::string> account_tokens; |
| 164 // As set of accounts last checkin was completed with. | 168 // As set of accounts last checkin was completed with. |
| 165 std::set<std::string> last_checkin_accounts; | 169 std::set<std::string> last_checkin_accounts; |
| 166 }; | 170 }; |
| 167 | 171 |
| 168 // Collection of pending registration requests. Keys are app IDs, while values | 172 // Collection of pending registration requests. Keys are RegistrationInfo |
| 169 // are pending registration requests to obtain a registration ID for | 173 // instance, while values are pending registration requests to obtain a |
| 170 // requesting application. | 174 // registration ID for requesting application. |
| 171 typedef std::map<std::string, RegistrationRequest*> | 175 typedef std::map<linked_ptr<RegistrationInfo>, |
| 172 PendingRegistrationRequests; | 176 RegistrationRequest*, |
| 177 RegistrationInfoComparer> PendingRegistrationRequests; |
| 173 | 178 |
| 174 // Collection of pending unregistration requests. Keys are app IDs, while | 179 // Collection of pending unregistration requests. Keys are RegistrationInfo |
| 175 // values are pending unregistration requests to disable the registration ID | 180 // instance, while values are pending unregistration requests to disable the |
| 176 // currently assigned to the application. | 181 // registration ID currently assigned to the application. |
| 177 typedef std::map<std::string, UnregistrationRequest*> | 182 typedef std::map<linked_ptr<RegistrationInfo>, |
| 178 PendingUnregistrationRequests; | 183 UnregistrationRequest*, |
| 184 RegistrationInfoComparer> PendingUnregistrationRequests; |
| 179 | 185 |
| 180 friend class GCMClientImplTest; | 186 friend class GCMClientImplTest; |
| 181 | 187 |
| 182 // Returns text representation of the enum State. | 188 // Returns text representation of the enum State. |
| 183 std::string GetStateString() const; | 189 std::string GetStateString() const; |
| 184 | 190 |
| 185 // Callbacks for the MCSClient. | 191 // Callbacks for the MCSClient. |
| 186 // Receives messages and dispatches them to relevant user delegates. | 192 // Receives messages and dispatches them to relevant user delegates. |
| 187 void OnMessageReceivedFromMCS(const gcm::MCSMessage& message); | 193 void OnMessageReceivedFromMCS(const gcm::MCSMessage& message); |
| 188 // Receives confirmation of sent messages or information about errors. | 194 // Receives confirmation of sent messages or information about errors. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // |gcm_store_| fails. | 246 // |gcm_store_| fails. |
| 241 void DefaultStoreCallback(bool success); | 247 void DefaultStoreCallback(bool success); |
| 242 | 248 |
| 243 // Callback for store operation where result does not matter. | 249 // Callback for store operation where result does not matter. |
| 244 void IgnoreWriteResultCallback(bool success); | 250 void IgnoreWriteResultCallback(bool success); |
| 245 | 251 |
| 246 // Callback for resetting the GCM store. | 252 // Callback for resetting the GCM store. |
| 247 void ResetStoreCallback(bool success); | 253 void ResetStoreCallback(bool success); |
| 248 | 254 |
| 249 // Completes the registration request. | 255 // Completes the registration request. |
| 250 void OnRegisterCompleted(const std::string& app_id, | 256 void OnRegisterCompleted( |
| 251 const std::vector<std::string>& sender_ids, | 257 const linked_ptr<RegistrationInfo>& registration_info, |
| 252 RegistrationRequest::Status status, | 258 RegistrationRequest::Status status, |
| 253 const std::string& registration_id); | 259 const std::string& registration_id); |
| 254 | 260 |
| 255 // Completes the unregistration request. | 261 // Completes the unregistration request. |
| 256 void OnUnregisterCompleted(const std::string& app_id, | 262 void OnUnregisterCompleted( |
| 257 UnregistrationRequest::Status status); | 263 const linked_ptr<RegistrationInfo>& registration_info, |
| 264 UnregistrationRequest::Status status); |
| 258 | 265 |
| 259 // Completes the GCM store destroy request. | 266 // Completes the GCM store destroy request. |
| 260 void OnGCMStoreDestroyed(bool success); | 267 void OnGCMStoreDestroyed(bool success); |
| 261 | 268 |
| 262 // Handles incoming data message and dispatches it the delegate of this class. | 269 // Handles incoming data message and dispatches it the delegate of this class. |
| 263 void HandleIncomingMessage(const gcm::MCSMessage& message); | 270 void HandleIncomingMessage(const gcm::MCSMessage& message); |
| 264 | 271 |
| 265 // Fires OnMessageReceived event on the delegate of this class, based on the | 272 // Fires OnMessageReceived event on the delegate of this class, based on the |
| 266 // details in |data_message_stanza| and |message_data|. | 273 // details in |data_message_stanza| and |message_data|. |
| 267 void HandleIncomingDataMessage( | 274 void HandleIncomingDataMessage( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 PendingUnregistrationRequests pending_unregistration_requests_; | 347 PendingUnregistrationRequests pending_unregistration_requests_; |
| 341 STLValueDeleter<PendingUnregistrationRequests> | 348 STLValueDeleter<PendingUnregistrationRequests> |
| 342 pending_unregistration_requests_deleter_; | 349 pending_unregistration_requests_deleter_; |
| 343 | 350 |
| 344 // G-services settings that were provided by MCS. | 351 // G-services settings that were provided by MCS. |
| 345 GServicesSettings gservices_settings_; | 352 GServicesSettings gservices_settings_; |
| 346 | 353 |
| 347 // Time of the last successful checkin. | 354 // Time of the last successful checkin. |
| 348 base::Time last_checkin_time_; | 355 base::Time last_checkin_time_; |
| 349 | 356 |
| 350 // Cached instance ID data, key is app id. | 357 // Cached instance ID data, key is app ID and value is pair of instance ID |
| 351 std::map<std::string, std::string> instance_id_data_; | 358 // and extra data. |
| 359 std::map<std::string, std::pair<std::string, std::string>> instance_id_data_; |
| 352 | 360 |
| 353 // Factory for creating references when scheduling periodic checkin. | 361 // Factory for creating references when scheduling periodic checkin. |
| 354 base::WeakPtrFactory<GCMClientImpl> periodic_checkin_ptr_factory_; | 362 base::WeakPtrFactory<GCMClientImpl> periodic_checkin_ptr_factory_; |
| 355 | 363 |
| 356 // Factory for creating references in callbacks. | 364 // Factory for creating references in callbacks. |
| 357 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; | 365 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; |
| 358 | 366 |
| 359 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); | 367 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); |
| 360 }; | 368 }; |
| 361 | 369 |
| 362 } // namespace gcm | 370 } // namespace gcm |
| 363 | 371 |
| 364 #endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ | 372 #endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ |
| OLD | NEW |