OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 GOOGLE_APIS_GCM_GCM_CLIENT_IMPL_H_ | 5 #ifndef GOOGLE_APIS_GCM_GCM_CLIENT_IMPL_H_ |
6 #define GOOGLE_APIS_GCM_GCM_CLIENT_IMPL_H_ | 6 #define GOOGLE_APIS_GCM_GCM_CLIENT_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "google_apis/gcm/base/mcs_message.h" | 16 #include "google_apis/gcm/base/mcs_message.h" |
17 #include "google_apis/gcm/engine/gcm_store.h" | 17 #include "google_apis/gcm/engine/gcm_store.h" |
18 #include "google_apis/gcm/engine/mcs_client.h" | 18 #include "google_apis/gcm/engine/mcs_client.h" |
19 #include "google_apis/gcm/engine/registration_request.h" | 19 #include "google_apis/gcm/engine/registration_request.h" |
20 #include "google_apis/gcm/engine/unregistration_request.h" | 20 #include "google_apis/gcm/engine/unregistration_request.h" |
21 #include "google_apis/gcm/gcm_client.h" | 21 #include "google_apis/gcm/gcm_client.h" |
22 #include "google_apis/gcm/protocol/checkin.pb.h" | 22 #include "google_apis/gcm/protocol/android_checkin.pb.h" |
23 #include "net/base/net_log.h" | 23 #include "net/base/net_log.h" |
24 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
25 | 25 |
26 class GURL; | 26 class GURL; |
27 | 27 |
28 namespace base { | 28 namespace base { |
29 class Clock; | 29 class Clock; |
30 } // namespace base | 30 } // namespace base |
31 | 31 |
32 namespace net { | 32 namespace net { |
33 class HttpNetworkSession; | 33 class HttpNetworkSession; |
34 } // namespace net | 34 } // namespace net |
35 | 35 |
36 namespace gcm { | 36 namespace gcm { |
37 | 37 |
38 class CheckinRequest; | 38 class CheckinRequest; |
39 class ConnectionFactory; | 39 class ConnectionFactory; |
40 class GCMClientImplTest; | 40 class GCMClientImplTest; |
41 | 41 |
42 // Map with GServices settings. | |
43 // TODO(fgorski): Extract services handling to a separate struct/class. | |
44 typedef std::map<std::string, std::string> GServicesSettingsMap; | |
45 | |
46 // Helper class for building GCM internals. Allows tests to inject fake versions | 42 // Helper class for building GCM internals. Allows tests to inject fake versions |
47 // as necessary. | 43 // as necessary. |
48 class GCM_EXPORT GCMInternalsBuilder { | 44 class GCM_EXPORT GCMInternalsBuilder { |
49 public: | 45 public: |
50 GCMInternalsBuilder(); | 46 GCMInternalsBuilder(); |
51 virtual ~GCMInternalsBuilder(); | 47 virtual ~GCMInternalsBuilder(); |
52 | 48 |
53 virtual scoped_ptr<base::Clock> BuildClock(); | 49 virtual scoped_ptr<base::Clock> BuildClock(); |
54 virtual scoped_ptr<MCSClient> BuildMCSClient( | 50 virtual scoped_ptr<MCSClient> BuildMCSClient( |
55 const std::string& version, | 51 const std::string& version, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // Starts a login on mcs_client_. | 156 // Starts a login on mcs_client_. |
161 void StartMCSLogin(); | 157 void StartMCSLogin(); |
162 // Resets state to before initialization. | 158 // Resets state to before initialization. |
163 void ResetState(); | 159 void ResetState(); |
164 // Sets state to ready. This will initiate the MCS login and notify the | 160 // Sets state to ready. This will initiate the MCS login and notify the |
165 // delegates. | 161 // delegates. |
166 void OnReady(); | 162 void OnReady(); |
167 | 163 |
168 // Starts a first time device checkin. | 164 // Starts a first time device checkin. |
169 void StartCheckin(); | 165 void StartCheckin(); |
170 // Completes the device checkin request by parsing the |checkin_response|. | 166 // Completes the device checkin request. |
171 // Function also cleans up the pending checkin. | 167 // |android_id| and |security_token| are expected to be non-zero or an error |
172 void OnCheckinCompleted( | 168 // is triggered. Function also cleans up the pending checkin. |
173 const checkin_proto::AndroidCheckinResponse& checkin_response); | 169 void OnCheckinCompleted(uint64 android_id, |
174 // Schedules next device checkin, based on |last_checkin_time| and | 170 uint64 security_token); |
175 // checkin_interval specified in GServices settings. | 171 // Schedules next device checkin, based on |last_checkin_time| and default |
| 172 // checkin interval. |
176 void SchedulePeriodicCheckin(const base::Time& last_checkin_time); | 173 void SchedulePeriodicCheckin(const base::Time& last_checkin_time); |
177 // Callback for setting last checkin time in the |gcm_store_|. | 174 // Callback for setting last checkin time in the |gcm_store_|. |
178 void SetLastCheckinTimeCallback(bool success); | 175 void SetLastCheckinTimeCallback(bool success); |
179 | 176 |
180 // Callback for persisting device credentials in the |gcm_store_|. | 177 // Callback for persisting device credentials in the |gcm_store_|. |
181 void SetDeviceCredentialsCallback(bool success); | 178 void SetDeviceCredentialsCallback(bool success); |
182 | 179 |
183 // Callback for persisting registration info in the |gcm_store_|. | 180 // Callback for persisting registration info in the |gcm_store_|. |
184 void UpdateRegistrationCallback(bool success); | 181 void UpdateRegistrationCallback(bool success); |
185 | 182 |
(...skipping 18 matching lines...) Expand all Loading... |
204 void HandleIncomingDataMessage( | 201 void HandleIncomingDataMessage( |
205 const mcs_proto::DataMessageStanza& data_message_stanza, | 202 const mcs_proto::DataMessageStanza& data_message_stanza, |
206 MessageData& message_data); | 203 MessageData& message_data); |
207 | 204 |
208 // Fires OnMessageSendError event on the delegate of this calss, based on the | 205 // Fires OnMessageSendError event on the delegate of this calss, based on the |
209 // details in |data_message_stanza| and |message_data|. | 206 // details in |data_message_stanza| and |message_data|. |
210 void HandleIncomingSendError( | 207 void HandleIncomingSendError( |
211 const mcs_proto::DataMessageStanza& data_message_stanza, | 208 const mcs_proto::DataMessageStanza& data_message_stanza, |
212 MessageData& message_data); | 209 MessageData& message_data); |
213 | 210 |
214 // Updates the G-services settings based on the |checkin_response|. It assumes | |
215 // base::Time::Now() is the checkin time. | |
216 void UpdateGServicesSettings( | |
217 const checkin_proto::AndroidCheckinResponse& checkin_response); | |
218 // Completes the G-services settings update request. | |
219 void UpdateGServicesSettingsCallback(bool success); | |
220 | |
221 // Builder for the GCM internals (mcs client, etc.). | 211 // Builder for the GCM internals (mcs client, etc.). |
222 scoped_ptr<GCMInternalsBuilder> internals_builder_; | 212 scoped_ptr<GCMInternalsBuilder> internals_builder_; |
223 | 213 |
224 // State of the GCM Client Implementation. | 214 // State of the GCM Client Implementation. |
225 State state_; | 215 State state_; |
226 | 216 |
227 Delegate* delegate_; | 217 Delegate* delegate_; |
228 | 218 |
229 // Device checkin info (android ID and security token used by device). | 219 // Device checkin info (android ID and security token used by device). |
230 CheckinInfo device_checkin_info_; | 220 CheckinInfo device_checkin_info_; |
231 | 221 |
232 // Clock used for timing of retry logic. Passed in for testing. Owned by | 222 // Clock used for timing of retry logic. Passed in for testing. Owned by |
233 // GCMClientImpl. | 223 // GCMClientImpl. |
234 scoped_ptr<base::Clock> clock_; | 224 scoped_ptr<base::Clock> clock_; |
235 | 225 |
236 // Information about the chrome build. | 226 // Information about the chrome build. |
237 // TODO(fgorski): Check if it can be passed in constructor and made const. | 227 // TODO(fgorski): Check if it can be passed in constructor and made const. |
238 checkin_proto::ChromeBuildProto chrome_build_proto_; | 228 checkin_proto::ChromeBuildProto chrome_build_proto_; |
239 | 229 |
240 // Persistent data store for keeping device credentials, messages and user to | 230 // Persistent data store for keeping device credentials, messages and user to |
241 // serial number mappings. | 231 // serial number mappings. |
242 scoped_ptr<GCMStore> gcm_store_; | 232 scoped_ptr<GCMStore> gcm_store_; |
243 | 233 |
244 scoped_refptr<net::HttpNetworkSession> network_session_; | 234 scoped_refptr<net::HttpNetworkSession> network_session_; |
245 net::BoundNetLog net_log_; | 235 net::BoundNetLog net_log_; |
246 scoped_ptr<ConnectionFactory> connection_factory_; | 236 scoped_ptr<ConnectionFactory> connection_factory_; |
247 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 237 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
248 | 238 |
249 // Map with GServices settings, such us checkin_interval, checkin_url, etc. | |
250 GServicesSettingsMap gservices_settings_; | |
251 | |
252 // Digest of the |gservices_settings|. | |
253 std::string gservices_digest_; | |
254 | |
255 // Controls receiving and sending of packets and reliable message queueing. | 239 // Controls receiving and sending of packets and reliable message queueing. |
256 scoped_ptr<MCSClient> mcs_client_; | 240 scoped_ptr<MCSClient> mcs_client_; |
257 | 241 |
258 scoped_ptr<CheckinRequest> checkin_request_; | 242 scoped_ptr<CheckinRequest> checkin_request_; |
259 std::vector<std::string> account_ids_; | 243 std::vector<std::string> account_ids_; |
260 | 244 |
261 // Cached registration info. | 245 // Cached registration info. |
262 RegistrationInfoMap registrations_; | 246 RegistrationInfoMap registrations_; |
263 | 247 |
264 // Currently pending registration requests. GCMClientImpl owns the | 248 // Currently pending registration requests. GCMClientImpl owns the |
(...skipping 10 matching lines...) Expand all Loading... |
275 | 259 |
276 // Factory for creating references in callbacks. | 260 // Factory for creating references in callbacks. |
277 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; | 261 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; |
278 | 262 |
279 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); | 263 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); |
280 }; | 264 }; |
281 | 265 |
282 } // namespace gcm | 266 } // namespace gcm |
283 | 267 |
284 #endif // GOOGLE_APIS_GCM_GCM_CLIENT_IMPL_H_ | 268 #endif // GOOGLE_APIS_GCM_GCM_CLIENT_IMPL_H_ |
OLD | NEW |