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