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/android_checkin.pb.h" | 22 #include "google_apis/gcm/protocol/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 typedef std::map<std::string, std::string> GServicesSettingsMap; |
| 44 |
42 // Helper class for building GCM internals. Allows tests to inject fake versions | 45 // Helper class for building GCM internals. Allows tests to inject fake versions |
43 // as necessary. | 46 // as necessary. |
44 class GCM_EXPORT GCMInternalsBuilder { | 47 class GCM_EXPORT GCMInternalsBuilder { |
45 public: | 48 public: |
46 GCMInternalsBuilder(); | 49 GCMInternalsBuilder(); |
47 virtual ~GCMInternalsBuilder(); | 50 virtual ~GCMInternalsBuilder(); |
48 | 51 |
49 virtual scoped_ptr<base::Clock> BuildClock(); | 52 virtual scoped_ptr<base::Clock> BuildClock(); |
50 virtual scoped_ptr<MCSClient> BuildMCSClient( | 53 virtual scoped_ptr<MCSClient> BuildMCSClient( |
51 const std::string& version, | 54 const std::string& version, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // Starts a login on mcs_client_. | 159 // Starts a login on mcs_client_. |
157 void StartMCSLogin(); | 160 void StartMCSLogin(); |
158 // Resets state to before initialization. | 161 // Resets state to before initialization. |
159 void ResetState(); | 162 void ResetState(); |
160 // Sets state to ready. This will initiate the MCS login and notify the | 163 // Sets state to ready. This will initiate the MCS login and notify the |
161 // delegates. | 164 // delegates. |
162 void OnReady(); | 165 void OnReady(); |
163 | 166 |
164 // Starts a first time device checkin. | 167 // Starts a first time device checkin. |
165 void StartCheckin(const CheckinInfo& checkin_info); | 168 void StartCheckin(const CheckinInfo& checkin_info); |
166 // Completes the device checkin request. | 169 // Completes the device checkin request by parsing the |checkin_response|. |
167 // |android_id| and |security_token| are expected to be non-zero or an error | 170 // Function also cleans up the pending checkin. |
168 // is triggered. Function also cleans up the pending checkin. | 171 void OnCheckinCompleted( |
169 void OnCheckinCompleted(uint64 android_id, | 172 const checkin_proto::AndroidCheckinResponse& checkin_response); |
170 uint64 security_token); | 173 // Schedules next device checkin, based on |last_checkin_time| and |
| 174 // checkin_interval specified in GServices settings. |
| 175 void SchedulePeriodicCheckin(const base::Time& last_checkin_time, |
| 176 const CheckinInfo& checkin_info); |
171 | 177 |
172 // Callback for persisting device credentials in the |gcm_store_|. | 178 // Callback for persisting device credentials in the |gcm_store_|. |
173 void SetDeviceCredentialsCallback(bool success); | 179 void SetDeviceCredentialsCallback(bool success); |
174 | 180 |
175 // Callback for persisting registration info in the |gcm_store_|. | 181 // Callback for persisting registration info in the |gcm_store_|. |
176 void UpdateRegistrationCallback(bool success); | 182 void UpdateRegistrationCallback(bool success); |
177 | 183 |
178 // Completes the registration request. | 184 // Completes the registration request. |
179 void OnRegisterCompleted(const std::string& app_id, | 185 void OnRegisterCompleted(const std::string& app_id, |
180 const std::vector<std::string>& sender_ids, | 186 const std::vector<std::string>& sender_ids, |
(...skipping 15 matching lines...) Expand all Loading... |
196 void HandleIncomingDataMessage( | 202 void HandleIncomingDataMessage( |
197 const mcs_proto::DataMessageStanza& data_message_stanza, | 203 const mcs_proto::DataMessageStanza& data_message_stanza, |
198 MessageData& message_data); | 204 MessageData& message_data); |
199 | 205 |
200 // Fires OnMessageSendError event on the delegate of this calss, based on the | 206 // Fires OnMessageSendError event on the delegate of this calss, based on the |
201 // details in |data_message_stanza| and |message_data|. | 207 // details in |data_message_stanza| and |message_data|. |
202 void HandleIncomingSendError( | 208 void HandleIncomingSendError( |
203 const mcs_proto::DataMessageStanza& data_message_stanza, | 209 const mcs_proto::DataMessageStanza& data_message_stanza, |
204 MessageData& message_data); | 210 MessageData& message_data); |
205 | 211 |
| 212 // Updates the GServicesSettings based on the |checkin_response|. |
| 213 void UpdateGServicesSettings( |
| 214 const checkin_proto::AndroidCheckinResponse& checkin_response); |
| 215 // Completes the GServicesSettings update request. |
| 216 void UpdateGServicesSettingsCallback(bool success); |
| 217 |
206 // Builder for the GCM internals (mcs client, etc.). | 218 // Builder for the GCM internals (mcs client, etc.). |
207 scoped_ptr<GCMInternalsBuilder> internals_builder_; | 219 scoped_ptr<GCMInternalsBuilder> internals_builder_; |
208 | 220 |
209 // State of the GCM Client Implementation. | 221 // State of the GCM Client Implementation. |
210 State state_; | 222 State state_; |
211 | 223 |
212 Delegate* delegate_; | 224 Delegate* delegate_; |
213 | 225 |
214 // Device checkin info (android ID and security token used by device). | 226 // Device checkin info (android ID and security token used by device). |
215 CheckinInfo device_checkin_info_; | 227 CheckinInfo device_checkin_info_; |
216 | 228 |
217 // Clock used for timing of retry logic. Passed in for testing. Owned by | 229 // Clock used for timing of retry logic. Passed in for testing. Owned by |
218 // GCMClientImpl. | 230 // GCMClientImpl. |
219 scoped_ptr<base::Clock> clock_; | 231 scoped_ptr<base::Clock> clock_; |
220 | 232 |
221 // Information about the chrome build. | 233 // Information about the chrome build. |
222 // TODO(fgorski): Check if it can be passed in constructor and made const. | 234 // TODO(fgorski): Check if it can be passed in constructor and made const. |
223 checkin_proto::ChromeBuildProto chrome_build_proto_; | 235 checkin_proto::ChromeBuildProto chrome_build_proto_; |
224 | 236 |
225 // Persistent data store for keeping device credentials, messages and user to | 237 // Persistent data store for keeping device credentials, messages and user to |
226 // serial number mappings. | 238 // serial number mappings. |
227 scoped_ptr<GCMStore> gcm_store_; | 239 scoped_ptr<GCMStore> gcm_store_; |
228 | 240 |
229 scoped_refptr<net::HttpNetworkSession> network_session_; | 241 scoped_refptr<net::HttpNetworkSession> network_session_; |
230 net::BoundNetLog net_log_; | 242 net::BoundNetLog net_log_; |
231 scoped_ptr<ConnectionFactory> connection_factory_; | 243 scoped_ptr<ConnectionFactory> connection_factory_; |
232 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 244 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
233 | 245 |
| 246 // Map with GServices settings, such us checkin_interval, checkin_url, etc. |
| 247 GServicesSettingsMap g_services_settings_; |
| 248 |
234 // Controls receiving and sending of packets and reliable message queueing. | 249 // Controls receiving and sending of packets and reliable message queueing. |
235 scoped_ptr<MCSClient> mcs_client_; | 250 scoped_ptr<MCSClient> mcs_client_; |
236 | 251 |
237 scoped_ptr<CheckinRequest> checkin_request_; | 252 scoped_ptr<CheckinRequest> checkin_request_; |
238 std::vector<std::string> account_ids_; | 253 std::vector<std::string> account_ids_; |
239 | 254 |
240 // Cached registration info. | 255 // Cached registration info. |
241 RegistrationInfoMap registrations_; | 256 RegistrationInfoMap registrations_; |
242 | 257 |
243 // Currently pending registration requests. GCMClientImpl owns the | 258 // Currently pending registration requests. GCMClientImpl owns the |
(...skipping 10 matching lines...) Expand all Loading... |
254 | 269 |
255 // Factory for creating references in callbacks. | 270 // Factory for creating references in callbacks. |
256 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; | 271 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; |
257 | 272 |
258 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); | 273 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); |
259 }; | 274 }; |
260 | 275 |
261 } // namespace gcm | 276 } // namespace gcm |
262 | 277 |
263 #endif // GOOGLE_APIS_GCM_GCM_CLIENT_IMPL_H_ | 278 #endif // GOOGLE_APIS_GCM_GCM_CLIENT_IMPL_H_ |
OLD | NEW |