Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/test/integration/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <ostream> | 9 #include <ostream> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 #include "sync/internal_api/public/util/sync_string_conversions.h" | 42 #include "sync/internal_api/public/util/sync_string_conversions.h" |
| 43 | 43 |
| 44 #if defined(ENABLE_MANAGED_USERS) | 44 #if defined(ENABLE_MANAGED_USERS) |
| 45 #include "chrome/browser/managed_mode/managed_user_constants.h" | 45 #include "chrome/browser/managed_mode/managed_user_constants.h" |
| 46 #endif | 46 #endif |
| 47 | 47 |
| 48 using syncer::sessions::SyncSessionSnapshot; | 48 using syncer::sessions::SyncSessionSnapshot; |
| 49 using invalidation::P2PInvalidationService; | 49 using invalidation::P2PInvalidationService; |
| 50 | 50 |
| 51 // The amount of time for which we wait for a sync operation to complete. | 51 // The amount of time for which we wait for a sync operation to complete. |
| 52 static const int kSyncOperationTimeoutMs = 45000; | 52 // Note: This must be less than the default 45 second timeout for integration |
| 53 // tests so that in case a sync operation times out, it is able to log a useful | |
| 54 // failure message before the test is killed. | |
| 55 static const int kSyncOperationTimeoutMs = 30000; | |
|
rlarocque
2014/01/28 02:50:48
Are you sure about this? I think I've seen sync t
Raghu Simha
2014/01/28 21:13:12
In that case, I'll undo this change and leave it f
| |
| 53 | 56 |
| 54 namespace { | 57 namespace { |
| 55 | 58 |
| 56 // Checks if a desired change in the state of the sync engine has taken place by | 59 // Checks if a desired change in the state of the sync engine has taken place by |
| 57 // running the callback passed to it. | 60 // running the callback passed to it. |
| 58 class CallbackStatusChecker : public StatusChangeChecker { | 61 class CallbackStatusChecker : public StatusChangeChecker { |
| 59 public: | 62 public: |
| 60 CallbackStatusChecker(base::Callback<bool()> callback, | 63 CallbackStatusChecker(base::Callback<bool()> callback, |
| 61 const std::string& source) | 64 const std::string& source) |
| 62 : StatusChangeChecker(source), | 65 : StatusChangeChecker(source), |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 89 // Backend initialization is blocked by an auth error. | 92 // Backend initialization is blocked by an auth error. |
| 90 if (harness->HasAuthError()) | 93 if (harness->HasAuthError()) |
| 91 return true; | 94 return true; |
| 92 // Backend initialization is blocked by a failure to fetch Oauth2 tokens. | 95 // Backend initialization is blocked by a failure to fetch Oauth2 tokens. |
| 93 if (harness->service()->IsRetryingAccessTokenFetchForTest()) | 96 if (harness->service()->IsRetryingAccessTokenFetchForTest()) |
| 94 return true; | 97 return true; |
| 95 // Still waiting on backend initialization. | 98 // Still waiting on backend initialization. |
| 96 return false; | 99 return false; |
| 97 } | 100 } |
| 98 | 101 |
| 99 // Helper function which returns true if initial sync is complete, or if the | |
| 100 // initial sync is blocked for some reason. | |
| 101 bool DoneWaitingForInitialSync(const ProfileSyncServiceHarness* harness) { | |
| 102 DCHECK(harness); | |
| 103 // Initial sync is complete. | |
| 104 if (harness->IsFullySynced()) | |
| 105 return true; | |
| 106 // Initial sync is blocked because custom passphrase is required. | |
| 107 if (harness->service()->passphrase_required_reason() == | |
| 108 syncer::REASON_DECRYPTION) { | |
| 109 return true; | |
| 110 } | |
| 111 // Initial sync is blocked by an auth error. | |
| 112 if (harness->HasAuthError()) | |
| 113 return true; | |
| 114 // Still waiting on initial sync. | |
| 115 return false; | |
| 116 } | |
| 117 | |
| 118 // Helper function which returns true if the sync client is fully synced, or if | |
| 119 // sync is blocked for some reason. | |
| 120 bool DoneWaitingForFullSync(const ProfileSyncServiceHarness* harness) { | |
| 121 DCHECK(harness); | |
| 122 // Sync is complete. | |
| 123 if (harness->IsFullySynced()) | |
| 124 return true; | |
| 125 // Sync is blocked by an auth error. | |
| 126 if (harness->HasAuthError()) | |
| 127 return true; | |
| 128 // Sync is blocked by a failure to fetch Oauth2 tokens. | |
| 129 if (harness->service()->IsRetryingAccessTokenFetchForTest()) | |
| 130 return true; | |
| 131 // Still waiting on sync. | |
| 132 return false; | |
| 133 } | |
| 134 | |
| 135 // Helper function which returns true if the sync client requires a custom | 102 // Helper function which returns true if the sync client requires a custom |
| 136 // passphrase to be entered for decryption. | 103 // passphrase to be entered for decryption. |
| 137 bool IsPassphraseRequired(const ProfileSyncServiceHarness* harness) { | 104 bool IsPassphraseRequired(const ProfileSyncServiceHarness* harness) { |
| 138 DCHECK(harness); | 105 DCHECK(harness); |
| 139 return harness->service()->IsPassphraseRequired(); | 106 return harness->service()->IsPassphraseRequired(); |
| 140 } | 107 } |
| 141 | 108 |
| 142 // Helper function which returns true if the custom passphrase entered was | 109 // Helper function which returns true if the custom passphrase entered was |
| 143 // accepted. | 110 // accepted. |
| 144 bool IsPassphraseAccepted(const ProfileSyncServiceHarness* harness) { | 111 bool IsPassphraseAccepted(const ProfileSyncServiceHarness* harness) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 if (!service()->IsUsingSecondaryPassphrase()) { | 247 if (!service()->IsUsingSecondaryPassphrase()) { |
| 281 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); | 248 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); |
| 282 } else { | 249 } else { |
| 283 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" | 250 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
| 284 " until SetDecryptionPassphrase is called."; | 251 " until SetDecryptionPassphrase is called."; |
| 285 return false; | 252 return false; |
| 286 } | 253 } |
| 287 | 254 |
| 288 // Wait for initial sync cycle to be completed. | 255 // Wait for initial sync cycle to be completed. |
| 289 DCHECK(service()->sync_initialized()); | 256 DCHECK(service()->sync_initialized()); |
| 290 CallbackStatusChecker initial_sync_checker( | 257 CallbackStatusChecker sync_setup_complete_checker( |
| 291 base::Bind(&DoneWaitingForInitialSync, base::Unretained(this)), | 258 base::Bind(&ProfileSyncServiceHarness::IsSyncSetupComplete, |
| 292 "DoneWaitingForInitialSync"); | 259 base::Unretained(this)), |
| 293 if (!AwaitStatusChange(&initial_sync_checker, "SetupSync")) { | 260 "IsSyncSetupComplete"); |
| 261 if (!AwaitStatusChange(&sync_setup_complete_checker, "SetupSync")) { | |
| 294 LOG(ERROR) << "Initial sync cycle did not complete after " | 262 LOG(ERROR) << "Initial sync cycle did not complete after " |
| 295 << kSyncOperationTimeoutMs / 1000 | 263 << kSyncOperationTimeoutMs / 1000 |
| 296 << " seconds."; | 264 << " seconds."; |
| 297 return false; | 265 return false; |
| 298 } | 266 } |
| 299 | 267 |
| 300 // Make sure that initial sync wasn't blocked by a missing passphrase. | 268 // Make sure that initial sync wasn't blocked by a missing passphrase. |
| 301 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { | 269 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { |
| 302 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" | 270 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
| 303 " until SetDecryptionPassphrase is called."; | 271 " until SetDecryptionPassphrase is called."; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 } | 360 } |
| 393 | 361 |
| 394 CallbackStatusChecker backend_initialized_checker( | 362 CallbackStatusChecker backend_initialized_checker( |
| 395 base::Bind(&DoneWaitingForBackendInitialization, | 363 base::Bind(&DoneWaitingForBackendInitialization, |
| 396 base::Unretained(this)), | 364 base::Unretained(this)), |
| 397 "DoneWaitingForBackendInitialization"); | 365 "DoneWaitingForBackendInitialization"); |
| 398 AwaitStatusChange(&backend_initialized_checker, "AwaitBackendInitialized"); | 366 AwaitStatusChange(&backend_initialized_checker, "AwaitBackendInitialized"); |
| 399 return service()->sync_initialized(); | 367 return service()->sync_initialized(); |
| 400 } | 368 } |
| 401 | 369 |
| 402 bool ProfileSyncServiceHarness::AwaitDataSyncCompletion() { | 370 // TODO(sync): Remove this method and replace calls with AwaitSteadyState once |
| 403 DVLOG(1) << GetClientInfoString("AwaitDataSyncCompletion"); | 371 // we stop comparing progress markers. |
| 404 | 372 bool ProfileSyncServiceHarness::AwaitCommitActivityCompletion() { |
| 405 DCHECK(service()->sync_initialized()); | 373 DVLOG(1) << GetClientInfoString("AwaitCommitActivityCompletion"); |
| 406 DCHECK(!IsSyncDisabled()); | |
| 407 | |
| 408 if (IsDataSynced()) { | |
| 409 // Client is already synced; don't wait. | |
| 410 return true; | |
| 411 } | |
| 412 | |
| 413 CallbackStatusChecker data_synced_checker( | |
| 414 base::Bind(&ProfileSyncServiceHarness::IsDataSynced, | |
| 415 base::Unretained(this)), | |
| 416 "IsDataSynced"); | |
| 417 return AwaitStatusChange(&data_synced_checker, "AwaitDataSyncCompletion"); | |
| 418 } | |
| 419 | |
| 420 bool ProfileSyncServiceHarness::AwaitFullSyncCompletion() { | |
| 421 DVLOG(1) << GetClientInfoString("AwaitFullSyncCompletion"); | |
| 422 if (IsSyncDisabled()) { | 374 if (IsSyncDisabled()) { |
| 423 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; | 375 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
| 424 return false; | 376 return false; |
| 425 } | 377 } |
| 426 | 378 |
| 427 if (IsFullySynced()) { | 379 AwaitSteadyState(); |
| 428 // Client is already synced; don't wait. | 380 if (IsCommitActivityComplete()) { |
| 381 // Client already has latest progress markers; don't wait. | |
| 429 return true; | 382 return true; |
| 430 } | 383 } |
| 431 | 384 |
| 432 DCHECK(service()->sync_initialized()); | 385 CallbackStatusChecker commit_activity_complete_checker( |
| 433 CallbackStatusChecker fully_synced_checker( | 386 base::Bind(&ProfileSyncServiceHarness::IsCommitActivityComplete, |
| 434 base::Bind(&DoneWaitingForFullSync, base::Unretained(this)), | 387 base::Unretained(this)), |
| 435 "DoneWaitingForFullSync"); | 388 "IsCommitActivityComplete"); |
| 436 AwaitStatusChange(&fully_synced_checker, "AwaitFullSyncCompletion"); | 389 AwaitStatusChange(&commit_activity_complete_checker, |
| 437 return IsFullySynced(); | 390 "AwaitCommitActivityCompletion"); |
| 391 return IsCommitActivityComplete(); | |
| 438 } | 392 } |
| 439 | 393 |
| 440 bool ProfileSyncServiceHarness::AwaitSyncDisabled() { | 394 bool ProfileSyncServiceHarness::AwaitSyncDisabled() { |
| 441 DCHECK(service()->HasSyncSetupCompleted()); | 395 DCHECK(service()->HasSyncSetupCompleted()); |
| 442 DCHECK(!IsSyncDisabled()); | 396 DCHECK(!IsSyncDisabled()); |
| 443 CallbackStatusChecker sync_disabled_checker( | 397 CallbackStatusChecker sync_disabled_checker( |
| 444 base::Bind(&ProfileSyncServiceHarness::IsSyncDisabled, | 398 base::Bind(&ProfileSyncServiceHarness::IsSyncDisabled, |
| 445 base::Unretained(this)), | 399 base::Unretained(this)), |
| 446 "IsSyncDisabled"); | 400 "IsSyncDisabled"); |
| 447 return AwaitStatusChange(&sync_disabled_checker, "AwaitSyncDisabled"); | 401 return AwaitStatusChange(&sync_disabled_checker, "AwaitSyncDisabled"); |
| 448 } | 402 } |
| 449 | 403 |
| 450 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( | 404 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
| 451 ProfileSyncServiceHarness* partner) { | 405 ProfileSyncServiceHarness* partner) { |
| 452 DVLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); | 406 DVLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); |
| 453 if (!AwaitFullSyncCompletion()) | 407 if (!AwaitCommitActivityCompletion()) |
| 454 return false; | 408 return false; |
| 455 return partner->WaitUntilProgressMarkersMatch(this); | 409 return partner->WaitUntilProgressMarkersMatch(this); |
| 456 } | 410 } |
| 457 | 411 |
| 458 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( | 412 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( |
| 459 std::vector<ProfileSyncServiceHarness*>& partners) { | 413 std::vector<ProfileSyncServiceHarness*>& partners) { |
| 460 DVLOG(1) << GetClientInfoString("AwaitGroupSyncCycleCompletion"); | 414 DVLOG(1) << GetClientInfoString("AwaitGroupSyncCycleCompletion"); |
| 461 if (!AwaitFullSyncCompletion()) | 415 if (!AwaitCommitActivityCompletion()) |
| 462 return false; | 416 return false; |
| 463 bool return_value = true; | 417 bool return_value = true; |
| 464 for (std::vector<ProfileSyncServiceHarness*>::iterator it = | 418 for (std::vector<ProfileSyncServiceHarness*>::iterator it = |
| 465 partners.begin(); it != partners.end(); ++it) { | 419 partners.begin(); it != partners.end(); ++it) { |
| 466 if ((this != *it) && (!(*it)->IsSyncDisabled())) { | 420 if ((this != *it) && (!(*it)->IsSyncDisabled())) { |
| 467 return_value = return_value && | 421 return_value = return_value && |
| 468 (*it)->WaitUntilProgressMarkersMatch(this); | 422 (*it)->WaitUntilProgressMarkersMatch(this); |
| 469 } | 423 } |
| 470 } | 424 } |
| 471 return return_value; | 425 return return_value; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 base::Unretained(this)), | 463 base::Unretained(this)), |
| 510 "MatchesPartnerClient"); | 464 "MatchesPartnerClient"); |
| 511 return_value = AwaitStatusChange(&matches_other_client_checker, | 465 return_value = AwaitStatusChange(&matches_other_client_checker, |
| 512 "WaitUntilProgressMarkersMatch"); | 466 "WaitUntilProgressMarkersMatch"); |
| 513 partner->service()->RemoveObserver(this); | 467 partner->service()->RemoveObserver(this); |
| 514 } | 468 } |
| 515 progress_marker_partner_ = NULL; | 469 progress_marker_partner_ = NULL; |
| 516 return return_value; | 470 return return_value; |
| 517 } | 471 } |
| 518 | 472 |
| 473 bool ProfileSyncServiceHarness::RunMessageLoop(bool quit_when_idle) { | |
| 474 base::OneShotTimer<ProfileSyncServiceHarness> timer; | |
| 475 timer.Start(FROM_HERE, | |
| 476 base::TimeDelta::FromMilliseconds(kSyncOperationTimeoutMs), | |
| 477 base::Bind(&ProfileSyncServiceHarness::QuitMessageLoop, | |
| 478 base::Unretained(this))); | |
| 479 { | |
| 480 base::MessageLoop* loop = base::MessageLoop::current(); | |
| 481 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | |
| 482 if (quit_when_idle) | |
| 483 loop->RunUntilIdle(); | |
| 484 else | |
| 485 loop->Run(); | |
| 486 } | |
| 487 | |
| 488 return timer.IsRunning(); | |
| 489 } | |
| 490 | |
| 491 bool ProfileSyncServiceHarness::AwaitSteadyState() { | |
|
rlarocque
2014/01/28 02:50:48
It's not clear to me what we can infer about the s
Raghu Simha
2014/01/28 21:13:12
AwaitStatusChange will run the message loop foreve
| |
| 492 bool success = RunMessageLoop(true /* quit_when_idle */); | |
| 493 if (success) { | |
| 494 DVLOG(1) << GetClientInfoString("AwaitSteadyState succeeded"); | |
| 495 return true; | |
| 496 } else { | |
| 497 DVLOG(0) << GetClientInfoString("AwaitSteadyState timed out"); | |
| 498 return false; | |
| 499 } | |
| 500 } | |
| 501 | |
| 519 bool ProfileSyncServiceHarness::AwaitStatusChange( | 502 bool ProfileSyncServiceHarness::AwaitStatusChange( |
| 520 StatusChangeChecker* checker, const std::string& source) { | 503 StatusChangeChecker* checker, const std::string& source) { |
| 521 DVLOG(1) << GetClientInfoString("AwaitStatusChange"); | 504 DVLOG(1) << GetClientInfoString("AwaitStatusChange"); |
| 522 | 505 |
| 523 if (IsSyncDisabled()) { | 506 if (IsSyncDisabled()) { |
| 524 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; | 507 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
| 525 return false; | 508 return false; |
| 526 } | 509 } |
| 527 | 510 |
| 528 DCHECK(status_change_checker_ == NULL); | 511 DCHECK(status_change_checker_ == NULL); |
| 529 status_change_checker_ = checker; | 512 status_change_checker_ = checker; |
| 530 | 513 bool success = RunMessageLoop(false /* quit_when_idle */); |
| 531 base::OneShotTimer<ProfileSyncServiceHarness> timer; | |
| 532 timer.Start(FROM_HERE, | |
| 533 base::TimeDelta::FromMilliseconds(kSyncOperationTimeoutMs), | |
| 534 base::Bind(&ProfileSyncServiceHarness::QuitMessageLoop, | |
| 535 base::Unretained(this))); | |
| 536 { | |
| 537 base::MessageLoop* loop = base::MessageLoop::current(); | |
| 538 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | |
| 539 loop->Run(); | |
| 540 } | |
| 541 | |
| 542 status_change_checker_ = NULL; | 514 status_change_checker_ = NULL; |
| 543 | 515 |
| 544 if (timer.IsRunning()) { | 516 if (success) { |
| 545 DVLOG(1) << GetClientInfoString("AwaitStatusChange succeeded"); | 517 DVLOG(1) << GetClientInfoString("AwaitStatusChange succeeded"); |
| 546 return true; | 518 return true; |
| 547 } else { | 519 } else { |
| 548 DVLOG(0) << GetClientInfoString(base::StringPrintf( | 520 DVLOG(0) << GetClientInfoString(base::StringPrintf( |
| 549 "AwaitStatusChange called from %s timed out", source.c_str())); | 521 "AwaitStatusChange called from %s timed out", source.c_str())); |
| 550 return false; | 522 return false; |
| 551 } | 523 } |
| 552 } | 524 } |
| 553 | 525 |
| 554 std::string ProfileSyncServiceHarness::GenerateFakeOAuth2RefreshTokenString() { | 526 std::string ProfileSyncServiceHarness::GenerateFakeOAuth2RefreshTokenString() { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 570 | 542 |
| 571 bool ProfileSyncServiceHarness::HasAuthError() const { | 543 bool ProfileSyncServiceHarness::HasAuthError() const { |
| 572 return service()->GetAuthError().state() == | 544 return service()->GetAuthError().state() == |
| 573 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | 545 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || |
| 574 service()->GetAuthError().state() == | 546 service()->GetAuthError().state() == |
| 575 GoogleServiceAuthError::SERVICE_ERROR || | 547 GoogleServiceAuthError::SERVICE_ERROR || |
| 576 service()->GetAuthError().state() == | 548 service()->GetAuthError().state() == |
| 577 GoogleServiceAuthError::REQUEST_CANCELED; | 549 GoogleServiceAuthError::REQUEST_CANCELED; |
| 578 } | 550 } |
| 579 | 551 |
| 580 // We use this function to share code between IsFullySynced and IsDataSynced. | 552 // TODO(sync): Remove this method once we stop relying on self notifications and |
| 581 bool ProfileSyncServiceHarness::IsDataSyncedImpl() const { | 553 // comparing progress markers. |
| 582 return ServiceIsPushingChanges() && | 554 bool ProfileSyncServiceHarness::IsCommitActivityComplete() const { |
|
rlarocque
2014/01/28 02:50:48
I think HasFullySyncedProgressMarkers() might be a
Raghu Simha
2014/01/28 21:13:12
I've renamed it to HasLatestProgressMarkers.
| |
| 583 GetStatus().notifications_enabled && | 555 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); |
| 584 !service()->HasUnsyncedItems() && | 556 return snap.model_neutral_state().num_successful_commits == 0 && |
| 585 !HasPendingBackendMigration(); | 557 !service()->HasUnsyncedItems(); |
| 586 } | 558 } |
| 587 | 559 |
| 588 bool ProfileSyncServiceHarness::IsDataSynced() const { | 560 bool ProfileSyncServiceHarness::IsSyncSetupComplete() const { |
| 589 if (service() == NULL) { | 561 return ServiceIsPushingChanges() && IsCommitActivityComplete(); |
| 590 DVLOG(1) << GetClientInfoString("IsDataSynced(): false"); | |
| 591 return false; | |
| 592 } | |
| 593 | |
| 594 bool is_data_synced = IsDataSyncedImpl(); | |
| 595 | |
| 596 DVLOG(1) << GetClientInfoString( | |
| 597 is_data_synced ? "IsDataSynced: true" : "IsDataSynced: false"); | |
| 598 return is_data_synced; | |
| 599 } | |
| 600 | |
| 601 bool ProfileSyncServiceHarness::IsFullySynced() const { | |
| 602 if (service() == NULL) { | |
| 603 DVLOG(1) << GetClientInfoString("IsFullySynced: false"); | |
| 604 return false; | |
| 605 } | |
| 606 // If we didn't try to commit anything in the previous cycle, there's a | |
| 607 // good chance that we're now fully up to date. | |
| 608 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); | |
| 609 bool is_fully_synced = | |
| 610 snap.model_neutral_state().num_successful_commits == 0 | |
| 611 && snap.model_neutral_state().commit_result == syncer::SYNCER_OK | |
| 612 && IsDataSyncedImpl(); | |
| 613 | |
| 614 DVLOG(1) << GetClientInfoString( | |
| 615 is_fully_synced ? "IsFullySynced: true" : "IsFullySynced: false"); | |
| 616 return is_fully_synced; | |
| 617 } | 562 } |
| 618 | 563 |
| 619 void ProfileSyncServiceHarness::FinishSyncSetup() { | 564 void ProfileSyncServiceHarness::FinishSyncSetup() { |
| 620 service()->SetSetupInProgress(false); | 565 service()->SetSetupInProgress(false); |
| 621 service()->SetSyncSetupCompleted(); | 566 service()->SetSyncSetupCompleted(); |
| 622 } | 567 } |
| 623 | 568 |
| 624 bool ProfileSyncServiceHarness::HasPendingBackendMigration() const { | |
| 625 browser_sync::BackendMigrator* migrator = | |
| 626 service()->GetBackendMigratorForTest(); | |
| 627 return migrator && migrator->state() != browser_sync::BackendMigrator::IDLE; | |
| 628 } | |
| 629 | |
| 630 bool ProfileSyncServiceHarness::AutoStartEnabled() { | 569 bool ProfileSyncServiceHarness::AutoStartEnabled() { |
| 631 return service()->auto_start_enabled(); | 570 return service()->auto_start_enabled(); |
| 632 } | 571 } |
| 633 | 572 |
| 634 bool ProfileSyncServiceHarness::MatchesPartnerClient() const { | 573 bool ProfileSyncServiceHarness::MatchesPartnerClient() const { |
| 635 // TODO(akalin): Shouldn't this belong with the intersection check? | |
| 636 // Otherwise, this function isn't symmetric. | |
| 637 DCHECK(progress_marker_partner_); | 574 DCHECK(progress_marker_partner_); |
| 638 if (!IsFullySynced()) { | |
| 639 DVLOG(2) << profile_debug_name_ << ": not synced, assuming doesn't match"; | |
| 640 return false; | |
| 641 } | |
| 642 | 575 |
| 643 // Only look for a match if we have at least one enabled datatype in | 576 // Only look for a match if we have at least one enabled datatype in |
| 644 // common with the partner client. | 577 // common with the partner client. |
| 645 const syncer::ModelTypeSet common_types = | 578 const syncer::ModelTypeSet common_types = |
| 646 Intersection(service()->GetActiveDataTypes(), | 579 Intersection(service()->GetActiveDataTypes(), |
| 647 progress_marker_partner_->service()->GetActiveDataTypes()); | 580 progress_marker_partner_->service()->GetActiveDataTypes()); |
| 648 | 581 |
| 649 DVLOG(2) << profile_debug_name_ << ", " | 582 DVLOG(2) << profile_debug_name_ << ", " |
| 650 << progress_marker_partner_->profile_debug_name_ | 583 << progress_marker_partner_->profile_debug_name_ |
| 651 << ": common types are " | 584 << ": common types are " |
| 652 << syncer::ModelTypeSetToString(common_types); | 585 << syncer::ModelTypeSetToString(common_types); |
| 653 | 586 |
| 654 if (!common_types.Empty() && !progress_marker_partner_->IsFullySynced()) { | |
| 655 DVLOG(2) << "non-empty common types and " | |
| 656 << progress_marker_partner_->profile_debug_name_ | |
| 657 << " isn't synced"; | |
| 658 return false; | |
| 659 } | |
| 660 | |
| 661 for (syncer::ModelTypeSet::Iterator i = common_types.First(); | 587 for (syncer::ModelTypeSet::Iterator i = common_types.First(); |
| 662 i.Good(); i.Inc()) { | 588 i.Good(); i.Inc()) { |
| 663 const std::string marker = GetSerializedProgressMarker(i.Get()); | 589 const std::string marker = GetSerializedProgressMarker(i.Get()); |
| 664 const std::string partner_marker = | 590 const std::string partner_marker = |
| 665 progress_marker_partner_->GetSerializedProgressMarker(i.Get()); | 591 progress_marker_partner_->GetSerializedProgressMarker(i.Get()); |
| 666 if (marker != partner_marker) { | 592 if (marker != partner_marker) { |
| 667 if (VLOG_IS_ON(2)) { | 593 if (VLOG_IS_ON(2)) { |
| 668 std::string marker_base64, partner_marker_base64; | 594 std::string marker_base64, partner_marker_base64; |
| 669 base::Base64Encode(marker, &marker_base64); | 595 base::Base64Encode(marker, &marker_base64); |
| 670 base::Base64Encode(partner_marker, &partner_marker_base64); | 596 base::Base64Encode(partner_marker, &partner_marker_base64); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 706 syncer::ModelTypeSet synced_datatypes = service()->GetPreferredDataTypes(); | 632 syncer::ModelTypeSet synced_datatypes = service()->GetPreferredDataTypes(); |
| 707 if (synced_datatypes.Has(datatype)) { | 633 if (synced_datatypes.Has(datatype)) { |
| 708 DVLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " | 634 DVLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " |
| 709 << syncer::ModelTypeToString(datatype) | 635 << syncer::ModelTypeToString(datatype) |
| 710 << " on " << profile_debug_name_ << "."; | 636 << " on " << profile_debug_name_ << "."; |
| 711 return true; | 637 return true; |
| 712 } | 638 } |
| 713 | 639 |
| 714 synced_datatypes.Put(syncer::ModelTypeFromInt(datatype)); | 640 synced_datatypes.Put(syncer::ModelTypeFromInt(datatype)); |
| 715 service()->OnUserChoseDatatypes(false, synced_datatypes); | 641 service()->OnUserChoseDatatypes(false, synced_datatypes); |
| 716 if (AwaitDataSyncCompletion()) { | 642 CallbackStatusChecker sync_setup_complete_checker( |
| 643 base::Bind(&ProfileSyncServiceHarness::IsSyncSetupComplete, | |
| 644 base::Unretained(this)), | |
| 645 "IsSyncSetupComplete"); | |
| 646 if (AwaitStatusChange(&sync_setup_complete_checker, | |
| 647 "EnableSyncForDatatype")) { | |
| 717 DVLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " | 648 DVLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " |
| 718 << syncer::ModelTypeToString(datatype) | 649 << syncer::ModelTypeToString(datatype) |
| 719 << " on " << profile_debug_name_ << "."; | 650 << " on " << profile_debug_name_ << "."; |
| 720 return true; | 651 return true; |
| 721 } | 652 } |
| 722 | 653 |
| 723 DVLOG(0) << GetClientInfoString("EnableSyncForDatatype failed"); | 654 DVLOG(0) << GetClientInfoString("EnableSyncForDatatype failed"); |
| 724 return false; | 655 return false; |
| 725 } | 656 } |
| 726 | 657 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 739 if (!synced_datatypes.Has(datatype)) { | 670 if (!synced_datatypes.Has(datatype)) { |
| 740 DVLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " | 671 DVLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " |
| 741 << syncer::ModelTypeToString(datatype) | 672 << syncer::ModelTypeToString(datatype) |
| 742 << " on " << profile_debug_name_ << "."; | 673 << " on " << profile_debug_name_ << "."; |
| 743 return true; | 674 return true; |
| 744 } | 675 } |
| 745 | 676 |
| 746 synced_datatypes.RetainAll(syncer::UserSelectableTypes()); | 677 synced_datatypes.RetainAll(syncer::UserSelectableTypes()); |
| 747 synced_datatypes.Remove(datatype); | 678 synced_datatypes.Remove(datatype); |
| 748 service()->OnUserChoseDatatypes(false, synced_datatypes); | 679 service()->OnUserChoseDatatypes(false, synced_datatypes); |
| 749 if (AwaitFullSyncCompletion()) { | 680 if (AwaitCommitActivityCompletion()) { |
| 750 DVLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " | 681 DVLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " |
| 751 << syncer::ModelTypeToString(datatype) | 682 << syncer::ModelTypeToString(datatype) |
| 752 << " on " << profile_debug_name_ << "."; | 683 << " on " << profile_debug_name_ << "."; |
| 753 return true; | 684 return true; |
| 754 } | 685 } |
| 755 | 686 |
| 756 DVLOG(0) << GetClientInfoString("DisableSyncForDatatype failed"); | 687 DVLOG(0) << GetClientInfoString("DisableSyncForDatatype failed"); |
| 757 return false; | 688 return false; |
| 758 } | 689 } |
| 759 | 690 |
| 760 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { | 691 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { |
| 761 DVLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes"); | 692 DVLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes"); |
| 762 | 693 |
| 763 if (IsSyncDisabled()) | 694 if (IsSyncDisabled()) |
| 764 return SetupSync(); | 695 return SetupSync(); |
| 765 | 696 |
| 766 if (service() == NULL) { | 697 if (service() == NULL) { |
| 767 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; | 698 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; |
| 768 return false; | 699 return false; |
| 769 } | 700 } |
| 770 | 701 |
| 771 service()->OnUserChoseDatatypes(true, syncer::ModelTypeSet::All()); | 702 service()->OnUserChoseDatatypes(true, syncer::ModelTypeSet::All()); |
| 772 if (AwaitFullSyncCompletion()) { | 703 CallbackStatusChecker sync_setup_complete_checker( |
| 704 base::Bind(&ProfileSyncServiceHarness::IsSyncSetupComplete, | |
| 705 base::Unretained(this)), | |
| 706 "IsSyncSetupComplete"); | |
| 707 if (AwaitStatusChange(&sync_setup_complete_checker, | |
| 708 "EnableSyncForAllDatatypes")) { | |
| 773 DVLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes " | 709 DVLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes " |
| 774 << "on " << profile_debug_name_ << "."; | 710 << "on " << profile_debug_name_ << "."; |
| 775 return true; | 711 return true; |
| 776 } | 712 } |
| 777 | 713 |
| 778 DVLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed"); | 714 DVLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed"); |
| 779 return false; | 715 return false; |
| 780 } | 716 } |
| 781 | 717 |
| 782 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { | 718 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 798 syncer::ModelType model_type) const { | 734 syncer::ModelType model_type) const { |
| 799 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); | 735 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); |
| 800 const syncer::ProgressMarkerMap& markers_map = | 736 const syncer::ProgressMarkerMap& markers_map = |
| 801 snap.download_progress_markers(); | 737 snap.download_progress_markers(); |
| 802 | 738 |
| 803 syncer::ProgressMarkerMap::const_iterator it = | 739 syncer::ProgressMarkerMap::const_iterator it = |
| 804 markers_map.find(model_type); | 740 markers_map.find(model_type); |
| 805 return (it != markers_map.end()) ? it->second : std::string(); | 741 return (it != markers_map.end()) ? it->second : std::string(); |
| 806 } | 742 } |
| 807 | 743 |
| 744 // TODO(sync): Clean up this method in a separate CL. Remove all snapshot fields | |
| 745 // and log shorter, more meaningful messages. | |
| 808 std::string ProfileSyncServiceHarness::GetClientInfoString( | 746 std::string ProfileSyncServiceHarness::GetClientInfoString( |
| 809 const std::string& message) const { | 747 const std::string& message) const { |
| 810 std::stringstream os; | 748 std::stringstream os; |
| 811 os << profile_debug_name_ << ": " << message << ": "; | 749 os << profile_debug_name_ << ": " << message << ": "; |
| 812 if (service()) { | 750 if (service()) { |
| 813 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); | 751 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); |
| 814 const ProfileSyncService::Status& status = GetStatus(); | 752 const ProfileSyncService::Status& status = GetStatus(); |
| 815 // Capture select info from the sync session snapshot and syncer status. | 753 // Capture select info from the sync session snapshot and syncer status. |
| 816 // TODO(rsimha): Audit the list of fields below, and eventually eliminate | |
| 817 // the use of the sync session snapshot. See crbug.com/323380. | |
| 818 os << ", has_unsynced_items: " | 754 os << ", has_unsynced_items: " |
| 819 << (service()->sync_initialized() ? service()->HasUnsyncedItems() : 0) | 755 << (service()->sync_initialized() ? service()->HasUnsyncedItems() : 0) |
| 820 << ", did_commit: " | 756 << ", did_commit: " |
| 821 << (snap.model_neutral_state().num_successful_commits == 0 && | 757 << (snap.model_neutral_state().num_successful_commits == 0 && |
| 822 snap.model_neutral_state().commit_result == syncer::SYNCER_OK) | 758 snap.model_neutral_state().commit_result == syncer::SYNCER_OK) |
| 823 << ", encryption conflicts: " | 759 << ", encryption conflicts: " |
| 824 << snap.num_encryption_conflicts() | 760 << snap.num_encryption_conflicts() |
| 825 << ", hierarchy conflicts: " | 761 << ", hierarchy conflicts: " |
| 826 << snap.num_hierarchy_conflicts() | 762 << snap.num_hierarchy_conflicts() |
| 827 << ", server conflicts: " | 763 << ", server conflicts: " |
| 828 << snap.num_server_conflicts() | 764 << snap.num_server_conflicts() |
| 829 << ", num_updates_downloaded : " | 765 << ", num_updates_downloaded : " |
| 830 << snap.model_neutral_state().num_updates_downloaded_total | 766 << snap.model_neutral_state().num_updates_downloaded_total |
| 831 << ", passphrase_required_reason: " | 767 << ", passphrase_required_reason: " |
| 832 << syncer::PassphraseRequiredReasonToString( | 768 << syncer::PassphraseRequiredReasonToString( |
| 833 service()->passphrase_required_reason()) | 769 service()->passphrase_required_reason()) |
| 834 << ", notifications_enabled: " | 770 << ", notifications_enabled: " |
| 835 << status.notifications_enabled | 771 << status.notifications_enabled |
| 836 << ", service_is_pushing_changes: " | 772 << ", service_is_pushing_changes: " |
| 837 << ServiceIsPushingChanges() | 773 << ServiceIsPushingChanges(); |
| 838 << ", has_pending_backend_migration: " | |
| 839 << HasPendingBackendMigration(); | |
| 840 } else { | 774 } else { |
| 841 os << "Sync service not available"; | 775 os << "Sync service not available"; |
| 842 } | 776 } |
| 843 return os.str(); | 777 return os.str(); |
| 844 } | 778 } |
| 845 | 779 |
| 846 bool ProfileSyncServiceHarness::EnableEncryption() { | 780 bool ProfileSyncServiceHarness::EnableEncryption() { |
| 847 if (IsEncryptionComplete()) | 781 if (IsEncryptionComplete()) |
| 848 return true; | 782 return true; |
| 849 service()->EnableEncryptEverything(); | 783 service()->EnableEncryptEverything(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 | 840 |
| 907 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 841 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 908 scoped_ptr<base::DictionaryValue> value( | 842 scoped_ptr<base::DictionaryValue> value( |
| 909 sync_ui_util::ConstructAboutInformation(service())); | 843 sync_ui_util::ConstructAboutInformation(service())); |
| 910 std::string service_status; | 844 std::string service_status; |
| 911 base::JSONWriter::WriteWithOptions(value.get(), | 845 base::JSONWriter::WriteWithOptions(value.get(), |
| 912 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 846 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 913 &service_status); | 847 &service_status); |
| 914 return service_status; | 848 return service_status; |
| 915 } | 849 } |
| OLD | NEW |