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> |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 void Initialize( | 104 void Initialize( |
105 const ChromeBuildInfo& chrome_build_info, | 105 const ChromeBuildInfo& chrome_build_info, |
106 const base::FilePath& store_path, | 106 const base::FilePath& store_path, |
107 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, | 107 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, |
108 const scoped_refptr<net::URLRequestContextGetter>& | 108 const scoped_refptr<net::URLRequestContextGetter>& |
109 url_request_context_getter, | 109 url_request_context_getter, |
110 scoped_ptr<Encryptor> encryptor, | 110 scoped_ptr<Encryptor> encryptor, |
111 GCMClient::Delegate* delegate) override; | 111 GCMClient::Delegate* delegate) override; |
112 void Start(StartMode start_mode) override; | 112 void Start(StartMode start_mode) override; |
113 void Stop() override; | 113 void Stop() override; |
114 void Register(const std::string& app_id, | 114 void Register(const linked_ptr<RegistrationInfo>& registration_info) override; |
115 const std::vector<std::string>& sender_ids) override; | 115 void Unregister( |
116 void Unregister(const std::string& app_id) override; | 116 const linked_ptr<RegistrationInfo>& registration_info) override; |
117 void Send(const std::string& app_id, | 117 void Send(const std::string& app_id, |
118 const std::string& receiver_id, | 118 const std::string& receiver_id, |
119 const OutgoingMessage& message) override; | 119 const OutgoingMessage& message) override; |
120 void SetRecording(bool recording) override; | 120 void SetRecording(bool recording) override; |
121 void ClearActivityLogs() override; | 121 void ClearActivityLogs() override; |
122 GCMStatistics GetStatistics() const override; | 122 GCMStatistics GetStatistics() const override; |
123 void SetAccountTokens( | 123 void SetAccountTokens( |
124 const std::vector<AccountTokenInfo>& account_tokens) override; | 124 const std::vector<AccountTokenInfo>& account_tokens) override; |
125 void UpdateAccountMapping(const AccountMapping& account_mapping) override; | 125 void UpdateAccountMapping(const AccountMapping& account_mapping) override; |
126 void RemoveAccountMapping(const std::string& account_id) override; | 126 void RemoveAccountMapping(const std::string& account_id) override; |
(...skipping 29 matching lines...) Expand all Loading... |
156 // True if accounts were already provided through SetAccountsForCheckin(), | 156 // True if accounts were already provided through SetAccountsForCheckin(), |
157 // or when |last_checkin_accounts| was loaded as empty. | 157 // or when |last_checkin_accounts| was loaded as empty. |
158 bool accounts_set; | 158 bool accounts_set; |
159 // Map of account email addresses and OAuth2 tokens that will be sent to the | 159 // Map of account email addresses and OAuth2 tokens that will be sent to the |
160 // checkin server on a next checkin. | 160 // checkin server on a next checkin. |
161 std::map<std::string, std::string> account_tokens; | 161 std::map<std::string, std::string> account_tokens; |
162 // As set of accounts last checkin was completed with. | 162 // As set of accounts last checkin was completed with. |
163 std::set<std::string> last_checkin_accounts; | 163 std::set<std::string> last_checkin_accounts; |
164 }; | 164 }; |
165 | 165 |
166 // Collection of pending registration requests. Keys are app IDs, while values | 166 // Collection of pending registration requests. Keys are RegistrationInfo |
167 // are pending registration requests to obtain a registration ID for | 167 // instance, while values are pending registration requests to obtain a |
168 // requesting application. | 168 // registration ID for requesting application. |
169 typedef std::map<std::string, RegistrationRequest*> | 169 typedef std::map<linked_ptr<RegistrationInfo>, |
170 PendingRegistrationRequests; | 170 RegistrationRequest*, |
| 171 RegistrationInfoComparer> PendingRegistrationRequests; |
171 | 172 |
172 // Collection of pending unregistration requests. Keys are app IDs, while | 173 // Collection of pending unregistration requests. Keys are RegistrationInfo |
173 // values are pending unregistration requests to disable the registration ID | 174 // instance, while values are pending unregistration requests to disable the |
174 // currently assigned to the application. | 175 // registration ID currently assigned to the application. |
175 typedef std::map<std::string, UnregistrationRequest*> | 176 typedef std::map<linked_ptr<RegistrationInfo>, |
176 PendingUnregistrationRequests; | 177 UnregistrationRequest*, |
| 178 RegistrationInfoComparer> PendingUnregistrationRequests; |
177 | 179 |
178 friend class GCMClientImplTest; | 180 friend class GCMClientImplTest; |
179 | 181 |
180 // Returns text representation of the enum State. | 182 // Returns text representation of the enum State. |
181 std::string GetStateString() const; | 183 std::string GetStateString() const; |
182 | 184 |
| 185 // Builds RequestInfo that is passed to registration/unregistration requests. |
| 186 scoped_ptr<RegistrationRequest::RequestInfo> |
| 187 BuildRegistrationRequestInfo( |
| 188 const RegistrationInfo& registration_info) const; |
| 189 scoped_ptr<UnregistrationRequest::RequestInfo> |
| 190 BuildUnregistrationRequestInfo( |
| 191 const RegistrationInfo& registration_info) const; |
| 192 |
183 // Callbacks for the MCSClient. | 193 // Callbacks for the MCSClient. |
184 // Receives messages and dispatches them to relevant user delegates. | 194 // Receives messages and dispatches them to relevant user delegates. |
185 void OnMessageReceivedFromMCS(const gcm::MCSMessage& message); | 195 void OnMessageReceivedFromMCS(const gcm::MCSMessage& message); |
186 // Receives confirmation of sent messages or information about errors. | 196 // Receives confirmation of sent messages or information about errors. |
187 void OnMessageSentToMCS(int64 user_serial_number, | 197 void OnMessageSentToMCS(int64 user_serial_number, |
188 const std::string& app_id, | 198 const std::string& app_id, |
189 const std::string& message_id, | 199 const std::string& message_id, |
190 MCSClient::MessageSendStatus status); | 200 MCSClient::MessageSendStatus status); |
191 // Receives information about mcs_client_ errors. | 201 // Receives information about mcs_client_ errors. |
192 void OnMCSError(); | 202 void OnMCSError(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // |gcm_store_| fails. | 248 // |gcm_store_| fails. |
239 void DefaultStoreCallback(bool success); | 249 void DefaultStoreCallback(bool success); |
240 | 250 |
241 // Callback for store operation where result does not matter. | 251 // Callback for store operation where result does not matter. |
242 void IgnoreWriteResultCallback(bool success); | 252 void IgnoreWriteResultCallback(bool success); |
243 | 253 |
244 // Callback for resetting the GCM store. | 254 // Callback for resetting the GCM store. |
245 void ResetStoreCallback(bool success); | 255 void ResetStoreCallback(bool success); |
246 | 256 |
247 // Completes the registration request. | 257 // Completes the registration request. |
248 void OnRegisterCompleted(const std::string& app_id, | 258 void OnRegisterCompleted( |
249 const std::vector<std::string>& sender_ids, | 259 const linked_ptr<RegistrationInfo>& registration_info, |
250 RegistrationRequest::Status status, | 260 RegistrationRequest::Status status, |
251 const std::string& registration_id); | 261 const std::string& registration_id); |
252 | 262 |
253 // Completes the unregistration request. | 263 // Completes the unregistration request. |
254 void OnUnregisterCompleted(const std::string& app_id, | 264 void OnUnregisterCompleted( |
255 UnregistrationRequest::Status status); | 265 const linked_ptr<RegistrationInfo>& registration_info, |
| 266 UnregistrationRequest::Status status); |
256 | 267 |
257 // Completes the GCM store destroy request. | 268 // Completes the GCM store destroy request. |
258 void OnGCMStoreDestroyed(bool success); | 269 void OnGCMStoreDestroyed(bool success); |
259 | 270 |
260 // Handles incoming data message and dispatches it the delegate of this class. | 271 // Handles incoming data message and dispatches it the delegate of this class. |
261 void HandleIncomingMessage(const gcm::MCSMessage& message); | 272 void HandleIncomingMessage(const gcm::MCSMessage& message); |
262 | 273 |
263 // Fires OnMessageReceived event on the delegate of this class, based on the | 274 // Fires OnMessageReceived event on the delegate of this class, based on the |
264 // details in |data_message_stanza| and |message_data|. | 275 // details in |data_message_stanza| and |message_data|. |
265 void HandleIncomingDataMessage( | 276 void HandleIncomingDataMessage( |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 364 |
354 // Factory for creating references in callbacks. | 365 // Factory for creating references in callbacks. |
355 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; | 366 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; |
356 | 367 |
357 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); | 368 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); |
358 }; | 369 }; |
359 | 370 |
360 } // namespace gcm | 371 } // namespace gcm |
361 | 372 |
362 #endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ | 373 #endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ |
OLD | NEW |