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 #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> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <sstream> | 12 #include <sstream> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/base64.h" | |
| 16 #include "base/compiler_specific.h" | |
| 15 #include "base/json/json_writer.h" | 17 #include "base/json/json_writer.h" |
| 16 #include "base/logging.h" | 18 #include "base/logging.h" |
| 17 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 18 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
| 19 #include "base/task.h" | 21 #include "base/task.h" |
| 20 #include "base/tracked.h" | 22 #include "base/tracked.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/sync/sessions/session_state.h" | 24 #include "chrome/browser/sync/sessions/session_state.h" |
| 23 #include "chrome/browser/sync/signin_manager.h" | 25 #include "chrome/browser/sync/signin_manager.h" |
| 24 #include "chrome/browser/sync/sync_ui_util.h" | 26 #include "chrome/browser/sync/sync_ui_util.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 wait_state_(INITIAL_WAIT_STATE), | 102 wait_state_(INITIAL_WAIT_STATE), |
| 101 profile_(profile), | 103 profile_(profile), |
| 102 service_(NULL), | 104 service_(NULL), |
| 103 timestamp_match_partner_(NULL), | 105 timestamp_match_partner_(NULL), |
| 104 username_(username), | 106 username_(username), |
| 105 password_(password), | 107 password_(password), |
| 106 profile_debug_name_(profile->GetDebugName()) { | 108 profile_debug_name_(profile->GetDebugName()) { |
| 107 if (IsSyncAlreadySetup()) { | 109 if (IsSyncAlreadySetup()) { |
| 108 service_ = profile_->GetProfileSyncService(); | 110 service_ = profile_->GetProfileSyncService(); |
| 109 service_->AddObserver(this); | 111 service_->AddObserver(this); |
| 112 ignore_result(TryListeningToMigrationEvents()); | |
| 110 wait_state_ = FULLY_SYNCED; | 113 wait_state_ = FULLY_SYNCED; |
| 111 } | 114 } |
| 112 } | 115 } |
| 113 | 116 |
| 114 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() {} | 117 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() {} |
| 115 | 118 |
| 116 // static | 119 // static |
| 117 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach( | 120 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach( |
| 118 Profile* profile) { | 121 Profile* profile) { |
| 119 if (!profile->HasProfileSyncService()) { | 122 if (!profile->HasProfileSyncService()) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 << " seconds."; | 176 << " seconds."; |
| 174 return false; | 177 return false; |
| 175 } | 178 } |
| 176 | 179 |
| 177 // Choose the datatypes to be synced. If all datatypes are to be synced, | 180 // Choose the datatypes to be synced. If all datatypes are to be synced, |
| 178 // set sync_everything to true; otherwise, set it to false. | 181 // set sync_everything to true; otherwise, set it to false. |
| 179 bool sync_everything = (synced_datatypes.size() == | 182 bool sync_everything = (synced_datatypes.size() == |
| 180 (syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE)); | 183 (syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE)); |
| 181 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 184 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 182 | 185 |
| 186 // Subscribe sync client to notifications from the backend migrator | |
| 187 // (possible only choosing data types). | |
|
Raghu Simha
2011/09/01 04:23:58
nit: Perhaps s/only choosing/only while choosing/
akalin
2011/09/01 04:39:05
Done.
| |
| 188 DCHECK(TryListeningToMigrationEvents()); | |
| 189 | |
| 183 // Make sure that a partner client hasn't already set an explicit passphrase. | 190 // Make sure that a partner client hasn't already set an explicit passphrase. |
| 184 if (wait_state_ == SET_PASSPHRASE_FAILED) { | 191 if (wait_state_ == SET_PASSPHRASE_FAILED) { |
| 185 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" | 192 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
| 186 " until SetPassphrase is called."; | 193 " until SetPassphrase is called."; |
| 187 return false; | 194 return false; |
| 188 } | 195 } |
| 189 | 196 |
| 190 // Wait for initial sync cycle to be completed. | 197 // Wait for initial sync cycle to be completed. |
| 191 DCHECK_EQ(wait_state_, WAITING_FOR_INITIAL_SYNC); | 198 DCHECK_EQ(wait_state_, WAITING_FOR_INITIAL_SYNC); |
| 192 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 199 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 203 " until SetPassphrase is called."; | 210 " until SetPassphrase is called."; |
| 204 return false; | 211 return false; |
| 205 } | 212 } |
| 206 | 213 |
| 207 // Indicate to the browser that sync setup is complete. | 214 // Indicate to the browser that sync setup is complete. |
| 208 service()->SetSyncSetupCompleted(); | 215 service()->SetSyncSetupCompleted(); |
| 209 | 216 |
| 210 return true; | 217 return true; |
| 211 } | 218 } |
| 212 | 219 |
| 220 bool ProfileSyncServiceHarness::TryListeningToMigrationEvents() { | |
| 221 browser_sync::BackendMigrator* migrator = | |
| 222 service_->GetBackendMigratorForTest(); | |
| 223 if (migrator && !migrator->HasMigrationObserver(this)) { | |
| 224 migrator->AddMigrationObserver(this); | |
| 225 return true; | |
| 226 } | |
| 227 return false; | |
| 228 } | |
| 229 | |
| 213 void ProfileSyncServiceHarness::SignalStateCompleteWithNextState( | 230 void ProfileSyncServiceHarness::SignalStateCompleteWithNextState( |
| 214 WaitState next_state) { | 231 WaitState next_state) { |
| 215 wait_state_ = next_state; | 232 wait_state_ = next_state; |
| 216 SignalStateComplete(); | 233 SignalStateComplete(); |
| 217 } | 234 } |
| 218 | 235 |
| 219 void ProfileSyncServiceHarness::SignalStateComplete() { | 236 void ProfileSyncServiceHarness::SignalStateComplete() { |
| 220 MessageLoop::current()->Quit(); | 237 MessageLoop::current()->Quit(); |
| 221 } | 238 } |
| 222 | 239 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 VLOG(1) << GetClientInfoString( | 354 VLOG(1) << GetClientInfoString( |
| 338 "WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION"); | 355 "WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION"); |
| 339 const browser_sync::sessions::SyncSessionSnapshot *snap = | 356 const browser_sync::sessions::SyncSessionSnapshot *snap = |
| 340 GetLastSessionSnapshot(); | 357 GetLastSessionSnapshot(); |
| 341 CHECK(snap); | 358 CHECK(snap); |
| 342 retry_verifier_.VerifyRetryInterval(*snap); | 359 retry_verifier_.VerifyRetryInterval(*snap); |
| 343 if (retry_verifier_.done()) | 360 if (retry_verifier_.done()) |
| 344 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); | 361 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); |
| 345 break; | 362 break; |
| 346 } | 363 } |
| 364 case WAITING_FOR_MIGRATION_TO_START: { | |
| 365 VLOG(1) << GetClientInfoString("WAITING_FOR_MIGRATION_TO_START"); | |
| 366 if (HasPendingBackendMigration()) { | |
| 367 SignalStateCompleteWithNextState(WAITING_FOR_MIGRATION_TO_FINISH); | |
| 368 } | |
| 369 break; | |
| 370 } | |
| 371 case WAITING_FOR_MIGRATION_TO_FINISH: { | |
| 372 VLOG(1) << GetClientInfoString("WAITING_FOR_MIGRATION_TO_FINISH"); | |
| 373 if (!HasPendingBackendMigration()) { | |
| 374 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); | |
| 375 } | |
| 376 break; | |
| 377 } | |
| 347 case SERVER_UNREACHABLE: { | 378 case SERVER_UNREACHABLE: { |
| 348 VLOG(1) << GetClientInfoString("SERVER_UNREACHABLE"); | 379 VLOG(1) << GetClientInfoString("SERVER_UNREACHABLE"); |
| 349 if (GetStatus().server_reachable) { | 380 if (GetStatus().server_reachable) { |
| 350 // The client was offline due to the network being disabled, but is now | 381 // The client was offline due to the network being disabled, but is now |
| 351 // back online. Wait for the pending sync cycle to complete. | 382 // back online. Wait for the pending sync cycle to complete. |
| 352 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); | 383 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); |
| 353 } | 384 } |
| 354 break; | 385 break; |
| 355 } | 386 } |
| 356 case SET_PASSPHRASE_FAILED: { | 387 case SET_PASSPHRASE_FAILED: { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 380 // classes using the the UI message loop. Defer to their handling. | 411 // classes using the the UI message loop. Defer to their handling. |
| 381 break; | 412 break; |
| 382 } | 413 } |
| 383 return original_wait_state != wait_state_; | 414 return original_wait_state != wait_state_; |
| 384 } | 415 } |
| 385 | 416 |
| 386 void ProfileSyncServiceHarness::OnStateChanged() { | 417 void ProfileSyncServiceHarness::OnStateChanged() { |
| 387 RunStateChangeMachine(); | 418 RunStateChangeMachine(); |
| 388 } | 419 } |
| 389 | 420 |
| 421 void ProfileSyncServiceHarness::OnMigrationStateChange() { | |
| 422 // Update migration state. | |
| 423 if (HasPendingBackendMigration()) { | |
| 424 // Merge current pending migration types into | |
| 425 // |pending_migration_types_|. | |
| 426 syncable::ModelTypeSet new_pending_migration_types = | |
| 427 service()->GetBackendMigratorForTest()-> | |
| 428 GetPendingMigrationTypesForTest(); | |
| 429 syncable::ModelTypeSet temp; | |
| 430 std::set_union(pending_migration_types_.begin(), | |
| 431 pending_migration_types_.end(), | |
| 432 new_pending_migration_types.begin(), | |
| 433 new_pending_migration_types.end(), | |
| 434 std::inserter(temp, temp.end())); | |
| 435 std::swap(pending_migration_types_, temp); | |
| 436 VLOG(1) << profile_debug_name_ << ": new pending migration types " | |
| 437 << syncable::ModelTypeSetToString(pending_migration_types_); | |
| 438 } else { | |
| 439 // Merge just-finished pending migration types into | |
| 440 // |migration_types_|. | |
| 441 syncable::ModelTypeSet temp; | |
| 442 std::set_union(pending_migration_types_.begin(), | |
| 443 pending_migration_types_.end(), | |
| 444 migrated_types_.begin(), | |
| 445 migrated_types_.end(), | |
| 446 std::inserter(temp, temp.end())); | |
| 447 std::swap(migrated_types_, temp); | |
| 448 pending_migration_types_.clear(); | |
| 449 VLOG(1) << profile_debug_name_ << ": new migrated types " | |
| 450 << syncable::ModelTypeSetToString(migrated_types_); | |
| 451 } | |
| 452 RunStateChangeMachine(); | |
| 453 } | |
| 454 | |
| 390 bool ProfileSyncServiceHarness::AwaitPassphraseRequired() { | 455 bool ProfileSyncServiceHarness::AwaitPassphraseRequired() { |
| 391 VLOG(1) << GetClientInfoString("AwaitPassphraseRequired"); | 456 VLOG(1) << GetClientInfoString("AwaitPassphraseRequired"); |
| 392 if (wait_state_ == SYNC_DISABLED) { | 457 if (wait_state_ == SYNC_DISABLED) { |
| 393 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; | 458 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
| 394 return false; | 459 return false; |
| 395 } | 460 } |
| 396 | 461 |
| 397 if (service()->IsPassphraseRequired()) { | 462 if (service()->IsPassphraseRequired()) { |
| 398 // It's already true that a passphrase is required; don't wait. | 463 // It's already true that a passphrase is required; don't wait. |
| 399 return true; | 464 return true; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 if (wait_state_ == SYNC_DISABLED) { | 527 if (wait_state_ == SYNC_DISABLED) { |
| 463 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; | 528 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
| 464 return false; | 529 return false; |
| 465 } | 530 } |
| 466 | 531 |
| 467 if (IsSynced()) { | 532 if (IsSynced()) { |
| 468 // Client is already synced; don't wait. | 533 // Client is already synced; don't wait. |
| 469 return true; | 534 return true; |
| 470 } | 535 } |
| 471 | 536 |
| 472 return AwaitSyncCycleCompletionHelper(reason); | |
| 473 } | |
| 474 | |
| 475 bool ProfileSyncServiceHarness::AwaitNextSyncCycleCompletion( | |
| 476 const std::string& reason) { | |
| 477 VLOG(1) << GetClientInfoString("AwaitNextSyncCycleCompletion"); | |
| 478 return AwaitSyncCycleCompletionHelper(reason); | |
| 479 } | |
| 480 | |
| 481 bool ProfileSyncServiceHarness::AwaitSyncCycleCompletionHelper( | |
| 482 const std::string& reason) { | |
| 483 if (wait_state_ == SERVER_UNREACHABLE) { | 537 if (wait_state_ == SERVER_UNREACHABLE) { |
| 484 // Client was offline; wait for it to go online, and then wait for sync. | 538 // Client was offline; wait for it to go online, and then wait for sync. |
| 485 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 539 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
| 486 DCHECK_EQ(wait_state_, WAITING_FOR_SYNC_TO_FINISH); | 540 DCHECK_EQ(wait_state_, WAITING_FOR_SYNC_TO_FINISH); |
| 487 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 541 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
| 488 } | 542 } |
| 489 | 543 |
| 490 DCHECK(service()->sync_initialized()); | 544 DCHECK(service()->sync_initialized()); |
| 491 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; | 545 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; |
| 492 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 546 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 515 const browser_sync::sessions::SyncSessionSnapshot *snap = | 569 const browser_sync::sessions::SyncSessionSnapshot *snap = |
| 516 GetLastSessionSnapshot(); | 570 GetLastSessionSnapshot(); |
| 517 CHECK(snap); | 571 CHECK(snap); |
| 518 retry_verifier_.Initialize(*snap); | 572 retry_verifier_.Initialize(*snap); |
| 519 wait_state_ = WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION; | 573 wait_state_ = WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION; |
| 520 AwaitStatusChangeWithTimeout(kExponentialBackoffVerificationTimeoutMs, | 574 AwaitStatusChangeWithTimeout(kExponentialBackoffVerificationTimeoutMs, |
| 521 "Verify Exponential backoff"); | 575 "Verify Exponential backoff"); |
| 522 return (retry_verifier_.Succeeded()); | 576 return (retry_verifier_.Succeeded()); |
| 523 } | 577 } |
| 524 | 578 |
| 579 bool ProfileSyncServiceHarness::AwaitMigration( | |
| 580 const syncable::ModelTypeSet& expected_migrated_types) { | |
| 581 VLOG(1) << GetClientInfoString("AwaitMigration"); | |
| 582 VLOG(1) << profile_debug_name_ << ": waiting until migration is done for " | |
| 583 << syncable::ModelTypeSetToString(expected_migrated_types); | |
| 584 while (true) { | |
| 585 bool migration_finished = | |
| 586 std::includes(migrated_types_.begin(), migrated_types_.end(), | |
| 587 expected_migrated_types.begin(), | |
| 588 expected_migrated_types.end()); | |
| 589 VLOG(1) << "Migrated types " | |
| 590 << syncable::ModelTypeSetToString(migrated_types_) | |
| 591 << (migration_finished ? " contains " : " does not contain ") | |
| 592 << syncable::ModelTypeSetToString(expected_migrated_types); | |
| 593 if (migration_finished) { | |
| 594 return true; | |
| 595 } | |
| 596 | |
| 597 if (HasPendingBackendMigration()) { | |
| 598 wait_state_ = WAITING_FOR_MIGRATION_TO_FINISH; | |
| 599 } else { | |
| 600 wait_state_ = WAITING_FOR_MIGRATION_TO_START; | |
| 601 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | |
| 602 "Wait for migration to start"); | |
| 603 if (wait_state_ != WAITING_FOR_MIGRATION_TO_FINISH) { | |
| 604 VLOG(1) << profile_debug_name_ | |
| 605 << ": wait state = " << wait_state_ | |
| 606 << " after migration start is not " | |
| 607 << "WAITING_FOR_MIGRATION_TO_FINISH"; | |
| 608 return false; | |
| 609 } | |
| 610 } | |
| 611 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | |
| 612 "Wait for migration to finish"); | |
| 613 if (wait_state_ != WAITING_FOR_NOTHING) { | |
| 614 VLOG(1) << profile_debug_name_ | |
| 615 << ": wait state = " << wait_state_ | |
| 616 << " after migration finish is not WAITING_FOR_NOTHING"; | |
| 617 return false; | |
| 618 } | |
| 619 if (!AwaitSyncCycleCompletion( | |
| 620 "Config sync cycle after migration cycle")) { | |
| 621 return false; | |
| 622 } | |
| 623 } | |
| 624 } | |
| 625 | |
| 525 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( | 626 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
| 526 ProfileSyncServiceHarness* partner) { | 627 ProfileSyncServiceHarness* partner) { |
| 527 VLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); | 628 VLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); |
| 528 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) | 629 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) |
| 529 return false; | 630 return false; |
| 530 return partner->WaitUntilTimestampMatches(this, | 631 return partner->WaitUntilTimestampMatches(this, |
| 531 "Sync cycle completion on passive client."); | 632 "Sync cycle completion on passive client."); |
| 532 } | 633 } |
| 533 | 634 |
| 534 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( | 635 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 725 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 625 // TODO(rsimha): Remove additional checks of snap->has_more_to_sync and | 726 // TODO(rsimha): Remove additional checks of snap->has_more_to_sync and |
| 626 // snap->unsynced_count once http://crbug.com/48989 is fixed. | 727 // snap->unsynced_count once http://crbug.com/48989 is fixed. |
| 627 bool is_synced = snap && | 728 bool is_synced = snap && |
| 628 snap->num_blocking_conflicting_updates == 0 && | 729 snap->num_blocking_conflicting_updates == 0 && |
| 629 ServiceIsPushingChanges() && | 730 ServiceIsPushingChanges() && |
| 630 GetStatus().notifications_enabled && | 731 GetStatus().notifications_enabled && |
| 631 !service()->HasUnsyncedItems() && | 732 !service()->HasUnsyncedItems() && |
| 632 !snap->has_more_to_sync && | 733 !snap->has_more_to_sync && |
| 633 snap->unsynced_count == 0 && | 734 snap->unsynced_count == 0 && |
| 634 !service()->HasPendingBackendMigration() && | 735 !HasPendingBackendMigration() && |
| 635 service()->passphrase_required_reason() != | 736 service()->passphrase_required_reason() != |
| 636 sync_api::REASON_SET_PASSPHRASE_FAILED; | 737 sync_api::REASON_SET_PASSPHRASE_FAILED; |
| 637 VLOG(1) << GetClientInfoString( | 738 VLOG(1) << GetClientInfoString( |
| 638 is_synced ? "IsSynced: true" : "IsSynced: false"); | 739 is_synced ? "IsSynced: true" : "IsSynced: false"); |
| 639 return is_synced; | 740 return is_synced; |
| 640 } | 741 } |
| 641 | 742 |
| 743 bool ProfileSyncServiceHarness::HasPendingBackendMigration() { | |
| 744 browser_sync::BackendMigrator* migrator = | |
| 745 service()->GetBackendMigratorForTest(); | |
| 746 return migrator && migrator->state() != browser_sync::BackendMigrator::IDLE; | |
| 747 } | |
| 748 | |
| 642 bool ProfileSyncServiceHarness::MatchesOtherClient( | 749 bool ProfileSyncServiceHarness::MatchesOtherClient( |
| 643 ProfileSyncServiceHarness* partner) { | 750 ProfileSyncServiceHarness* partner) { |
| 644 if (!IsSynced()) | 751 // TODO(akalin): Shouldn't this with the intersection check? |
| 752 // Otherwise, this function isn't symmetric. | |
| 753 if (!IsSynced()) { | |
| 754 VLOG(1) << profile_debug_name_ << ": not synced, assuming doesn't match"; | |
| 645 return false; | 755 return false; |
| 756 } | |
| 646 | 757 |
| 647 // Only look for a match if we have at least one enabled datatype in | 758 // Only look for a match if we have at least one enabled datatype in |
| 648 // common with the partner client. | 759 // common with the partner client. |
| 649 syncable::ModelTypeSet types, other_types, intersection_types; | 760 syncable::ModelTypeSet types, other_types, intersection_types; |
| 650 service()->GetPreferredDataTypes(&types); | 761 service()->GetPreferredDataTypes(&types); |
| 651 partner->service()->GetPreferredDataTypes(&other_types); | 762 partner->service()->GetPreferredDataTypes(&other_types); |
| 652 std::set_intersection(types.begin(), types.end(), other_types.begin(), | 763 std::set_intersection(types.begin(), types.end(), other_types.begin(), |
| 653 other_types.end(), | 764 other_types.end(), |
| 654 inserter(intersection_types, | 765 inserter(intersection_types, |
| 655 intersection_types.begin())); | 766 intersection_types.begin())); |
| 767 | |
| 768 VLOG(1) << profile_debug_name_ << ", " << partner->profile_debug_name_ | |
| 769 << ": common types are " | |
| 770 << syncable::ModelTypeSetToString(intersection_types); | |
| 771 | |
| 772 if (!intersection_types.empty() && !partner->IsSynced()) { | |
| 773 VLOG(1) << "non-empty common types and " | |
| 774 << partner->profile_debug_name_ << " isn't synced"; | |
| 775 return false; | |
| 776 } | |
| 777 | |
| 656 for (syncable::ModelTypeSet::iterator i = intersection_types.begin(); | 778 for (syncable::ModelTypeSet::iterator i = intersection_types.begin(); |
| 657 i != intersection_types.end(); | 779 i != intersection_types.end(); ++i) { |
| 658 ++i) { | 780 const std::string timestamp = GetUpdatedTimestamp(*i); |
| 659 if (!partner->IsSynced() || | 781 const std::string partner_timestamp = partner->GetUpdatedTimestamp(*i); |
| 660 partner->GetUpdatedTimestamp(*i) != GetUpdatedTimestamp(*i)) { | 782 if (timestamp != partner_timestamp) { |
| 783 if (VLOG_IS_ON(1)) { | |
| 784 std::string timestamp_base64, partner_timestamp_base64; | |
| 785 if (!base::Base64Encode(timestamp, ×tamp_base64)) { | |
| 786 NOTREACHED(); | |
| 787 } | |
| 788 if (!base::Base64Encode( | |
| 789 partner_timestamp, &partner_timestamp_base64)) { | |
| 790 NOTREACHED(); | |
| 791 } | |
| 792 VLOG(1) << syncable::ModelTypeToString(*i) << ": " | |
| 793 << profile_debug_name_ << " timestamp = " | |
| 794 << timestamp_base64 << ", " | |
| 795 << partner->profile_debug_name_ | |
| 796 << " partner timestamp = " | |
| 797 << partner_timestamp_base64; | |
| 798 } | |
| 661 return false; | 799 return false; |
| 662 } | 800 } |
| 663 } | 801 } |
| 664 return true; | 802 return true; |
| 665 } | 803 } |
| 666 | 804 |
| 667 const SyncSessionSnapshot* | 805 const SyncSessionSnapshot* |
| 668 ProfileSyncServiceHarness::GetLastSessionSnapshot() const { | 806 ProfileSyncServiceHarness::GetLastSessionSnapshot() const { |
| 669 DCHECK(service_ != NULL) << "Sync service has not yet been set up."; | 807 DCHECK(service_ != NULL) << "Sync service has not yet been set up."; |
| 670 if (service_->sync_initialized()) { | 808 if (service_->sync_initialized()) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 << ", num_updates_downloaded : " | 955 << ", num_updates_downloaded : " |
| 818 << snap->syncer_status.num_updates_downloaded_total | 956 << snap->syncer_status.num_updates_downloaded_total |
| 819 << ", passphrase_required_reason: " | 957 << ", passphrase_required_reason: " |
| 820 << sync_api::PassphraseRequiredReasonToString( | 958 << sync_api::PassphraseRequiredReasonToString( |
| 821 service()->passphrase_required_reason()) | 959 service()->passphrase_required_reason()) |
| 822 << ", notifications_enabled: " | 960 << ", notifications_enabled: " |
| 823 << status.notifications_enabled | 961 << status.notifications_enabled |
| 824 << ", service_is_pushing_changes: " | 962 << ", service_is_pushing_changes: " |
| 825 << ServiceIsPushingChanges() | 963 << ServiceIsPushingChanges() |
| 826 << ", has_pending_backend_migration: " | 964 << ", has_pending_backend_migration: " |
| 827 << service()->HasPendingBackendMigration(); | 965 << HasPendingBackendMigration(); |
| 828 } else { | 966 } else { |
| 829 os << "Sync session snapshot not available"; | 967 os << "Sync session snapshot not available"; |
| 830 } | 968 } |
| 831 } else { | 969 } else { |
| 832 os << "Sync service not available"; | 970 os << "Sync service not available"; |
| 833 } | 971 } |
| 834 return os.str(); | 972 return os.str(); |
| 835 } | 973 } |
| 836 | 974 |
| 837 bool ProfileSyncServiceHarness::EnableEncryptionForType( | 975 bool ProfileSyncServiceHarness::EnableEncryptionForType( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 return (synced_types.count(type) != 0); | 1033 return (synced_types.count(type) != 0); |
| 896 } | 1034 } |
| 897 | 1035 |
| 898 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 1036 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 899 DictionaryValue value; | 1037 DictionaryValue value; |
| 900 sync_ui_util::ConstructAboutInformation(service_, &value); | 1038 sync_ui_util::ConstructAboutInformation(service_, &value); |
| 901 std::string service_status; | 1039 std::string service_status; |
| 902 base::JSONWriter::Write(&value, true, &service_status); | 1040 base::JSONWriter::Write(&value, true, &service_status); |
| 903 return service_status; | 1041 return service_status; |
| 904 } | 1042 } |
| OLD | NEW |