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. |
| 134 // TODO(fgorski): Convert to a class with explicit getters/setters. |
131 struct CheckinInfo { | 135 struct CheckinInfo { |
132 CheckinInfo() : android_id(0), secret(0) {} | 136 CheckinInfo(); |
| 137 ~CheckinInfo(); |
133 bool IsValid() const { return android_id != 0 && secret != 0; } | 138 bool IsValid() const { return android_id != 0 && secret != 0; } |
134 void Reset() { | 139 void SnapshotCheckinAccounts(); |
135 android_id = 0; | 140 void Reset(); |
136 secret = 0; | |
137 } | |
138 | 141 |
| 142 // Android ID of the device as assigned by the server. |
139 uint64 android_id; | 143 uint64 android_id; |
| 144 // Security token of the device as assigned by the server. |
140 uint64 secret; | 145 uint64 secret; |
| 146 // True if accounts were already provided through SetAccountsForCheckin(), |
| 147 // or when |last_checkin_accounts| was loaded as empty. |
| 148 bool accounts_set; |
| 149 // Map of account email addresses and OAuth2 tokens that will be sent to the |
| 150 // checkin server on a next checkin. |
| 151 std::map<std::string, std::string> account_tokens; |
| 152 // As set of accounts last checkin was completed with. |
| 153 std::set<std::string> last_checkin_accounts; |
141 }; | 154 }; |
142 | 155 |
143 // Collection of pending registration requests. Keys are app IDs, while values | 156 // Collection of pending registration requests. Keys are app IDs, while values |
144 // are pending registration requests to obtain a registration ID for | 157 // are pending registration requests to obtain a registration ID for |
145 // requesting application. | 158 // requesting application. |
146 typedef std::map<std::string, RegistrationRequest*> | 159 typedef std::map<std::string, RegistrationRequest*> |
147 PendingRegistrationRequests; | 160 PendingRegistrationRequests; |
148 | 161 |
149 // Collection of pending unregistration requests. Keys are app IDs, while | 162 // Collection of pending unregistration requests. Keys are app IDs, while |
150 // values are pending unregistration requests to disable the registration ID | 163 // values are pending unregistration requests to disable the registration ID |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 205 |
193 // Callback passed to GCMStore::SetGServicesSettings. | 206 // Callback passed to GCMStore::SetGServicesSettings. |
194 void SetGServicesSettingsCallback(bool success); | 207 void SetGServicesSettingsCallback(bool success); |
195 | 208 |
196 // Schedules next periodic device checkin and makes sure there is at most one | 209 // 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 | 210 // pending checkin at a time. This function is meant to be called after a |
198 // successful checkin. | 211 // successful checkin. |
199 void SchedulePeriodicCheckin(); | 212 void SchedulePeriodicCheckin(); |
200 // Gets the time until next checkin. | 213 // Gets the time until next checkin. |
201 base::TimeDelta GetTimeToNextCheckin() const; | 214 base::TimeDelta GetTimeToNextCheckin() const; |
202 // Callback for setting last checkin time in the |gcm_store_|. | 215 // Callback for setting last checkin information in the |gcm_store_|. |
203 void SetLastCheckinTimeCallback(bool success); | 216 void SetLastCheckinInfoCallback(bool success); |
204 | 217 |
205 // Callback for persisting device credentials in the |gcm_store_|. | 218 // Callback for persisting device credentials in the |gcm_store_|. |
206 void SetDeviceCredentialsCallback(bool success); | 219 void SetDeviceCredentialsCallback(bool success); |
207 | 220 |
208 // Callback for persisting registration info in the |gcm_store_|. | 221 // Callback for persisting registration info in the |gcm_store_|. |
209 void UpdateRegistrationCallback(bool success); | 222 void UpdateRegistrationCallback(bool success); |
210 | 223 |
211 // Completes the registration request. | 224 // Completes the registration request. |
212 void OnRegisterCompleted(const std::string& app_id, | 225 void OnRegisterCompleted(const std::string& app_id, |
213 const std::vector<std::string>& sender_ids, | 226 const std::vector<std::string>& sender_ids, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 311 |
299 // Factory for creating references in callbacks. | 312 // Factory for creating references in callbacks. |
300 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; | 313 base::WeakPtrFactory<GCMClientImpl> weak_ptr_factory_; |
301 | 314 |
302 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); | 315 DISALLOW_COPY_AND_ASSIGN(GCMClientImpl); |
303 }; | 316 }; |
304 | 317 |
305 } // namespace gcm | 318 } // namespace gcm |
306 | 319 |
307 #endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ | 320 #endif // COMPONENTS_GCM_DRIVER_GCM_CLIENT_IMPL_H_ |
OLD | NEW |