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/monitoring/gcm_stats_recorder.h" | |
23 #include "google_apis/gcm/protocol/android_checkin.pb.h" | |
24 #include "google_apis/gcm/protocol/checkin.pb.h" | 22 #include "google_apis/gcm/protocol/checkin.pb.h" |
25 #include "net/base/net_log.h" | 23 #include "net/base/net_log.h" |
26 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
27 | 25 |
28 class GURL; | 26 class GURL; |
29 | 27 |
30 namespace base { | 28 namespace base { |
31 class Clock; | 29 class Clock; |
32 } // namespace base | 30 } // namespace base |
33 | 31 |
34 namespace mcs_proto { | |
35 class DataMessageStanza; | |
36 } // namespace mcs_proto | |
37 | |
38 namespace net { | 32 namespace net { |
39 class HttpNetworkSession; | 33 class HttpNetworkSession; |
40 } // namespace net | 34 } // namespace net |
41 | 35 |
42 namespace gcm { | 36 namespace gcm { |
43 | 37 |
44 class CheckinRequest; | 38 class CheckinRequest; |
45 class ConnectionFactory; | 39 class ConnectionFactory; |
46 class GCMClientImplTest; | 40 class GCMClientImplTest; |
47 | 41 |
48 // 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 |
49 // as necessary. | 43 // as necessary. |
50 class GCM_EXPORT GCMInternalsBuilder { | 44 class GCM_EXPORT GCMInternalsBuilder { |
51 public: | 45 public: |
52 GCMInternalsBuilder(); | 46 GCMInternalsBuilder(); |
53 virtual ~GCMInternalsBuilder(); | 47 virtual ~GCMInternalsBuilder(); |
54 | 48 |
55 virtual scoped_ptr<base::Clock> BuildClock(); | 49 virtual scoped_ptr<base::Clock> BuildClock(); |
56 virtual scoped_ptr<MCSClient> BuildMCSClient( | 50 virtual scoped_ptr<MCSClient> BuildMCSClient( |
57 const std::string& version, | 51 const std::string& version, |
58 base::Clock* clock, | 52 base::Clock* clock, |
59 ConnectionFactory* connection_factory, | 53 ConnectionFactory* connection_factory, |
60 GCMStore* gcm_store, | 54 GCMStore* gcm_store); |
61 GCMStatsRecorder* recorder); | |
62 virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory( | 55 virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory( |
63 const std::vector<GURL>& endpoints, | 56 const std::vector<GURL>& endpoints, |
64 const net::BackoffEntry::Policy& backoff_policy, | 57 const net::BackoffEntry::Policy& backoff_policy, |
65 scoped_refptr<net::HttpNetworkSession> network_session, | 58 scoped_refptr<net::HttpNetworkSession> network_session, |
66 net::NetLog* net_log); | 59 net::NetLog* net_log); |
67 }; | 60 }; |
68 | 61 |
69 // Implements the GCM Client. It is used to coordinate MCS Client (communication | 62 // Implements the GCM Client. It is used to coordinate MCS Client (communication |
70 // with MCS) and other pieces of GCM infrastructure like Registration and | 63 // with MCS) and other pieces of GCM infrastructure like Registration and |
71 // Checkins. It also allows for registering user delegates that host | 64 // Checkins. It also allows for registering user delegates that host |
(...skipping 14 matching lines...) Expand all Loading... |
86 Delegate* delegate) OVERRIDE; | 79 Delegate* delegate) OVERRIDE; |
87 virtual void Load() OVERRIDE; | 80 virtual void Load() OVERRIDE; |
88 virtual void Stop() OVERRIDE; | 81 virtual void Stop() OVERRIDE; |
89 virtual void CheckOut() OVERRIDE; | 82 virtual void CheckOut() OVERRIDE; |
90 virtual void Register(const std::string& app_id, | 83 virtual void Register(const std::string& app_id, |
91 const std::vector<std::string>& sender_ids) OVERRIDE; | 84 const std::vector<std::string>& sender_ids) OVERRIDE; |
92 virtual void Unregister(const std::string& app_id) OVERRIDE; | 85 virtual void Unregister(const std::string& app_id) OVERRIDE; |
93 virtual void Send(const std::string& app_id, | 86 virtual void Send(const std::string& app_id, |
94 const std::string& receiver_id, | 87 const std::string& receiver_id, |
95 const OutgoingMessage& message) OVERRIDE; | 88 const OutgoingMessage& message) OVERRIDE; |
96 virtual void SetRecording(bool recording) OVERRIDE; | |
97 virtual void ClearActivityLogs() OVERRIDE; | |
98 virtual GCMStatistics GetStatistics() const OVERRIDE; | 89 virtual GCMStatistics GetStatistics() const OVERRIDE; |
99 | 90 |
100 private: | 91 private: |
101 // State representation of the GCMClient. | 92 // State representation of the GCMClient. |
102 // Any change made to this enum should have corresponding change in the | 93 // Any change made to this enum should have corresponding change in the |
103 // GetStateString(...) function. | 94 // GetStateString(...) function. |
104 enum State { | 95 enum State { |
105 // Uninitialized. | 96 // Uninitialized. |
106 UNINITIALIZED, | 97 UNINITIALIZED, |
107 // Initialized, | 98 // Initialized, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 203 |
213 // Fires OnMessageSendError event on the delegate of this calss, based on the | 204 // Fires OnMessageSendError event on the delegate of this calss, based on the |
214 // details in |data_message_stanza| and |message_data|. | 205 // details in |data_message_stanza| and |message_data|. |
215 void HandleIncomingSendError( | 206 void HandleIncomingSendError( |
216 const mcs_proto::DataMessageStanza& data_message_stanza, | 207 const mcs_proto::DataMessageStanza& data_message_stanza, |
217 MessageData& message_data); | 208 MessageData& message_data); |
218 | 209 |
219 // Builder for the GCM internals (mcs client, etc.). | 210 // Builder for the GCM internals (mcs client, etc.). |
220 scoped_ptr<GCMInternalsBuilder> internals_builder_; | 211 scoped_ptr<GCMInternalsBuilder> internals_builder_; |
221 | 212 |
222 // Recorder that logs GCM activities. | |
223 GCMStatsRecorder recorder_; | |
224 | |
225 // State of the GCM Client Implementation. | 213 // State of the GCM Client Implementation. |
226 State state_; | 214 State state_; |
227 | 215 |
228 Delegate* delegate_; | 216 Delegate* delegate_; |
229 | 217 |
230 // Device checkin info (android ID and security token used by device). | 218 // Device checkin info (android ID and security token used by device). |
231 CheckinInfo device_checkin_info_; | 219 CheckinInfo device_checkin_info_; |
232 | 220 |
233 // Clock used for timing of retry logic. Passed in for testing. Owned by | 221 // Clock used for timing of retry logic. Passed in for testing. Owned by |
234 // GCMClientImpl. | 222 // GCMClientImpl. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 258 |
271 // Factory for creating references in callbacks. | 259 // Factory for creating references in callbacks. |
272 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; | 260 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; |
273 | 261 |
274 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); | 262 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); |
275 }; | 263 }; |
276 | 264 |
277 } // namespace gcm | 265 } // namespace gcm |
278 | 266 |
279 #endif // GOOGLE_APIS_GCM_GCM_CLIENT_IMPL_H_ | 267 #endif // GOOGLE_APIS_GCM_GCM_CLIENT_IMPL_H_ |
OLD | NEW |