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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 case WAITING_FOR_ON_BACKEND_INITIALIZED: { | 249 case WAITING_FOR_ON_BACKEND_INITIALIZED: { |
250 VLOG(1) << GetClientInfoString("WAITING_FOR_ON_BACKEND_INITIALIZED"); | 250 VLOG(1) << GetClientInfoString("WAITING_FOR_ON_BACKEND_INITIALIZED"); |
251 if (service()->sync_initialized()) { | 251 if (service()->sync_initialized()) { |
252 // The sync backend is initialized. | 252 // The sync backend is initialized. |
253 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); | 253 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); |
254 } | 254 } |
255 break; | 255 break; |
256 } | 256 } |
257 case WAITING_FOR_INITIAL_SYNC: { | 257 case WAITING_FOR_INITIAL_SYNC: { |
258 VLOG(1) << GetClientInfoString("WAITING_FOR_INITIAL_SYNC"); | 258 VLOG(1) << GetClientInfoString("WAITING_FOR_INITIAL_SYNC"); |
259 if (IsSynced()) { | 259 if (IsFullySynced()) { |
260 // The first sync cycle is now complete. We can start running tests. | 260 // The first sync cycle is now complete. We can start running tests. |
261 SignalStateCompleteWithNextState(FULLY_SYNCED); | 261 SignalStateCompleteWithNextState(FULLY_SYNCED); |
262 break; | 262 break; |
263 } | 263 } |
264 if (service()->passphrase_required_reason() == | 264 if (service()->passphrase_required_reason() == |
265 sync_api::REASON_SET_PASSPHRASE_FAILED) { | 265 sync_api::REASON_SET_PASSPHRASE_FAILED) { |
266 // A passphrase is required for decryption and we don't have it. Do not | 266 // A passphrase is required for decryption and we don't have it. Do not |
267 // wait any more. | 267 // wait any more. |
268 SignalStateCompleteWithNextState(SET_PASSPHRASE_FAILED); | 268 SignalStateCompleteWithNextState(SET_PASSPHRASE_FAILED); |
269 break; | 269 break; |
270 } | 270 } |
271 break; | 271 break; |
272 } | 272 } |
273 case WAITING_FOR_SYNC_TO_FINISH: { | 273 case WAITING_FOR_FULL_SYNC: { |
274 VLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_TO_FINISH"); | 274 VLOG(1) << GetClientInfoString("WAITING_FOR_FULL_SYNC"); |
275 if (IsSynced()) { | 275 if (IsFullySynced()) { |
276 // The sync cycle we were waiting for is complete. | 276 // The sync cycle we were waiting for is complete. |
277 SignalStateCompleteWithNextState(FULLY_SYNCED); | 277 SignalStateCompleteWithNextState(FULLY_SYNCED); |
278 break; | 278 break; |
279 } | 279 } |
280 if (service()->passphrase_required_reason() == | 280 if (service()->passphrase_required_reason() == |
281 sync_api::REASON_SET_PASSPHRASE_FAILED) { | 281 sync_api::REASON_SET_PASSPHRASE_FAILED) { |
282 // A passphrase is required for decryption and we don't have it. Do not | 282 // A passphrase is required for decryption and we don't have it. Do not |
283 // wait any more. | 283 // wait any more. |
284 SignalStateCompleteWithNextState(SET_PASSPHRASE_FAILED); | 284 SignalStateCompleteWithNextState(SET_PASSPHRASE_FAILED); |
285 break; | 285 break; |
286 } | 286 } |
287 if (!GetStatus().server_reachable) { | 287 if (!GetStatus().server_reachable) { |
288 // The client cannot reach the sync server because the network is | 288 // The client cannot reach the sync server because the network is |
289 // disabled. There is no need to wait anymore. | 289 // disabled. There is no need to wait anymore. |
290 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); | 290 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); |
291 break; | 291 break; |
292 } | 292 } |
293 break; | 293 break; |
294 } | 294 } |
| 295 case WAITING_FOR_DATA_SYNC: { |
| 296 if (IsDataSynced()) { |
| 297 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 298 break; |
| 299 } |
| 300 break; |
| 301 } |
295 case WAITING_FOR_UPDATES: { | 302 case WAITING_FOR_UPDATES: { |
296 VLOG(1) << GetClientInfoString("WAITING_FOR_UPDATES"); | 303 VLOG(1) << GetClientInfoString("WAITING_FOR_UPDATES"); |
297 DCHECK(timestamp_match_partner_); | 304 DCHECK(timestamp_match_partner_); |
298 if (!MatchesOtherClient(timestamp_match_partner_)) { | 305 if (!MatchesOtherClient(timestamp_match_partner_)) { |
299 // The client is not yet fully synced; keep waiting until we converge. | 306 // The client is not yet fully synced; keep waiting until we converge. |
300 break; | 307 break; |
301 } | 308 } |
302 timestamp_match_partner_->service()->RemoveObserver(this); | 309 timestamp_match_partner_->service()->RemoveObserver(this); |
303 timestamp_match_partner_ = NULL; | 310 timestamp_match_partner_ = NULL; |
304 | 311 |
(...skipping 17 matching lines...) Expand all Loading... |
322 SignalStateCompleteWithNextState(FULLY_SYNCED); | 329 SignalStateCompleteWithNextState(FULLY_SYNCED); |
323 } | 330 } |
324 break; | 331 break; |
325 } | 332 } |
326 case WAITING_FOR_ENCRYPTION: { | 333 case WAITING_FOR_ENCRYPTION: { |
327 VLOG(1) << GetClientInfoString("WAITING_FOR_ENCRYPTION"); | 334 VLOG(1) << GetClientInfoString("WAITING_FOR_ENCRYPTION"); |
328 // The correctness of this if condition may depend on the ordering of its | 335 // The correctness of this if condition may depend on the ordering of its |
329 // sub-expressions. See crbug.com/98607, crbug.com/95619. | 336 // sub-expressions. See crbug.com/98607, crbug.com/95619. |
330 // TODO(rlarocque): Figure out a less brittle way of detecting this. | 337 // TODO(rlarocque): Figure out a less brittle way of detecting this. |
331 if (IsTypeEncrypted(waiting_for_encryption_type_) && | 338 if (IsTypeEncrypted(waiting_for_encryption_type_) && |
332 IsSynced() && | 339 IsFullySynced() && |
333 GetLastSessionSnapshot()->num_conflicting_updates == 0) { | 340 GetLastSessionSnapshot()->num_conflicting_updates == 0) { |
334 // Encryption is now complete for the the type in which we were waiting. | 341 // Encryption is now complete for the the type in which we were waiting. |
335 SignalStateCompleteWithNextState(FULLY_SYNCED); | 342 SignalStateCompleteWithNextState(FULLY_SYNCED); |
336 break; | 343 break; |
337 } | 344 } |
338 if (!GetStatus().server_reachable) { | 345 if (!GetStatus().server_reachable) { |
339 // The client cannot reach the sync server because the network is | 346 // The client cannot reach the sync server because the network is |
340 // disabled. There is no need to wait anymore. | 347 // disabled. There is no need to wait anymore. |
341 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); | 348 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); |
342 break; | 349 break; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 // An actionable error has been detected. | 403 // An actionable error has been detected. |
397 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); | 404 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); |
398 } | 405 } |
399 break; | 406 break; |
400 } | 407 } |
401 case SERVER_UNREACHABLE: { | 408 case SERVER_UNREACHABLE: { |
402 VLOG(1) << GetClientInfoString("SERVER_UNREACHABLE"); | 409 VLOG(1) << GetClientInfoString("SERVER_UNREACHABLE"); |
403 if (GetStatus().server_reachable) { | 410 if (GetStatus().server_reachable) { |
404 // The client was offline due to the network being disabled, but is now | 411 // The client was offline due to the network being disabled, but is now |
405 // back online. Wait for the pending sync cycle to complete. | 412 // back online. Wait for the pending sync cycle to complete. |
406 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); | 413 SignalStateCompleteWithNextState(WAITING_FOR_FULL_SYNC); |
407 } | 414 } |
408 break; | 415 break; |
409 } | 416 } |
410 case SET_PASSPHRASE_FAILED: { | 417 case SET_PASSPHRASE_FAILED: { |
411 // A passphrase is required for decryption. There is nothing the sync | 418 // A passphrase is required for decryption. There is nothing the sync |
412 // client can do until SetPassphrase() is called. | 419 // client can do until SetPassphrase() is called. |
413 VLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED"); | 420 VLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED"); |
414 break; | 421 break; |
415 } | 422 } |
416 case FULLY_SYNCED: { | 423 case FULLY_SYNCED: { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 << " seconds."; | 544 << " seconds."; |
538 return false; | 545 return false; |
539 } | 546 } |
540 | 547 |
541 // Wait for sync configuration to complete. | 548 // Wait for sync configuration to complete. |
542 wait_state_ = WAITING_FOR_SYNC_CONFIGURATION; | 549 wait_state_ = WAITING_FOR_SYNC_CONFIGURATION; |
543 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 550 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
544 "Waiting for sync configuration."); | 551 "Waiting for sync configuration."); |
545 } | 552 } |
546 | 553 |
547 bool ProfileSyncServiceHarness::AwaitSyncCycleCompletion( | 554 bool ProfileSyncServiceHarness::AwaitDataSyncCompletion( |
548 const std::string& reason) { | 555 const std::string& reason) { |
549 VLOG(1) << GetClientInfoString("AwaitSyncCycleCompletion"); | 556 VLOG(1) << GetClientInfoString("AwaitDataSyncCompletion"); |
| 557 |
| 558 DCHECK(service()->sync_initialized()); |
| 559 DCHECK_NE(wait_state_, SYNC_DISABLED); |
| 560 DCHECK_NE(wait_state_, SERVER_UNREACHABLE); |
| 561 |
| 562 if (IsDataSynced()) { |
| 563 // Client is already synced; don't wait. |
| 564 return true; |
| 565 } |
| 566 |
| 567 wait_state_ = WAITING_FOR_DATA_SYNC; |
| 568 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
| 569 if (wait_state_ == FULLY_SYNCED) { |
| 570 return true; |
| 571 } else { |
| 572 LOG(ERROR) << "AwaitDataSyncCompletion failed, state is now: " << wait_state
_; |
| 573 return false; |
| 574 } |
| 575 } |
| 576 |
| 577 bool ProfileSyncServiceHarness::AwaitFullSyncCompletion( |
| 578 const std::string& reason) { |
| 579 VLOG(1) << GetClientInfoString("AwaitFullSyncCompletion"); |
550 if (wait_state_ == SYNC_DISABLED) { | 580 if (wait_state_ == SYNC_DISABLED) { |
551 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; | 581 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
552 return false; | 582 return false; |
553 } | 583 } |
554 | 584 |
555 if (IsSynced()) { | 585 if (IsFullySynced()) { |
556 // Client is already synced; don't wait. | 586 // Client is already synced; don't wait. |
557 return true; | 587 return true; |
558 } | 588 } |
559 | 589 |
560 if (wait_state_ == SERVER_UNREACHABLE) { | 590 if (wait_state_ == SERVER_UNREACHABLE) { |
561 // Client was offline; wait for it to go online, and then wait for sync. | 591 // Client was offline; wait for it to go online, and then wait for sync. |
562 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 592 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
563 DCHECK_EQ(wait_state_, WAITING_FOR_SYNC_TO_FINISH); | 593 DCHECK_EQ(wait_state_, WAITING_FOR_FULL_SYNC); |
564 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 594 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
565 } | 595 } |
566 | 596 |
567 DCHECK(service()->sync_initialized()); | 597 DCHECK(service()->sync_initialized()); |
568 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; | 598 wait_state_ = WAITING_FOR_FULL_SYNC; |
569 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 599 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
570 if (wait_state_ == FULLY_SYNCED) { | 600 if (wait_state_ == FULLY_SYNCED) { |
571 // Client is online; sync was successful. | 601 // Client is online; sync was successful. |
572 return true; | 602 return true; |
573 } else if (wait_state_ == SERVER_UNREACHABLE) { | 603 } else if (wait_state_ == SERVER_UNREACHABLE) { |
574 // Client is offline; sync was unsuccessful. | 604 // Client is offline; sync was unsuccessful. |
575 LOG(ERROR) << "Client went offline after waiting for sync to finish"; | 605 LOG(ERROR) << "Client went offline after waiting for sync to finish"; |
576 return false; | 606 return false; |
577 } else { | 607 } else { |
578 LOG(ERROR) << "Invalid wait state: " << wait_state_; | 608 LOG(ERROR) << "Invalid wait state: " << wait_state_; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 } | 673 } |
644 } | 674 } |
645 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 675 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
646 "Wait for migration to finish"); | 676 "Wait for migration to finish"); |
647 if (wait_state_ != WAITING_FOR_NOTHING) { | 677 if (wait_state_ != WAITING_FOR_NOTHING) { |
648 VLOG(1) << profile_debug_name_ | 678 VLOG(1) << profile_debug_name_ |
649 << ": wait state = " << wait_state_ | 679 << ": wait state = " << wait_state_ |
650 << " after migration finish is not WAITING_FOR_NOTHING"; | 680 << " after migration finish is not WAITING_FOR_NOTHING"; |
651 return false; | 681 return false; |
652 } | 682 } |
653 if (!AwaitSyncCycleCompletion( | 683 // We must use AwaitDataSyncCompletion rather than the more common |
| 684 // AwaitFullSyncCompletion. As long as crbug.com/97780 is open, we will |
| 685 // rely on self-notifiations to ensure that timestamps are udpated, which |
| 686 // allows AwaitFullSyncCompletion to return. However, in some migration |
| 687 // tests these notifications are completely disabled, so the timestamps do |
| 688 // not get updated. This is why we must use the less strict condition, |
| 689 // AwaitDataSyncCompletion. |
| 690 if (!AwaitDataSyncCompletion( |
654 "Config sync cycle after migration cycle")) { | 691 "Config sync cycle after migration cycle")) { |
655 return false; | 692 return false; |
656 } | 693 } |
657 } | 694 } |
658 } | 695 } |
659 | 696 |
660 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( | 697 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
661 ProfileSyncServiceHarness* partner) { | 698 ProfileSyncServiceHarness* partner) { |
662 VLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); | 699 VLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); |
663 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) | 700 if (!AwaitFullSyncCompletion("Sync cycle completion on active client.")) |
664 return false; | 701 return false; |
665 return partner->WaitUntilTimestampMatches(this, | 702 return partner->WaitUntilTimestampMatches(this, |
666 "Sync cycle completion on passive client."); | 703 "Sync cycle completion on passive client."); |
667 } | 704 } |
668 | 705 |
669 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( | 706 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( |
670 std::vector<ProfileSyncServiceHarness*>& partners) { | 707 std::vector<ProfileSyncServiceHarness*>& partners) { |
671 VLOG(1) << GetClientInfoString("AwaitGroupSyncCycleCompletion"); | 708 VLOG(1) << GetClientInfoString("AwaitGroupSyncCycleCompletion"); |
672 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) | 709 if (!AwaitFullSyncCompletion("Sync cycle completion on active client.")) |
673 return false; | 710 return false; |
674 bool return_value = true; | 711 bool return_value = true; |
675 for (std::vector<ProfileSyncServiceHarness*>::iterator it = | 712 for (std::vector<ProfileSyncServiceHarness*>::iterator it = |
676 partners.begin(); it != partners.end(); ++it) { | 713 partners.begin(); it != partners.end(); ++it) { |
677 if ((this != *it) && ((*it)->wait_state_ != SYNC_DISABLED)) { | 714 if ((this != *it) && ((*it)->wait_state_ != SYNC_DISABLED)) { |
678 return_value = return_value && | 715 return_value = return_value && |
679 (*it)->WaitUntilTimestampMatches(this, | 716 (*it)->WaitUntilTimestampMatches(this, |
680 "Sync cycle completion on partner client."); | 717 "Sync cycle completion on partner client."); |
681 } | 718 } |
682 } | 719 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 VLOG(0) << GetClientInfoString("AwaitStatusChangeWithTimeout timed out"); | 781 VLOG(0) << GetClientInfoString("AwaitStatusChangeWithTimeout timed out"); |
745 return false; | 782 return false; |
746 } | 783 } |
747 } | 784 } |
748 | 785 |
749 ProfileSyncService::Status ProfileSyncServiceHarness::GetStatus() { | 786 ProfileSyncService::Status ProfileSyncServiceHarness::GetStatus() { |
750 DCHECK(service() != NULL) << "GetStatus(): service() is NULL."; | 787 DCHECK(service() != NULL) << "GetStatus(): service() is NULL."; |
751 return service()->QueryDetailedSyncStatus(); | 788 return service()->QueryDetailedSyncStatus(); |
752 } | 789 } |
753 | 790 |
754 bool ProfileSyncServiceHarness::IsSynced() { | 791 // We use this function to share code between IsFullySynced and IsDataSynced |
755 if (service() == NULL) { | 792 // while ensuring that all conditions are evaluated using on the same snapshot. |
756 VLOG(1) << GetClientInfoString("IsSynced: false"); | 793 bool ProfileSyncServiceHarness::IsDataSyncedImpl( |
757 return false; | 794 const browser_sync::sessions::SyncSessionSnapshot *snap) { |
758 } | 795 return snap && |
759 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | |
760 // TODO(rsimha): Remove additional checks of snap->has_more_to_sync and | |
761 // snap->unsynced_count once http://crbug.com/48989 is fixed. | |
762 bool is_synced = snap && | |
763 snap->num_blocking_conflicting_updates == 0 && | 796 snap->num_blocking_conflicting_updates == 0 && |
764 ServiceIsPushingChanges() && | 797 ServiceIsPushingChanges() && |
765 GetStatus().notifications_enabled && | 798 GetStatus().notifications_enabled && |
766 !service()->HasUnsyncedItems() && | 799 !service()->HasUnsyncedItems() && |
767 !snap->has_more_to_sync && | 800 !snap->has_more_to_sync && |
768 snap->unsynced_count == 0 && | |
769 !HasPendingBackendMigration() && | 801 !HasPendingBackendMigration() && |
770 service()->passphrase_required_reason() != | 802 service()->passphrase_required_reason() != |
771 sync_api::REASON_SET_PASSPHRASE_FAILED; | 803 sync_api::REASON_SET_PASSPHRASE_FAILED; |
| 804 } |
| 805 |
| 806 bool ProfileSyncServiceHarness::IsDataSynced() { |
| 807 if (service() == NULL) { |
| 808 VLOG(1) << GetClientInfoString("IsDataSynced(): false"); |
| 809 return false; |
| 810 } |
| 811 |
| 812 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 813 bool is_data_synced = IsDataSyncedImpl(snap); |
| 814 |
772 VLOG(1) << GetClientInfoString( | 815 VLOG(1) << GetClientInfoString( |
773 is_synced ? "IsSynced: true" : "IsSynced: false"); | 816 is_data_synced ? "IsDataSynced: true" : "IsDataSynced: false"); |
774 return is_synced; | 817 return is_data_synced; |
| 818 } |
| 819 |
| 820 bool ProfileSyncServiceHarness::IsFullySynced() { |
| 821 if (service() == NULL) { |
| 822 VLOG(1) << GetClientInfoString("IsFullySynced: false"); |
| 823 return false; |
| 824 } |
| 825 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 826 // snap->unsynced_count == 0 is a fairly reliable indicator of whether or not |
| 827 // our timestamp is in sync with the server. |
| 828 bool is_fully_synced = IsDataSyncedImpl(snap) && |
| 829 snap->unsynced_count == 0; |
| 830 |
| 831 VLOG(1) << GetClientInfoString( |
| 832 is_fully_synced ? "IsFullySynced: true" : "IsFullySynced: false"); |
| 833 return is_fully_synced; |
775 } | 834 } |
776 | 835 |
777 bool ProfileSyncServiceHarness::HasPendingBackendMigration() { | 836 bool ProfileSyncServiceHarness::HasPendingBackendMigration() { |
778 browser_sync::BackendMigrator* migrator = | 837 browser_sync::BackendMigrator* migrator = |
779 service()->GetBackendMigratorForTest(); | 838 service()->GetBackendMigratorForTest(); |
780 return migrator && migrator->state() != browser_sync::BackendMigrator::IDLE; | 839 return migrator && migrator->state() != browser_sync::BackendMigrator::IDLE; |
781 } | 840 } |
782 | 841 |
783 bool ProfileSyncServiceHarness::MatchesOtherClient( | 842 bool ProfileSyncServiceHarness::MatchesOtherClient( |
784 ProfileSyncServiceHarness* partner) { | 843 ProfileSyncServiceHarness* partner) { |
785 // TODO(akalin): Shouldn't this belong with the intersection check? | 844 // TODO(akalin): Shouldn't this belong with the intersection check? |
786 // Otherwise, this function isn't symmetric. | 845 // Otherwise, this function isn't symmetric. |
787 if (!IsSynced()) { | 846 if (!IsFullySynced()) { |
788 VLOG(2) << profile_debug_name_ << ": not synced, assuming doesn't match"; | 847 VLOG(2) << profile_debug_name_ << ": not synced, assuming doesn't match"; |
789 return false; | 848 return false; |
790 } | 849 } |
791 | 850 |
792 // Only look for a match if we have at least one enabled datatype in | 851 // Only look for a match if we have at least one enabled datatype in |
793 // common with the partner client. | 852 // common with the partner client. |
794 syncable::ModelTypeSet types, other_types, intersection_types; | 853 syncable::ModelTypeSet types, other_types, intersection_types; |
795 service()->GetPreferredDataTypes(&types); | 854 service()->GetPreferredDataTypes(&types); |
796 partner->service()->GetPreferredDataTypes(&other_types); | 855 partner->service()->GetPreferredDataTypes(&other_types); |
797 std::set_intersection(types.begin(), types.end(), other_types.begin(), | 856 std::set_intersection(types.begin(), types.end(), other_types.begin(), |
798 other_types.end(), | 857 other_types.end(), |
799 inserter(intersection_types, | 858 inserter(intersection_types, |
800 intersection_types.begin())); | 859 intersection_types.begin())); |
801 | 860 |
802 VLOG(2) << profile_debug_name_ << ", " << partner->profile_debug_name_ | 861 VLOG(2) << profile_debug_name_ << ", " << partner->profile_debug_name_ |
803 << ": common types are " | 862 << ": common types are " |
804 << syncable::ModelTypeSetToString(intersection_types); | 863 << syncable::ModelTypeSetToString(intersection_types); |
805 | 864 |
806 if (!intersection_types.empty() && !partner->IsSynced()) { | 865 if (!intersection_types.empty() && !partner->IsFullySynced()) { |
807 VLOG(2) << "non-empty common types and " | 866 VLOG(2) << "non-empty common types and " |
808 << partner->profile_debug_name_ << " isn't synced"; | 867 << partner->profile_debug_name_ << " isn't synced"; |
809 return false; | 868 return false; |
810 } | 869 } |
811 | 870 |
812 for (syncable::ModelTypeSet::iterator i = intersection_types.begin(); | 871 for (syncable::ModelTypeSet::iterator i = intersection_types.begin(); |
813 i != intersection_types.end(); ++i) { | 872 i != intersection_types.end(); ++i) { |
814 const std::string timestamp = GetUpdatedTimestamp(*i); | 873 const std::string timestamp = GetUpdatedTimestamp(*i); |
815 const std::string partner_timestamp = partner->GetUpdatedTimestamp(*i); | 874 const std::string partner_timestamp = partner->GetUpdatedTimestamp(*i); |
816 if (timestamp != partner_timestamp) { | 875 if (timestamp != partner_timestamp) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); | 924 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); |
866 if (it != synced_datatypes.end()) { | 925 if (it != synced_datatypes.end()) { |
867 VLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " | 926 VLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " |
868 << syncable::ModelTypeToString(datatype) | 927 << syncable::ModelTypeToString(datatype) |
869 << " on " << profile_debug_name_ << "."; | 928 << " on " << profile_debug_name_ << "."; |
870 return true; | 929 return true; |
871 } | 930 } |
872 | 931 |
873 synced_datatypes.insert(syncable::ModelTypeFromInt(datatype)); | 932 synced_datatypes.insert(syncable::ModelTypeFromInt(datatype)); |
874 service()->OnUserChoseDatatypes(false, synced_datatypes); | 933 service()->OnUserChoseDatatypes(false, synced_datatypes); |
875 if (AwaitSyncCycleCompletion("Datatype configuration.")) { | 934 if (AwaitFullSyncCompletion("Datatype configuration.")) { |
876 VLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " | 935 VLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " |
877 << syncable::ModelTypeToString(datatype) | 936 << syncable::ModelTypeToString(datatype) |
878 << " on " << profile_debug_name_ << "."; | 937 << " on " << profile_debug_name_ << "."; |
879 return true; | 938 return true; |
880 } | 939 } |
881 | 940 |
882 VLOG(0) << GetClientInfoString("EnableSyncForDatatype failed"); | 941 VLOG(0) << GetClientInfoString("EnableSyncForDatatype failed"); |
883 return false; | 942 return false; |
884 } | 943 } |
885 | 944 |
(...skipping 12 matching lines...) Expand all Loading... |
898 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); | 957 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); |
899 if (it == synced_datatypes.end()) { | 958 if (it == synced_datatypes.end()) { |
900 VLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " | 959 VLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " |
901 << syncable::ModelTypeToString(datatype) | 960 << syncable::ModelTypeToString(datatype) |
902 << " on " << profile_debug_name_ << "."; | 961 << " on " << profile_debug_name_ << "."; |
903 return true; | 962 return true; |
904 } | 963 } |
905 | 964 |
906 synced_datatypes.erase(it); | 965 synced_datatypes.erase(it); |
907 service()->OnUserChoseDatatypes(false, synced_datatypes); | 966 service()->OnUserChoseDatatypes(false, synced_datatypes); |
908 if (AwaitSyncCycleCompletion("Datatype reconfiguration.")) { | 967 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { |
909 VLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " | 968 VLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " |
910 << syncable::ModelTypeToString(datatype) | 969 << syncable::ModelTypeToString(datatype) |
911 << " on " << profile_debug_name_ << "."; | 970 << " on " << profile_debug_name_ << "."; |
912 return true; | 971 return true; |
913 } | 972 } |
914 | 973 |
915 VLOG(0) << GetClientInfoString("DisableSyncForDatatype failed"); | 974 VLOG(0) << GetClientInfoString("DisableSyncForDatatype failed"); |
916 return false; | 975 return false; |
917 } | 976 } |
918 | 977 |
919 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { | 978 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { |
920 VLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes"); | 979 VLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes"); |
921 | 980 |
922 if (wait_state_ == SYNC_DISABLED) { | 981 if (wait_state_ == SYNC_DISABLED) { |
923 return SetupSync(); | 982 return SetupSync(); |
924 } | 983 } |
925 | 984 |
926 if (service() == NULL) { | 985 if (service() == NULL) { |
927 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; | 986 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; |
928 return false; | 987 return false; |
929 } | 988 } |
930 | 989 |
931 syncable::ModelTypeSet synced_datatypes; | 990 syncable::ModelTypeSet synced_datatypes; |
932 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 991 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
933 i < syncable::MODEL_TYPE_COUNT; | 992 i < syncable::MODEL_TYPE_COUNT; |
934 ++i) { | 993 ++i) { |
935 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); | 994 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); |
936 } | 995 } |
937 service()->OnUserChoseDatatypes(true, synced_datatypes); | 996 service()->OnUserChoseDatatypes(true, synced_datatypes); |
938 if (AwaitSyncCycleCompletion("Datatype reconfiguration.")) { | 997 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { |
939 VLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes on " | 998 VLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes on " |
940 << profile_debug_name_ << "."; | 999 << profile_debug_name_ << "."; |
941 return true; | 1000 return true; |
942 } | 1001 } |
943 | 1002 |
944 VLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed"); | 1003 VLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed"); |
945 return false; | 1004 return false; |
946 } | 1005 } |
947 | 1006 |
948 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { | 1007 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 // Wait some time to let the enryption finish. | 1087 // Wait some time to let the enryption finish. |
1029 return WaitForTypeEncryption(type); | 1088 return WaitForTypeEncryption(type); |
1030 } | 1089 } |
1031 | 1090 |
1032 bool ProfileSyncServiceHarness::WaitForTypeEncryption( | 1091 bool ProfileSyncServiceHarness::WaitForTypeEncryption( |
1033 syncable::ModelType type) { | 1092 syncable::ModelType type) { |
1034 // The correctness of this if condition depends on the ordering of its | 1093 // The correctness of this if condition depends on the ordering of its |
1035 // sub-expressions. See crbug.com/95619. | 1094 // sub-expressions. See crbug.com/95619. |
1036 // TODO(rlarocque): Figure out a less brittle way of detecting this. | 1095 // TODO(rlarocque): Figure out a less brittle way of detecting this. |
1037 if (IsTypeEncrypted(type) && | 1096 if (IsTypeEncrypted(type) && |
1038 IsSynced() && | 1097 IsFullySynced() && |
1039 GetLastSessionSnapshot()->num_conflicting_updates == 0) { | 1098 GetLastSessionSnapshot()->num_conflicting_updates == 0) { |
1040 // Encryption is already complete for |type|; do not wait. | 1099 // Encryption is already complete for |type|; do not wait. |
1041 return true; | 1100 return true; |
1042 } | 1101 } |
1043 | 1102 |
1044 std::string reason = "Waiting for encryption."; | 1103 std::string reason = "Waiting for encryption."; |
1045 wait_state_ = WAITING_FOR_ENCRYPTION; | 1104 wait_state_ = WAITING_FOR_ENCRYPTION; |
1046 waiting_for_encryption_type_ = type; | 1105 waiting_for_encryption_type_ = type; |
1047 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason)) { | 1106 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason)) { |
1048 LOG(ERROR) << "Did not receive EncryptionComplete notification after" | 1107 LOG(ERROR) << "Did not receive EncryptionComplete notification after" |
(...skipping 22 matching lines...) Expand all Loading... |
1071 return (synced_types.count(type) != 0); | 1130 return (synced_types.count(type) != 0); |
1072 } | 1131 } |
1073 | 1132 |
1074 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 1133 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
1075 DictionaryValue value; | 1134 DictionaryValue value; |
1076 sync_ui_util::ConstructAboutInformation(service_, &value); | 1135 sync_ui_util::ConstructAboutInformation(service_, &value); |
1077 std::string service_status; | 1136 std::string service_status; |
1078 base::JSONWriter::Write(&value, true, &service_status); | 1137 base::JSONWriter::Write(&value, true, &service_status); |
1079 return service_status; | 1138 return service_status; |
1080 } | 1139 } |
OLD | NEW |