| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cstddef> | 7 #include <cstddef> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <ostream> | 9 #include <ostream> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 bool StateChangeTimeoutEvent::Abort() { | 94 bool StateChangeTimeoutEvent::Abort() { |
| 95 aborted_ = true; | 95 aborted_ = true; |
| 96 caller_ = NULL; | 96 caller_ = NULL; |
| 97 return !did_timeout_; | 97 return !did_timeout_; |
| 98 } | 98 } |
| 99 | 99 |
| 100 ProfileSyncServiceHarness::ProfileSyncServiceHarness( | 100 ProfileSyncServiceHarness::ProfileSyncServiceHarness( |
| 101 Profile* profile, | 101 Profile* profile, |
| 102 const std::string& username, | 102 const std::string& username, |
| 103 const std::string& password) | 103 const std::string& password) |
| 104 : waiting_for_encryption_type_(syncable::UNSPECIFIED), | 104 : waiting_for_encryption_type_(syncer::UNSPECIFIED), |
| 105 wait_state_(INITIAL_WAIT_STATE), | 105 wait_state_(INITIAL_WAIT_STATE), |
| 106 profile_(profile), | 106 profile_(profile), |
| 107 service_(NULL), | 107 service_(NULL), |
| 108 timestamp_match_partner_(NULL), | 108 timestamp_match_partner_(NULL), |
| 109 username_(username), | 109 username_(username), |
| 110 password_(password), | 110 password_(password), |
| 111 profile_debug_name_(profile->GetDebugName()), | 111 profile_debug_name_(profile->GetDebugName()), |
| 112 waiting_for_status_change_(false) { | 112 waiting_for_status_change_(false) { |
| 113 if (IsSyncAlreadySetup()) { | 113 if (IsSyncAlreadySetup()) { |
| 114 service_ = ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 114 service_ = ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 137 username_ = username; | 137 username_ = username; |
| 138 password_ = password; | 138 password_ = password; |
| 139 } | 139 } |
| 140 | 140 |
| 141 bool ProfileSyncServiceHarness::IsSyncAlreadySetup() { | 141 bool ProfileSyncServiceHarness::IsSyncAlreadySetup() { |
| 142 return ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | 142 return ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( |
| 143 profile_); | 143 profile_); |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool ProfileSyncServiceHarness::SetupSync() { | 146 bool ProfileSyncServiceHarness::SetupSync() { |
| 147 bool result = SetupSync(syncable::ModelTypeSet::All()); | 147 bool result = SetupSync(syncer::ModelTypeSet::All()); |
| 148 if (result == false) { | 148 if (result == false) { |
| 149 std::string status = GetServiceStatus(); | 149 std::string status = GetServiceStatus(); |
| 150 LOG(ERROR) << profile_debug_name_ | 150 LOG(ERROR) << profile_debug_name_ |
| 151 << ": SetupSync failed. Syncer status:\n" << status; | 151 << ": SetupSync failed. Syncer status:\n" << status; |
| 152 } else { | 152 } else { |
| 153 DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; | 153 DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; |
| 154 } | 154 } |
| 155 return result; | 155 return result; |
| 156 } | 156 } |
| 157 | 157 |
| 158 bool ProfileSyncServiceHarness::SetupSync( | 158 bool ProfileSyncServiceHarness::SetupSync( |
| 159 syncable::ModelTypeSet synced_datatypes) { | 159 syncer::ModelTypeSet synced_datatypes) { |
| 160 // Initialize the sync client's profile sync service object. | 160 // Initialize the sync client's profile sync service object. |
| 161 service_ = | 161 service_ = |
| 162 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); | 162 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
| 163 if (service_ == NULL) { | 163 if (service_ == NULL) { |
| 164 LOG(ERROR) << "SetupSync(): service_ is null."; | 164 LOG(ERROR) << "SetupSync(): service_ is null."; |
| 165 return false; | 165 return false; |
| 166 } | 166 } |
| 167 | 167 |
| 168 // Subscribe sync client to notifications from the profile sync service. | 168 // Subscribe sync client to notifications from the profile sync service. |
| 169 if (!service_->HasObserver(this)) | 169 if (!service_->HasObserver(this)) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 185 if (!AwaitBackendInitialized()) { | 185 if (!AwaitBackendInitialized()) { |
| 186 LOG(ERROR) << "OnBackendInitialized() not seen after " | 186 LOG(ERROR) << "OnBackendInitialized() not seen after " |
| 187 << kLiveSyncOperationTimeoutMs / 1000 | 187 << kLiveSyncOperationTimeoutMs / 1000 |
| 188 << " seconds."; | 188 << " seconds."; |
| 189 return false; | 189 return false; |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Choose the datatypes to be synced. If all datatypes are to be synced, | 192 // Choose the datatypes to be synced. If all datatypes are to be synced, |
| 193 // set sync_everything to true; otherwise, set it to false. | 193 // set sync_everything to true; otherwise, set it to false. |
| 194 bool sync_everything = | 194 bool sync_everything = |
| 195 synced_datatypes.Equals(syncable::ModelTypeSet::All()); | 195 synced_datatypes.Equals(syncer::ModelTypeSet::All()); |
| 196 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 196 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 197 | 197 |
| 198 // Subscribe sync client to notifications from the backend migrator | 198 // Subscribe sync client to notifications from the backend migrator |
| 199 // (possible only after choosing data types). | 199 // (possible only after choosing data types). |
| 200 if (!TryListeningToMigrationEvents()) { | 200 if (!TryListeningToMigrationEvents()) { |
| 201 NOTREACHED(); | 201 NOTREACHED(); |
| 202 return false; | 202 return false; |
| 203 } | 203 } |
| 204 | 204 |
| 205 // Make sure that a partner client hasn't already set an explicit passphrase. | 205 // Make sure that a partner client hasn't already set an explicit passphrase. |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 442 |
| 443 void ProfileSyncServiceHarness::OnMigrationStateChange() { | 443 void ProfileSyncServiceHarness::OnMigrationStateChange() { |
| 444 // Update migration state. | 444 // Update migration state. |
| 445 if (HasPendingBackendMigration()) { | 445 if (HasPendingBackendMigration()) { |
| 446 // Merge current pending migration types into | 446 // Merge current pending migration types into |
| 447 // |pending_migration_types_|. | 447 // |pending_migration_types_|. |
| 448 pending_migration_types_.PutAll( | 448 pending_migration_types_.PutAll( |
| 449 service()->GetBackendMigratorForTest()-> | 449 service()->GetBackendMigratorForTest()-> |
| 450 GetPendingMigrationTypesForTest()); | 450 GetPendingMigrationTypesForTest()); |
| 451 DVLOG(1) << profile_debug_name_ << ": new pending migration types " | 451 DVLOG(1) << profile_debug_name_ << ": new pending migration types " |
| 452 << syncable::ModelTypeSetToString(pending_migration_types_); | 452 << syncer::ModelTypeSetToString(pending_migration_types_); |
| 453 } else { | 453 } else { |
| 454 // Merge just-finished pending migration types into | 454 // Merge just-finished pending migration types into |
| 455 // |migration_types_|. | 455 // |migration_types_|. |
| 456 migrated_types_.PutAll(pending_migration_types_); | 456 migrated_types_.PutAll(pending_migration_types_); |
| 457 pending_migration_types_.Clear(); | 457 pending_migration_types_.Clear(); |
| 458 DVLOG(1) << profile_debug_name_ << ": new migrated types " | 458 DVLOG(1) << profile_debug_name_ << ": new migrated types " |
| 459 << syncable::ModelTypeSetToString(migrated_types_); | 459 << syncer::ModelTypeSetToString(migrated_types_); |
| 460 } | 460 } |
| 461 RunStateChangeMachine(); | 461 RunStateChangeMachine(); |
| 462 } | 462 } |
| 463 | 463 |
| 464 bool ProfileSyncServiceHarness::AwaitPassphraseRequired() { | 464 bool ProfileSyncServiceHarness::AwaitPassphraseRequired() { |
| 465 DVLOG(1) << GetClientInfoString("AwaitPassphraseRequired"); | 465 DVLOG(1) << GetClientInfoString("AwaitPassphraseRequired"); |
| 466 if (wait_state_ == SYNC_DISABLED) { | 466 if (wait_state_ == SYNC_DISABLED) { |
| 467 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; | 467 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
| 468 return false; | 468 return false; |
| 469 } | 469 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 CHECK(status.sync_protocol_error.action == syncer::UNKNOWN_ACTION); | 600 CHECK(status.sync_protocol_error.action == syncer::UNKNOWN_ACTION); |
| 601 wait_state_ = WAITING_FOR_ACTIONABLE_ERROR; | 601 wait_state_ = WAITING_FOR_ACTIONABLE_ERROR; |
| 602 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 602 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 603 "Waiting for actionable error"); | 603 "Waiting for actionable error"); |
| 604 status = GetStatus(); | 604 status = GetStatus(); |
| 605 return (status.sync_protocol_error.action != syncer::UNKNOWN_ACTION && | 605 return (status.sync_protocol_error.action != syncer::UNKNOWN_ACTION && |
| 606 service_->HasUnrecoverableError()); | 606 service_->HasUnrecoverableError()); |
| 607 } | 607 } |
| 608 | 608 |
| 609 bool ProfileSyncServiceHarness::AwaitMigration( | 609 bool ProfileSyncServiceHarness::AwaitMigration( |
| 610 syncable::ModelTypeSet expected_migrated_types) { | 610 syncer::ModelTypeSet expected_migrated_types) { |
| 611 DVLOG(1) << GetClientInfoString("AwaitMigration"); | 611 DVLOG(1) << GetClientInfoString("AwaitMigration"); |
| 612 DVLOG(1) << profile_debug_name_ << ": waiting until migration is done for " | 612 DVLOG(1) << profile_debug_name_ << ": waiting until migration is done for " |
| 613 << syncable::ModelTypeSetToString(expected_migrated_types); | 613 << syncer::ModelTypeSetToString(expected_migrated_types); |
| 614 while (true) { | 614 while (true) { |
| 615 bool migration_finished = migrated_types_.HasAll(expected_migrated_types); | 615 bool migration_finished = migrated_types_.HasAll(expected_migrated_types); |
| 616 DVLOG(1) << "Migrated types " | 616 DVLOG(1) << "Migrated types " |
| 617 << syncable::ModelTypeSetToString(migrated_types_) | 617 << syncer::ModelTypeSetToString(migrated_types_) |
| 618 << (migration_finished ? " contains " : " does not contain ") | 618 << (migration_finished ? " contains " : " does not contain ") |
| 619 << syncable::ModelTypeSetToString(expected_migrated_types); | 619 << syncer::ModelTypeSetToString(expected_migrated_types); |
| 620 if (migration_finished) { | 620 if (migration_finished) { |
| 621 return true; | 621 return true; |
| 622 } | 622 } |
| 623 | 623 |
| 624 if (HasPendingBackendMigration()) { | 624 if (HasPendingBackendMigration()) { |
| 625 wait_state_ = WAITING_FOR_MIGRATION_TO_FINISH; | 625 wait_state_ = WAITING_FOR_MIGRATION_TO_FINISH; |
| 626 } else { | 626 } else { |
| 627 wait_state_ = WAITING_FOR_MIGRATION_TO_START; | 627 wait_state_ = WAITING_FOR_MIGRATION_TO_START; |
| 628 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 628 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 629 "Wait for migration to start"); | 629 "Wait for migration to start"); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 ProfileSyncServiceHarness* partner) { | 818 ProfileSyncServiceHarness* partner) { |
| 819 // TODO(akalin): Shouldn't this belong with the intersection check? | 819 // TODO(akalin): Shouldn't this belong with the intersection check? |
| 820 // Otherwise, this function isn't symmetric. | 820 // Otherwise, this function isn't symmetric. |
| 821 if (!IsFullySynced()) { | 821 if (!IsFullySynced()) { |
| 822 DVLOG(2) << profile_debug_name_ << ": not synced, assuming doesn't match"; | 822 DVLOG(2) << profile_debug_name_ << ": not synced, assuming doesn't match"; |
| 823 return false; | 823 return false; |
| 824 } | 824 } |
| 825 | 825 |
| 826 // Only look for a match if we have at least one enabled datatype in | 826 // Only look for a match if we have at least one enabled datatype in |
| 827 // common with the partner client. | 827 // common with the partner client. |
| 828 const syncable::ModelTypeSet common_types = | 828 const syncer::ModelTypeSet common_types = |
| 829 Intersection(service()->GetPreferredDataTypes(), | 829 Intersection(service()->GetPreferredDataTypes(), |
| 830 partner->service()->GetPreferredDataTypes()); | 830 partner->service()->GetPreferredDataTypes()); |
| 831 | 831 |
| 832 DVLOG(2) << profile_debug_name_ << ", " << partner->profile_debug_name_ | 832 DVLOG(2) << profile_debug_name_ << ", " << partner->profile_debug_name_ |
| 833 << ": common types are " | 833 << ": common types are " |
| 834 << syncable::ModelTypeSetToString(common_types); | 834 << syncer::ModelTypeSetToString(common_types); |
| 835 | 835 |
| 836 if (!common_types.Empty() && !partner->IsFullySynced()) { | 836 if (!common_types.Empty() && !partner->IsFullySynced()) { |
| 837 DVLOG(2) << "non-empty common types and " | 837 DVLOG(2) << "non-empty common types and " |
| 838 << partner->profile_debug_name_ << " isn't synced"; | 838 << partner->profile_debug_name_ << " isn't synced"; |
| 839 return false; | 839 return false; |
| 840 } | 840 } |
| 841 | 841 |
| 842 for (syncable::ModelTypeSet::Iterator i = common_types.First(); | 842 for (syncer::ModelTypeSet::Iterator i = common_types.First(); |
| 843 i.Good(); i.Inc()) { | 843 i.Good(); i.Inc()) { |
| 844 const std::string timestamp = GetUpdatedTimestamp(i.Get()); | 844 const std::string timestamp = GetUpdatedTimestamp(i.Get()); |
| 845 const std::string partner_timestamp = partner->GetUpdatedTimestamp(i.Get()); | 845 const std::string partner_timestamp = partner->GetUpdatedTimestamp(i.Get()); |
| 846 if (timestamp != partner_timestamp) { | 846 if (timestamp != partner_timestamp) { |
| 847 if (VLOG_IS_ON(2)) { | 847 if (VLOG_IS_ON(2)) { |
| 848 std::string timestamp_base64, partner_timestamp_base64; | 848 std::string timestamp_base64, partner_timestamp_base64; |
| 849 if (!base::Base64Encode(timestamp, ×tamp_base64)) { | 849 if (!base::Base64Encode(timestamp, ×tamp_base64)) { |
| 850 NOTREACHED(); | 850 NOTREACHED(); |
| 851 } | 851 } |
| 852 if (!base::Base64Encode( | 852 if (!base::Base64Encode( |
| 853 partner_timestamp, &partner_timestamp_base64)) { | 853 partner_timestamp, &partner_timestamp_base64)) { |
| 854 NOTREACHED(); | 854 NOTREACHED(); |
| 855 } | 855 } |
| 856 DVLOG(2) << syncable::ModelTypeToString(i.Get()) << ": " | 856 DVLOG(2) << syncer::ModelTypeToString(i.Get()) << ": " |
| 857 << profile_debug_name_ << " timestamp = " | 857 << profile_debug_name_ << " timestamp = " |
| 858 << timestamp_base64 << ", " | 858 << timestamp_base64 << ", " |
| 859 << partner->profile_debug_name_ | 859 << partner->profile_debug_name_ |
| 860 << " partner timestamp = " | 860 << " partner timestamp = " |
| 861 << partner_timestamp_base64; | 861 << partner_timestamp_base64; |
| 862 } | 862 } |
| 863 return false; | 863 return false; |
| 864 } | 864 } |
| 865 } | 865 } |
| 866 return true; | 866 return true; |
| 867 } | 867 } |
| 868 | 868 |
| 869 SyncSessionSnapshot ProfileSyncServiceHarness::GetLastSessionSnapshot() const { | 869 SyncSessionSnapshot ProfileSyncServiceHarness::GetLastSessionSnapshot() const { |
| 870 DCHECK(service_ != NULL) << "Sync service has not yet been set up."; | 870 DCHECK(service_ != NULL) << "Sync service has not yet been set up."; |
| 871 if (service_->sync_initialized()) { | 871 if (service_->sync_initialized()) { |
| 872 return service_->GetLastSessionSnapshot(); | 872 return service_->GetLastSessionSnapshot(); |
| 873 } | 873 } |
| 874 return SyncSessionSnapshot(); | 874 return SyncSessionSnapshot(); |
| 875 } | 875 } |
| 876 | 876 |
| 877 bool ProfileSyncServiceHarness::EnableSyncForDatatype( | 877 bool ProfileSyncServiceHarness::EnableSyncForDatatype( |
| 878 syncable::ModelType datatype) { | 878 syncer::ModelType datatype) { |
| 879 DVLOG(1) << GetClientInfoString( | 879 DVLOG(1) << GetClientInfoString( |
| 880 "EnableSyncForDatatype(" | 880 "EnableSyncForDatatype(" |
| 881 + std::string(syncable::ModelTypeToString(datatype)) + ")"); | 881 + std::string(syncer::ModelTypeToString(datatype)) + ")"); |
| 882 | 882 |
| 883 if (wait_state_ == SYNC_DISABLED) { | 883 if (wait_state_ == SYNC_DISABLED) { |
| 884 return SetupSync(syncable::ModelTypeSet(datatype)); | 884 return SetupSync(syncer::ModelTypeSet(datatype)); |
| 885 } | 885 } |
| 886 | 886 |
| 887 if (service() == NULL) { | 887 if (service() == NULL) { |
| 888 LOG(ERROR) << "EnableSyncForDatatype(): service() is null."; | 888 LOG(ERROR) << "EnableSyncForDatatype(): service() is null."; |
| 889 return false; | 889 return false; |
| 890 } | 890 } |
| 891 | 891 |
| 892 syncable::ModelTypeSet synced_datatypes = | 892 syncer::ModelTypeSet synced_datatypes = service()->GetPreferredDataTypes(); |
| 893 service()->GetPreferredDataTypes(); | |
| 894 if (synced_datatypes.Has(datatype)) { | 893 if (synced_datatypes.Has(datatype)) { |
| 895 DVLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " | 894 DVLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " |
| 896 << syncable::ModelTypeToString(datatype) | 895 << syncer::ModelTypeToString(datatype) |
| 897 << " on " << profile_debug_name_ << "."; | 896 << " on " << profile_debug_name_ << "."; |
| 898 return true; | 897 return true; |
| 899 } | 898 } |
| 900 | 899 |
| 901 synced_datatypes.Put(syncable::ModelTypeFromInt(datatype)); | 900 synced_datatypes.Put(syncer::ModelTypeFromInt(datatype)); |
| 902 service()->OnUserChoseDatatypes(false, synced_datatypes); | 901 service()->OnUserChoseDatatypes(false, synced_datatypes); |
| 903 if (AwaitDataSyncCompletion("Datatype configuration.")) { | 902 if (AwaitDataSyncCompletion("Datatype configuration.")) { |
| 904 DVLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " | 903 DVLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " |
| 905 << syncable::ModelTypeToString(datatype) | 904 << syncer::ModelTypeToString(datatype) |
| 906 << " on " << profile_debug_name_ << "."; | 905 << " on " << profile_debug_name_ << "."; |
| 907 return true; | 906 return true; |
| 908 } | 907 } |
| 909 | 908 |
| 910 DVLOG(0) << GetClientInfoString("EnableSyncForDatatype failed"); | 909 DVLOG(0) << GetClientInfoString("EnableSyncForDatatype failed"); |
| 911 return false; | 910 return false; |
| 912 } | 911 } |
| 913 | 912 |
| 914 bool ProfileSyncServiceHarness::DisableSyncForDatatype( | 913 bool ProfileSyncServiceHarness::DisableSyncForDatatype( |
| 915 syncable::ModelType datatype) { | 914 syncer::ModelType datatype) { |
| 916 DVLOG(1) << GetClientInfoString( | 915 DVLOG(1) << GetClientInfoString( |
| 917 "DisableSyncForDatatype(" | 916 "DisableSyncForDatatype(" |
| 918 + std::string(syncable::ModelTypeToString(datatype)) + ")"); | 917 + std::string(syncer::ModelTypeToString(datatype)) + ")"); |
| 919 | 918 |
| 920 if (service() == NULL) { | 919 if (service() == NULL) { |
| 921 LOG(ERROR) << "DisableSyncForDatatype(): service() is null."; | 920 LOG(ERROR) << "DisableSyncForDatatype(): service() is null."; |
| 922 return false; | 921 return false; |
| 923 } | 922 } |
| 924 | 923 |
| 925 syncable::ModelTypeSet synced_datatypes = | 924 syncer::ModelTypeSet synced_datatypes = service()->GetPreferredDataTypes(); |
| 926 service()->GetPreferredDataTypes(); | |
| 927 if (!synced_datatypes.Has(datatype)) { | 925 if (!synced_datatypes.Has(datatype)) { |
| 928 DVLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " | 926 DVLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " |
| 929 << syncable::ModelTypeToString(datatype) | 927 << syncer::ModelTypeToString(datatype) |
| 930 << " on " << profile_debug_name_ << "."; | 928 << " on " << profile_debug_name_ << "."; |
| 931 return true; | 929 return true; |
| 932 } | 930 } |
| 933 | 931 |
| 934 synced_datatypes.Remove(datatype); | 932 synced_datatypes.Remove(datatype); |
| 935 service()->OnUserChoseDatatypes(false, synced_datatypes); | 933 service()->OnUserChoseDatatypes(false, synced_datatypes); |
| 936 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { | 934 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { |
| 937 DVLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " | 935 DVLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " |
| 938 << syncable::ModelTypeToString(datatype) | 936 << syncer::ModelTypeToString(datatype) |
| 939 << " on " << profile_debug_name_ << "."; | 937 << " on " << profile_debug_name_ << "."; |
| 940 return true; | 938 return true; |
| 941 } | 939 } |
| 942 | 940 |
| 943 DVLOG(0) << GetClientInfoString("DisableSyncForDatatype failed"); | 941 DVLOG(0) << GetClientInfoString("DisableSyncForDatatype failed"); |
| 944 return false; | 942 return false; |
| 945 } | 943 } |
| 946 | 944 |
| 947 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { | 945 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { |
| 948 DVLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes"); | 946 DVLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes"); |
| 949 | 947 |
| 950 if (wait_state_ == SYNC_DISABLED) { | 948 if (wait_state_ == SYNC_DISABLED) { |
| 951 return SetupSync(); | 949 return SetupSync(); |
| 952 } | 950 } |
| 953 | 951 |
| 954 if (service() == NULL) { | 952 if (service() == NULL) { |
| 955 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; | 953 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; |
| 956 return false; | 954 return false; |
| 957 } | 955 } |
| 958 | 956 |
| 959 service()->OnUserChoseDatatypes(true, syncable::ModelTypeSet::All()); | 957 service()->OnUserChoseDatatypes(true, syncer::ModelTypeSet::All()); |
| 960 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { | 958 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { |
| 961 DVLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes " | 959 DVLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes " |
| 962 << "on " << profile_debug_name_ << "."; | 960 << "on " << profile_debug_name_ << "."; |
| 963 return true; | 961 return true; |
| 964 } | 962 } |
| 965 | 963 |
| 966 DVLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed"); | 964 DVLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed"); |
| 967 return false; | 965 return false; |
| 968 } | 966 } |
| 969 | 967 |
| 970 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { | 968 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { |
| 971 DVLOG(1) << GetClientInfoString("DisableSyncForAllDatatypes"); | 969 DVLOG(1) << GetClientInfoString("DisableSyncForAllDatatypes"); |
| 972 | 970 |
| 973 if (service() == NULL) { | 971 if (service() == NULL) { |
| 974 LOG(ERROR) << "DisableSyncForAllDatatypes(): service() is null."; | 972 LOG(ERROR) << "DisableSyncForAllDatatypes(): service() is null."; |
| 975 return false; | 973 return false; |
| 976 } | 974 } |
| 977 | 975 |
| 978 service()->DisableForUser(); | 976 service()->DisableForUser(); |
| 979 wait_state_ = SYNC_DISABLED; | 977 wait_state_ = SYNC_DISABLED; |
| 980 DVLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all " | 978 DVLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all " |
| 981 << "datatypes on " << profile_debug_name_; | 979 << "datatypes on " << profile_debug_name_; |
| 982 return true; | 980 return true; |
| 983 } | 981 } |
| 984 | 982 |
| 985 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( | 983 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( |
| 986 syncable::ModelType model_type) { | 984 syncer::ModelType model_type) { |
| 987 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); | 985 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); |
| 988 return snap.download_progress_markers()[model_type]; | 986 return snap.download_progress_markers()[model_type]; |
| 989 } | 987 } |
| 990 | 988 |
| 991 std::string ProfileSyncServiceHarness::GetClientInfoString( | 989 std::string ProfileSyncServiceHarness::GetClientInfoString( |
| 992 const std::string& message) { | 990 const std::string& message) { |
| 993 std::stringstream os; | 991 std::stringstream os; |
| 994 os << profile_debug_name_ << ": " << message << ": "; | 992 os << profile_debug_name_ << ": " << message << ": "; |
| 995 if (service()) { | 993 if (service()) { |
| 996 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); | 994 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1024 << HasPendingBackendMigration(); | 1022 << HasPendingBackendMigration(); |
| 1025 } else { | 1023 } else { |
| 1026 os << "Sync service not available"; | 1024 os << "Sync service not available"; |
| 1027 } | 1025 } |
| 1028 return os.str(); | 1026 return os.str(); |
| 1029 } | 1027 } |
| 1030 | 1028 |
| 1031 // TODO(zea): Rename this EnableEncryption, since we no longer turn on | 1029 // TODO(zea): Rename this EnableEncryption, since we no longer turn on |
| 1032 // encryption for individual types but for all. | 1030 // encryption for individual types but for all. |
| 1033 bool ProfileSyncServiceHarness::EnableEncryptionForType( | 1031 bool ProfileSyncServiceHarness::EnableEncryptionForType( |
| 1034 syncable::ModelType type) { | 1032 syncer::ModelType type) { |
| 1035 const syncable::ModelTypeSet encrypted_types = | 1033 const syncer::ModelTypeSet encrypted_types = |
| 1036 service_->GetEncryptedDataTypes(); | 1034 service_->GetEncryptedDataTypes(); |
| 1037 if (encrypted_types.Has(type)) | 1035 if (encrypted_types.Has(type)) |
| 1038 return true; | 1036 return true; |
| 1039 service_->EnableEncryptEverything(); | 1037 service_->EnableEncryptEverything(); |
| 1040 | 1038 |
| 1041 // In order to kick off the encryption we have to reconfigure. Just grab the | 1039 // In order to kick off the encryption we have to reconfigure. Just grab the |
| 1042 // currently synced types and use them. | 1040 // currently synced types and use them. |
| 1043 const syncable::ModelTypeSet synced_datatypes = | 1041 const syncer::ModelTypeSet synced_datatypes = |
| 1044 service_->GetPreferredDataTypes(); | 1042 service_->GetPreferredDataTypes(); |
| 1045 bool sync_everything = | 1043 bool sync_everything = |
| 1046 synced_datatypes.Equals(syncable::ModelTypeSet::All()); | 1044 synced_datatypes.Equals(syncer::ModelTypeSet::All()); |
| 1047 service_->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 1045 service_->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 1048 | 1046 |
| 1049 // Wait some time to let the enryption finish. | 1047 // Wait some time to let the enryption finish. |
| 1050 return WaitForTypeEncryption(type); | 1048 return WaitForTypeEncryption(type); |
| 1051 } | 1049 } |
| 1052 | 1050 |
| 1053 bool ProfileSyncServiceHarness::WaitForTypeEncryption( | 1051 bool ProfileSyncServiceHarness::WaitForTypeEncryption(syncer::ModelType type) { |
| 1054 syncable::ModelType type) { | |
| 1055 // The correctness of this if condition depends on the ordering of its | 1052 // The correctness of this if condition depends on the ordering of its |
| 1056 // sub-expressions. See crbug.com/95619. | 1053 // sub-expressions. See crbug.com/95619. |
| 1057 // TODO(rlarocque): Figure out a less brittle way of detecting this. | 1054 // TODO(rlarocque): Figure out a less brittle way of detecting this. |
| 1058 if (IsTypeEncrypted(type) && | 1055 if (IsTypeEncrypted(type) && |
| 1059 IsFullySynced() && | 1056 IsFullySynced() && |
| 1060 GetLastSessionSnapshot().num_encryption_conflicts() == 0) { | 1057 GetLastSessionSnapshot().num_encryption_conflicts() == 0) { |
| 1061 // Encryption is already complete for |type|; do not wait. | 1058 // Encryption is already complete for |type|; do not wait. |
| 1062 return true; | 1059 return true; |
| 1063 } | 1060 } |
| 1064 | 1061 |
| 1065 std::string reason = "Waiting for encryption."; | 1062 std::string reason = "Waiting for encryption."; |
| 1066 wait_state_ = WAITING_FOR_ENCRYPTION; | 1063 wait_state_ = WAITING_FOR_ENCRYPTION; |
| 1067 waiting_for_encryption_type_ = type; | 1064 waiting_for_encryption_type_ = type; |
| 1068 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason)) { | 1065 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason)) { |
| 1069 LOG(ERROR) << "Did not receive EncryptionComplete notification after" | 1066 LOG(ERROR) << "Did not receive EncryptionComplete notification after" |
| 1070 << kLiveSyncOperationTimeoutMs / 1000 | 1067 << kLiveSyncOperationTimeoutMs / 1000 |
| 1071 << " seconds."; | 1068 << " seconds."; |
| 1072 return false; | 1069 return false; |
| 1073 } | 1070 } |
| 1074 return IsTypeEncrypted(type); | 1071 return IsTypeEncrypted(type); |
| 1075 } | 1072 } |
| 1076 | 1073 |
| 1077 bool ProfileSyncServiceHarness::IsTypeEncrypted(syncable::ModelType type) { | 1074 bool ProfileSyncServiceHarness::IsTypeEncrypted(syncer::ModelType type) { |
| 1078 const syncable::ModelTypeSet encrypted_types = | 1075 const syncer::ModelTypeSet encrypted_types = |
| 1079 service_->GetEncryptedDataTypes(); | 1076 service_->GetEncryptedDataTypes(); |
| 1080 bool is_type_encrypted = service_->GetEncryptedDataTypes().Has(type); | 1077 bool is_type_encrypted = service_->GetEncryptedDataTypes().Has(type); |
| 1081 DVLOG(2) << syncable::ModelTypeToString(type) << " is " | 1078 DVLOG(2) << syncer::ModelTypeToString(type) << " is " |
| 1082 << (is_type_encrypted ? "" : "not ") << "encrypted; " | 1079 << (is_type_encrypted ? "" : "not ") << "encrypted; " |
| 1083 << "encrypted types = " | 1080 << "encrypted types = " |
| 1084 << syncable::ModelTypeSetToString(encrypted_types); | 1081 << syncer::ModelTypeSetToString(encrypted_types); |
| 1085 return is_type_encrypted; | 1082 return is_type_encrypted; |
| 1086 } | 1083 } |
| 1087 | 1084 |
| 1088 bool ProfileSyncServiceHarness::IsTypeRunning(syncable::ModelType type) { | 1085 bool ProfileSyncServiceHarness::IsTypeRunning(syncer::ModelType type) { |
| 1089 browser_sync::DataTypeController::StateMap state_map; | 1086 browser_sync::DataTypeController::StateMap state_map; |
| 1090 service_->GetDataTypeControllerStates(&state_map); | 1087 service_->GetDataTypeControllerStates(&state_map); |
| 1091 return (state_map.count(type) != 0 && | 1088 return (state_map.count(type) != 0 && |
| 1092 state_map[type] == browser_sync::DataTypeController::RUNNING); | 1089 state_map[type] == browser_sync::DataTypeController::RUNNING); |
| 1093 } | 1090 } |
| 1094 | 1091 |
| 1095 bool ProfileSyncServiceHarness::IsTypePreferred(syncable::ModelType type) { | 1092 bool ProfileSyncServiceHarness::IsTypePreferred(syncer::ModelType type) { |
| 1096 return service_->GetPreferredDataTypes().Has(type); | 1093 return service_->GetPreferredDataTypes().Has(type); |
| 1097 } | 1094 } |
| 1098 | 1095 |
| 1099 size_t ProfileSyncServiceHarness::GetNumEntries() const { | 1096 size_t ProfileSyncServiceHarness::GetNumEntries() const { |
| 1100 return GetLastSessionSnapshot().num_entries(); | 1097 return GetLastSessionSnapshot().num_entries(); |
| 1101 } | 1098 } |
| 1102 | 1099 |
| 1103 size_t ProfileSyncServiceHarness::GetNumDatatypes() const { | 1100 size_t ProfileSyncServiceHarness::GetNumDatatypes() const { |
| 1104 browser_sync::DataTypeController::StateMap state_map; | 1101 browser_sync::DataTypeController::StateMap state_map; |
| 1105 service_->GetDataTypeControllerStates(&state_map); | 1102 service_->GetDataTypeControllerStates(&state_map); |
| 1106 return state_map.size(); | 1103 return state_map.size(); |
| 1107 } | 1104 } |
| 1108 | 1105 |
| 1109 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 1106 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 1110 DictionaryValue value; | 1107 DictionaryValue value; |
| 1111 sync_ui_util::ConstructAboutInformation(service_, &value); | 1108 sync_ui_util::ConstructAboutInformation(service_, &value); |
| 1112 std::string service_status; | 1109 std::string service_status; |
| 1113 base::JSONWriter::WriteWithOptions(&value, | 1110 base::JSONWriter::WriteWithOptions(&value, |
| 1114 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 1111 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 1115 &service_status); | 1112 &service_status); |
| 1116 return service_status; | 1113 return service_status; |
| 1117 } | 1114 } |
| OLD | NEW |