Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sync/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/profile_sync_service_harness.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <ostream> | 10 #include <ostream> |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 const std::string& password) { | 131 const std::string& password) { |
| 132 username_ = username; | 132 username_ = username; |
| 133 password_ = password; | 133 password_ = password; |
| 134 } | 134 } |
| 135 | 135 |
| 136 bool ProfileSyncServiceHarness::IsSyncAlreadySetup() { | 136 bool ProfileSyncServiceHarness::IsSyncAlreadySetup() { |
| 137 return profile_->HasProfileSyncService(); | 137 return profile_->HasProfileSyncService(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 bool ProfileSyncServiceHarness::SetupSync() { | 140 bool ProfileSyncServiceHarness::SetupSync() { |
| 141 syncable::ModelTypeSet synced_datatypes; | 141 syncable::ModelEnumSet synced_datatypes; |
| 142 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 142 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 143 i < syncable::MODEL_TYPE_COUNT; ++i) { | 143 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 144 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); | 144 synced_datatypes.Put(syncable::ModelTypeFromInt(i)); |
| 145 } | 145 } |
| 146 bool result = SetupSync(synced_datatypes); | 146 bool result = SetupSync(synced_datatypes); |
| 147 if (result == false) { | 147 if (result == false) { |
| 148 std::string status = GetServiceStatus(); | 148 std::string status = GetServiceStatus(); |
| 149 LOG(ERROR) << profile_debug_name_ | 149 LOG(ERROR) << profile_debug_name_ |
| 150 << ": SetupSync failed. Syncer status:\n" << status; | 150 << ": SetupSync failed. Syncer status:\n" << status; |
| 151 } else { | 151 } else { |
| 152 DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; | 152 DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; |
| 153 } | 153 } |
| 154 return result; | 154 return result; |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool ProfileSyncServiceHarness::SetupSync( | 157 bool ProfileSyncServiceHarness::SetupSync( |
| 158 const syncable::ModelTypeSet& synced_datatypes) { | 158 syncable::ModelEnumSet synced_datatypes) { |
| 159 // Initialize the sync client's profile sync service object. | 159 // Initialize the sync client's profile sync service object. |
| 160 service_ = profile_->GetProfileSyncService(""); | 160 service_ = profile_->GetProfileSyncService(""); |
| 161 if (service_ == NULL) { | 161 if (service_ == NULL) { |
| 162 LOG(ERROR) << "SetupSync(): service_ is null."; | 162 LOG(ERROR) << "SetupSync(): service_ is null."; |
| 163 return false; | 163 return false; |
| 164 } | 164 } |
| 165 | 165 |
| 166 // Subscribe sync client to notifications from the profile sync service. | 166 // Subscribe sync client to notifications from the profile sync service. |
| 167 if (!service_->HasObserver(this)) | 167 if (!service_->HasObserver(this)) |
| 168 service_->AddObserver(this); | 168 service_->AddObserver(this); |
| 169 | 169 |
| 170 // Authenticate sync client using GAIA credentials. | 170 // Authenticate sync client using GAIA credentials. |
| 171 service_->signin()->StartSignIn(username_, password_, "", ""); | 171 service_->signin()->StartSignIn(username_, password_, "", ""); |
| 172 | 172 |
| 173 // Wait for the OnBackendInitialized() callback. | 173 // Wait for the OnBackendInitialized() callback. |
| 174 if (!AwaitBackendInitialized()) { | 174 if (!AwaitBackendInitialized()) { |
| 175 LOG(ERROR) << "OnBackendInitialized() not seen after " | 175 LOG(ERROR) << "OnBackendInitialized() not seen after " |
| 176 << kLiveSyncOperationTimeoutMs / 1000 | 176 << kLiveSyncOperationTimeoutMs / 1000 |
| 177 << " seconds."; | 177 << " seconds."; |
| 178 return false; | 178 return false; |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Choose the datatypes to be synced. If all datatypes are to be synced, | 181 // Choose the datatypes to be synced. If all datatypes are to be synced, |
| 182 // set sync_everything to true; otherwise, set it to false. | 182 // set sync_everything to true; otherwise, set it to false. |
| 183 bool sync_everything = (synced_datatypes.size() == | 183 bool sync_everything = (synced_datatypes.Size() == |
| 184 (syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE)); | 184 (syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE)); |
| 185 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 185 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 186 | 186 |
| 187 // Subscribe sync client to notifications from the backend migrator | 187 // Subscribe sync client to notifications from the backend migrator |
| 188 // (possible only after choosing data types). | 188 // (possible only after choosing data types). |
| 189 if (!TryListeningToMigrationEvents()) { | 189 if (!TryListeningToMigrationEvents()) { |
| 190 NOTREACHED(); | 190 NOTREACHED(); |
| 191 return false; | 191 return false; |
| 192 } | 192 } |
| 193 | 193 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 | 447 |
| 448 void ProfileSyncServiceHarness::OnStateChanged() { | 448 void ProfileSyncServiceHarness::OnStateChanged() { |
| 449 RunStateChangeMachine(); | 449 RunStateChangeMachine(); |
| 450 } | 450 } |
| 451 | 451 |
| 452 void ProfileSyncServiceHarness::OnMigrationStateChange() { | 452 void ProfileSyncServiceHarness::OnMigrationStateChange() { |
| 453 // Update migration state. | 453 // Update migration state. |
| 454 if (HasPendingBackendMigration()) { | 454 if (HasPendingBackendMigration()) { |
| 455 // Merge current pending migration types into | 455 // Merge current pending migration types into |
| 456 // |pending_migration_types_|. | 456 // |pending_migration_types_|. |
| 457 syncable::ModelTypeSet new_pending_migration_types = | 457 pending_migration_types_.PutAll( |
| 458 service()->GetBackendMigratorForTest()-> | 458 service()->GetBackendMigratorForTest()-> |
| 459 GetPendingMigrationTypesForTest(); | 459 GetPendingMigrationTypesForTest()); |
|
Nicolas Zea
2011/12/08 01:49:37
indent by four more spaces
akalin
2011/12/09 19:10:10
Done.
| |
| 460 syncable::ModelTypeSet temp; | |
| 461 std::set_union(pending_migration_types_.begin(), | |
| 462 pending_migration_types_.end(), | |
| 463 new_pending_migration_types.begin(), | |
| 464 new_pending_migration_types.end(), | |
| 465 std::inserter(temp, temp.end())); | |
| 466 std::swap(pending_migration_types_, temp); | |
| 467 DVLOG(1) << profile_debug_name_ << ": new pending migration types " | 460 DVLOG(1) << profile_debug_name_ << ": new pending migration types " |
| 468 << syncable::ModelTypeSetToString(pending_migration_types_); | 461 << syncable::ModelEnumSetToString(pending_migration_types_); |
| 469 } else { | 462 } else { |
| 470 // Merge just-finished pending migration types into | 463 // Merge just-finished pending migration types into |
| 471 // |migration_types_|. | 464 // |migration_types_|. |
| 472 syncable::ModelTypeSet temp; | 465 migrated_types_.PutAll(pending_migration_types_); |
| 473 std::set_union(pending_migration_types_.begin(), | 466 pending_migration_types_.Clear(); |
| 474 pending_migration_types_.end(), | |
| 475 migrated_types_.begin(), | |
| 476 migrated_types_.end(), | |
| 477 std::inserter(temp, temp.end())); | |
| 478 std::swap(migrated_types_, temp); | |
| 479 pending_migration_types_.clear(); | |
| 480 DVLOG(1) << profile_debug_name_ << ": new migrated types " | 467 DVLOG(1) << profile_debug_name_ << ": new migrated types " |
| 481 << syncable::ModelTypeSetToString(migrated_types_); | 468 << syncable::ModelEnumSetToString(migrated_types_); |
| 482 } | 469 } |
| 483 RunStateChangeMachine(); | 470 RunStateChangeMachine(); |
| 484 } | 471 } |
| 485 | 472 |
| 486 bool ProfileSyncServiceHarness::AwaitPassphraseRequired() { | 473 bool ProfileSyncServiceHarness::AwaitPassphraseRequired() { |
| 487 DVLOG(1) << GetClientInfoString("AwaitPassphraseRequired"); | 474 DVLOG(1) << GetClientInfoString("AwaitPassphraseRequired"); |
| 488 if (wait_state_ == SYNC_DISABLED) { | 475 if (wait_state_ == SYNC_DISABLED) { |
| 489 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; | 476 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
| 490 return false; | 477 return false; |
| 491 } | 478 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 CHECK(status.sync_protocol_error.action == browser_sync::UNKNOWN_ACTION); | 623 CHECK(status.sync_protocol_error.action == browser_sync::UNKNOWN_ACTION); |
| 637 wait_state_ = WAITING_FOR_ACTIONABLE_ERROR; | 624 wait_state_ = WAITING_FOR_ACTIONABLE_ERROR; |
| 638 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 625 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 639 "Waiting for actionable error"); | 626 "Waiting for actionable error"); |
| 640 status = GetStatus(); | 627 status = GetStatus(); |
| 641 return (status.sync_protocol_error.action != browser_sync::UNKNOWN_ACTION && | 628 return (status.sync_protocol_error.action != browser_sync::UNKNOWN_ACTION && |
| 642 service_->unrecoverable_error_detected()); | 629 service_->unrecoverable_error_detected()); |
| 643 } | 630 } |
| 644 | 631 |
| 645 bool ProfileSyncServiceHarness::AwaitMigration( | 632 bool ProfileSyncServiceHarness::AwaitMigration( |
| 646 const syncable::ModelTypeSet& expected_migrated_types) { | 633 syncable::ModelEnumSet expected_migrated_types) { |
| 647 DVLOG(1) << GetClientInfoString("AwaitMigration"); | 634 DVLOG(1) << GetClientInfoString("AwaitMigration"); |
| 648 DVLOG(1) << profile_debug_name_ << ": waiting until migration is done for " | 635 DVLOG(1) << profile_debug_name_ << ": waiting until migration is done for " |
| 649 << syncable::ModelTypeSetToString(expected_migrated_types); | 636 << syncable::ModelEnumSetToString(expected_migrated_types); |
| 650 while (true) { | 637 while (true) { |
| 651 bool migration_finished = | 638 bool migration_finished = migrated_types_.HasAll(expected_migrated_types); |
| 652 std::includes(migrated_types_.begin(), migrated_types_.end(), | |
| 653 expected_migrated_types.begin(), | |
| 654 expected_migrated_types.end()); | |
| 655 DVLOG(1) << "Migrated types " | 639 DVLOG(1) << "Migrated types " |
| 656 << syncable::ModelTypeSetToString(migrated_types_) | 640 << syncable::ModelEnumSetToString(migrated_types_) |
| 657 << (migration_finished ? " contains " : " does not contain ") | 641 << (migration_finished ? " contains " : " does not contain ") |
| 658 << syncable::ModelTypeSetToString(expected_migrated_types); | 642 << syncable::ModelEnumSetToString(expected_migrated_types); |
| 659 if (migration_finished) { | 643 if (migration_finished) { |
| 660 return true; | 644 return true; |
| 661 } | 645 } |
| 662 | 646 |
| 663 if (HasPendingBackendMigration()) { | 647 if (HasPendingBackendMigration()) { |
| 664 wait_state_ = WAITING_FOR_MIGRATION_TO_FINISH; | 648 wait_state_ = WAITING_FOR_MIGRATION_TO_FINISH; |
| 665 } else { | 649 } else { |
| 666 wait_state_ = WAITING_FOR_MIGRATION_TO_START; | 650 wait_state_ = WAITING_FOR_MIGRATION_TO_START; |
| 667 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 651 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 668 "Wait for migration to start"); | 652 "Wait for migration to start"); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 ProfileSyncServiceHarness* partner) { | 822 ProfileSyncServiceHarness* partner) { |
| 839 // TODO(akalin): Shouldn't this belong with the intersection check? | 823 // TODO(akalin): Shouldn't this belong with the intersection check? |
| 840 // Otherwise, this function isn't symmetric. | 824 // Otherwise, this function isn't symmetric. |
| 841 if (!IsFullySynced()) { | 825 if (!IsFullySynced()) { |
| 842 DVLOG(2) << profile_debug_name_ << ": not synced, assuming doesn't match"; | 826 DVLOG(2) << profile_debug_name_ << ": not synced, assuming doesn't match"; |
| 843 return false; | 827 return false; |
| 844 } | 828 } |
| 845 | 829 |
| 846 // Only look for a match if we have at least one enabled datatype in | 830 // Only look for a match if we have at least one enabled datatype in |
| 847 // common with the partner client. | 831 // common with the partner client. |
| 848 syncable::ModelTypeSet types, other_types, intersection_types; | 832 syncable::ModelEnumSet types, other_types, intersection_types; |
| 849 service()->GetPreferredDataTypes(&types); | 833 types = service()->GetPreferredDataTypes(); |
| 850 partner->service()->GetPreferredDataTypes(&other_types); | 834 other_types = partner->service()->GetPreferredDataTypes(); |
| 851 std::set_intersection(types.begin(), types.end(), other_types.begin(), | 835 intersection_types = Intersection(types, other_types); |
| 852 other_types.end(), | |
| 853 inserter(intersection_types, | |
| 854 intersection_types.begin())); | |
| 855 | 836 |
| 856 DVLOG(2) << profile_debug_name_ << ", " << partner->profile_debug_name_ | 837 DVLOG(2) << profile_debug_name_ << ", " << partner->profile_debug_name_ |
| 857 << ": common types are " | 838 << ": common types are " |
| 858 << syncable::ModelTypeSetToString(intersection_types); | 839 << syncable::ModelEnumSetToString(intersection_types); |
| 859 | 840 |
| 860 if (!intersection_types.empty() && !partner->IsFullySynced()) { | 841 if (!intersection_types.Empty() && !partner->IsFullySynced()) { |
| 861 DVLOG(2) << "non-empty common types and " | 842 DVLOG(2) << "non-empty common types and " |
| 862 << partner->profile_debug_name_ << " isn't synced"; | 843 << partner->profile_debug_name_ << " isn't synced"; |
| 863 return false; | 844 return false; |
| 864 } | 845 } |
| 865 | 846 |
| 866 for (syncable::ModelTypeSet::iterator i = intersection_types.begin(); | 847 for (syncable::ModelEnumSet::Iterator i = intersection_types.First(); |
| 867 i != intersection_types.end(); ++i) { | 848 i.Good(); i.Inc()) { |
| 868 const std::string timestamp = GetUpdatedTimestamp(*i); | 849 const std::string timestamp = GetUpdatedTimestamp(i.Get()); |
| 869 const std::string partner_timestamp = partner->GetUpdatedTimestamp(*i); | 850 const std::string partner_timestamp = partner->GetUpdatedTimestamp(i.Get()); |
| 870 if (timestamp != partner_timestamp) { | 851 if (timestamp != partner_timestamp) { |
| 871 if (VLOG_IS_ON(2)) { | 852 if (VLOG_IS_ON(2)) { |
| 872 std::string timestamp_base64, partner_timestamp_base64; | 853 std::string timestamp_base64, partner_timestamp_base64; |
| 873 if (!base::Base64Encode(timestamp, ×tamp_base64)) { | 854 if (!base::Base64Encode(timestamp, ×tamp_base64)) { |
| 874 NOTREACHED(); | 855 NOTREACHED(); |
| 875 } | 856 } |
| 876 if (!base::Base64Encode( | 857 if (!base::Base64Encode( |
| 877 partner_timestamp, &partner_timestamp_base64)) { | 858 partner_timestamp, &partner_timestamp_base64)) { |
| 878 NOTREACHED(); | 859 NOTREACHED(); |
| 879 } | 860 } |
| 880 DVLOG(2) << syncable::ModelTypeToString(*i) << ": " | 861 DVLOG(2) << syncable::ModelTypeToString(i.Get()) << ": " |
| 881 << profile_debug_name_ << " timestamp = " | 862 << profile_debug_name_ << " timestamp = " |
| 882 << timestamp_base64 << ", " | 863 << timestamp_base64 << ", " |
| 883 << partner->profile_debug_name_ | 864 << partner->profile_debug_name_ |
| 884 << " partner timestamp = " | 865 << " partner timestamp = " |
| 885 << partner_timestamp_base64; | 866 << partner_timestamp_base64; |
| 886 } | 867 } |
| 887 return false; | 868 return false; |
| 888 } | 869 } |
| 889 } | 870 } |
| 890 return true; | 871 return true; |
| 891 } | 872 } |
| 892 | 873 |
| 893 const SyncSessionSnapshot* | 874 const SyncSessionSnapshot* |
| 894 ProfileSyncServiceHarness::GetLastSessionSnapshot() const { | 875 ProfileSyncServiceHarness::GetLastSessionSnapshot() const { |
| 895 DCHECK(service_ != NULL) << "Sync service has not yet been set up."; | 876 DCHECK(service_ != NULL) << "Sync service has not yet been set up."; |
| 896 if (service_->sync_initialized()) { | 877 if (service_->sync_initialized()) { |
| 897 return service_->GetLastSessionSnapshot(); | 878 return service_->GetLastSessionSnapshot(); |
| 898 } | 879 } |
| 899 return NULL; | 880 return NULL; |
| 900 } | 881 } |
| 901 | 882 |
| 902 bool ProfileSyncServiceHarness::EnableSyncForDatatype( | 883 bool ProfileSyncServiceHarness::EnableSyncForDatatype( |
| 903 syncable::ModelType datatype) { | 884 syncable::ModelType datatype) { |
| 904 DVLOG(1) << GetClientInfoString( | 885 DVLOG(1) << GetClientInfoString( |
| 905 "EnableSyncForDatatype(" | 886 "EnableSyncForDatatype(" |
| 906 + std::string(syncable::ModelTypeToString(datatype)) + ")"); | 887 + std::string(syncable::ModelTypeToString(datatype)) + ")"); |
| 907 | 888 |
| 908 syncable::ModelTypeSet synced_datatypes; | 889 syncable::ModelEnumSet synced_datatypes; |
| 909 if (wait_state_ == SYNC_DISABLED) { | 890 if (wait_state_ == SYNC_DISABLED) { |
| 910 synced_datatypes.insert(datatype); | 891 synced_datatypes.Put(datatype); |
| 911 return SetupSync(synced_datatypes); | 892 return SetupSync(synced_datatypes); |
| 912 } | 893 } |
| 913 | 894 |
| 914 if (service() == NULL) { | 895 if (service() == NULL) { |
| 915 LOG(ERROR) << "EnableSyncForDatatype(): service() is null."; | 896 LOG(ERROR) << "EnableSyncForDatatype(): service() is null."; |
| 916 return false; | 897 return false; |
| 917 } | 898 } |
| 918 | 899 |
| 919 service()->GetPreferredDataTypes(&synced_datatypes); | 900 synced_datatypes = service()->GetPreferredDataTypes(); |
| 920 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); | 901 if (synced_datatypes.Has(datatype)) { |
| 921 if (it != synced_datatypes.end()) { | |
| 922 DVLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " | 902 DVLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " |
| 923 << syncable::ModelTypeToString(datatype) | 903 << syncable::ModelTypeToString(datatype) |
| 924 << " on " << profile_debug_name_ << "."; | 904 << " on " << profile_debug_name_ << "."; |
| 925 return true; | 905 return true; |
| 926 } | 906 } |
| 927 | 907 |
| 928 synced_datatypes.insert(syncable::ModelTypeFromInt(datatype)); | 908 synced_datatypes.Put(syncable::ModelTypeFromInt(datatype)); |
| 929 service()->OnUserChoseDatatypes(false, synced_datatypes); | 909 service()->OnUserChoseDatatypes(false, synced_datatypes); |
| 930 if (AwaitFullSyncCompletion("Datatype configuration.")) { | 910 if (AwaitFullSyncCompletion("Datatype configuration.")) { |
| 931 DVLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " | 911 DVLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " |
| 932 << syncable::ModelTypeToString(datatype) | 912 << syncable::ModelTypeToString(datatype) |
| 933 << " on " << profile_debug_name_ << "."; | 913 << " on " << profile_debug_name_ << "."; |
| 934 return true; | 914 return true; |
| 935 } | 915 } |
| 936 | 916 |
| 937 DVLOG(0) << GetClientInfoString("EnableSyncForDatatype failed"); | 917 DVLOG(0) << GetClientInfoString("EnableSyncForDatatype failed"); |
| 938 return false; | 918 return false; |
| 939 } | 919 } |
| 940 | 920 |
| 941 bool ProfileSyncServiceHarness::DisableSyncForDatatype( | 921 bool ProfileSyncServiceHarness::DisableSyncForDatatype( |
| 942 syncable::ModelType datatype) { | 922 syncable::ModelType datatype) { |
| 943 DVLOG(1) << GetClientInfoString( | 923 DVLOG(1) << GetClientInfoString( |
| 944 "DisableSyncForDatatype(" | 924 "DisableSyncForDatatype(" |
| 945 + std::string(syncable::ModelTypeToString(datatype)) + ")"); | 925 + std::string(syncable::ModelTypeToString(datatype)) + ")"); |
| 946 | 926 |
| 947 syncable::ModelTypeSet synced_datatypes; | 927 syncable::ModelEnumSet synced_datatypes; |
| 948 if (service() == NULL) { | 928 if (service() == NULL) { |
| 949 LOG(ERROR) << "DisableSyncForDatatype(): service() is null."; | 929 LOG(ERROR) << "DisableSyncForDatatype(): service() is null."; |
| 950 return false; | 930 return false; |
| 951 } | 931 } |
| 952 | 932 |
| 953 service()->GetPreferredDataTypes(&synced_datatypes); | 933 synced_datatypes = service()->GetPreferredDataTypes(); |
| 954 syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); | 934 if (synced_datatypes.Has(datatype)) { |
| 955 if (it == synced_datatypes.end()) { | |
| 956 DVLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " | 935 DVLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " |
| 957 << syncable::ModelTypeToString(datatype) | 936 << syncable::ModelTypeToString(datatype) |
| 958 << " on " << profile_debug_name_ << "."; | 937 << " on " << profile_debug_name_ << "."; |
| 959 return true; | 938 return true; |
| 960 } | 939 } |
| 961 | 940 |
| 962 synced_datatypes.erase(it); | 941 synced_datatypes.Remove(datatype); |
| 963 service()->OnUserChoseDatatypes(false, synced_datatypes); | 942 service()->OnUserChoseDatatypes(false, synced_datatypes); |
| 964 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { | 943 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { |
| 965 DVLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " | 944 DVLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " |
| 966 << syncable::ModelTypeToString(datatype) | 945 << syncable::ModelTypeToString(datatype) |
| 967 << " on " << profile_debug_name_ << "."; | 946 << " on " << profile_debug_name_ << "."; |
| 968 return true; | 947 return true; |
| 969 } | 948 } |
| 970 | 949 |
| 971 DVLOG(0) << GetClientInfoString("DisableSyncForDatatype failed"); | 950 DVLOG(0) << GetClientInfoString("DisableSyncForDatatype failed"); |
| 972 return false; | 951 return false; |
| 973 } | 952 } |
| 974 | 953 |
| 975 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { | 954 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { |
| 976 DVLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes"); | 955 DVLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes"); |
| 977 | 956 |
| 978 if (wait_state_ == SYNC_DISABLED) { | 957 if (wait_state_ == SYNC_DISABLED) { |
| 979 return SetupSync(); | 958 return SetupSync(); |
| 980 } | 959 } |
| 981 | 960 |
| 982 if (service() == NULL) { | 961 if (service() == NULL) { |
| 983 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; | 962 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; |
| 984 return false; | 963 return false; |
| 985 } | 964 } |
| 986 | 965 |
| 987 syncable::ModelTypeSet synced_datatypes; | 966 syncable::ModelEnumSet synced_datatypes; |
| 988 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 967 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 989 i < syncable::MODEL_TYPE_COUNT; | 968 i < syncable::MODEL_TYPE_COUNT; |
| 990 ++i) { | 969 ++i) { |
| 991 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); | 970 synced_datatypes.Put(syncable::ModelTypeFromInt(i)); |
| 992 } | 971 } |
| 993 service()->OnUserChoseDatatypes(true, synced_datatypes); | 972 service()->OnUserChoseDatatypes(true, synced_datatypes); |
| 994 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { | 973 if (AwaitFullSyncCompletion("Datatype reconfiguration.")) { |
| 995 DVLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes " | 974 DVLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes " |
| 996 << "on " << profile_debug_name_ << "."; | 975 << "on " << profile_debug_name_ << "."; |
| 997 return true; | 976 return true; |
| 998 } | 977 } |
| 999 | 978 |
| 1000 DVLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed"); | 979 DVLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed"); |
| 1001 return false; | 980 return false; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1059 } else { | 1038 } else { |
| 1060 os << "Sync service not available"; | 1039 os << "Sync service not available"; |
| 1061 } | 1040 } |
| 1062 return os.str(); | 1041 return os.str(); |
| 1063 } | 1042 } |
| 1064 | 1043 |
| 1065 // TODO(zea): Rename this EnableEncryption, since we no longer turn on | 1044 // TODO(zea): Rename this EnableEncryption, since we no longer turn on |
| 1066 // encryption for individual types but for all. | 1045 // encryption for individual types but for all. |
| 1067 bool ProfileSyncServiceHarness::EnableEncryptionForType( | 1046 bool ProfileSyncServiceHarness::EnableEncryptionForType( |
| 1068 syncable::ModelType type) { | 1047 syncable::ModelType type) { |
| 1069 syncable::ModelTypeSet encrypted_types; | 1048 syncable::ModelEnumSet encrypted_types = |
| 1070 service_->GetEncryptedDataTypes(&encrypted_types); | 1049 service_->GetEncryptedDataTypes(); |
| 1071 if (encrypted_types.count(type) > 0) | 1050 if (encrypted_types.Has(type)) |
| 1072 return true; | 1051 return true; |
| 1073 service_->EnableEncryptEverything(); | 1052 service_->EnableEncryptEverything(); |
| 1074 | 1053 |
| 1075 // In order to kick off the encryption we have to reconfigure. Just grab the | 1054 // In order to kick off the encryption we have to reconfigure. Just grab the |
| 1076 // currently synced types and use them. | 1055 // currently synced types and use them. |
| 1077 syncable::ModelTypeSet synced_datatypes; | 1056 syncable::ModelEnumSet synced_datatypes = |
| 1078 service_->GetPreferredDataTypes(&synced_datatypes); | 1057 service_->GetPreferredDataTypes(); |
| 1079 bool sync_everything = (synced_datatypes.size() == | 1058 bool sync_everything = (synced_datatypes.Size() == |
| 1080 (syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE)); | 1059 (syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE)); |
| 1081 service_->OnUserChoseDatatypes(sync_everything, | 1060 service_->OnUserChoseDatatypes(sync_everything, |
| 1082 synced_datatypes); | 1061 synced_datatypes); |
| 1083 | 1062 |
| 1084 // Wait some time to let the enryption finish. | 1063 // Wait some time to let the enryption finish. |
| 1085 return WaitForTypeEncryption(type); | 1064 return WaitForTypeEncryption(type); |
| 1086 } | 1065 } |
| 1087 | 1066 |
| 1088 bool ProfileSyncServiceHarness::WaitForTypeEncryption( | 1067 bool ProfileSyncServiceHarness::WaitForTypeEncryption( |
| 1089 syncable::ModelType type) { | 1068 syncable::ModelType type) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1103 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason)) { | 1082 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason)) { |
| 1104 LOG(ERROR) << "Did not receive EncryptionComplete notification after" | 1083 LOG(ERROR) << "Did not receive EncryptionComplete notification after" |
| 1105 << kLiveSyncOperationTimeoutMs / 1000 | 1084 << kLiveSyncOperationTimeoutMs / 1000 |
| 1106 << " seconds."; | 1085 << " seconds."; |
| 1107 return false; | 1086 return false; |
| 1108 } | 1087 } |
| 1109 return IsTypeEncrypted(type); | 1088 return IsTypeEncrypted(type); |
| 1110 } | 1089 } |
| 1111 | 1090 |
| 1112 bool ProfileSyncServiceHarness::IsTypeEncrypted(syncable::ModelType type) { | 1091 bool ProfileSyncServiceHarness::IsTypeEncrypted(syncable::ModelType type) { |
| 1113 syncable::ModelTypeSet encrypted_types; | 1092 syncable::ModelEnumSet encrypted_types = |
| 1114 service_->GetEncryptedDataTypes(&encrypted_types); | 1093 service_->GetEncryptedDataTypes(); |
| 1115 bool is_type_encrypted = (encrypted_types.count(type) != 0); | 1094 bool is_type_encrypted = encrypted_types.Has(type); |
| 1116 DVLOG(2) << syncable::ModelTypeToString(type) << " is " | 1095 DVLOG(2) << syncable::ModelTypeToString(type) << " is " |
| 1117 << (is_type_encrypted ? "" : "not ") << "encrypted; " | 1096 << (is_type_encrypted ? "" : "not ") << "encrypted; " |
| 1118 << "encrypted types = " | 1097 << "encrypted types = " |
| 1119 << syncable::ModelTypeSetToString(encrypted_types); | 1098 << syncable::ModelEnumSetToString(encrypted_types); |
| 1120 return is_type_encrypted; | 1099 return is_type_encrypted; |
| 1121 } | 1100 } |
| 1122 | 1101 |
| 1123 bool ProfileSyncServiceHarness::IsTypeRunning(syncable::ModelType type) { | 1102 bool ProfileSyncServiceHarness::IsTypeRunning(syncable::ModelType type) { |
| 1124 browser_sync::DataTypeController::StateMap state_map; | 1103 browser_sync::DataTypeController::StateMap state_map; |
| 1125 service_->GetDataTypeControllerStates(&state_map); | 1104 service_->GetDataTypeControllerStates(&state_map); |
| 1126 return (state_map.count(type) != 0 && | 1105 return (state_map.count(type) != 0 && |
| 1127 state_map[type] == browser_sync::DataTypeController::RUNNING); | 1106 state_map[type] == browser_sync::DataTypeController::RUNNING); |
| 1128 } | 1107 } |
| 1129 | 1108 |
| 1130 bool ProfileSyncServiceHarness::IsTypePreferred(syncable::ModelType type) { | 1109 bool ProfileSyncServiceHarness::IsTypePreferred(syncable::ModelType type) { |
| 1131 syncable::ModelTypeSet synced_types; | 1110 return service_->GetPreferredDataTypes().Has(type); |
| 1132 service_->GetPreferredDataTypes(&synced_types); | |
| 1133 return (synced_types.count(type) != 0); | |
| 1134 } | 1111 } |
| 1135 | 1112 |
| 1136 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 1113 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 1137 DictionaryValue value; | 1114 DictionaryValue value; |
| 1138 sync_ui_util::ConstructAboutInformation(service_, &value); | 1115 sync_ui_util::ConstructAboutInformation(service_, &value); |
| 1139 std::string service_status; | 1116 std::string service_status; |
| 1140 base::JSONWriter::Write(&value, true, &service_status); | 1117 base::JSONWriter::Write(&value, true, &service_status); |
| 1141 return service_status; | 1118 return service_status; |
| 1142 } | 1119 } |
| OLD | NEW |