| 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 #include "chrome/browser/sync/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/profile_sync_service_harness.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <ostream> | 10 #include <ostream> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/sync/sessions/session_state.h" | 22 #include "chrome/browser/sync/sessions/session_state.h" |
| 23 #include "chrome/browser/sync/signin_manager.h" | 23 #include "chrome/browser/sync/signin_manager.h" |
| 24 #include "chrome/browser/sync/sync_ui_util.h" | 24 #include "chrome/browser/sync/sync_ui_util.h" |
| 25 | 25 |
| 26 using browser_sync::sessions::SyncSessionSnapshot; | 26 using browser_sync::sessions::SyncSessionSnapshot; |
| 27 | 27 |
| 28 // The amount of time for which we wait for a live sync operation to complete. | 28 // The amount of time for which we wait for a live sync operation to complete. |
| 29 static const int kLiveSyncOperationTimeoutMs = 45000; | 29 static const int kLiveSyncOperationTimeoutMs = 45000; |
| 30 | 30 |
| 31 // The amount of time we wait for testcases that verify exponential backoff. |
| 32 static const int kExponentialBackoffVerificationTimeoutMs = 60000; |
| 33 |
| 31 // Simple class to implement a timeout using PostDelayedTask. If it is not | 34 // Simple class to implement a timeout using PostDelayedTask. If it is not |
| 32 // aborted before picked up by a message queue, then it asserts with the message | 35 // aborted before picked up by a message queue, then it asserts with the message |
| 33 // provided. This class is not thread safe. | 36 // provided. This class is not thread safe. |
| 34 class StateChangeTimeoutEvent | 37 class StateChangeTimeoutEvent |
| 35 : public base::RefCountedThreadSafe<StateChangeTimeoutEvent> { | 38 : public base::RefCountedThreadSafe<StateChangeTimeoutEvent> { |
| 36 public: | 39 public: |
| 37 StateChangeTimeoutEvent(ProfileSyncServiceHarness* caller, | 40 StateChangeTimeoutEvent(ProfileSyncServiceHarness* caller, |
| 38 const std::string& message); | 41 const std::string& message); |
| 39 | 42 |
| 40 // The entry point to the class from PostDelayedTask. | 43 // The entry point to the class from PostDelayedTask. |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 314 } |
| 312 break; | 315 break; |
| 313 } | 316 } |
| 314 case WAITING_FOR_SYNC_DISABLED: { | 317 case WAITING_FOR_SYNC_DISABLED: { |
| 315 VLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_DISABLED"); | 318 VLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_DISABLED"); |
| 316 if (service()->HasSyncSetupCompleted() == false) { | 319 if (service()->HasSyncSetupCompleted() == false) { |
| 317 // Sync has been disabled. | 320 // Sync has been disabled. |
| 318 SignalStateCompleteWithNextState(SYNC_DISABLED); | 321 SignalStateCompleteWithNextState(SYNC_DISABLED); |
| 319 } | 322 } |
| 320 } | 323 } |
| 324 case WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION: { |
| 325 if (retry_verifier_.VerifyRetryInterval(*GetLastSessionSnapshot()) |
| 326 == false) { |
| 327 SignalStateCompleteWithNextState( |
| 328 EXPONENTIAL_BACKOFF_VERIFICATION_FAILED); |
| 329 } else { |
| 330 // We only verify the first 5 retries. |
| 331 if (retry_verifier_.RetryCount() >= 5) { |
| 332 SignalStateCompleteWithNextState( |
| 333 EXPONENTIAL_BACKOFF_VERIFICATION_SUCEEDED); |
| 334 } |
| 335 } |
| 336 } |
| 337 break; |
| 321 case SERVER_UNREACHABLE: { | 338 case SERVER_UNREACHABLE: { |
| 322 VLOG(1) << GetClientInfoString("SERVER_UNREACHABLE"); | 339 VLOG(1) << GetClientInfoString("SERVER_UNREACHABLE"); |
| 323 if (GetStatus().server_reachable) { | 340 if (GetStatus().server_reachable) { |
| 324 // The client was offline due to the network being disabled, but is now | 341 // The client was offline due to the network being disabled, but is now |
| 325 // back online. Wait for the pending sync cycle to complete. | 342 // back online. Wait for the pending sync cycle to complete. |
| 326 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); | 343 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); |
| 327 } | 344 } |
| 328 break; | 345 break; |
| 329 } | 346 } |
| 330 case SET_PASSPHRASE_FAILED: { | 347 case SET_PASSPHRASE_FAILED: { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 DCHECK(wait_state_ != SYNC_DISABLED); | 482 DCHECK(wait_state_ != SYNC_DISABLED); |
| 466 wait_state_ = WAITING_FOR_SYNC_DISABLED; | 483 wait_state_ = WAITING_FOR_SYNC_DISABLED; |
| 467 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 484 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
| 468 if (wait_state_ == SYNC_DISABLED) { | 485 if (wait_state_ == SYNC_DISABLED) { |
| 469 return true; | 486 return true; |
| 470 } else { | 487 } else { |
| 471 return false; | 488 return false; |
| 472 } | 489 } |
| 473 } | 490 } |
| 474 | 491 |
| 492 bool ProfileSyncServiceHarness::AwaitExponentialBackoffVerification() { |
| 493 retry_verifier_.Initialize(*GetLastSessionSnapshot()); |
| 494 wait_state_ = WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION; |
| 495 AwaitStatusChangeWithTimeout(kExponentialBackoffVerificationTimeoutMs, |
| 496 "Verify Exponential backoff"); |
| 497 return (wait_state_ == EXPONENTIAL_BACKOFF_VERIFICATION_SUCEEDED); |
| 498 } |
| 499 |
| 475 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( | 500 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
| 476 ProfileSyncServiceHarness* partner) { | 501 ProfileSyncServiceHarness* partner) { |
| 477 VLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); | 502 VLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); |
| 478 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) | 503 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) |
| 479 return false; | 504 return false; |
| 480 return partner->WaitUntilTimestampMatches(this, | 505 return partner->WaitUntilTimestampMatches(this, |
| 481 "Sync cycle completion on passive client."); | 506 "Sync cycle completion on passive client."); |
| 482 } | 507 } |
| 483 | 508 |
| 484 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( | 509 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 return true; | 852 return true; |
| 828 } | 853 } |
| 829 | 854 |
| 830 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 855 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 831 DictionaryValue value; | 856 DictionaryValue value; |
| 832 sync_ui_util::ConstructAboutInformation(service_, &value); | 857 sync_ui_util::ConstructAboutInformation(service_, &value); |
| 833 std::string service_status; | 858 std::string service_status; |
| 834 base::JSONWriter::Write(&value, true, &service_status); | 859 base::JSONWriter::Write(&value, true, &service_status); |
| 835 return service_status; | 860 return service_status; |
| 836 } | 861 } |
| OLD | NEW |