| 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 = |
| 893 service()->GetPreferredDataTypes(); | 893 service()->GetPreferredDataTypes(); |
| 894 if (synced_datatypes.Has(datatype)) { | 894 if (synced_datatypes.Has(datatype)) { |
| 895 DVLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " | 895 DVLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " |
| 896 << syncable::ModelTypeToString(datatype) | 896 << syncer::ModelTypeToString(datatype) |
| 897 << " on " << profile_debug_name_ << "."; | 897 << " on " << profile_debug_name_ << "."; |
| 898 return true; | 898 return true; |
| 899 } | 899 } |
| 900 | 900 |
| 901 synced_datatypes.Put(syncable::ModelTypeFromInt(datatype)); | 901 synced_datatypes.Put(syncer::ModelTypeFromInt(datatype)); |
| 902 service()->OnUserChoseDatatypes(false, synced_datatypes); | 902 service()->OnUserChoseDatatypes(false, synced_datatypes); |
| 903 if (AwaitDataSyncCompletion("Datatype configuration.")) { | 903 if (AwaitDataSyncCompletion("Datatype configuration.")) { |
| 904 DVLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " | 904 DVLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " |
| 905 << syncable::ModelTypeToString(datatype) | 905 << syncer::ModelTypeToString(datatype) |
| 906 << " on " << profile_debug_name_ << "."; | 906 << " on " << profile_debug_name_ << "."; |
| 907 return true; | 907 return true; |
| 908 } | 908 } |
| 909 | 909 |
| 910 DVLOG(0) << GetClientInfoString("EnableSyncForDatatype failed"); | 910 DVLOG(0) << GetClientInfoString("EnableSyncForDatatype failed"); |
| 911 return false; | 911 return false; |
| 912 } | 912 } |
| 913 | 913 |
| 914 bool ProfileSyncServiceHarness::DisableSyncForDatatype( | 914 bool ProfileSyncServiceHarness::DisableSyncForDatatype( |
| 915 syncable::ModelType datatype) { | 915 syncer::ModelType datatype) { |
| 916 DVLOG(1) << GetClientInfoString( | 916 DVLOG(1) << GetClientInfoString( |
| 917 "DisableSyncForDatatype(" | 917 "DisableSyncForDatatype(" |
| 918 + std::string(syncable::ModelTypeToString(datatype)) + ")"); | 918 + std::string(syncer::ModelTypeToString(datatype)) + ")"); |
| 919 | 919 |
| 920 if (service() == NULL) { | 920 if (service() == NULL) { |
| 921 LOG(ERROR) << "DisableSyncForDatatype(): service() is null."; | 921 LOG(ERROR) << "DisableSyncForDatatype(): service() is null."; |
| 922 return false; | 922 return false; |
| 923 } | 923 } |
| 924 | 924 |
| 925 syncable::ModelTypeSet synced_datatypes = | 925 syncer::ModelTypeSet synced_datatypes = |
| 926 service()->GetPreferredDataTypes(); | 926 service()->GetPreferredDataTypes(); |
| 927 if (!synced_datatypes.Has(datatype)) { | 927 if (!synced_datatypes.Has(datatype)) { |
| 928 DVLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " | 928 DVLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " |
| 929 << syncable::ModelTypeToString(datatype) | 929 << syncer::ModelTypeToString(datatype) |
| 930 << " on " << profile_debug_name_ << "."; | 930 << " on " << profile_debug_name_ << "."; |
| 931 return true; | 931 return true; |
| 932 } | 932 } |
| 933 | 933 |
| 934 synced_datatypes.Remove(datatype); | 934 synced_datatypes.Remove(datatype); |
| 935 service()->OnUserChoseDatatypes(false, synced_datatypes); | 935 service()->OnUserChoseDatatypes(false, synced_datatypes); |
| 936 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { | 936 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { |
| 937 DVLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " | 937 DVLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " |
| 938 << syncable::ModelTypeToString(datatype) | 938 << syncer::ModelTypeToString(datatype) |
| 939 << " on " << profile_debug_name_ << "."; | 939 << " on " << profile_debug_name_ << "."; |
| 940 return true; | 940 return true; |
| 941 } | 941 } |
| 942 | 942 |
| 943 DVLOG(0) << GetClientInfoString("DisableSyncForDatatype failed"); | 943 DVLOG(0) << GetClientInfoString("DisableSyncForDatatype failed"); |
| 944 return false; | 944 return false; |
| 945 } | 945 } |
| 946 | 946 |
| 947 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { | 947 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { |
| 948 DVLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes"); | 948 DVLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes"); |
| 949 | 949 |
| 950 if (wait_state_ == SYNC_DISABLED) { | 950 if (wait_state_ == SYNC_DISABLED) { |
| 951 return SetupSync(); | 951 return SetupSync(); |
| 952 } | 952 } |
| 953 | 953 |
| 954 if (service() == NULL) { | 954 if (service() == NULL) { |
| 955 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; | 955 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; |
| 956 return false; | 956 return false; |
| 957 } | 957 } |
| 958 | 958 |
| 959 service()->OnUserChoseDatatypes(true, syncable::ModelTypeSet::All()); | 959 service()->OnUserChoseDatatypes(true, syncer::ModelTypeSet::All()); |
| 960 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { | 960 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { |
| 961 DVLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes " | 961 DVLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes " |
| 962 << "on " << profile_debug_name_ << "."; | 962 << "on " << profile_debug_name_ << "."; |
| 963 return true; | 963 return true; |
| 964 } | 964 } |
| 965 | 965 |
| 966 DVLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed"); | 966 DVLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed"); |
| 967 return false; | 967 return false; |
| 968 } | 968 } |
| 969 | 969 |
| 970 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { | 970 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { |
| 971 DVLOG(1) << GetClientInfoString("DisableSyncForAllDatatypes"); | 971 DVLOG(1) << GetClientInfoString("DisableSyncForAllDatatypes"); |
| 972 | 972 |
| 973 if (service() == NULL) { | 973 if (service() == NULL) { |
| 974 LOG(ERROR) << "DisableSyncForAllDatatypes(): service() is null."; | 974 LOG(ERROR) << "DisableSyncForAllDatatypes(): service() is null."; |
| 975 return false; | 975 return false; |
| 976 } | 976 } |
| 977 | 977 |
| 978 service()->DisableForUser(); | 978 service()->DisableForUser(); |
| 979 wait_state_ = SYNC_DISABLED; | 979 wait_state_ = SYNC_DISABLED; |
| 980 DVLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all " | 980 DVLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all " |
| 981 << "datatypes on " << profile_debug_name_; | 981 << "datatypes on " << profile_debug_name_; |
| 982 return true; | 982 return true; |
| 983 } | 983 } |
| 984 | 984 |
| 985 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( | 985 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( |
| 986 syncable::ModelType model_type) { | 986 syncer::ModelType model_type) { |
| 987 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); | 987 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); |
| 988 return snap.download_progress_markers()[model_type]; | 988 return snap.download_progress_markers()[model_type]; |
| 989 } | 989 } |
| 990 | 990 |
| 991 std::string ProfileSyncServiceHarness::GetClientInfoString( | 991 std::string ProfileSyncServiceHarness::GetClientInfoString( |
| 992 const std::string& message) { | 992 const std::string& message) { |
| 993 std::stringstream os; | 993 std::stringstream os; |
| 994 os << profile_debug_name_ << ": " << message << ": "; | 994 os << profile_debug_name_ << ": " << message << ": "; |
| 995 if (service()) { | 995 if (service()) { |
| 996 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); | 996 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1024 << HasPendingBackendMigration(); | 1024 << HasPendingBackendMigration(); |
| 1025 } else { | 1025 } else { |
| 1026 os << "Sync service not available"; | 1026 os << "Sync service not available"; |
| 1027 } | 1027 } |
| 1028 return os.str(); | 1028 return os.str(); |
| 1029 } | 1029 } |
| 1030 | 1030 |
| 1031 // TODO(zea): Rename this EnableEncryption, since we no longer turn on | 1031 // TODO(zea): Rename this EnableEncryption, since we no longer turn on |
| 1032 // encryption for individual types but for all. | 1032 // encryption for individual types but for all. |
| 1033 bool ProfileSyncServiceHarness::EnableEncryptionForType( | 1033 bool ProfileSyncServiceHarness::EnableEncryptionForType( |
| 1034 syncable::ModelType type) { | 1034 syncer::ModelType type) { |
| 1035 const syncable::ModelTypeSet encrypted_types = | 1035 const syncer::ModelTypeSet encrypted_types = |
| 1036 service_->GetEncryptedDataTypes(); | 1036 service_->GetEncryptedDataTypes(); |
| 1037 if (encrypted_types.Has(type)) | 1037 if (encrypted_types.Has(type)) |
| 1038 return true; | 1038 return true; |
| 1039 service_->EnableEncryptEverything(); | 1039 service_->EnableEncryptEverything(); |
| 1040 | 1040 |
| 1041 // In order to kick off the encryption we have to reconfigure. Just grab the | 1041 // In order to kick off the encryption we have to reconfigure. Just grab the |
| 1042 // currently synced types and use them. | 1042 // currently synced types and use them. |
| 1043 const syncable::ModelTypeSet synced_datatypes = | 1043 const syncer::ModelTypeSet synced_datatypes = |
| 1044 service_->GetPreferredDataTypes(); | 1044 service_->GetPreferredDataTypes(); |
| 1045 bool sync_everything = | 1045 bool sync_everything = |
| 1046 synced_datatypes.Equals(syncable::ModelTypeSet::All()); | 1046 synced_datatypes.Equals(syncer::ModelTypeSet::All()); |
| 1047 service_->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 1047 service_->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 1048 | 1048 |
| 1049 // Wait some time to let the enryption finish. | 1049 // Wait some time to let the enryption finish. |
| 1050 return WaitForTypeEncryption(type); | 1050 return WaitForTypeEncryption(type); |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 bool ProfileSyncServiceHarness::WaitForTypeEncryption( | 1053 bool ProfileSyncServiceHarness::WaitForTypeEncryption( |
| 1054 syncable::ModelType type) { | 1054 syncer::ModelType type) { |
| 1055 // The correctness of this if condition depends on the ordering of its | 1055 // The correctness of this if condition depends on the ordering of its |
| 1056 // sub-expressions. See crbug.com/95619. | 1056 // sub-expressions. See crbug.com/95619. |
| 1057 // TODO(rlarocque): Figure out a less brittle way of detecting this. | 1057 // TODO(rlarocque): Figure out a less brittle way of detecting this. |
| 1058 if (IsTypeEncrypted(type) && | 1058 if (IsTypeEncrypted(type) && |
| 1059 IsFullySynced() && | 1059 IsFullySynced() && |
| 1060 GetLastSessionSnapshot().num_encryption_conflicts() == 0) { | 1060 GetLastSessionSnapshot().num_encryption_conflicts() == 0) { |
| 1061 // Encryption is already complete for |type|; do not wait. | 1061 // Encryption is already complete for |type|; do not wait. |
| 1062 return true; | 1062 return true; |
| 1063 } | 1063 } |
| 1064 | 1064 |
| 1065 std::string reason = "Waiting for encryption."; | 1065 std::string reason = "Waiting for encryption."; |
| 1066 wait_state_ = WAITING_FOR_ENCRYPTION; | 1066 wait_state_ = WAITING_FOR_ENCRYPTION; |
| 1067 waiting_for_encryption_type_ = type; | 1067 waiting_for_encryption_type_ = type; |
| 1068 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason)) { | 1068 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason)) { |
| 1069 LOG(ERROR) << "Did not receive EncryptionComplete notification after" | 1069 LOG(ERROR) << "Did not receive EncryptionComplete notification after" |
| 1070 << kLiveSyncOperationTimeoutMs / 1000 | 1070 << kLiveSyncOperationTimeoutMs / 1000 |
| 1071 << " seconds."; | 1071 << " seconds."; |
| 1072 return false; | 1072 return false; |
| 1073 } | 1073 } |
| 1074 return IsTypeEncrypted(type); | 1074 return IsTypeEncrypted(type); |
| 1075 } | 1075 } |
| 1076 | 1076 |
| 1077 bool ProfileSyncServiceHarness::IsTypeEncrypted(syncable::ModelType type) { | 1077 bool ProfileSyncServiceHarness::IsTypeEncrypted(syncer::ModelType type) { |
| 1078 const syncable::ModelTypeSet encrypted_types = | 1078 const syncer::ModelTypeSet encrypted_types = |
| 1079 service_->GetEncryptedDataTypes(); | 1079 service_->GetEncryptedDataTypes(); |
| 1080 bool is_type_encrypted = service_->GetEncryptedDataTypes().Has(type); | 1080 bool is_type_encrypted = service_->GetEncryptedDataTypes().Has(type); |
| 1081 DVLOG(2) << syncable::ModelTypeToString(type) << " is " | 1081 DVLOG(2) << syncer::ModelTypeToString(type) << " is " |
| 1082 << (is_type_encrypted ? "" : "not ") << "encrypted; " | 1082 << (is_type_encrypted ? "" : "not ") << "encrypted; " |
| 1083 << "encrypted types = " | 1083 << "encrypted types = " |
| 1084 << syncable::ModelTypeSetToString(encrypted_types); | 1084 << syncer::ModelTypeSetToString(encrypted_types); |
| 1085 return is_type_encrypted; | 1085 return is_type_encrypted; |
| 1086 } | 1086 } |
| 1087 | 1087 |
| 1088 bool ProfileSyncServiceHarness::IsTypeRunning(syncable::ModelType type) { | 1088 bool ProfileSyncServiceHarness::IsTypeRunning(syncer::ModelType type) { |
| 1089 browser_sync::DataTypeController::StateMap state_map; | 1089 browser_sync::DataTypeController::StateMap state_map; |
| 1090 service_->GetDataTypeControllerStates(&state_map); | 1090 service_->GetDataTypeControllerStates(&state_map); |
| 1091 return (state_map.count(type) != 0 && | 1091 return (state_map.count(type) != 0 && |
| 1092 state_map[type] == browser_sync::DataTypeController::RUNNING); | 1092 state_map[type] == browser_sync::DataTypeController::RUNNING); |
| 1093 } | 1093 } |
| 1094 | 1094 |
| 1095 bool ProfileSyncServiceHarness::IsTypePreferred(syncable::ModelType type) { | 1095 bool ProfileSyncServiceHarness::IsTypePreferred(syncer::ModelType type) { |
| 1096 return service_->GetPreferredDataTypes().Has(type); | 1096 return service_->GetPreferredDataTypes().Has(type); |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 size_t ProfileSyncServiceHarness::GetNumEntries() const { | 1099 size_t ProfileSyncServiceHarness::GetNumEntries() const { |
| 1100 return GetLastSessionSnapshot().num_entries(); | 1100 return GetLastSessionSnapshot().num_entries(); |
| 1101 } | 1101 } |
| 1102 | 1102 |
| 1103 size_t ProfileSyncServiceHarness::GetNumDatatypes() const { | 1103 size_t ProfileSyncServiceHarness::GetNumDatatypes() const { |
| 1104 browser_sync::DataTypeController::StateMap state_map; | 1104 browser_sync::DataTypeController::StateMap state_map; |
| 1105 service_->GetDataTypeControllerStates(&state_map); | 1105 service_->GetDataTypeControllerStates(&state_map); |
| 1106 return state_map.size(); | 1106 return state_map.size(); |
| 1107 } | 1107 } |
| 1108 | 1108 |
| 1109 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 1109 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 1110 DictionaryValue value; | 1110 DictionaryValue value; |
| 1111 sync_ui_util::ConstructAboutInformation(service_, &value); | 1111 sync_ui_util::ConstructAboutInformation(service_, &value); |
| 1112 std::string service_status; | 1112 std::string service_status; |
| 1113 base::JSONWriter::WriteWithOptions(&value, | 1113 base::JSONWriter::WriteWithOptions(&value, |
| 1114 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 1114 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 1115 &service_status); | 1115 &service_status); |
| 1116 return service_status; | 1116 return service_status; |
| 1117 } | 1117 } |
| OLD | NEW |