OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ | 5 #ifndef SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ |
6 #define SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ | 6 #define SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // ThreadChecker thread, as we want to kill any pending http traffic without | 217 // ThreadChecker thread, as we want to kill any pending http traffic without |
218 // having to wait for the request to complete. | 218 // having to wait for the request to complete. |
219 void TerminateAllIO(); | 219 void TerminateAllIO(); |
220 | 220 |
221 void set_client_id(const std::string& client_id) { | 221 void set_client_id(const std::string& client_id) { |
222 DCHECK(thread_checker_.CalledOnValidThread()); | 222 DCHECK(thread_checker_.CalledOnValidThread()); |
223 DCHECK(client_id_.empty()); | 223 DCHECK(client_id_.empty()); |
224 client_id_.assign(client_id); | 224 client_id_.assign(client_id); |
225 } | 225 } |
226 | 226 |
227 // Returns true if the auth token is succesfully set and false otherwise. | 227 // Sets a new auth token and time. |auth_token_time| is an optional parameter |
228 bool set_auth_token(const std::string& auth_token) { | 228 // that contains the date the auth token was fetched/refreshed, and is used |
229 DCHECK(thread_checker_.CalledOnValidThread()); | 229 // for histogramms/logging only. |
230 if (previously_invalidated_token != auth_token) { | 230 bool SetAuthToken(const std::string& auth_token, |
231 auth_token_.assign(auth_token); | 231 const base::Time& auth_token_time); |
232 previously_invalidated_token = std::string(); | |
233 return true; | |
234 } | |
235 return false; | |
236 } | |
237 | 232 |
238 // Our out-of-band invalidations channel can encounter auth errors, | 233 // Our out-of-band invalidations channel can encounter auth errors, |
239 // and when it does so it tells us via this method to prevent making more | 234 // and when it does so it tells us via this method to prevent making more |
240 // requests with known-bad tokens. This will put the | 235 // requests with known-bad tokens. This will put the |
241 // ServerConnectionManager in an auth error state as if it received an | 236 // ServerConnectionManager in an auth error state as if it received an |
242 // HTTP 401 from sync servers. | 237 // HTTP 401 from sync servers. |
243 void OnInvalidationCredentialsRejected(); | 238 void OnInvalidationCredentialsRejected(); |
244 | 239 |
245 bool HasInvalidAuthToken() { | 240 bool HasInvalidAuthToken() { |
246 return auth_token_.empty(); | 241 return auth_token_.empty(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 287 |
293 // Indicates whether or not requests should be made using HTTPS. | 288 // Indicates whether or not requests should be made using HTTPS. |
294 bool use_ssl_; | 289 bool use_ssl_; |
295 | 290 |
296 // The paths we post to. | 291 // The paths we post to. |
297 std::string proto_sync_path_; | 292 std::string proto_sync_path_; |
298 | 293 |
299 // The auth token to use in authenticated requests. | 294 // The auth token to use in authenticated requests. |
300 std::string auth_token_; | 295 std::string auth_token_; |
301 | 296 |
| 297 // The time at which this auth token was last created/refreshed. |
| 298 // Used for histogramming. |
| 299 base::Time auth_token_time_; |
| 300 |
302 // The previous auth token that is invalid now. | 301 // The previous auth token that is invalid now. |
303 std::string previously_invalidated_token; | 302 std::string previously_invalidated_token; |
304 | 303 |
305 ObserverList<ServerConnectionEventListener> listeners_; | 304 ObserverList<ServerConnectionEventListener> listeners_; |
306 | 305 |
307 HttpResponse::ServerConnectionCode server_status_; | 306 HttpResponse::ServerConnectionCode server_status_; |
308 | 307 |
309 base::ThreadChecker thread_checker_; | 308 base::ThreadChecker thread_checker_; |
310 | 309 |
311 // Protects all variables below to allow bailing out of active connections. | 310 // Protects all variables below to allow bailing out of active connections. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 void NotifyStatusChanged(); | 342 void NotifyStatusChanged(); |
344 | 343 |
345 DISALLOW_COPY_AND_ASSIGN(ServerConnectionManager); | 344 DISALLOW_COPY_AND_ASSIGN(ServerConnectionManager); |
346 }; | 345 }; |
347 | 346 |
348 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); | 347 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); |
349 | 348 |
350 } // namespace syncer | 349 } // namespace syncer |
351 | 350 |
352 #endif // SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ | 351 #endif // SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ |
OLD | NEW |