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 <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
16 #include "components/gcm_driver/gcm_client.h" | 17 #include "components/gcm_driver/gcm_client.h" |
17 #include "components/gcm_driver/gcm_stats_recorder_impl.h" | 18 #include "components/gcm_driver/gcm_stats_recorder_impl.h" |
18 #include "google_apis/gcm/base/mcs_message.h" | 19 #include "google_apis/gcm/base/mcs_message.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 virtual void CheckOut() OVERRIDE; | 95 virtual void CheckOut() OVERRIDE; |
95 virtual void Register(const std::string& app_id, | 96 virtual void Register(const std::string& app_id, |
96 const std::vector<std::string>& sender_ids) OVERRIDE; | 97 const std::vector<std::string>& sender_ids) OVERRIDE; |
97 virtual void Unregister(const std::string& app_id) OVERRIDE; | 98 virtual void Unregister(const std::string& app_id) OVERRIDE; |
98 virtual void Send(const std::string& app_id, | 99 virtual void Send(const std::string& app_id, |
99 const std::string& receiver_id, | 100 const std::string& receiver_id, |
100 const OutgoingMessage& message) OVERRIDE; | 101 const OutgoingMessage& message) OVERRIDE; |
101 virtual void SetRecording(bool recording) OVERRIDE; | 102 virtual void SetRecording(bool recording) OVERRIDE; |
102 virtual void ClearActivityLogs() OVERRIDE; | 103 virtual void ClearActivityLogs() OVERRIDE; |
103 virtual GCMStatistics GetStatistics() const OVERRIDE; | 104 virtual GCMStatistics GetStatistics() const OVERRIDE; |
105 virtual void SetAccountsForCheckin( | |
106 const std::map<std::string, std::string>& account_tokens) OVERRIDE; | |
104 | 107 |
105 // GCMStatsRecorder::Delegate implemenation. | 108 // GCMStatsRecorder::Delegate implemenation. |
106 virtual void OnActivityRecorded() OVERRIDE; | 109 virtual void OnActivityRecorded() OVERRIDE; |
107 | 110 |
108 // ConnectionFactory::ConnectionListener implementation. | 111 // ConnectionFactory::ConnectionListener implementation. |
109 virtual void OnConnected(const GURL& current_server, | 112 virtual void OnConnected(const GURL& current_server, |
110 const net::IPEndPoint& ip_endpoint) OVERRIDE; | 113 const net::IPEndPoint& ip_endpoint) OVERRIDE; |
111 virtual void OnDisconnected() OVERRIDE; | 114 virtual void OnDisconnected() OVERRIDE; |
112 | 115 |
113 private: | 116 private: |
114 // State representation of the GCMClient. | 117 // State representation of the GCMClient. |
115 // Any change made to this enum should have corresponding change in the | 118 // Any change made to this enum should have corresponding change in the |
116 // GetStateString(...) function. | 119 // GetStateString(...) function. |
117 enum State { | 120 enum State { |
118 // Uninitialized. | 121 // Uninitialized. |
119 UNINITIALIZED, | 122 UNINITIALIZED, |
120 // Initialized, | 123 // Initialized, |
121 INITIALIZED, | 124 INITIALIZED, |
122 // GCM store loading is in progress. | 125 // GCM store loading is in progress. |
123 LOADING, | 126 LOADING, |
124 // Initial device checkin is in progress. | 127 // Initial device checkin is in progress. |
125 INITIAL_DEVICE_CHECKIN, | 128 INITIAL_DEVICE_CHECKIN, |
126 // Ready to accept requests. | 129 // Ready to accept requests. |
127 READY, | 130 READY, |
128 }; | 131 }; |
129 | 132 |
130 // The check-in info for the user. Returned by the server. | 133 // The check-in info for the device. |
131 struct CheckinInfo { | 134 struct CheckinInfo { |
132 CheckinInfo() : android_id(0), secret(0) {} | 135 CheckinInfo(); |
136 ~CheckinInfo(); | |
133 bool IsValid() const { return android_id != 0 && secret != 0; } | 137 bool IsValid() const { return android_id != 0 && secret != 0; } |
134 void Reset() { | 138 void SnapshotCheckinAccounts(); |
Nicolas Zea
2014/07/16 20:53:54
Hmm, I wonder if this struct is becoming complex e
fgorski
2014/07/17 03:35:35
Ack. Lemme do a separate patch for that, there is
| |
135 android_id = 0; | 139 void Reset(); |
136 secret = 0; | |
137 } | |
138 | 140 |
141 // Android ID of the device as assigned by the server. | |
139 uint64 android_id; | 142 uint64 android_id; |
143 // Security token of the device as assigned by the server. | |
140 uint64 secret; | 144 uint64 secret; |
145 // True if accounts where already provided through SetAccountsForCheckin(), | |
Nicolas Zea
2014/07/16 20:53:54
nit: where -> were
fgorski
2014/07/17 03:35:35
Done.
| |
146 // or when |last_checkin_accounts| was loaded as empty. | |
147 bool accounts_set; | |
148 // Map of account email addresses and OAuth2 tokens that will be sent to the | |
149 // checkin server on a next checkin. | |
150 std::map<std::string, std::string> account_tokens; | |
151 // As set of accounts last checkin was completed with. | |
152 std::set<std::string> last_checkin_accounts; | |
141 }; | 153 }; |
142 | 154 |
143 // Collection of pending registration requests. Keys are app IDs, while values | 155 // Collection of pending registration requests. Keys are app IDs, while values |
144 // are pending registration requests to obtain a registration ID for | 156 // are pending registration requests to obtain a registration ID for |
145 // requesting application. | 157 // requesting application. |
146 typedef std::map<std::string, RegistrationRequest*> | 158 typedef std::map<std::string, RegistrationRequest*> |
147 PendingRegistrationRequests; | 159 PendingRegistrationRequests; |
148 | 160 |
149 // Collection of pending unregistration requests. Keys are app IDs, while | 161 // Collection of pending unregistration requests. Keys are app IDs, while |
150 // values are pending unregistration requests to disable the registration ID | 162 // values are pending unregistration requests to disable the registration ID |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 | 204 |
193 // Callback passed to GCMStore::SetGServicesSettings. | 205 // Callback passed to GCMStore::SetGServicesSettings. |
194 void SetGServicesSettingsCallback(bool success); | 206 void SetGServicesSettingsCallback(bool success); |
195 | 207 |
196 // Schedules next periodic device checkin and makes sure there is at most one | 208 // Schedules next periodic device checkin and makes sure there is at most one |
197 // pending checkin at a time. This function is meant to be called after a | 209 // pending checkin at a time. This function is meant to be called after a |
198 // successful checkin. | 210 // successful checkin. |
199 void SchedulePeriodicCheckin(); | 211 void SchedulePeriodicCheckin(); |
200 // Gets the time until next checkin. | 212 // Gets the time until next checkin. |
201 base::TimeDelta GetTimeToNextCheckin() const; | 213 base::TimeDelta GetTimeToNextCheckin() const; |
202 // Callback for setting last checkin time in the |gcm_store_|. | 214 // Callback for setting last checkin information in the |gcm_store_|. |
203 void SetLastCheckinTimeCallback(bool success); | 215 void SetLastCheckinInfoCallback(bool success); |
204 | 216 |
205 // Callback for persisting device credentials in the |gcm_store_|. | 217 // Callback for persisting device credentials in the |gcm_store_|. |
206 void SetDeviceCredentialsCallback(bool success); | 218 void SetDeviceCredentialsCallback(bool success); |
207 | 219 |
208 // Callback for persisting registration info in the |gcm_store_|. | 220 // Callback for persisting registration info in the |gcm_store_|. |
209 void UpdateRegistrationCallback(bool success); | 221 void UpdateRegistrationCallback(bool success); |
210 | 222 |
211 // Completes the registration request. | 223 // Completes the registration request. |
212 void OnRegisterCompleted(const std::string& app_id, | 224 void OnRegisterCompleted(const std::string& app_id, |
213 const std::vector<std::string>& sender_ids, | 225 const std::vector<std::string>& sender_ids, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 | 310 |
299 // Factory for creating references in callbacks. | 311 // Factory for creating references in callbacks. |
300 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; | 312 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; |
301 | 313 |
302 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); | 314 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); |
303 }; | 315 }; |
304 | 316 |
305 } // namespace gcm | 317 } // namespace gcm |
306 | 318 |
307 #endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ | 319 #endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ |
OLD | NEW |