Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ |
| 6 #define CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ | 6 #define CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <iosfwd> | 9 #include <iosfwd> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 | 270 |
| 271 // Factory method to create a Post object we can use for communication with | 271 // Factory method to create a Post object we can use for communication with |
| 272 // the server. | 272 // the server. |
| 273 virtual Post* MakePost(); | 273 virtual Post* MakePost(); |
| 274 | 274 |
| 275 void set_client_id(const std::string& client_id) { | 275 void set_client_id(const std::string& client_id) { |
| 276 DCHECK(client_id_.empty()); | 276 DCHECK(client_id_.empty()); |
| 277 client_id_.assign(client_id); | 277 client_id_.assign(client_id); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void set_auth_token(const std::string& auth_token) { | 280 // Returns true if the auth token is succesfully set and false otherwise. |
| 281 bool set_auth_token(const std::string& auth_token) { | |
| 281 // TODO(chron): Consider adding a message loop check here. | 282 // TODO(chron): Consider adding a message loop check here. |
| 282 base::AutoLock lock(auth_token_mutex_); | 283 base::AutoLock lock(auth_token_mutex_); |
| 283 auth_token_.assign(auth_token); | 284 if (previous_invalid_token_ != auth_token) { |
| 285 auth_token_.assign(auth_token); | |
| 286 previous_invalid_token_ = std::string(); | |
| 287 return true; | |
| 288 } | |
| 289 return false; | |
| 290 } | |
| 291 | |
| 292 void reset_auth_token() { | |
|
tim (not reviewing)
2011/08/04 00:24:40
lets call this InvalidateAndClearAuthToken() (or
lipalani1
2011/08/04 01:14:33
Done.
| |
| 293 // Copy over the token to previous invalid token. | |
| 294 base::AutoLock lock(auth_token_mutex_); | |
| 295 if (!auth_token_.empty()) { | |
| 296 previous_invalid_token_.assign(auth_token_); | |
|
tim (not reviewing)
2011/08/04 00:24:40
With the method change above, lets tweak this slig
lipalani1
2011/08/04 01:14:33
Done.
| |
| 297 auth_token_ = std::string(); | |
| 298 } | |
| 284 } | 299 } |
| 285 | 300 |
| 286 const std::string auth_token() const { | 301 const std::string auth_token() const { |
| 287 base::AutoLock lock(auth_token_mutex_); | 302 base::AutoLock lock(auth_token_mutex_); |
| 288 return auth_token_; | 303 return auth_token_; |
| 289 } | 304 } |
| 290 | 305 |
| 291 protected: | 306 protected: |
| 292 inline std::string proto_sync_path() const { | 307 inline std::string proto_sync_path() const { |
| 293 base::AutoLock lock(path_mutex_); | 308 base::AutoLock lock(path_mutex_); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 | 346 |
| 332 // The paths we post to. | 347 // The paths we post to. |
| 333 mutable base::Lock path_mutex_; | 348 mutable base::Lock path_mutex_; |
| 334 std::string proto_sync_path_; | 349 std::string proto_sync_path_; |
| 335 std::string get_time_path_; | 350 std::string get_time_path_; |
| 336 | 351 |
| 337 mutable base::Lock auth_token_mutex_; | 352 mutable base::Lock auth_token_mutex_; |
| 338 // The auth token to use in authenticated requests. Set by the AuthWatcher. | 353 // The auth token to use in authenticated requests. Set by the AuthWatcher. |
| 339 std::string auth_token_; | 354 std::string auth_token_; |
| 340 | 355 |
| 356 // The previous auth token that is invalid now. | |
|
tim (not reviewing)
2011/08/04 00:24:40
rename the var as suggested, and comment could be
lipalani1
2011/08/04 01:14:33
Done.
| |
| 357 std::string previous_invalid_token_; | |
| 358 | |
| 341 base::Lock error_count_mutex_; // Protects error_count_ | 359 base::Lock error_count_mutex_; // Protects error_count_ |
| 342 int error_count_; // Tracks the number of connection errors. | 360 int error_count_; // Tracks the number of connection errors. |
| 343 | 361 |
| 344 scoped_refptr<ObserverListThreadSafe<ServerConnectionEventListener> > | 362 scoped_refptr<ObserverListThreadSafe<ServerConnectionEventListener> > |
| 345 listeners_; | 363 listeners_; |
| 346 | 364 |
| 347 // Volatile so various threads can call server_status() without | 365 // Volatile so various threads can call server_status() without |
| 348 // synchronization. | 366 // synchronization. |
| 349 volatile HttpResponse::ServerConnectionCode server_status_; | 367 volatile HttpResponse::ServerConnectionCode server_status_; |
| 350 bool server_reachable_; | 368 bool server_reachable_; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 368 // settings. | 386 // settings. |
| 369 bool FillMessageWithShareDetails(sync_pb::ClientToServerMessage* csm, | 387 bool FillMessageWithShareDetails(sync_pb::ClientToServerMessage* csm, |
| 370 syncable::DirectoryManager* manager, | 388 syncable::DirectoryManager* manager, |
| 371 const std::string& share); | 389 const std::string& share); |
| 372 | 390 |
| 373 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); | 391 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); |
| 374 | 392 |
| 375 } // namespace browser_sync | 393 } // namespace browser_sync |
| 376 | 394 |
| 377 #endif // CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ | 395 #endif // CHROME_BROWSER_SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ |
| OLD | NEW |