summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc10
-rw-r--r--chrome/browser/sync/backend_migrator.cc79
-rw-r--r--chrome/browser/sync/backend_migrator.h6
-rw-r--r--chrome/browser/sync/backend_migrator_unittest.cc118
-rw-r--r--chrome/browser/sync/engine/all_status.cc2
-rw-r--r--chrome/browser/sync/engine/all_status.h2
-rw-r--r--chrome/browser/sync/engine/apply_updates_command_unittest.cc65
-rw-r--r--chrome/browser/sync/engine/get_commit_ids_command.cc31
-rw-r--r--chrome/browser/sync/engine/get_commit_ids_command.h16
-rw-r--r--chrome/browser/sync/engine/nigori_util.cc16
-rw-r--r--chrome/browser/sync/engine/nigori_util.h6
-rw-r--r--chrome/browser/sync/engine/nigori_util_unittest.cc12
-rw-r--r--chrome/browser/sync/engine/syncer_proto_util.cc8
-rw-r--r--chrome/browser/sync/engine/syncer_proto_util_unittest.cc12
-rw-r--r--chrome/browser/sync/engine/syncer_unittest.cc5
-rw-r--r--chrome/browser/sync/engine/syncer_util.cc2
-rw-r--r--chrome/browser/sync/failed_datatypes_handler.cc12
-rw-r--r--chrome/browser/sync/failed_datatypes_handler.h2
-rw-r--r--chrome/browser/sync/glue/bookmark_model_associator.cc4
-rw-r--r--chrome/browser/sync/glue/data_type_manager.h6
-rw-r--r--chrome/browser/sync/glue/data_type_manager_impl.cc34
-rw-r--r--chrome/browser/sync/glue/data_type_manager_impl.h6
-rw-r--r--chrome/browser/sync/glue/data_type_manager_impl_unittest.cc48
-rw-r--r--chrome/browser/sync/glue/data_type_manager_mock.cc2
-rw-r--r--chrome/browser/sync/glue/data_type_manager_mock.h4
-rw-r--r--chrome/browser/sync/glue/generic_change_processor.cc5
-rw-r--r--chrome/browser/sync/glue/session_model_associator.cc6
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.cc54
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.h20
-rw-r--r--chrome/browser/sync/glue/sync_backend_host_mock.h4
-rw-r--r--chrome/browser/sync/glue/sync_backend_host_unittest.cc8
-rw-r--r--chrome/browser/sync/glue/sync_backend_registrar.cc59
-rw-r--r--chrome/browser/sync/glue/sync_backend_registrar.h8
-rw-r--r--chrome/browser/sync/glue/sync_backend_registrar_unittest.cc61
-rw-r--r--chrome/browser/sync/glue/theme_model_associator.cc6
-rw-r--r--chrome/browser/sync/glue/typed_url_model_associator.cc6
-rw-r--r--chrome/browser/sync/internal_api/base_transaction.cc2
-rw-r--r--chrome/browser/sync/internal_api/base_transaction.h2
-rw-r--r--chrome/browser/sync/internal_api/debug_info_event_listener.cc2
-rw-r--r--chrome/browser/sync/internal_api/debug_info_event_listener.h2
-rw-r--r--chrome/browser/sync/internal_api/sync_manager.cc52
-rw-r--r--chrome/browser/sync/internal_api/sync_manager.h14
-rw-r--r--chrome/browser/sync/internal_api/syncapi_unittest.cc46
-rw-r--r--chrome/browser/sync/internal_api/write_node.cc5
-rw-r--r--chrome/browser/sync/js/js_sync_manager_observer.cc4
-rw-r--r--chrome/browser/sync/js/js_sync_manager_observer.h2
-rw-r--r--chrome/browser/sync/js/js_sync_manager_observer_unittest.cc4
-rw-r--r--chrome/browser/sync/profile_sync_service.cc115
-rw-r--r--chrome/browser/sync/profile_sync_service.h21
-rw-r--r--chrome/browser/sync/profile_sync_service_harness.cc136
-rw-r--r--chrome/browser/sync/profile_sync_service_harness.h8
-rw-r--r--chrome/browser/sync/profile_sync_service_mock.h8
-rw-r--r--chrome/browser/sync/profile_sync_service_password_unittest.cc6
-rw-r--r--chrome/browser/sync/profile_sync_service_startup_unittest.cc7
-rw-r--r--chrome/browser/sync/profile_sync_service_typed_url_unittest.cc8
-rw-r--r--chrome/browser/sync/protocol/sync_protocol_error.h2
-rw-r--r--chrome/browser/sync/sessions/sync_session_context.cc15
-rw-r--r--chrome/browser/sync/sessions/sync_session_context.h4
-rw-r--r--chrome/browser/sync/sessions/sync_session_context_unittest.cc14
-rw-r--r--chrome/browser/sync/sync_prefs.cc116
-rw-r--r--chrome/browser/sync/sync_prefs.h12
-rw-r--r--chrome/browser/sync/sync_prefs_unittest.cc92
-rw-r--r--chrome/browser/sync/sync_setup_flow.cc43
-rw-r--r--chrome/browser/sync/sync_setup_flow.h2
-rw-r--r--chrome/browser/sync/sync_setup_wizard_unittest.cc24
-rw-r--r--chrome/browser/sync/sync_ui_util.cc2
-rw-r--r--chrome/browser/sync/syncable/model_type.cc53
-rw-r--r--chrome/browser/sync/syncable/model_type.h15
-rw-r--r--chrome/browser/sync/syncable/model_type_unittest.cc33
-rw-r--r--chrome/browser/sync/test/integration/enable_disable_test.cc44
-rw-r--r--chrome/browser/sync/test/integration/migration_errors_test.cc17
-rw-r--r--chrome/browser/sync/util/cryptographer.cc83
-rw-r--r--chrome/browser/sync/util/cryptographer.h12
-rw-r--r--chrome/browser/sync/util/cryptographer_unittest.cc120
-rw-r--r--chrome/browser/ui/webui/sync_setup_handler.cc62
75 files changed, 874 insertions, 1080 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 6f316e4..88fbd3b 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -4962,12 +4962,12 @@ void TestingAutomationProvider::GetSyncInfo(Browser* browser,
sync_info->SetString("last synced", service->GetLastSyncedTimeString());
sync_info->SetInteger("updates received", status.updates_received);
ListValue* synced_datatype_list = new ListValue;
- syncable::ModelTypeSet synced_datatypes;
- service->GetPreferredDataTypes(&synced_datatypes);
- for (syncable::ModelTypeSet::iterator it = synced_datatypes.begin();
- it != synced_datatypes.end(); ++it) {
+ const syncable::ModelEnumSet synced_datatypes =
+ service->GetPreferredDataTypes();
+ for (syncable::ModelEnumSet::Iterator it = synced_datatypes.First();
+ it.Good(); it.Inc()) {
synced_datatype_list->Append(
- new StringValue(syncable::ModelTypeToString(*it)));
+ new StringValue(syncable::ModelTypeToString(it.Get())));
}
sync_info->Set("synced datatypes", synced_datatype_list);
}
diff --git a/chrome/browser/sync/backend_migrator.cc b/chrome/browser/sync/backend_migrator.cc
index 66c050c..a0dabde 100644
--- a/chrome/browser/sync/backend_migrator.cc
+++ b/chrome/browser/sync/backend_migrator.cc
@@ -4,8 +4,6 @@
#include "chrome/browser/sync/backend_migrator.h"
-#include <algorithm>
-
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
#include "base/tracked_objects.h"
@@ -19,7 +17,7 @@
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
-using syncable::ModelTypeSet;
+using syncable::ModelEnumSet;
namespace browser_sync {
@@ -49,19 +47,13 @@ BackendMigrator::~BackendMigrator() {
#define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": "
-void BackendMigrator::MigrateTypes(const syncable::ModelTypeSet& types) {
- const ModelTypeSet old_to_migrate = to_migrate_;
- {
- ModelTypeSet temp;
- std::set_union(to_migrate_.begin(), to_migrate_.end(),
- types.begin(), types.end(),
- std::inserter(temp, temp.end()));
- std::swap(temp, to_migrate_);
- }
- SDVLOG(1) << "MigrateTypes called with " << ModelTypeSetToString(types)
- << ", old_to_migrate = " << ModelTypeSetToString(old_to_migrate)
- << ", to_migrate_ = " << ModelTypeSetToString(to_migrate_);
- if (old_to_migrate == to_migrate_) {
+void BackendMigrator::MigrateTypes(syncable::ModelEnumSet types) {
+ const ModelEnumSet old_to_migrate = to_migrate_;
+ to_migrate_.PutAll(types);
+ SDVLOG(1) << "MigrateTypes called with " << ModelEnumSetToString(types)
+ << ", old_to_migrate = " << ModelEnumSetToString(old_to_migrate)
+ << ", to_migrate_ = " << ModelEnumSetToString(to_migrate_);
+ if (old_to_migrate.Equals(to_migrate_)) {
SDVLOG(1) << "MigrateTypes called with no new types; ignoring";
return;
}
@@ -111,16 +103,12 @@ bool BackendMigrator::TryStart() {
void BackendMigrator::RestartMigration() {
// We'll now disable any running types that need to be migrated.
ChangeState(DISABLING_TYPES);
- ModelTypeSet full_set;
- service_->GetPreferredDataTypes(&full_set);
- ModelTypeSet difference;
- std::set_difference(full_set.begin(), full_set.end(),
- to_migrate_.begin(), to_migrate_.end(),
- std::inserter(difference, difference.end()));
- bool configure_with_nigori = to_migrate_.count(syncable::NIGORI) == 0;
+ const ModelEnumSet full_set = service_->GetPreferredDataTypes();
+ const ModelEnumSet difference = Difference(full_set, to_migrate_);
+ bool configure_with_nigori = !to_migrate_.Has(syncable::NIGORI);
SDVLOG(1) << "BackendMigrator disabling types "
- << ModelTypeSetToString(to_migrate_) << "; configuring "
- << ModelTypeSetToString(difference)
+ << ModelEnumSetToString(to_migrate_) << "; configuring "
+ << ModelEnumSetToString(difference)
<< (configure_with_nigori ? " with nigori" : " without nigori");
// Add nigori for config or not based upon if the server told us to migrate
@@ -153,16 +141,16 @@ void BackendMigrator::Observe(int type,
namespace {
-syncable::ModelTypeSet GetUnsyncedDataTypes(sync_api::UserShare* user_share) {
+syncable::ModelEnumSet GetUnsyncedDataTypes(sync_api::UserShare* user_share) {
sync_api::ReadTransaction trans(FROM_HERE, user_share);
- syncable::ModelTypeSet unsynced_data_types;
+ syncable::ModelEnumSet unsynced_data_types;
for (int i = syncable::FIRST_REAL_MODEL_TYPE;
i < syncable::MODEL_TYPE_COUNT; ++i) {
syncable::ModelType type = syncable::ModelTypeFromInt(i);
sync_pb::DataTypeProgressMarker progress_marker;
trans.GetLookup()->GetDownloadProgress(type, &progress_marker);
if (progress_marker.token().empty()) {
- unsynced_data_types.insert(type);
+ unsynced_data_types.Put(type);
}
}
return unsynced_data_types;
@@ -173,9 +161,9 @@ syncable::ModelTypeSet GetUnsyncedDataTypes(sync_api::UserShare* user_share) {
void BackendMigrator::OnConfigureDone(
const DataTypeManager::ConfigureResult& result) {
SDVLOG(1) << "OnConfigureDone with requested types "
- << ModelTypeSetToString(result.requested_types)
+ << ModelEnumSetToString(result.requested_types)
<< ", status " << result.status
- << ", and to_migrate_ = " << ModelTypeSetToString(to_migrate_);
+ << ", and to_migrate_ = " << ModelEnumSetToString(to_migrate_);
if (state_ == WAITING_TO_START) {
if (!TryStart())
SDVLOG(1) << "Manager still not configured; still waiting";
@@ -184,14 +172,11 @@ void BackendMigrator::OnConfigureDone(
DCHECK_GT(state_, WAITING_TO_START);
- ModelTypeSet intersection;
- std::set_intersection(
- result.requested_types.begin(), result.requested_types.end(),
- to_migrate_.begin(), to_migrate_.end(),
- std::inserter(intersection, intersection.end()));
+ const ModelEnumSet intersection =
+ Intersection(result.requested_types, to_migrate_);
// This intersection check is to determine if our disable request
// was interrupted by a user changing preferred types.
- if (state_ == DISABLING_TYPES && !intersection.empty()) {
+ if (state_ == DISABLING_TYPES && !intersection.Empty()) {
SDVLOG(1) << "Disable request interrupted by user changing types";
RestartMigration();
return;
@@ -207,19 +192,18 @@ void BackendMigrator::OnConfigureDone(
// migration as the type will still be enabled on restart.
SLOG(WARNING) << "Unable to migrate, configuration failed!";
ChangeState(IDLE);
- to_migrate_.clear();
+ to_migrate_.Clear();
return;
}
if (state_ == DISABLING_TYPES) {
- const syncable::ModelTypeSet& unsynced_types =
+ const syncable::ModelEnumSet unsynced_types =
GetUnsyncedDataTypes(user_share_);
- if (!std::includes(unsynced_types.begin(), unsynced_types.end(),
- to_migrate_.begin(), to_migrate_.end())) {
+ if (!unsynced_types.HasAll(to_migrate_)) {
SLOG(WARNING) << "Set of unsynced types: "
- << syncable::ModelTypeSetToString(unsynced_types)
+ << syncable::ModelEnumSetToString(unsynced_types)
<< " does not contain types to migrate: "
- << syncable::ModelTypeSetToString(to_migrate_)
+ << syncable::ModelEnumSetToString(to_migrate_)
<< "; not re-enabling yet";
return;
}
@@ -227,18 +211,17 @@ void BackendMigrator::OnConfigureDone(
ChangeState(REENABLING_TYPES);
// Don't use |to_migrate_| for the re-enabling because the user
// may have chosen to disable types during the migration.
- ModelTypeSet full_set;
- service_->GetPreferredDataTypes(&full_set);
+ const ModelEnumSet full_set = service_->GetPreferredDataTypes();
SDVLOG(1) << "BackendMigrator re-enabling types: "
- << syncable::ModelTypeSetToString(full_set);
+ << syncable::ModelEnumSetToString(full_set);
manager_->Configure(full_set, sync_api::CONFIGURE_REASON_MIGRATION);
} else if (state_ == REENABLING_TYPES) {
// We're done!
ChangeState(IDLE);
SDVLOG(1) << "BackendMigrator: Migration complete for: "
- << syncable::ModelTypeSetToString(to_migrate_);
- to_migrate_.clear();
+ << syncable::ModelEnumSetToString(to_migrate_);
+ to_migrate_.Clear();
}
}
@@ -246,7 +229,7 @@ BackendMigrator::State BackendMigrator::state() const {
return state_;
}
-syncable::ModelTypeSet
+syncable::ModelEnumSet
BackendMigrator::GetPendingMigrationTypesForTest() const {
return to_migrate_;
}
diff --git a/chrome/browser/sync/backend_migrator.h b/chrome/browser/sync/backend_migrator.h
index 7e771cb..ad34132 100644
--- a/chrome/browser/sync/backend_migrator.h
+++ b/chrome/browser/sync/backend_migrator.h
@@ -55,7 +55,7 @@ class BackendMigrator : public content::NotificationObserver {
virtual ~BackendMigrator();
// Starts a sequence of events that will disable and reenable |types|.
- void MigrateTypes(const syncable::ModelTypeSet& types);
+ void MigrateTypes(syncable::ModelEnumSet types);
void AddMigrationObserver(MigrationObserver* observer);
bool HasMigrationObserver(MigrationObserver* observer) const;
@@ -69,7 +69,7 @@ class BackendMigrator : public content::NotificationObserver {
State state() const;
// Returns the types that are currently pending migration (if any).
- syncable::ModelTypeSet GetPendingMigrationTypesForTest() const;
+ syncable::ModelEnumSet GetPendingMigrationTypesForTest() const;
private:
void ChangeState(State new_state);
@@ -97,7 +97,7 @@ class BackendMigrator : public content::NotificationObserver {
ObserverList<MigrationObserver> migration_observers_;
- syncable::ModelTypeSet to_migrate_;
+ syncable::ModelEnumSet to_migrate_;
base::WeakPtrFactory<BackendMigrator> weak_ptr_factory_;
diff --git a/chrome/browser/sync/backend_migrator_unittest.cc b/chrome/browser/sync/backend_migrator_unittest.cc
index 873e844..c52f1a5 100644
--- a/chrome/browser/sync/backend_migrator_unittest.cc
+++ b/chrome/browser/sync/backend_migrator_unittest.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/sync/protocol/sync.pb.h"
#include "chrome/browser/sync/sessions/session_state.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
+#include "chrome/browser/sync/syncable/model_type_test_util.h"
#include "chrome/browser/sync/test/engine/test_user_share.h"
#include "chrome/common/chrome_notification_types.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -22,7 +23,6 @@ using ::testing::Eq;
using ::testing::Mock;
using ::testing::NiceMock;
using ::testing::Return;
-using ::testing::SetArgumentPointee;
namespace browser_sync {
@@ -39,17 +39,17 @@ class BackendMigratorTest : public testing::Test {
test_user_share_.SetUp();
Mock::VerifyAndClear(manager());
Mock::VerifyAndClear(&service_);
- preferred_types_.insert(syncable::BOOKMARKS);
- preferred_types_.insert(syncable::PREFERENCES);
- preferred_types_.insert(syncable::AUTOFILL);
+ preferred_types_.Put(syncable::BOOKMARKS);
+ preferred_types_.Put(syncable::PREFERENCES);
+ preferred_types_.Put(syncable::AUTOFILL);
- ON_CALL(service_, GetPreferredDataTypes(_)).
- WillByDefault(SetArgumentPointee<0>(preferred_types_));
+ ON_CALL(service_, GetPreferredDataTypes()).
+ WillByDefault(Return(preferred_types_));
migrator_.reset(
new BackendMigrator(
"Profile0", test_user_share_.user_share(), service(), manager()));
- SetUnsyncedTypes(syncable::ModelTypeSet());
+ SetUnsyncedTypes(syncable::ModelEnumSet());
}
virtual void TearDown() {
@@ -59,14 +59,14 @@ class BackendMigratorTest : public testing::Test {
// Marks all types in |unsynced_types| as unsynced and all other
// types as synced.
- void SetUnsyncedTypes(const syncable::ModelTypeSet& unsynced_types) {
+ void SetUnsyncedTypes(syncable::ModelEnumSet unsynced_types) {
sync_api::WriteTransaction trans(FROM_HERE,
test_user_share_.user_share());
for (int i = syncable::FIRST_REAL_MODEL_TYPE;
i < syncable::MODEL_TYPE_COUNT; ++i) {
syncable::ModelType type = syncable::ModelTypeFromInt(i);
sync_pb::DataTypeProgressMarker progress_marker;
- if (unsynced_types.count(type) == 0) {
+ if (!unsynced_types.Has(type)) {
progress_marker.set_token("dummy");
}
trans.GetLookup()->SetDownloadProgress(type, progress_marker);
@@ -74,7 +74,7 @@ class BackendMigratorTest : public testing::Test {
}
void SendConfigureDone(DataTypeManager::ConfigureStatus status,
- const syncable::ModelTypeSet& requested_types) {
+ syncable::ModelEnumSet requested_types) {
if (status == DataTypeManager::OK) {
DataTypeManager::ConfigureResult result(status, requested_types);
content::NotificationService::current()->Notify(
@@ -97,19 +97,19 @@ class BackendMigratorTest : public testing::Test {
ProfileSyncService* service() { return &service_; }
DataTypeManagerMock* manager() { return &manager_; }
- const syncable::ModelTypeSet& preferred_types() { return preferred_types_; }
+ syncable::ModelEnumSet preferred_types() { return preferred_types_; }
BackendMigrator* migrator() { return migrator_.get(); }
void RemovePreferredType(syncable::ModelType type) {
- preferred_types_.erase(type);
+ preferred_types_.Remove(type);
Mock::VerifyAndClear(&service_);
- ON_CALL(service_, GetPreferredDataTypes(_)).
- WillByDefault(SetArgumentPointee<0>(preferred_types_));
+ ON_CALL(service_, GetPreferredDataTypes()).
+ WillByDefault(Return(preferred_types_));
}
private:
scoped_ptr<SyncSessionSnapshot> snap_;
MessageLoop message_loop_;
- syncable::ModelTypeSet preferred_types_;
+ syncable::ModelEnumSet preferred_types_;
NiceMock<ProfileSyncServiceMock> service_;
NiceMock<DataTypeManagerMock> manager_;
TestUserShare test_user_share_;
@@ -130,10 +130,10 @@ TEST_F(BackendMigratorTest, Sanity) {
migrator()->AddMigrationObserver(&migration_observer);
EXPECT_CALL(migration_observer, OnMigrationStateChange()).Times(4);
- syncable::ModelTypeSet to_migrate, difference;
- to_migrate.insert(syncable::PREFERENCES);
- difference.insert(syncable::AUTOFILL);
- difference.insert(syncable::BOOKMARKS);
+ syncable::ModelEnumSet to_migrate, difference;
+ to_migrate.Put(syncable::PREFERENCES);
+ difference.Put(syncable::AUTOFILL);
+ difference.Put(syncable::BOOKMARKS);
EXPECT_CALL(*manager(), state())
.WillOnce(Return(DataTypeManager::CONFIGURED));
@@ -147,7 +147,7 @@ TEST_F(BackendMigratorTest, Sanity) {
SendConfigureDone(DataTypeManager::OK, difference);
EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state());
- SetUnsyncedTypes(syncable::ModelTypeSet());
+ SetUnsyncedTypes(syncable::ModelEnumSet());
SendConfigureDone(DataTypeManager::OK, preferred_types());
EXPECT_EQ(BackendMigrator::IDLE, migrator()->state());
@@ -157,10 +157,10 @@ TEST_F(BackendMigratorTest, Sanity) {
// Test that in the normal case with Nigori a migration transitions through
// each state and wind up back in IDLE.
TEST_F(BackendMigratorTest, MigrateNigori) {
- syncable::ModelTypeSet to_migrate, difference;
- to_migrate.insert(syncable::NIGORI);
- difference.insert(syncable::AUTOFILL);
- difference.insert(syncable::BOOKMARKS);
+ syncable::ModelEnumSet to_migrate, difference;
+ to_migrate.Put(syncable::NIGORI);
+ difference.Put(syncable::AUTOFILL);
+ difference.Put(syncable::BOOKMARKS);
EXPECT_CALL(*manager(), state())
.WillOnce(Return(DataTypeManager::CONFIGURED));
@@ -175,7 +175,7 @@ TEST_F(BackendMigratorTest, MigrateNigori) {
SendConfigureDone(DataTypeManager::OK, difference);
EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state());
- SetUnsyncedTypes(syncable::ModelTypeSet());
+ SetUnsyncedTypes(syncable::ModelEnumSet());
SendConfigureDone(DataTypeManager::OK, preferred_types());
EXPECT_EQ(BackendMigrator::IDLE, migrator()->state());
}
@@ -184,8 +184,8 @@ TEST_F(BackendMigratorTest, MigrateNigori) {
// Test that the migrator waits for the data type manager to be idle before
// starting a migration.
TEST_F(BackendMigratorTest, WaitToStart) {
- syncable::ModelTypeSet to_migrate;
- to_migrate.insert(syncable::PREFERENCES);
+ syncable::ModelEnumSet to_migrate;
+ to_migrate.Put(syncable::PREFERENCES);
EXPECT_CALL(*manager(), state())
.WillOnce(Return(DataTypeManager::CONFIGURING));
@@ -197,8 +197,8 @@ TEST_F(BackendMigratorTest, WaitToStart) {
EXPECT_CALL(*manager(), state())
.WillOnce(Return(DataTypeManager::CONFIGURED));
EXPECT_CALL(*manager(), Configure(_, sync_api::CONFIGURE_REASON_MIGRATION));
- SetUnsyncedTypes(syncable::ModelTypeSet());
- SendConfigureDone(DataTypeManager::OK, syncable::ModelTypeSet());
+ SetUnsyncedTypes(syncable::ModelEnumSet());
+ SendConfigureDone(DataTypeManager::OK, syncable::ModelEnumSet());
EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
}
@@ -206,12 +206,12 @@ TEST_F(BackendMigratorTest, WaitToStart) {
// Test that the migrator can cope with a migration request while a migration
// is in progress.
TEST_F(BackendMigratorTest, RestartMigration) {
- syncable::ModelTypeSet to_migrate1, to_migrate2, to_migrate_union, bookmarks;
- to_migrate1.insert(syncable::PREFERENCES);
- to_migrate2.insert(syncable::AUTOFILL);
- to_migrate_union.insert(syncable::PREFERENCES);
- to_migrate_union.insert(syncable::AUTOFILL);
- bookmarks.insert(syncable::BOOKMARKS);
+ syncable::ModelEnumSet to_migrate1, to_migrate2, to_migrate_union, bookmarks;
+ to_migrate1.Put(syncable::PREFERENCES);
+ to_migrate2.Put(syncable::AUTOFILL);
+ to_migrate_union.Put(syncable::PREFERENCES);
+ to_migrate_union.Put(syncable::AUTOFILL);
+ bookmarks.Put(syncable::BOOKMARKS);
EXPECT_CALL(*manager(), state())
.WillOnce(Return(DataTypeManager::CONFIGURED));
@@ -222,10 +222,8 @@ TEST_F(BackendMigratorTest, RestartMigration) {
EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
migrator()->MigrateTypes(to_migrate2);
- syncable::ModelTypeSet difference1;
- std::set_difference(preferred_types().begin(), preferred_types().end(),
- to_migrate1.begin(), to_migrate1.end(),
- std::inserter(difference1, difference1.end()));
+ const syncable::ModelEnumSet difference1 =
+ Difference(preferred_types(), to_migrate1);
Mock::VerifyAndClearExpectations(manager());
EXPECT_CALL(*manager(), Configure(_, sync_api::CONFIGURE_REASON_MIGRATION))
@@ -242,23 +240,23 @@ TEST_F(BackendMigratorTest, RestartMigration) {
// Test that an external invocation of Configure(...) during a migration results
// in a migration reattempt.
TEST_F(BackendMigratorTest, InterruptedWhileDisablingTypes) {
- syncable::ModelTypeSet to_migrate;
- syncable::ModelTypeSet difference;
- to_migrate.insert(syncable::PREFERENCES);
- difference.insert(syncable::AUTOFILL);
- difference.insert(syncable::BOOKMARKS);
+ syncable::ModelEnumSet to_migrate;
+ syncable::ModelEnumSet difference;
+ to_migrate.Put(syncable::PREFERENCES);
+ difference.Put(syncable::AUTOFILL);
+ difference.Put(syncable::BOOKMARKS);
EXPECT_CALL(*manager(), state())
.WillOnce(Return(DataTypeManager::CONFIGURED));
- EXPECT_CALL(*manager(), Configure(difference,
+ EXPECT_CALL(*manager(), Configure(HasModelTypes(difference),
sync_api::CONFIGURE_REASON_MIGRATION));
migrator()->MigrateTypes(to_migrate);
EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
Mock::VerifyAndClearExpectations(manager());
- EXPECT_CALL(*manager(), Configure(difference,
+ EXPECT_CALL(*manager(), Configure(HasModelTypes(difference),
sync_api::CONFIGURE_REASON_MIGRATION));
- SetUnsyncedTypes(syncable::ModelTypeSet());
+ SetUnsyncedTypes(syncable::ModelEnumSet());
SendConfigureDone(DataTypeManager::OK, preferred_types());
EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
@@ -268,10 +266,10 @@ TEST_F(BackendMigratorTest, InterruptedWhileDisablingTypes) {
// migrator while it's waiting for disabled types to have been purged
// from the sync db.
TEST_F(BackendMigratorTest, WaitingForPurge) {
- syncable::ModelTypeSet to_migrate, difference;
- to_migrate.insert(syncable::PREFERENCES);
- to_migrate.insert(syncable::AUTOFILL);
- difference.insert(syncable::BOOKMARKS);
+ syncable::ModelEnumSet to_migrate, difference;
+ to_migrate.Put(syncable::PREFERENCES);
+ to_migrate.Put(syncable::AUTOFILL);
+ difference.Put(syncable::BOOKMARKS);
EXPECT_CALL(*manager(), state())
.WillOnce(Return(DataTypeManager::CONFIGURED));
@@ -284,8 +282,8 @@ TEST_F(BackendMigratorTest, WaitingForPurge) {
SendConfigureDone(DataTypeManager::OK, difference);
EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
- syncable::ModelTypeSet prefs;
- prefs.insert(syncable::PREFERENCES);
+ syncable::ModelEnumSet prefs;
+ prefs.Put(syncable::PREFERENCES);
SetUnsyncedTypes(prefs);
SendConfigureDone(DataTypeManager::OK, difference);
EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
@@ -296,8 +294,8 @@ TEST_F(BackendMigratorTest, WaitingForPurge) {
}
TEST_F(BackendMigratorTest, MigratedTypeDisabledByUserDuringMigration) {
- syncable::ModelTypeSet to_migrate;
- to_migrate.insert(syncable::PREFERENCES);
+ syncable::ModelEnumSet to_migrate;
+ to_migrate.Put(syncable::PREFERENCES);
EXPECT_CALL(*manager(), state())
.WillOnce(Return(DataTypeManager::CONFIGURED));
@@ -309,22 +307,22 @@ TEST_F(BackendMigratorTest, MigratedTypeDisabledByUserDuringMigration) {
SetUnsyncedTypes(to_migrate);
SendConfigureDone(DataTypeManager::OK, preferred_types());
EXPECT_EQ(BackendMigrator::REENABLING_TYPES, migrator()->state());
- SetUnsyncedTypes(syncable::ModelTypeSet());
+ SetUnsyncedTypes(syncable::ModelEnumSet());
SendConfigureDone(DataTypeManager::OK, preferred_types());
EXPECT_EQ(BackendMigrator::IDLE, migrator()->state());
}
TEST_F(BackendMigratorTest, ConfigureFailure) {
- syncable::ModelTypeSet to_migrate;
- to_migrate.insert(syncable::PREFERENCES);
+ syncable::ModelEnumSet to_migrate;
+ to_migrate.Put(syncable::PREFERENCES);
EXPECT_CALL(*manager(), state())
.WillOnce(Return(DataTypeManager::CONFIGURED));
EXPECT_CALL(*manager(), Configure(_, sync_api::CONFIGURE_REASON_MIGRATION))
.Times(1);
migrator()->MigrateTypes(to_migrate);
- SetUnsyncedTypes(syncable::ModelTypeSet());
- SendConfigureDone(DataTypeManager::ABORTED, syncable::ModelTypeSet());
+ SetUnsyncedTypes(syncable::ModelEnumSet());
+ SendConfigureDone(DataTypeManager::ABORTED, syncable::ModelEnumSet());
EXPECT_EQ(BackendMigrator::IDLE, migrator()->state());
}
diff --git a/chrome/browser/sync/engine/all_status.cc b/chrome/browser/sync/engine/all_status.cc
index 7a0fabe..e8bb066 100644
--- a/chrome/browser/sync/engine/all_status.cc
+++ b/chrome/browser/sync/engine/all_status.cc
@@ -173,7 +173,7 @@ void AllStatus::IncrementNotificationsReceived() {
++status_.notifications_received;
}
-void AllStatus::SetEncryptedTypes(const syncable::ModelTypeSet& types) {
+void AllStatus::SetEncryptedTypes(syncable::ModelEnumSet types) {
ScopedStatusLock lock(this);
status_.encrypted_types = types;
}
diff --git a/chrome/browser/sync/engine/all_status.h b/chrome/browser/sync/engine/all_status.h
index 5f142cb..0e6238c 100644
--- a/chrome/browser/sync/engine/all_status.h
+++ b/chrome/browser/sync/engine/all_status.h
@@ -44,7 +44,7 @@ class AllStatus : public SyncEngineEventListener {
void IncrementNotificationsReceived();
- void SetEncryptedTypes(const syncable::ModelTypeSet& types);
+ void SetEncryptedTypes(syncable::ModelEnumSet types);
void SetCryptographerReady(bool ready);
void SetCryptoHasPendingKeys(bool has_pending_keys);
diff --git a/chrome/browser/sync/engine/apply_updates_command_unittest.cc b/chrome/browser/sync/engine/apply_updates_command_unittest.cc
index 734f9207..cadc14f 100644
--- a/chrome/browser/sync/engine/apply_updates_command_unittest.cc
+++ b/chrome/browser/sync/engine/apply_updates_command_unittest.cc
@@ -27,7 +27,6 @@ namespace browser_sync {
using sessions::SyncSession;
using std::string;
using syncable::Entry;
-using syncable::GetAllRealModelTypes;
using syncable::Id;
using syncable::MutableEntry;
using syncable::ReadTransaction;
@@ -427,16 +426,16 @@ TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) {
// Storing the cryptographer separately is bad, but for this test we
// know it's safe.
Cryptographer* cryptographer;
- syncable::ModelTypeSet encrypted_types;
- encrypted_types.insert(syncable::PASSWORDS);
- encrypted_types.insert(syncable::NIGORI);
+ syncable::ModelEnumSet encrypted_types;
+ encrypted_types.Put(syncable::PASSWORDS);
+ encrypted_types.Put(syncable::NIGORI);
{
ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
ASSERT_TRUE(dir.good());
ReadTransaction trans(FROM_HERE, dir);
cryptographer =
session()->context()->directory_manager()->GetCryptographer(&trans);
- EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes());
+ EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types));
}
// Nigori node updates should update the Cryptographer.
@@ -449,7 +448,7 @@ TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) {
specifics.MutableExtension(sync_pb::nigori);
other_cryptographer.GetKeys(nigori->mutable_encrypted());
nigori->set_encrypt_bookmarks(true);
- encrypted_types.insert(syncable::BOOKMARKS);
+ encrypted_types.Put(syncable::BOOKMARKS);
CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI),
specifics, true);
EXPECT_FALSE(cryptographer->has_pending_keys());
@@ -470,23 +469,25 @@ TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) {
EXPECT_FALSE(cryptographer->is_ready());
EXPECT_TRUE(cryptographer->has_pending_keys());
- EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes());
+ EXPECT_TRUE(
+ cryptographer->GetEncryptedTypes()
+ .Equals(syncable::ModelEnumSet::All()));
}
TEST_F(ApplyUpdatesCommandTest, NigoriUpdateForDisabledTypes) {
// Storing the cryptographer separately is bad, but for this test we
// know it's safe.
Cryptographer* cryptographer;
- syncable::ModelTypeSet encrypted_types;
- encrypted_types.insert(syncable::PASSWORDS);
- encrypted_types.insert(syncable::NIGORI);
+ syncable::ModelEnumSet encrypted_types;
+ encrypted_types.Put(syncable::PASSWORDS);
+ encrypted_types.Put(syncable::NIGORI);
{
ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
ASSERT_TRUE(dir.good());
ReadTransaction trans(FROM_HERE, dir);
cryptographer =
session()->context()->directory_manager()->GetCryptographer(&trans);
- EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes());
+ EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types));
}
// Nigori node updates should update the Cryptographer.
@@ -500,8 +501,8 @@ TEST_F(ApplyUpdatesCommandTest, NigoriUpdateForDisabledTypes) {
other_cryptographer.GetKeys(nigori->mutable_encrypted());
nigori->set_encrypt_sessions(true);
nigori->set_encrypt_themes(true);
- encrypted_types.insert(syncable::SESSIONS);
- encrypted_types.insert(syncable::THEMES);
+ encrypted_types.Put(syncable::SESSIONS);
+ encrypted_types.Put(syncable::THEMES);
CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI),
specifics, true);
EXPECT_FALSE(cryptographer->has_pending_keys());
@@ -522,23 +523,25 @@ TEST_F(ApplyUpdatesCommandTest, NigoriUpdateForDisabledTypes) {
EXPECT_FALSE(cryptographer->is_ready());
EXPECT_TRUE(cryptographer->has_pending_keys());
- EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes());
+ EXPECT_TRUE(
+ cryptographer->GetEncryptedTypes()
+ .Equals(syncable::ModelEnumSet::All()));
}
TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) {
// Storing the cryptographer separately is bad, but for this test we
// know it's safe.
Cryptographer* cryptographer;
- syncable::ModelTypeSet encrypted_types;
- encrypted_types.insert(syncable::PASSWORDS);
- encrypted_types.insert(syncable::NIGORI);
+ syncable::ModelEnumSet encrypted_types;
+ encrypted_types.Put(syncable::PASSWORDS);
+ encrypted_types.Put(syncable::NIGORI);
{
ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
ASSERT_TRUE(dir.good());
ReadTransaction trans(FROM_HERE, dir);
cryptographer =
session()->context()->directory_manager()->GetCryptographer(&trans);
- EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes());
+ EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types));
// With default encrypted_types, this should be true.
@@ -576,7 +579,7 @@ TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) {
specifics.MutableExtension(sync_pb::nigori);
cryptographer->GetKeys(nigori->mutable_encrypted());
nigori->set_encrypt_bookmarks(true);
- encrypted_types.insert(syncable::BOOKMARKS);
+ encrypted_types.Put(syncable::BOOKMARKS);
CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI),
specifics, true);
EXPECT_FALSE(cryptographer->has_pending_keys());
@@ -618,7 +621,8 @@ TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) {
// If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes
// should be encrypted now.
- EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes());
+ EXPECT_TRUE(syncable::ModelEnumSet::All().Equals(
+ cryptographer->GetEncryptedTypes()));
EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types));
Syncer::UnsyncedMetaHandles handles;
@@ -631,17 +635,16 @@ TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) {
// Storing the cryptographer separately is bad, but for this test we
// know it's safe.
Cryptographer* cryptographer;
- syncable::ModelTypeSet encrypted_types;
- encrypted_types.insert(syncable::PASSWORDS);
- encrypted_types.insert(syncable::NIGORI);
+ syncable::ModelEnumSet encrypted_types;
+ encrypted_types.Put(syncable::PASSWORDS);
+ encrypted_types.Put(syncable::NIGORI);
{
ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
ASSERT_TRUE(dir.good());
ReadTransaction trans(FROM_HERE, dir);
cryptographer =
session()->context()->directory_manager()->GetCryptographer(&trans);
- EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes());
-
+ EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types));
// With default encrypted_types, this should be true.
EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types));
@@ -681,7 +684,7 @@ TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) {
specifics.MutableExtension(sync_pb::nigori);
other_cryptographer.GetKeys(nigori->mutable_encrypted());
nigori->set_encrypt_bookmarks(true);
- encrypted_types.insert(syncable::BOOKMARKS);
+ encrypted_types.Put(syncable::BOOKMARKS);
CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI),
specifics, true);
EXPECT_FALSE(cryptographer->has_pending_keys());
@@ -725,10 +728,12 @@ TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) {
// Since we're in conflict, the specifics don't reflect the unapplied
// changes.
EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types));
- encrypted_types.clear();
- encrypted_types.insert(syncable::PASSWORDS);
- encrypted_types.insert(syncable::BOOKMARKS);
- EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes());
+ encrypted_types.Clear();
+ encrypted_types.Put(syncable::PASSWORDS);
+ encrypted_types.Put(syncable::BOOKMARKS);
+ EXPECT_TRUE(
+ cryptographer->GetEncryptedTypes().Equals(
+ syncable::ModelEnumSet().All()));
Syncer::UnsyncedMetaHandles handles;
SyncerUtil::GetUnsyncedEntries(&trans, &handles);
diff --git a/chrome/browser/sync/engine/get_commit_ids_command.cc b/chrome/browser/sync/engine/get_commit_ids_command.cc
index 4c280ec..aa90ccc 100644
--- a/chrome/browser/sync/engine/get_commit_ids_command.cc
+++ b/chrome/browser/sync/engine/get_commit_ids_command.cc
@@ -44,7 +44,7 @@ void GetCommitIdsCommand::ExecuteImpl(SyncSession* session) {
passphrase_missing_ = cryptographer->has_pending_keys();
};
- const syncable::ModelTypeSet& throttled_types =
+ const syncable::ModelEnumSet throttled_types =
session->context()->GetThrottledTypes();
// We filter out all unready entries from the set of unsynced handles to
// ensure we don't trigger useless sync cycles attempting to retry due to
@@ -74,10 +74,10 @@ namespace {
// and not requiring encryption (any entry containing an encrypted datatype
// while the cryptographer requires a passphrase is not ready for commit.)
// 2. Its type is not currently throttled.
-bool IsEntryReadyForCommit(const syncable::ModelTypeSet& encrypted_types,
+bool IsEntryReadyForCommit(syncable::ModelEnumSet encrypted_types,
bool passphrase_missing,
const syncable::Entry& entry,
- const syncable::ModelTypeSet& throttled_types) {
+ syncable::ModelEnumSet throttled_types) {
if (!entry.Get(syncable::IS_UNSYNCED))
return false;
@@ -93,12 +93,13 @@ bool IsEntryReadyForCommit(const syncable::ModelTypeSet& encrypted_types,
return false;
}
- syncable::ModelType type = entry.GetModelType();
+ const syncable::ModelType type = entry.GetModelType();
// We special case the nigori node because even though it is considered an
// "encrypted type", not all nigori node changes require valid encryption
// (ex: sync_tabs).
- if (type != syncable::NIGORI &&
- encrypted_types.count(type) > 0 &&
+ if (syncable::IsRealDataType(type) &&
+ (type != syncable::NIGORI) &&
+ encrypted_types.Has(type) &&
(passphrase_missing ||
syncable::EntryNeedsEncryption(encrypted_types, entry))) {
// This entry requires encryption but is not properly encrypted (possibly
@@ -111,7 +112,7 @@ bool IsEntryReadyForCommit(const syncable::ModelTypeSet& encrypted_types,
}
// Look at the throttled types.
- if (throttled_types.count(type) > 0)
+ if (syncable::IsRealDataType(type) && throttled_types.Has(type))
return false;
return true;
@@ -121,7 +122,7 @@ bool IsEntryReadyForCommit(const syncable::ModelTypeSet& encrypted_types,
void GetCommitIdsCommand::FilterUnreadyEntries(
syncable::BaseTransaction* trans,
- const syncable::ModelTypeSet& throttled_types,
+ syncable::ModelEnumSet throttled_types,
syncable::Directory::UnsyncedMetaHandles* unsynced_handles) {
syncable::Directory::UnsyncedMetaHandles::iterator iter;
syncable::Directory::UnsyncedMetaHandles new_unsynced_handles;
@@ -144,7 +145,7 @@ void GetCommitIdsCommand::AddUncommittedParentsAndTheirPredecessors(
syncable::BaseTransaction* trans,
syncable::Id parent_id,
const ModelSafeRoutingInfo& routes,
- const syncable::ModelTypeSet& throttled_types) {
+ syncable::ModelEnumSet throttled_types) {
OrderedCommitSet item_dependencies(routes);
// Climb the tree adding entries leaf -> root.
@@ -169,8 +170,8 @@ void GetCommitIdsCommand::AddUncommittedParentsAndTheirPredecessors(
}
bool GetCommitIdsCommand::AddItem(syncable::Entry* item,
- const syncable::ModelTypeSet& throttled_types,
- OrderedCommitSet* result) {
+ syncable::ModelEnumSet throttled_types,
+ OrderedCommitSet* result) {
if (!IsEntryReadyForCommit(encrypted_types_, passphrase_missing_, *item,
throttled_types))
return false;
@@ -186,7 +187,7 @@ bool GetCommitIdsCommand::AddItem(syncable::Entry* item,
bool GetCommitIdsCommand::AddItemThenPredecessors(
syncable::BaseTransaction* trans,
- const syncable::ModelTypeSet& throttled_types,
+ syncable::ModelEnumSet throttled_types,
syncable::Entry* item,
syncable::IndexedBitField inclusion_filter,
OrderedCommitSet* result) {
@@ -210,7 +211,7 @@ bool GetCommitIdsCommand::AddItemThenPredecessors(
void GetCommitIdsCommand::AddPredecessorsThenItem(
syncable::BaseTransaction* trans,
- const syncable::ModelTypeSet& throttled_types,
+ syncable::ModelEnumSet throttled_types,
syncable::Entry* item,
syncable::IndexedBitField inclusion_filter,
const ModelSafeRoutingInfo& routes) {
@@ -230,7 +231,7 @@ void GetCommitIdsCommand::AddCreatesAndMoves(
const vector<int64>& unsynced_handles,
syncable::WriteTransaction* write_transaction,
const ModelSafeRoutingInfo& routes,
- const syncable::ModelTypeSet& throttled_types) {
+ syncable::ModelEnumSet throttled_types) {
// Add moves and creates, and prepend their uncommitted parents.
for (CommitMetahandleIterator iterator(unsynced_handles, write_transaction,
ordered_commit_set_.get());
@@ -341,7 +342,7 @@ void GetCommitIdsCommand::AddDeletes(const vector<int64>& unsynced_handles,
void GetCommitIdsCommand::BuildCommitIds(const vector<int64>& unsynced_handles,
syncable::WriteTransaction* write_transaction,
const ModelSafeRoutingInfo& routes,
- const syncable::ModelTypeSet& throttled_types) {
+ syncable::ModelEnumSet throttled_types) {
ordered_commit_set_.reset(new OrderedCommitSet(routes));
// Commits follow these rules:
// 1. Moves or creates are preceded by needed folder creates, from
diff --git a/chrome/browser/sync/engine/get_commit_ids_command.h b/chrome/browser/sync/engine/get_commit_ids_command.h
index 6422e73..5cd923a 100644
--- a/chrome/browser/sync/engine/get_commit_ids_command.h
+++ b/chrome/browser/sync/engine/get_commit_ids_command.h
@@ -34,7 +34,7 @@ class GetCommitIdsCommand : public SyncerCommand {
void BuildCommitIds(const vector<int64>& unsynced_handles,
syncable::WriteTransaction* write_transaction,
const ModelSafeRoutingInfo& routes,
- const syncable::ModelTypeSet& throttled_types);
+ syncable::ModelEnumSet throttled_types);
// TODO(chron): Remove writes from this iterator. As a warning, this
// iterator causes writes to entries and so isn't a pure iterator.
@@ -117,28 +117,28 @@ class GetCommitIdsCommand : public SyncerCommand {
// 2. Its type is currently throttled.
void FilterUnreadyEntries(
syncable::BaseTransaction* trans,
- const syncable::ModelTypeSet& throttled_types,
+ syncable::ModelEnumSet throttled_types,
syncable::Directory::UnsyncedMetaHandles* unsynced_handles);
void AddUncommittedParentsAndTheirPredecessors(
syncable::BaseTransaction* trans,
syncable::Id parent_id,
const ModelSafeRoutingInfo& routes,
- const syncable::ModelTypeSet& throttled_types);
+ syncable::ModelEnumSet throttled_types);
// OrderedCommitSet helpers for adding predecessors in order.
// TODO(ncarter): Refactor these so that the |result| parameter goes away,
// and AddItem doesn't need to consider two OrderedCommitSets.
bool AddItem(syncable::Entry* item,
- const syncable::ModelTypeSet& throttled_types,
+ syncable::ModelEnumSet throttled_types,
sessions::OrderedCommitSet* result);
bool AddItemThenPredecessors(syncable::BaseTransaction* trans,
- const syncable::ModelTypeSet& throttled_types,
+ syncable::ModelEnumSet throttled_types,
syncable::Entry* item,
syncable::IndexedBitField inclusion_filter,
sessions::OrderedCommitSet* result);
void AddPredecessorsThenItem(syncable::BaseTransaction* trans,
- const syncable::ModelTypeSet& throttled_types,
+ syncable::ModelEnumSet throttled_types,
syncable::Entry* item,
syncable::IndexedBitField inclusion_filter,
const ModelSafeRoutingInfo& routes);
@@ -148,7 +148,7 @@ class GetCommitIdsCommand : public SyncerCommand {
void AddCreatesAndMoves(const vector<int64>& unsynced_handles,
syncable::WriteTransaction* write_transaction,
const ModelSafeRoutingInfo& routes,
- const syncable::ModelTypeSet& throttled_types);
+ syncable::ModelEnumSet throttled_types);
void AddDeletes(const vector<int64>& unsynced_handles,
syncable::WriteTransaction* write_transaction);
@@ -157,7 +157,7 @@ class GetCommitIdsCommand : public SyncerCommand {
int requested_commit_batch_size_;
bool passphrase_missing_;
- syncable::ModelTypeSet encrypted_types_;
+ syncable::ModelEnumSet encrypted_types_;
DISALLOW_COPY_AND_ASSIGN(GetCommitIdsCommand);
};
diff --git a/chrome/browser/sync/engine/nigori_util.cc b/chrome/browser/sync/engine/nigori_util.cc
index 3e0c27c..df9bd4d 100644
--- a/chrome/browser/sync/engine/nigori_util.cc
+++ b/chrome/browser/sync/engine/nigori_util.cc
@@ -19,8 +19,6 @@ bool ProcessUnsyncedChangesForEncryption(
WriteTransaction* const trans,
browser_sync::Cryptographer* cryptographer) {
DCHECK(cryptographer->is_ready());
- syncable::ModelTypeSet encrypted_types = cryptographer->GetEncryptedTypes();
-
// Get list of all datatypes with unsynced changes. It's possible that our
// local changes need to be encrypted if encryption for that datatype was
// just turned on (and vice versa). This should never affect passwords.
@@ -40,7 +38,7 @@ bool ProcessUnsyncedChangesForEncryption(
bool VerifyUnsyncedChangesAreEncrypted(
BaseTransaction* const trans,
- const ModelTypeSet& encrypted_types) {
+ ModelEnumSet encrypted_types) {
std::vector<int64> handles;
browser_sync::SyncerUtil::GetUnsyncedEntries(trans, &handles);
for (size_t i = 0; i < handles.size(); ++i) {
@@ -55,7 +53,7 @@ bool VerifyUnsyncedChangesAreEncrypted(
return true;
}
-bool EntryNeedsEncryption(const ModelTypeSet& encrypted_types,
+bool EntryNeedsEncryption(ModelEnumSet encrypted_types,
const Entry& entry) {
if (!entry.Get(UNIQUE_SERVER_TAG).empty())
return false; // We don't encrypt unique server nodes.
@@ -66,16 +64,18 @@ bool EntryNeedsEncryption(const ModelTypeSet& encrypted_types,
// the data, nor for determining if data is encrypted. We simply ensure it has
// been overwritten to avoid any possible leaks of sensitive data.
return SpecificsNeedsEncryption(encrypted_types, entry.Get(SPECIFICS)) ||
- (encrypted_types.count(type) > 0 &&
+ (encrypted_types.Has(type) &&
entry.Get(NON_UNIQUE_NAME) != kEncryptedString);
}
-bool SpecificsNeedsEncryption(const ModelTypeSet& encrypted_types,
+bool SpecificsNeedsEncryption(ModelEnumSet encrypted_types,
const sync_pb::EntitySpecifics& specifics) {
- ModelType type = GetModelTypeFromSpecifics(specifics);
+ const ModelType type = GetModelTypeFromSpecifics(specifics);
+ if (!syncable::IsRealDataType(type))
+ return false;
if (type == PASSWORDS || type == NIGORI)
return false; // These types have their own encryption schemes.
- if (encrypted_types.count(type) == 0)
+ if (!encrypted_types.Has(type))
return false; // This type does not require encryption
return !specifics.has_encrypted();
}
diff --git a/chrome/browser/sync/engine/nigori_util.h b/chrome/browser/sync/engine/nigori_util.h
index 6f35537..08ed0d4 100644
--- a/chrome/browser/sync/engine/nigori_util.h
+++ b/chrome/browser/sync/engine/nigori_util.h
@@ -36,7 +36,7 @@ class WriteTransaction;
// modify the data and does not care if data is unnecessarily encrypted.
bool VerifyUnsyncedChangesAreEncrypted(
BaseTransaction* const trans,
- const ModelTypeSet& encrypted_types);
+ ModelEnumSet encrypted_types);
// Processes all unsynced changes and ensures they are appropriately encrypted
// or unencrypted, based on |encrypted_types|.
@@ -47,11 +47,11 @@ bool ProcessUnsyncedChangesForEncryption(
// Returns true if the entry requires encryption but is not encrypted, false
// otherwise. Note: this does not check that already encrypted entries are
// encrypted with the proper key.
-bool EntryNeedsEncryption(const ModelTypeSet& encrypted_types,
+bool EntryNeedsEncryption(ModelEnumSet encrypted_types,
const Entry& entry);
// Same as EntryNeedsEncryption, but looks at specifics.
-bool SpecificsNeedsEncryption(const ModelTypeSet& encrypted_types,
+bool SpecificsNeedsEncryption(ModelEnumSet encrypted_types,
const sync_pb::EntitySpecifics& specifics);
// Verifies all data of type |type| is encrypted appropriately.
diff --git a/chrome/browser/sync/engine/nigori_util_unittest.cc b/chrome/browser/sync/engine/nigori_util_unittest.cc
index c984985..6ec2291 100644
--- a/chrome/browser/sync/engine/nigori_util_unittest.cc
+++ b/chrome/browser/sync/engine/nigori_util_unittest.cc
@@ -12,12 +12,12 @@ namespace syncable {
typedef testing::Test NigoriUtilTest;
TEST(NigoriUtilTest, SpecificsNeedsEncryption) {
- ModelTypeSet encrypted_types;
- encrypted_types.insert(BOOKMARKS);
- encrypted_types.insert(PASSWORDS);
+ ModelEnumSet encrypted_types;
+ encrypted_types.Put(BOOKMARKS);
+ encrypted_types.Put(PASSWORDS);
sync_pb::EntitySpecifics specifics;
- EXPECT_FALSE(SpecificsNeedsEncryption(ModelTypeSet(), specifics));
+ EXPECT_FALSE(SpecificsNeedsEncryption(ModelEnumSet(), specifics));
EXPECT_FALSE(SpecificsNeedsEncryption(encrypted_types, specifics));
AddDefaultExtensionValue(PREFERENCES, &specifics);
@@ -30,11 +30,11 @@ TEST(NigoriUtilTest, SpecificsNeedsEncryption) {
bookmark_specifics.MutableExtension(sync_pb::bookmark)->set_title("title");
bookmark_specifics.MutableExtension(sync_pb::bookmark)->set_url("url");
EXPECT_TRUE(SpecificsNeedsEncryption(encrypted_types, bookmark_specifics));
- EXPECT_FALSE(SpecificsNeedsEncryption(ModelTypeSet(), bookmark_specifics));
+ EXPECT_FALSE(SpecificsNeedsEncryption(ModelEnumSet(), bookmark_specifics));
bookmark_specifics.mutable_encrypted();
EXPECT_FALSE(SpecificsNeedsEncryption(encrypted_types, bookmark_specifics));
- EXPECT_FALSE(SpecificsNeedsEncryption(ModelTypeSet(), bookmark_specifics));
+ EXPECT_FALSE(SpecificsNeedsEncryption(ModelEnumSet(), bookmark_specifics));
sync_pb::EntitySpecifics password_specifics;
AddDefaultExtensionValue(PASSWORDS, &password_specifics);
diff --git a/chrome/browser/sync/engine/syncer_proto_util.cc b/chrome/browser/sync/engine/syncer_proto_util.cc
index ca782f3..5c7f757 100644
--- a/chrome/browser/sync/engine/syncer_proto_util.cc
+++ b/chrome/browser/sync/engine/syncer_proto_util.cc
@@ -194,11 +194,11 @@ void SyncerProtoUtil::HandleThrottleError(
sessions::SyncSessionContext* context,
sessions::SyncSession::Delegate* delegate) {
DCHECK_EQ(error.error_type, browser_sync::THROTTLED);
- if (error.error_data_types.size() > 0) {
- context->SetUnthrottleTime(error.error_data_types, throttled_until);
- } else {
+ if (error.error_data_types.Empty()) {
// No datatypes indicates the client should be completely throttled.
delegate->OnSilencedUntil(throttled_until);
+ } else {
+ context->SetUnthrottleTime(error.error_data_types, throttled_until);
}
}
@@ -278,7 +278,7 @@ browser_sync::SyncProtocolError ConvertErrorPBToLocalType(
// THROTTLED is currently the only error code that uses |error_data_types|.
DCHECK_EQ(error.error_type(), ClientToServerResponse::THROTTLED);
for (int i = 0; i < error.error_data_type_ids_size(); ++i) {
- sync_protocol_error.error_data_types.insert(
+ sync_protocol_error.error_data_types.Put(
syncable::GetModelTypeFromExtensionFieldNumber(
error.error_data_type_ids(i)));
}
diff --git a/chrome/browser/sync/engine/syncer_proto_util_unittest.cc b/chrome/browser/sync/engine/syncer_proto_util_unittest.cc
index c05b192..1fd0f67 100644
--- a/chrome/browser/sync/engine/syncer_proto_util_unittest.cc
+++ b/chrome/browser/sync/engine/syncer_proto_util_unittest.cc
@@ -18,6 +18,7 @@
#include "chrome/browser/sync/protocol/sync.pb.h"
#include "chrome/browser/sync/syncable/blob.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
+#include "chrome/browser/sync/syncable/model_type_test_util.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/sync/test/engine/mock_connection_manager.h"
#include "chrome/browser/sync/test/engine/test_directory_setter_upper.h"
@@ -26,7 +27,6 @@
using syncable::Blob;
using syncable::ScopedDirLookup;
-using syncable::ModelTypeSet;
using ::testing::_;
namespace browser_sync {
@@ -36,7 +36,7 @@ class MockSyncSessionContext : public SyncSessionContext {
public:
MockSyncSessionContext() {}
~MockSyncSessionContext() {}
- MOCK_METHOD2(SetUnthrottleTime, void(const ModelTypeSet&,
+ MOCK_METHOD2(SetUnthrottleTime, void(syncable::ModelEnumSet,
const base::TimeTicks&));
};
@@ -275,14 +275,14 @@ TEST_F(SyncerProtoUtilTest, HandleThrottlingWithDatatypes) {
MockSyncSessionContext context;
SyncProtocolError error;
error.error_type = browser_sync::THROTTLED;
- syncable::ModelTypeSet types;
- types.insert(syncable::BOOKMARKS);
- types.insert(syncable::PASSWORDS);
+ syncable::ModelEnumSet types;
+ types.Put(syncable::BOOKMARKS);
+ types.Put(syncable::PASSWORDS);
error.error_data_types = types;
base::TimeTicks ticks = base::TimeTicks::Now();
- EXPECT_CALL(context, SetUnthrottleTime(types, ticks));
+ EXPECT_CALL(context, SetUnthrottleTime(HasModelTypes(types), ticks));
SyncerProtoUtil::HandleThrottleError(error, ticks, &context, NULL);
}
diff --git a/chrome/browser/sync/engine/syncer_unittest.cc b/chrome/browser/sync/engine/syncer_unittest.cc
index d511beb..eabe323 100644
--- a/chrome/browser/sync/engine/syncer_unittest.cc
+++ b/chrome/browser/sync/engine/syncer_unittest.cc
@@ -370,7 +370,7 @@ class SyncerTest : public testing::Test,
GetCommitIdsCommand command(limit);
command.BuildCommitIds(
session_->status_controller().unsynced_handles(),
- session_->write_transaction(), routes, syncable::ModelTypeSet());
+ session_->write_transaction(), routes, syncable::ModelEnumSet());
vector<syncable::Id> output =
command.ordered_commit_set_->GetAllCommitIds();
size_t truncated_size = std::min(limit, expected_id_order.size());
@@ -558,8 +558,7 @@ TEST_F(SyncerTest, GetCommitIdsCommandTruncates) {
TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) {
ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
ASSERT_TRUE(dir.good());
- syncable::ModelTypeSet throttled_types;
- throttled_types.insert(syncable::BOOKMARKS);
+ const syncable::ModelEnumSet throttled_types(syncable::BOOKMARKS);
KeyParams key_params = {"localhost", "dummy", "foobar"};
sync_pb::EntitySpecifics bookmark_data;
AddDefaultExtensionValue(syncable::BOOKMARKS, &bookmark_data);
diff --git a/chrome/browser/sync/engine/syncer_util.cc b/chrome/browser/sync/engine/syncer_util.cc
index 9ffe6dd..77551d9 100644
--- a/chrome/browser/sync/engine/syncer_util.cc
+++ b/chrome/browser/sync/engine/syncer_util.cc
@@ -299,7 +299,7 @@ UpdateAttemptResponse SyncerUtil::AttemptToUpdateEntry(
cryptographer->Update(nigori);
// Make sure any unsynced changes are properly encrypted as necessary.
- syncable::ModelTypeSet encrypted_types =
+ const syncable::ModelEnumSet encrypted_types =
cryptographer->GetEncryptedTypes();
if (!VerifyUnsyncedChangesAreEncrypted(trans, encrypted_types) &&
(!cryptographer->is_ready() ||
diff --git a/chrome/browser/sync/failed_datatypes_handler.cc b/chrome/browser/sync/failed_datatypes_handler.cc
index d1feb34..2bd5864 100644
--- a/chrome/browser/sync/failed_datatypes_handler.cc
+++ b/chrome/browser/sync/failed_datatypes_handler.cc
@@ -15,23 +15,23 @@ FailedDatatypesHandler::FailedDatatypesHandler(ProfileSyncService* service)
FailedDatatypesHandler::~FailedDatatypesHandler() {
}
-syncable::ModelTypeSet FailedDatatypesHandler::GetFailedTypes() const {
- syncable::ModelTypeSet result;
+syncable::ModelEnumSet FailedDatatypesHandler::GetFailedTypes() const {
+ syncable::ModelEnumSet result;
for (std::list<SyncError>::const_iterator it = errors_.begin();
it != errors_.end(); ++it) {
- DCHECK(result.count(it->type()) == 0);
- result.insert(it->type());
+ DCHECK(!result.Has(it->type()));
+ result.Put(it->type());
}
return result;
}
bool FailedDatatypesHandler::UpdateFailedDatatypes(
DataTypeManager::ConfigureResult result) {
- syncable::ModelTypeSet types = GetFailedTypes();
+ const syncable::ModelEnumSet types = GetFailedTypes();
bool any_new_failed_types = false;
for (std::list<SyncError>::iterator it = result.errors.begin();
it != result.errors.end(); ++it) {
- DCHECK(types.count(it->type()) == 0);
+ DCHECK(!types.Has(it->type()));
any_new_failed_types = true;
errors_.push_back(*it);
}
diff --git a/chrome/browser/sync/failed_datatypes_handler.h b/chrome/browser/sync/failed_datatypes_handler.h
index 5b5ca7a..b03713c 100644
--- a/chrome/browser/sync/failed_datatypes_handler.h
+++ b/chrome/browser/sync/failed_datatypes_handler.h
@@ -28,7 +28,7 @@ class FailedDatatypesHandler {
void OnUserChoseDatatypes();
// Returns the types that are failing.
- syncable::ModelTypeSet GetFailedTypes() const;
+ syncable::ModelEnumSet GetFailedTypes() const;
// Returns if there are any failed types.
bool AnyFailedDatatype() const;
diff --git a/chrome/browser/sync/glue/bookmark_model_associator.cc b/chrome/browser/sync/glue/bookmark_model_associator.cc
index 8d3066a..03eb2a1 100644
--- a/chrome/browser/sync/glue/bookmark_model_associator.cc
+++ b/chrome/browser/sync/glue/bookmark_model_associator.cc
@@ -616,9 +616,9 @@ bool BookmarkModelAssociator::LoadAssociations() {
bool BookmarkModelAssociator::CryptoReadyIfNecessary() {
// We only access the cryptographer while holding a transaction.
sync_api::ReadTransaction trans(FROM_HERE, user_share_);
- const syncable::ModelTypeSet& encrypted_types =
+ const syncable::ModelEnumSet encrypted_types =
sync_api::GetEncryptedTypes(&trans);
- return encrypted_types.count(syncable::BOOKMARKS) == 0 ||
+ return !encrypted_types.Has(syncable::BOOKMARKS) ||
trans.GetCryptographer()->is_ready();
}
diff --git a/chrome/browser/sync/glue/data_type_manager.h b/chrome/browser/sync/glue/data_type_manager.h
index 2b51a0e..eb02f11 100644
--- a/chrome/browser/sync/glue/data_type_manager.h
+++ b/chrome/browser/sync/glue/data_type_manager.h
@@ -48,7 +48,7 @@ class DataTypeManager {
UNRECOVERABLE_ERROR // We got an unrecoverable error during startup.
};
- typedef std::set<syncable::ModelType> TypeSet;
+ typedef syncable::ModelEnumSet TypeSet;
// Note: |errors| is only filled when status is not OK.
struct ConfigureResult {
@@ -81,10 +81,10 @@ class DataTypeManager {
// Note that you may call Configure() while configuration is in
// progress. Configuration will be complete only when the
// desired_types supplied in the last call to Configure is achieved.
- virtual void Configure(const TypeSet& desired_types,
+ virtual void Configure(TypeSet desired_types,
sync_api::ConfigureReason reason) = 0;
- virtual void ConfigureWithoutNigori(const TypeSet& desired_types,
+ virtual void ConfigureWithoutNigori(TypeSet desired_types,
sync_api::ConfigureReason reason) = 0;
// Synchronously stops all registered data types. If called after
diff --git a/chrome/browser/sync/glue/data_type_manager_impl.cc b/chrome/browser/sync/glue/data_type_manager_impl.cc
index 1c2d533..5d5fd50 100644
--- a/chrome/browser/sync/glue/data_type_manager_impl.cc
+++ b/chrome/browser/sync/glue/data_type_manager_impl.cc
@@ -98,9 +98,10 @@ bool DataTypeManagerImpl::GetControllersNeedingStart(
// Add any data type controllers into the needs_start_ list that are
// currently NOT_RUNNING or STOPPING.
bool found_any = false;
- for (TypeSet::const_iterator it = last_requested_types_.begin();
- it != last_requested_types_.end(); ++it) {
- DataTypeController::TypeMap::const_iterator dtc = controllers_->find(*it);
+ for (TypeSet::Iterator it = last_requested_types_.First();
+ it.Good(); it.Inc()) {
+ DataTypeController::TypeMap::const_iterator dtc =
+ controllers_->find(it.Get());
if (dtc != controllers_->end() &&
(dtc->second->state() == DataTypeController::NOT_RUNNING ||
dtc->second->state() == DataTypeController::STOPPING)) {
@@ -116,17 +117,17 @@ bool DataTypeManagerImpl::GetControllersNeedingStart(
return found_any;
}
-void DataTypeManagerImpl::Configure(const TypeSet& desired_types,
+void DataTypeManagerImpl::Configure(TypeSet desired_types,
sync_api::ConfigureReason reason) {
ConfigureImpl(desired_types, reason, true);
}
-void DataTypeManagerImpl::ConfigureWithoutNigori(const TypeSet& desired_types,
+void DataTypeManagerImpl::ConfigureWithoutNigori(TypeSet desired_types,
sync_api::ConfigureReason reason) {
ConfigureImpl(desired_types, reason, false);
}
-void DataTypeManagerImpl::ConfigureImpl(const TypeSet& desired_types,
+void DataTypeManagerImpl::ConfigureImpl(TypeSet desired_types,
sync_api::ConfigureReason reason,
bool enable_nigori) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -137,7 +138,7 @@ void DataTypeManagerImpl::ConfigureImpl(const TypeSet& desired_types,
}
if (state_ == CONFIGURED &&
- last_requested_types_ == desired_types &&
+ last_requested_types_.Equals(desired_types) &&
reason == sync_api::CONFIGURE_REASON_RECONFIGURATION) {
// If we're already configured and the types haven't changed, we can exit
// out early.
@@ -171,7 +172,7 @@ void DataTypeManagerImpl::ConfigureImpl(const TypeSet& desired_types,
for (DataTypeController::TypeMap::const_iterator it = controllers_->begin();
it != controllers_->end(); ++it) {
DataTypeController* dtc = (*it).second;
- if (desired_types.count(dtc->type()) == 0 && (
+ if (!desired_types.Has(dtc->type()) && (
dtc->state() == DataTypeController::MODEL_STARTING ||
dtc->state() == DataTypeController::ASSOCIATING ||
dtc->state() == DataTypeController::RUNNING ||
@@ -216,22 +217,17 @@ void DataTypeManagerImpl::Restart(sync_api::ConfigureReason reason,
// The task will be invoked when updates are downloaded.
state_ = DOWNLOAD_PENDING;
// Hopefully http://crbug.com/79970 will make this less verbose.
- syncable::ModelTypeSet all_types;
- const syncable::ModelTypeSet& types_to_add = last_requested_types_;
- syncable::ModelTypeSet types_to_remove;
+ syncable::ModelEnumSet all_types;
for (DataTypeController::TypeMap::const_iterator it =
controllers_->begin(); it != controllers_->end(); ++it) {
- all_types.insert(it->first);
+ all_types.Put(it->first);
}
+ const syncable::ModelEnumSet types_to_add = last_requested_types_;
// Check that types_to_add \subseteq all_types.
- DCHECK(std::includes(all_types.begin(), all_types.end(),
- types_to_add.begin(), types_to_add.end()));
+ DCHECK(all_types.HasAll(types_to_add));
// Set types_to_remove to all_types \setminus types_to_add.
- ignore_result(
- std::set_difference(
- all_types.begin(), all_types.end(),
- types_to_add.begin(), types_to_add.end(),
- std::inserter(types_to_remove, types_to_remove.end())));
+ const syncable::ModelEnumSet types_to_remove =
+ Difference(all_types, types_to_add);
backend_->ConfigureDataTypes(
types_to_add,
types_to_remove,
diff --git a/chrome/browser/sync/glue/data_type_manager_impl.h b/chrome/browser/sync/glue/data_type_manager_impl.h
index 093f302..a3c9f86 100644
--- a/chrome/browser/sync/glue/data_type_manager_impl.h
+++ b/chrome/browser/sync/glue/data_type_manager_impl.h
@@ -30,12 +30,12 @@ class DataTypeManagerImpl : public DataTypeManager {
virtual ~DataTypeManagerImpl();
// DataTypeManager interface.
- virtual void Configure(const TypeSet& desired_types,
+ virtual void Configure(TypeSet desired_types,
sync_api::ConfigureReason reason) OVERRIDE;
// Needed only for backend migration.
virtual void ConfigureWithoutNigori(
- const TypeSet& desired_types,
+ TypeSet desired_types,
sync_api::ConfigureReason reason) OVERRIDE;
virtual void Stop() OVERRIDE;
@@ -75,7 +75,7 @@ class DataTypeManagerImpl : public DataTypeManager {
// Restart().
void AddToConfigureTime();
- virtual void ConfigureImpl(const TypeSet& desired_types,
+ virtual void ConfigureImpl(TypeSet desired_types,
sync_api::ConfigureReason reason,
bool enable_nigori);
diff --git a/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc b/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc
index 937a259..0e7b265 100644
--- a/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc
+++ b/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc
@@ -55,8 +55,8 @@ DataTypeManager::ConfigureStatus GetStatus(
}
void DoConfigureDataTypes(
- const syncable::ModelTypeSet& types_to_add,
- const syncable::ModelTypeSet& types_to_remove,
+ syncable::ModelEnumSet types_to_add,
+ syncable::ModelEnumSet types_to_remove,
sync_api::ConfigureReason reason,
base::Callback<void(syncable::ModelEnumSet)> ready_task,
bool enable_nigori) {
@@ -180,7 +180,7 @@ class DataTypeManagerImplTest : public testing::Test {
EXPECT_CALL(backend_,
ConfigureDataTypes(_, _, _, _, enable_nigori)).Times(1);
DataTypeManagerImpl dtm(&backend_, &controllers_);
- types_.insert(syncable::BOOKMARKS);
+ types_.Put(syncable::BOOKMARKS);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
Configure(&dtm, types_, sync_api::CONFIGURE_REASON_RECONFIGURATION,
@@ -218,7 +218,7 @@ class DataTypeManagerImplTest : public testing::Test {
.WillOnce(DoAll(Invoke(DoConfigureDataTypes),
InvokeWithoutArgs(QuitMessageLoop)));
- types_.insert(syncable::BOOKMARKS);
+ types_.Put(syncable::BOOKMARKS);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
@@ -227,7 +227,7 @@ class DataTypeManagerImplTest : public testing::Test {
// At this point, the bookmarks dtc should be in flight. Add
// preferences and continue starting bookmarks.
- types_.insert(syncable::PREFERENCES);
+ types_.Put(syncable::PREFERENCES);
Configure(&dtm, types_, sync_api::CONFIGURE_REASON_RECONFIGURATION,
enable_nigori);
callback->Run(DataTypeController::OK, SyncError());
@@ -262,14 +262,14 @@ class DataTypeManagerImplTest : public testing::Test {
WillOnce(SaveArg<3>(&task)).
WillOnce(DoDefault());
- types_.insert(syncable::BOOKMARKS);
+ types_.Put(syncable::BOOKMARKS);
Configure(&dtm, types_, sync_api::CONFIGURE_REASON_RECONFIGURATION,
enable_nigori);
// Configure should stop in the DOWNLOAD_PENDING state because we
// are waiting for the download ready task to be run.
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm.state());
- types_.insert(syncable::PREFERENCES);
+ types_.Put(syncable::PREFERENCES);
Configure(&dtm, types_, sync_api::CONFIGURE_REASON_RECONFIGURATION,
enable_nigori);
@@ -289,7 +289,7 @@ class DataTypeManagerImplTest : public testing::Test {
NiceMock<SyncBackendHostMock> backend_;
content::NotificationObserverMock observer_;
content::NotificationRegistrar registrar_;
- std::set<syncable::ModelType> types_;
+ syncable::ModelEnumSet types_;
};
TEST_F(DataTypeManagerImplTest, NoControllers) {
@@ -317,7 +317,7 @@ TEST_F(DataTypeManagerImplTest, ConfigureOneStopWhileStarting) {
controllers_[syncable::BOOKMARKS] = bookmark_dtc;
EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _, _, true)).Times(1);
DataTypeManagerImpl dtm(&backend_, &controllers_);
- types_.insert(syncable::BOOKMARKS);
+ types_.Put(syncable::BOOKMARKS);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
dtm.Configure(types_, sync_api::CONFIGURE_REASON_RECONFIGURATION);
@@ -332,7 +332,7 @@ TEST_F(DataTypeManagerImplTest, ConfigureOneStopWhileAssociating) {
controllers_[syncable::BOOKMARKS] = bookmark_dtc;
EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _, _, true)).Times(1);
DataTypeManagerImpl dtm(&backend_, &controllers_);
- types_.insert(syncable::BOOKMARKS);
+ types_.Put(syncable::BOOKMARKS);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
dtm.Configure(types_, sync_api::CONFIGURE_REASON_RECONFIGURATION);
@@ -353,7 +353,7 @@ TEST_F(DataTypeManagerImplTest, OneWaitingForCrypto) {
EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _, _, true)).Times(1);
DataTypeManagerImpl dtm(&backend_, &controllers_);
- types_.insert(syncable::PASSWORDS);
+ types_.Put(syncable::PASSWORDS);
SetConfigureStartExpectation();
dtm.Configure(types_, sync_api::CONFIGURE_REASON_RECONFIGURATION);
@@ -390,14 +390,14 @@ TEST_F(DataTypeManagerImplTest, ConfigureOneThenAnother) {
EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _, _, true)).Times(2);
DataTypeManagerImpl dtm(&backend_, &controllers_);
- types_.insert(syncable::BOOKMARKS);
+ types_.Put(syncable::BOOKMARKS);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
dtm.Configure(types_, sync_api::CONFIGURE_REASON_RECONFIGURATION);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
- types_.insert(syncable::PREFERENCES);
+ types_.Put(syncable::PREFERENCES);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
dtm.Configure(types_, sync_api::CONFIGURE_REASON_RECONFIGURATION);
@@ -417,15 +417,15 @@ TEST_F(DataTypeManagerImplTest, ConfigureOneThenSwitch) {
EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _, _, true)).Times(2);
DataTypeManagerImpl dtm(&backend_, &controllers_);
- types_.insert(syncable::BOOKMARKS);
+ types_.Put(syncable::BOOKMARKS);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
dtm.Configure(types_, sync_api::CONFIGURE_REASON_RECONFIGURATION);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
- types_.clear();
- types_.insert(syncable::PREFERENCES);
+ types_.Clear();
+ types_.Put(syncable::PREFERENCES);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
dtm.Configure(types_, sync_api::CONFIGURE_REASON_RECONFIGURATION);
@@ -458,7 +458,7 @@ TEST_F(DataTypeManagerImplTest, OneFailingController) {
SetConfigureDoneExpectation(DataTypeManager::UNRECOVERABLE_ERROR);
EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _, _, true)).Times(1);
- types_.insert(syncable::BOOKMARKS);
+ types_.Put(syncable::BOOKMARKS);
dtm.Configure(types_, sync_api::CONFIGURE_REASON_RECONFIGURATION);
EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
}
@@ -482,8 +482,8 @@ TEST_F(DataTypeManagerImplTest, StopWhileInFlight) {
SetConfigureDoneExpectation(DataTypeManager::ABORTED);
EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _, _, true)).Times(1);
- types_.insert(syncable::BOOKMARKS);
- types_.insert(syncable::PREFERENCES);
+ types_.Put(syncable::BOOKMARKS);
+ types_.Put(syncable::PREFERENCES);
dtm.Configure(types_, sync_api::CONFIGURE_REASON_RECONFIGURATION);
// Configure should stop in the CONFIGURING state because we are
// waiting for the preferences callback to be invoked.
@@ -516,8 +516,8 @@ TEST_F(DataTypeManagerImplTest, SecondControllerFails) {
SetConfigureDoneExpectation(DataTypeManager::UNRECOVERABLE_ERROR);
EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _, _, true)).Times(1);
- types_.insert(syncable::BOOKMARKS);
- types_.insert(syncable::PREFERENCES);
+ types_.Put(syncable::BOOKMARKS);
+ types_.Put(syncable::PREFERENCES);
dtm.Configure(types_, sync_api::CONFIGURE_REASON_RECONFIGURATION);
EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
}
@@ -552,8 +552,8 @@ TEST_F(DataTypeManagerImplTest, OneControllerFailsAssociation) {
SetConfigureDoneExpectation(DataTypeManager::PARTIAL_SUCCESS);
EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _, _, true)).Times(1);
- types_.insert(syncable::BOOKMARKS);
- types_.insert(syncable::PREFERENCES);
+ types_.Put(syncable::BOOKMARKS);
+ types_.Put(syncable::PREFERENCES);
dtm.Configure(types_, sync_api::CONFIGURE_REASON_RECONFIGURATION);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
@@ -603,7 +603,7 @@ TEST_F(DataTypeManagerImplTest, StopWhileDownloadPending) {
EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _, _, true)).
WillOnce(SaveArg<3>(&task));
- types_.insert(syncable::BOOKMARKS);
+ types_.Put(syncable::BOOKMARKS);
dtm.Configure(types_, sync_api::CONFIGURE_REASON_RECONFIGURATION);
// Configure should stop in the DOWNLOAD_PENDING state because we
// are waiting for the download ready task to be run.
diff --git a/chrome/browser/sync/glue/data_type_manager_mock.cc b/chrome/browser/sync/glue/data_type_manager_mock.cc
index be50dbb..ebc70ed 100644
--- a/chrome/browser/sync/glue/data_type_manager_mock.cc
+++ b/chrome/browser/sync/glue/data_type_manager_mock.cc
@@ -9,7 +9,7 @@
namespace browser_sync {
DataTypeManagerMock::DataTypeManagerMock()
- : result_(OK, syncable::ModelTypeSet()) {
+ : result_(OK, syncable::ModelEnumSet()) {
// By default, calling Configure will send a SYNC_CONFIGURE_START
// and SYNC_CONFIGURE_DONE notification with a DataTypeManager::OK
diff --git a/chrome/browser/sync/glue/data_type_manager_mock.h b/chrome/browser/sync/glue/data_type_manager_mock.h
index b7f3ca8..71d5096 100644
--- a/chrome/browser/sync/glue/data_type_manager_mock.h
+++ b/chrome/browser/sync/glue/data_type_manager_mock.h
@@ -55,9 +55,9 @@ class DataTypeManagerMock : public DataTypeManager {
DataTypeManagerMock();
virtual ~DataTypeManagerMock();
- MOCK_METHOD2(Configure, void(const TypeSet&, sync_api::ConfigureReason));
+ MOCK_METHOD2(Configure, void(TypeSet, sync_api::ConfigureReason));
MOCK_METHOD2(ConfigureWithoutNigori,
- void(const TypeSet&, sync_api::ConfigureReason));
+ void(TypeSet, sync_api::ConfigureReason));
MOCK_METHOD0(Stop, void());
MOCK_METHOD0(controllers, const DataTypeController::TypeMap&());
MOCK_METHOD0(state, State());
diff --git a/chrome/browser/sync/glue/generic_change_processor.cc b/chrome/browser/sync/glue/generic_change_processor.cc
index b49ac1c..d9fa42a 100644
--- a/chrome/browser/sync/glue/generic_change_processor.cc
+++ b/chrome/browser/sync/glue/generic_change_processor.cc
@@ -252,9 +252,8 @@ bool GenericChangeProcessor::CryptoReadyIfNecessary(syncable::ModelType type) {
DCHECK_NE(type, syncable::UNSPECIFIED);
// We only access the cryptographer while holding a transaction.
sync_api::ReadTransaction trans(FROM_HERE, share_handle());
- const syncable::ModelTypeSet& encrypted_types =
- GetEncryptedTypes(&trans);
- return encrypted_types.count(type) == 0 ||
+ const syncable::ModelEnumSet encrypted_types = GetEncryptedTypes(&trans);
+ return !encrypted_types.Has(type) ||
trans.GetCryptographer()->is_ready();
}
diff --git a/chrome/browser/sync/glue/session_model_associator.cc b/chrome/browser/sync/glue/session_model_associator.cc
index 44c0727..8d6f54e 100644
--- a/chrome/browser/sync/glue/session_model_associator.cc
+++ b/chrome/browser/sync/glue/session_model_associator.cc
@@ -1247,9 +1247,9 @@ void SessionModelAssociator::PopulateSessionSpecificsTab(
bool SessionModelAssociator::CryptoReadyIfNecessary() {
// We only access the cryptographer while holding a transaction.
sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
- syncable::ModelTypeSet encrypted_types;
- encrypted_types = sync_api::GetEncryptedTypes(&trans);
- return encrypted_types.count(SESSIONS) == 0 ||
+ const syncable::ModelEnumSet encrypted_types =
+ sync_api::GetEncryptedTypes(&trans);
+ return !encrypted_types.Has(SESSIONS) ||
sync_service_->IsCryptographerReady(&trans);
}
diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc
index d2f86d0..255f3e3 100644
--- a/chrome/browser/sync/glue/sync_backend_host.cc
+++ b/chrome/browser/sync/glue/sync_backend_host.cc
@@ -102,7 +102,7 @@ void SyncBackendHost::Initialize(
SyncFrontend* frontend,
const WeakHandle<JsEventHandler>& event_handler,
const GURL& sync_service_url,
- const syncable::ModelTypeSet& initial_types,
+ syncable::ModelEnumSet initial_types,
const SyncCredentials& credentials,
bool delete_sync_data_folder) {
if (!sync_thread_.Start())
@@ -111,10 +111,10 @@ void SyncBackendHost::Initialize(
frontend_ = frontend;
DCHECK(frontend);
- syncable::ModelTypeSet initial_types_with_nigori(initial_types);
+ syncable::ModelEnumSet initial_types_with_nigori(initial_types);
CHECK(sync_prefs_.get());
if (sync_prefs_->HasSyncSetupCompleted()) {
- initial_types_with_nigori.insert(syncable::NIGORI);
+ initial_types_with_nigori.Put(syncable::NIGORI);
}
registrar_.reset(new SyncBackendRegistrar(initial_types_with_nigori,
@@ -247,19 +247,19 @@ void SyncBackendHost::Shutdown(bool sync_disabled) {
}
void SyncBackendHost::ConfigureDataTypes(
- const syncable::ModelTypeSet& types_to_add,
- const syncable::ModelTypeSet& types_to_remove,
+ syncable::ModelEnumSet types_to_add,
+ syncable::ModelEnumSet types_to_remove,
sync_api::ConfigureReason reason,
base::Callback<void(syncable::ModelEnumSet)> ready_task,
bool enable_nigori) {
- syncable::ModelTypeSet types_to_add_with_nigori = types_to_add;
- syncable::ModelTypeSet types_to_remove_with_nigori = types_to_remove;
+ syncable::ModelEnumSet types_to_add_with_nigori = types_to_add;
+ syncable::ModelEnumSet types_to_remove_with_nigori = types_to_remove;
if (enable_nigori) {
- types_to_add_with_nigori.insert(syncable::NIGORI);
- types_to_remove_with_nigori.erase(syncable::NIGORI);
+ types_to_add_with_nigori.Put(syncable::NIGORI);
+ types_to_remove_with_nigori.Remove(syncable::NIGORI);
} else {
- types_to_add_with_nigori.erase(syncable::NIGORI);
- types_to_remove_with_nigori.insert(syncable::NIGORI);
+ types_to_add_with_nigori.Remove(syncable::NIGORI);
+ types_to_remove_with_nigori.Put(syncable::NIGORI);
}
// Only one configure is allowed at a time.
DCHECK(!pending_config_mode_state_.get());
@@ -277,7 +277,7 @@ void SyncBackendHost::ConfigureDataTypes(
// Cleanup disabled types before starting configuration so that
// callers can assume that the data types are cleaned up once
// configuration is done.
- if (!types_to_remove_with_nigori.empty()) {
+ if (!types_to_remove_with_nigori.Empty()) {
sync_thread_.message_loop()->PostTask(
FROM_HERE,
base::Bind(&SyncBackendHost::Core::DoRequestCleanupDisabledTypes,
@@ -482,7 +482,7 @@ void SyncBackendHost::Core::OnClearServerDataSucceeded() {
}
void SyncBackendHost::Core::OnEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) {
if (!sync_loop_)
return;
@@ -794,7 +794,7 @@ void SyncBackendHost::Core::NotifyUpdatedToken(const std::string& token) {
}
void SyncBackendHost::Core::NotifyEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) {
if (!host_)
return;
@@ -823,8 +823,7 @@ void SyncBackendHost::Core::HandleSyncCycleCompletedOnFrontendLoop(
const syncable::ModelEnumSet to_migrate =
snapshot->syncer_status.types_needing_local_migration;
if (!to_migrate.Empty())
- host_->frontend_->OnMigrationNeededForTypes(
- syncable::ModelEnumSetToSet(to_migrate));
+ host_->frontend_->OnMigrationNeededForTypes(to_migrate);
// Process any changes to the datatypes we're syncing.
// TODO(sync): add support for removing types.
@@ -837,10 +836,8 @@ void SyncBackendHost::Core::HandleSyncCycleCompletedOnFrontendLoop(
if (host_->pending_download_state_.get()) {
scoped_ptr<PendingConfigureDataTypesState> state(
host_->pending_download_state_.release());
- const syncable::ModelEnumSet types_to_add =
- syncable::ModelTypeSetToEnumSet(state->types_to_add);
- const syncable::ModelEnumSet added_types =
- syncable::ModelTypeSetToEnumSet(state->added_types);
+ const syncable::ModelEnumSet types_to_add = state->types_to_add;
+ const syncable::ModelEnumSet added_types = state->added_types;
DCHECK(types_to_add.HasAll(added_types));
const syncable::ModelEnumSet initial_sync_ended =
snapshot->initial_sync_ended;
@@ -886,7 +883,7 @@ void SyncBackendHost::Core::FinishConfigureDataTypesOnFrontendLoop() {
void SyncBackendHost::AddExperimentalTypes() {
CHECK(initialized());
- syncable::ModelTypeSet to_add;
+ syncable::ModelEnumSet to_add;
if (core_->sync_manager()->ReceivedExperimentalTypes(&to_add))
frontend_->OnDataTypesChanged(to_add);
}
@@ -922,8 +919,8 @@ void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop(
case NOT_INITIALIZED:
initialization_state_ = DOWNLOADING_NIGORI;
ConfigureDataTypes(
- syncable::ModelTypeSet(),
- syncable::ModelTypeSet(),
+ syncable::ModelEnumSet(),
+ syncable::ModelEnumSet(),
sync_api::CONFIGURE_REASON_NEW_CLIENT,
// Calls back into this function.
base::Bind(
@@ -977,15 +974,15 @@ void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop() {
SVLOG(1) << "Syncer in config mode. SBH executing "
<< "FinishConfigureDataTypesOnFrontendLoop";
- if (pending_config_mode_state_->added_types.empty() &&
+ if (pending_config_mode_state_->added_types.Empty() &&
!core_->sync_manager()->InitialSyncEndedForAllEnabledTypes()) {
- syncable::ModelTypeSet enabled_types;
+ syncable::ModelEnumSet enabled_types;
ModelSafeRoutingInfo routing_info;
registrar_->GetModelSafeRoutingInfo(&routing_info);
for (ModelSafeRoutingInfo::const_iterator i = routing_info.begin();
i != routing_info.end(); ++i) {
- enabled_types.insert(i->first);
+ enabled_types.Put(i->first);
}
// TODO(tim): Log / UMA / count this somehow?
@@ -1002,7 +999,7 @@ void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop() {
// If we've added types, we always want to request a nudge/config (even if
// the initial sync is ended), in case we could not decrypt the data.
- if (pending_config_mode_state_->added_types.empty()) {
+ if (pending_config_mode_state_->added_types.Empty()) {
SVLOG(1) << "No new types added; calling ready_task directly";
// No new types - just notify the caller that the types are available.
const syncable::ModelEnumSet failed_configuration_types;
@@ -1012,8 +1009,7 @@ void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop() {
// Always configure nigori if it's enabled.
syncable::ModelEnumSet types_to_config =
- syncable::ModelTypeSetToEnumSet(
- pending_download_state_->added_types);
+ pending_download_state_->added_types;
if (IsNigoriEnabled()) {
// Note: Nigori is the only type that gets added with a nonempty
// progress marker during config. If the server returns a migration
diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h
index 80dfa87..269cc54 100644
--- a/chrome/browser/sync/glue/sync_backend_host.h
+++ b/chrome/browser/sync/glue/sync_backend_host.h
@@ -103,7 +103,7 @@ class SyncFrontend {
// of encrypted types is Cryptographer::SensitiveTypes() and that
// the encrypt everything flag is false.
virtual void OnEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) = 0;
// Called after we finish encrypting the current set of encrypted
@@ -112,10 +112,10 @@ class SyncFrontend {
// Called to perform migration of |types|.
virtual void OnMigrationNeededForTypes(
- const syncable::ModelTypeSet& types) = 0;
+ syncable::ModelEnumSet types) = 0;
// Inform the Frontend that new datatypes are available for registration.
- virtual void OnDataTypesChanged(const syncable::ModelTypeSet& to_add) = 0;
+ virtual void OnDataTypesChanged(syncable::ModelEnumSet to_add) = 0;
// Called when the sync cycle returns there is an user actionable error.
virtual void OnActionableError(
@@ -157,7 +157,7 @@ class SyncBackendHost {
void Initialize(SyncFrontend* frontend,
const WeakHandle<JsEventHandler>& event_handler,
const GURL& service_url,
- const syncable::ModelTypeSet& initial_types,
+ syncable::ModelEnumSet initial_types,
const sync_api::SyncCredentials& credentials,
bool delete_sync_data_folder);
@@ -193,8 +193,8 @@ class SyncBackendHost {
// set of all types that failed configuration (i.e., if its argument
// is non-empty, then an error was encountered).
virtual void ConfigureDataTypes(
- const syncable::ModelTypeSet& types_to_add,
- const syncable::ModelTypeSet& types_to_remove,
+ syncable::ModelEnumSet types_to_add,
+ syncable::ModelEnumSet types_to_remove,
sync_api::ConfigureReason reason,
base::Callback<void(syncable::ModelEnumSet)> ready_task,
bool enable_nigori);
@@ -295,7 +295,7 @@ class SyncBackendHost {
virtual void OnClearServerDataFailed() OVERRIDE;
virtual void OnClearServerDataSucceeded() OVERRIDE;
virtual void OnEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) OVERRIDE;
virtual void OnEncryptionComplete() OVERRIDE;
virtual void OnActionableError(
@@ -461,7 +461,7 @@ class SyncBackendHost {
// Invoked when the set of encrypted types or the encrypt
// everything flag changes.
void NotifyEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything);
// Invoked when sync finishes encrypting new datatypes.
@@ -550,10 +550,10 @@ class SyncBackendHost {
// The set of types that we are waiting to be initially synced in a
// configuration cycle.
- syncable::ModelTypeSet types_to_add;
+ syncable::ModelEnumSet types_to_add;
// Additional details about which types were added.
- syncable::ModelTypeSet added_types;
+ syncable::ModelEnumSet added_types;
sync_api::ConfigureReason reason;
};
diff --git a/chrome/browser/sync/glue/sync_backend_host_mock.h b/chrome/browser/sync/glue/sync_backend_host_mock.h
index 3e2f7da..09eaec5 100644
--- a/chrome/browser/sync/glue/sync_backend_host_mock.h
+++ b/chrome/browser/sync/glue/sync_backend_host_mock.h
@@ -22,8 +22,8 @@ class SyncBackendHostMock : public SyncBackendHost {
virtual ~SyncBackendHostMock();
MOCK_METHOD5(ConfigureDataTypes,
- void(const std::set<syncable::ModelType>&,
- const std::set<syncable::ModelType>&,
+ void(syncable::ModelEnumSet,
+ syncable::ModelEnumSet,
sync_api::ConfigureReason,
base::Callback<void(syncable::ModelEnumSet)>,
bool));
diff --git a/chrome/browser/sync/glue/sync_backend_host_unittest.cc b/chrome/browser/sync/glue/sync_backend_host_unittest.cc
index cea326a..7232247 100644
--- a/chrome/browser/sync/glue/sync_backend_host_unittest.cc
+++ b/chrome/browser/sync/glue/sync_backend_host_unittest.cc
@@ -40,10 +40,10 @@ class MockSyncFrontend : public SyncFrontend {
MOCK_METHOD1(OnPassphraseRequired, void(sync_api::PassphraseRequiredReason));
MOCK_METHOD0(OnPassphraseAccepted, void());
MOCK_METHOD2(OnEncryptedTypesChanged,
- void(const syncable::ModelTypeSet&, bool));
+ void(syncable::ModelEnumSet, bool));
MOCK_METHOD0(OnEncryptionComplete, void());
- MOCK_METHOD1(OnMigrationNeededForTypes, void(const syncable::ModelTypeSet&));
- MOCK_METHOD1(OnDataTypesChanged, void(const syncable::ModelTypeSet&));
+ MOCK_METHOD1(OnMigrationNeededForTypes, void(syncable::ModelEnumSet));
+ MOCK_METHOD1(OnDataTypesChanged, void(syncable::ModelEnumSet));
MOCK_METHOD1(OnActionableError,
void(const browser_sync::SyncProtocolError& sync_error));
};
@@ -97,7 +97,7 @@ TEST_F(SyncBackendHostTest, InitShutdown) {
backend.Initialize(&mock_frontend,
WeakHandle<JsEventHandler>(),
GURL(k_mock_url),
- syncable::ModelTypeSet(),
+ syncable::ModelEnumSet(),
credentials,
true);
backend.StopSyncingForShutdown();
diff --git a/chrome/browser/sync/glue/sync_backend_registrar.cc b/chrome/browser/sync/glue/sync_backend_registrar.cc
index 7ef21a4..942db51 100644
--- a/chrome/browser/sync/glue/sync_backend_registrar.cc
+++ b/chrome/browser/sync/glue/sync_backend_registrar.cc
@@ -4,7 +4,6 @@
#include "chrome/browser/sync/glue/sync_backend_registrar.h"
-#include <algorithm>
#include <cstddef>
#include "base/compiler_specific.h"
@@ -52,7 +51,7 @@ bool IsOnThreadForGroup(ModelSafeGroup group) {
} // namespace
SyncBackendRegistrar::SyncBackendRegistrar(
- const syncable::ModelTypeSet& initial_types,
+ syncable::ModelEnumSet initial_types,
const std::string& name, Profile* profile,
MessageLoop* sync_loop) :
name_(name),
@@ -72,9 +71,9 @@ SyncBackendRegistrar::SyncBackendRegistrar(
// routing_info map. We set them to group passive, meaning that
// updates will be applied to sync, but not dispatched to the native
// models.
- for (syncable::ModelTypeSet::const_iterator it = initial_types.begin();
- it != initial_types.end(); ++it) {
- routing_info_[*it] = GROUP_PASSIVE;
+ for (syncable::ModelEnumSet::Iterator it = initial_types.First();
+ it.Good(); it.Inc()) {
+ routing_info_[it.Get()] = GROUP_PASSIVE;
}
HistoryService* history_service = profile->GetHistoryService(
@@ -82,7 +81,7 @@ SyncBackendRegistrar::SyncBackendRegistrar(
if (history_service) {
workers_[GROUP_HISTORY] = new HistoryModelWorker(history_service);
} else {
- LOG_IF(WARNING, initial_types.count(syncable::TYPED_URLS) > 0)
+ LOG_IF(WARNING, initial_types.Has(syncable::TYPED_URLS))
<< "History store disabled, cannot sync Omnibox History";
routing_info_.erase(syncable::TYPED_URLS);
}
@@ -92,7 +91,7 @@ SyncBackendRegistrar::SyncBackendRegistrar(
if (password_store) {
workers_[GROUP_PASSWORD] = new PasswordModelWorker(password_store);
} else {
- LOG_IF(WARNING, initial_types.count(syncable::PASSWORDS) > 0)
+ LOG_IF(WARNING, initial_types.Has(syncable::PASSWORDS))
<< "Password store not initialized, cannot sync passwords";
routing_info_.erase(syncable::PASSWORDS);
}
@@ -109,51 +108,45 @@ bool SyncBackendRegistrar::IsNigoriEnabled() const {
return routing_info_.find(syncable::NIGORI) != routing_info_.end();
}
-syncable::ModelTypeSet SyncBackendRegistrar::ConfigureDataTypes(
- const syncable::ModelTypeSet& types_to_add,
- const syncable::ModelTypeSet& types_to_remove) {
+syncable::ModelEnumSet SyncBackendRegistrar::ConfigureDataTypes(
+ syncable::ModelEnumSet types_to_add,
+ syncable::ModelEnumSet types_to_remove) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (DCHECK_IS_ON()) {
- syncable::ModelTypeSet intersection;
- std::set_intersection(types_to_add.begin(), types_to_add.end(),
- types_to_remove.begin(), types_to_remove.end(),
- std::inserter(intersection, intersection.end()));
- DCHECK(intersection.empty());
- }
- syncable::ModelTypeSet filtered_types_to_add = types_to_add;
+ DCHECK(Intersection(types_to_add, types_to_remove).Empty());
+ syncable::ModelEnumSet filtered_types_to_add = types_to_add;
if (workers_.count(GROUP_HISTORY) == 0) {
LOG(WARNING) << "No history worker -- removing TYPED_URLS";
- filtered_types_to_add.erase(syncable::TYPED_URLS);
+ filtered_types_to_add.Remove(syncable::TYPED_URLS);
}
if (workers_.count(GROUP_PASSWORD) == 0) {
LOG(WARNING) << "No password worker -- removing PASSWORDS";
- filtered_types_to_add.erase(syncable::PASSWORDS);
+ filtered_types_to_add.Remove(syncable::PASSWORDS);
}
base::AutoLock lock(lock_);
- syncable::ModelTypeSet newly_added_types;
- for (syncable::ModelTypeSet::const_iterator it =
- filtered_types_to_add.begin();
- it != filtered_types_to_add.end(); ++it) {
+ syncable::ModelEnumSet newly_added_types;
+ for (syncable::ModelEnumSet::Iterator it =
+ filtered_types_to_add.First();
+ it.Good(); it.Inc()) {
// Add a newly specified data type as GROUP_PASSIVE into the
// routing_info, if it does not already exist.
- if (routing_info_.count(*it) == 0) {
- routing_info_[*it] = GROUP_PASSIVE;
- newly_added_types.insert(*it);
+ if (routing_info_.count(it.Get()) == 0) {
+ routing_info_[it.Get()] = GROUP_PASSIVE;
+ newly_added_types.Put(it.Get());
}
}
- for (syncable::ModelTypeSet::const_iterator it = types_to_remove.begin();
- it != types_to_remove.end(); ++it) {
- routing_info_.erase(*it);
+ for (syncable::ModelEnumSet::Iterator it = types_to_remove.First();
+ it.Good(); it.Inc()) {
+ routing_info_.erase(it.Get());
}
// TODO(akalin): Use SVLOG/SLOG if we add any more logging.
DVLOG(1) << name_ << ": Adding types "
- << syncable::ModelTypeSetToString(types_to_add)
+ << syncable::ModelEnumSetToString(types_to_add)
<< " (with newly-added types "
- << syncable::ModelTypeSetToString(newly_added_types)
+ << syncable::ModelEnumSetToString(newly_added_types)
<< ") and removing types "
- << syncable::ModelTypeSetToString(types_to_remove)
+ << syncable::ModelEnumSetToString(types_to_remove)
<< " to get new routing info "
<< ModelSafeRoutingInfoToString(routing_info_);
diff --git a/chrome/browser/sync/glue/sync_backend_registrar.h b/chrome/browser/sync/glue/sync_backend_registrar.h
index 66e1881..1fb2f2c 100644
--- a/chrome/browser/sync/glue/sync_backend_registrar.h
+++ b/chrome/browser/sync/glue/sync_backend_registrar.h
@@ -39,7 +39,7 @@ class SyncBackendRegistrar : public ModelSafeWorkerRegistrar,
// (initially put in the passive group). |name| is used for
// debugging. Does not take ownership of |profile| or |sync_loop|.
// Must be created on the UI thread.
- SyncBackendRegistrar(const syncable::ModelTypeSet& initial_types,
+ SyncBackendRegistrar(syncable::ModelEnumSet initial_types,
const std::string& name,
Profile* profile,
MessageLoop* sync_loop);
@@ -66,9 +66,9 @@ class SyncBackendRegistrar : public ModelSafeWorkerRegistrar,
// not already there (initially put in the passive group).
// |types_to_remove| and |types_to_add| must be disjoint. Returns
// the set of newly-added types. Must be called on the UI thread.
- syncable::ModelTypeSet ConfigureDataTypes(
- const syncable::ModelTypeSet& types_to_add,
- const syncable::ModelTypeSet& types_to_remove);
+ syncable::ModelEnumSet ConfigureDataTypes(
+ syncable::ModelEnumSet types_to_add,
+ syncable::ModelEnumSet types_to_remove);
// Must be called from the UI thread. (See destructor comment.)
void StopOnUIThread();
diff --git a/chrome/browser/sync/glue/sync_backend_registrar_unittest.cc b/chrome/browser/sync/glue/sync_backend_registrar_unittest.cc
index 7ba8d22..3dabf54 100644
--- a/chrome/browser/sync/glue/sync_backend_registrar_unittest.cc
+++ b/chrome/browser/sync/glue/sync_backend_registrar_unittest.cc
@@ -30,9 +30,9 @@ using syncable::THEMES;
using syncable::NIGORI;
using syncable::PASSWORDS;
using syncable::MODEL_TYPE_COUNT;
+using syncable::ModelEnumSet;
using syncable::ModelType;
using syncable::ModelTypeFromInt;
-using syncable::ModelTypeSet;
class SyncBackendRegistrarTest : public testing::Test {
protected:
@@ -56,10 +56,10 @@ class SyncBackendRegistrarTest : public testing::Test {
}
void ExpectHasProcessorsForTypes(const SyncBackendRegistrar& registrar,
- const ModelTypeSet& types) {
+ ModelEnumSet types) {
for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
ModelType model_type = ModelTypeFromInt(i);
- EXPECT_EQ(types.count(model_type) > 0,
+ EXPECT_EQ(types.Has(model_type),
registrar.IsTypeActivatedForTest(model_type));
}
}
@@ -73,7 +73,7 @@ class SyncBackendRegistrarTest : public testing::Test {
TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) {
TestingProfile profile;
- SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_);
+ SyncBackendRegistrar registrar(ModelEnumSet(), "test", &profile, &loop_);
EXPECT_FALSE(registrar.IsNigoriEnabled());
{
std::vector<ModelSafeWorker*> workers;
@@ -81,17 +81,14 @@ TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) {
EXPECT_EQ(4u, workers.size());
}
ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo());
- ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
+ ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
registrar.OnSyncerShutdownComplete();
registrar.StopOnUIThread();
}
TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) {
TestingProfile profile;
- ModelTypeSet initial_types;
- initial_types.insert(BOOKMARKS);
- initial_types.insert(NIGORI);
- initial_types.insert(PASSWORDS);
+ const ModelEnumSet initial_types(BOOKMARKS, NIGORI, PASSWORDS);
SyncBackendRegistrar registrar(initial_types, "test", &profile, &loop_);
EXPECT_TRUE(registrar.IsNigoriEnabled());
{
@@ -106,21 +103,19 @@ TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) {
// Passwords dropped because of no password store.
ExpectRoutingInfo(&registrar, expected_routing_info);
}
- ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
+ ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
registrar.OnSyncerShutdownComplete();
registrar.StopOnUIThread();
}
TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) {
TestingProfile profile;
- SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_);
+ SyncBackendRegistrar registrar(ModelEnumSet(), "test", &profile, &loop_);
// Add.
- ModelTypeSet types1;
- types1.insert(BOOKMARKS);
- types1.insert(NIGORI);
- types1.insert(AUTOFILL);
- EXPECT_EQ(types1, registrar.ConfigureDataTypes(types1, ModelTypeSet()));
+ const ModelEnumSet types1(BOOKMARKS, NIGORI, AUTOFILL);
+ EXPECT_TRUE(
+ registrar.ConfigureDataTypes(types1, ModelEnumSet()).Equals(types1));
{
ModelSafeRoutingInfo expected_routing_info;
expected_routing_info[BOOKMARKS] = GROUP_PASSIVE;
@@ -128,25 +123,23 @@ TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) {
expected_routing_info[AUTOFILL] = GROUP_PASSIVE;
ExpectRoutingInfo(&registrar, expected_routing_info);
}
- ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
+ ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
// Add and remove.
- ModelTypeSet types2;
- types2.insert(PREFERENCES);
- types2.insert(THEMES);
- EXPECT_EQ(types2, registrar.ConfigureDataTypes(types2, types1));
+ const ModelEnumSet types2(PREFERENCES, THEMES);
+ EXPECT_TRUE(registrar.ConfigureDataTypes(types2, types1).Equals(types2));
{
ModelSafeRoutingInfo expected_routing_info;
expected_routing_info[PREFERENCES] = GROUP_PASSIVE;
expected_routing_info[THEMES] = GROUP_PASSIVE;
ExpectRoutingInfo(&registrar, expected_routing_info);
}
- ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
+ ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
// Remove.
- EXPECT_TRUE(registrar.ConfigureDataTypes(ModelTypeSet(), types2).empty());
+ EXPECT_TRUE(registrar.ConfigureDataTypes(ModelEnumSet(), types2).Empty());
ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo());
- ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
+ ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
registrar.OnSyncerShutdownComplete();
registrar.StopOnUIThread();
@@ -161,7 +154,7 @@ void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) {
TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) {
InSequence in_sequence;
TestingProfile profile;
- SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_);
+ SyncBackendRegistrar registrar(ModelEnumSet(), "test", &profile, &loop_);
// Should do nothing.
TriggerChanges(&registrar, BOOKMARKS);
@@ -178,9 +171,9 @@ TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) {
EXPECT_CALL(change_processor_mock, IsRunning())
.WillRepeatedly(Return(false));
- ModelTypeSet types;
- types.insert(BOOKMARKS);
- EXPECT_EQ(types, registrar.ConfigureDataTypes(types, ModelTypeSet()));
+ const ModelEnumSet types(BOOKMARKS);
+ EXPECT_TRUE(
+ registrar.ConfigureDataTypes(types, ModelEnumSet()).Equals(types));
registrar.ActivateDataType(BOOKMARKS, GROUP_UI,
&change_processor_mock,
test_user_share_.user_share());
@@ -195,7 +188,7 @@ TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) {
registrar.DeactivateDataType(BOOKMARKS);
ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo());
- ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
+ ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
// Should do nothing.
TriggerChanges(&registrar, BOOKMARKS);
@@ -208,7 +201,7 @@ TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) {
content::TestBrowserThread db_thread(BrowserThread::DB, &loop_);
InSequence in_sequence;
TestingProfile profile;
- SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_);
+ SyncBackendRegistrar registrar(ModelEnumSet(), "test", &profile, &loop_);
// Should do nothing.
TriggerChanges(&registrar, AUTOFILL);
@@ -225,9 +218,9 @@ TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) {
EXPECT_CALL(change_processor_mock, IsRunning())
.WillRepeatedly(Return(false));
- ModelTypeSet types;
- types.insert(AUTOFILL);
- EXPECT_EQ(types, registrar.ConfigureDataTypes(types, ModelTypeSet()));
+ const ModelEnumSet types(AUTOFILL);
+ EXPECT_TRUE(
+ registrar.ConfigureDataTypes(types, ModelEnumSet()).Equals(types));
registrar.ActivateDataType(AUTOFILL, GROUP_DB,
&change_processor_mock,
test_user_share_.user_share());
@@ -242,7 +235,7 @@ TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) {
registrar.DeactivateDataType(AUTOFILL);
ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo());
- ExpectHasProcessorsForTypes(registrar, ModelTypeSet());
+ ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
// Should do nothing.
TriggerChanges(&registrar, AUTOFILL);
diff --git a/chrome/browser/sync/glue/theme_model_associator.cc b/chrome/browser/sync/glue/theme_model_associator.cc
index e410041..9f17196 100644
--- a/chrome/browser/sync/glue/theme_model_associator.cc
+++ b/chrome/browser/sync/glue/theme_model_associator.cc
@@ -103,9 +103,9 @@ bool ThemeModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
bool ThemeModelAssociator::CryptoReadyIfNecessary() {
// We only access the cryptographer while holding a transaction.
sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
- syncable::ModelTypeSet encrypted_types;
- encrypted_types = sync_api::GetEncryptedTypes(&trans);
- return encrypted_types.count(syncable::THEMES) == 0 ||
+ const syncable::ModelEnumSet encrypted_types =
+ sync_api::GetEncryptedTypes(&trans);
+ return !encrypted_types.Has(syncable::THEMES) ||
sync_service_->IsCryptographerReady(&trans);
}
diff --git a/chrome/browser/sync/glue/typed_url_model_associator.cc b/chrome/browser/sync/glue/typed_url_model_associator.cc
index 5109a97b..ac07ff7 100644
--- a/chrome/browser/sync/glue/typed_url_model_associator.cc
+++ b/chrome/browser/sync/glue/typed_url_model_associator.cc
@@ -820,9 +820,9 @@ void TypedUrlModelAssociator::UpdateURLRowFromTypedUrlSpecifics(
bool TypedUrlModelAssociator::CryptoReadyIfNecessary() {
// We only access the cryptographer while holding a transaction.
sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
- syncable::ModelTypeSet encrypted_types;
- encrypted_types = sync_api::GetEncryptedTypes(&trans);
- return encrypted_types.count(syncable::TYPED_URLS) == 0 ||
+ const syncable::ModelEnumSet encrypted_types =
+ sync_api::GetEncryptedTypes(&trans);
+ return !encrypted_types.Has(syncable::TYPED_URLS) ||
sync_service_->IsCryptographerReady(&trans);
}
diff --git a/chrome/browser/sync/internal_api/base_transaction.cc b/chrome/browser/sync/internal_api/base_transaction.cc
index 8d26702..8a7e123 100644
--- a/chrome/browser/sync/internal_api/base_transaction.cc
+++ b/chrome/browser/sync/internal_api/base_transaction.cc
@@ -26,7 +26,7 @@ BaseTransaction::~BaseTransaction() {
delete lookup_;
}
-syncable::ModelTypeSet GetEncryptedTypes(
+syncable::ModelEnumSet GetEncryptedTypes(
const sync_api::BaseTransaction* trans) {
Cryptographer* cryptographer = trans->GetCryptographer();
return cryptographer->GetEncryptedTypes();
diff --git a/chrome/browser/sync/internal_api/base_transaction.h b/chrome/browser/sync/internal_api/base_transaction.h
index 9bf2fb3..5459295 100644
--- a/chrome/browser/sync/internal_api/base_transaction.h
+++ b/chrome/browser/sync/internal_api/base_transaction.h
@@ -51,7 +51,7 @@ class BaseTransaction {
DISALLOW_COPY_AND_ASSIGN(BaseTransaction);
};
-syncable::ModelTypeSet GetEncryptedTypes(
+syncable::ModelEnumSet GetEncryptedTypes(
const sync_api::BaseTransaction* trans);
} // namespace sync_api
diff --git a/chrome/browser/sync/internal_api/debug_info_event_listener.cc b/chrome/browser/sync/internal_api/debug_info_event_listener.cc
index 4ed3338..e657782 100644
--- a/chrome/browser/sync/internal_api/debug_info_event_listener.cc
+++ b/chrome/browser/sync/internal_api/debug_info_event_listener.cc
@@ -73,7 +73,7 @@ void DebugInfoEventListener::OnClearServerDataSucceeded() {
}
void DebugInfoEventListener::OnEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) {
CreateAndAddEvent(sync_pb::DebugEventInfo::ENCRYPTED_TYPES_CHANGED);
}
diff --git a/chrome/browser/sync/internal_api/debug_info_event_listener.h b/chrome/browser/sync/internal_api/debug_info_event_listener.h
index c796a57..ed2200a 100644
--- a/chrome/browser/sync/internal_api/debug_info_event_listener.h
+++ b/chrome/browser/sync/internal_api/debug_info_event_listener.h
@@ -46,7 +46,7 @@ class DebugInfoEventListener : public sync_api::SyncManager::Observer,
virtual void OnClearServerDataFailed() OVERRIDE;
virtual void OnClearServerDataSucceeded() OVERRIDE;
virtual void OnEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) OVERRIDE;
virtual void OnEncryptionComplete() OVERRIDE;
virtual void OnActionableError(
diff --git a/chrome/browser/sync/internal_api/sync_manager.cc b/chrome/browser/sync/internal_api/sync_manager.cc
index bc084d5..792f269 100644
--- a/chrome/browser/sync/internal_api/sync_manager.cc
+++ b/chrome/browser/sync/internal_api/sync_manager.cc
@@ -262,7 +262,7 @@ class SyncManager::SyncInternal
// Cryptographer::Observer implementation.
virtual void OnEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) OVERRIDE;
// SyncNotifierObserver implementation.
@@ -321,12 +321,12 @@ class SyncManager::SyncInternal
virtual void OnIPAddressChanged() OVERRIDE;
bool InitialSyncEndedForAllEnabledTypes() {
- syncable::ModelTypeSet types;
+ syncable::ModelEnumSet types;
ModelSafeRoutingInfo enabled_types;
registrar_->GetModelSafeRoutingInfo(&enabled_types);
for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin();
i != enabled_types.end(); ++i) {
- types.insert(i->first);
+ types.Put(i->first);
}
return InitialSyncEndedForTypes(types, &share_);
@@ -1135,18 +1135,18 @@ void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) {
Cryptographer* cryptographer = trans->GetCryptographer();
if (!cryptographer || !cryptographer->is_ready())
return;
- syncable::ModelTypeSet encrypted_types = GetEncryptedTypes(trans);
+ syncable::ModelEnumSet encrypted_types = GetEncryptedTypes(trans);
ModelSafeRoutingInfo routes;
registrar_->GetModelSafeRoutingInfo(&routes);
std::string tag;
- for (syncable::ModelTypeSet::iterator iter = encrypted_types.begin();
- iter != encrypted_types.end(); ++iter) {
- if (*iter == syncable::PASSWORDS ||
- *iter == syncable::NIGORI ||
- routes.count(*iter) == 0)
+ for (syncable::ModelEnumSet::Iterator iter = encrypted_types.First();
+ iter.Good(); iter.Inc()) {
+ if (iter.Get() == syncable::PASSWORDS ||
+ iter.Get() == syncable::NIGORI ||
+ routes.count(iter.Get()) == 0)
continue;
ReadNode type_root(trans);
- tag = syncable::ModelTypeToRootTag(*iter);
+ tag = syncable::ModelTypeToRootTag(iter.Get());
if (!type_root.InitByTagLookup(tag)) {
// This can happen when we enable a datatype for the first time on restart
// (for example when we upgrade) and therefore haven't done the initial
@@ -1852,7 +1852,7 @@ JsArgList SyncManager::SyncInternal::FindNodesContainingString(
}
void SyncManager::SyncInternal::OnEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) {
// NOTE: We're in a transaction.
FOR_EACH_OBSERVER(
@@ -1981,12 +1981,12 @@ void SyncManager::RefreshEncryption() {
data_->RefreshEncryption();
}
-syncable::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const {
+syncable::ModelEnumSet SyncManager::GetEncryptedDataTypesForTest() const {
ReadTransaction trans(FROM_HERE, GetUserShare());
return GetEncryptedTypes(&trans);
}
-bool SyncManager::ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add)
+bool SyncManager::ReceivedExperimentalTypes(syncable::ModelEnumSet* to_add)
const {
ReadTransaction trans(FROM_HERE, GetUserShare());
ReadNode node(&trans);
@@ -1995,7 +1995,7 @@ bool SyncManager::ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add)
return false;
}
if (node.GetNigoriSpecifics().sync_tabs()) {
- to_add->insert(syncable::SESSIONS);
+ to_add->Put(syncable::SESSIONS);
return true;
}
return false;
@@ -2041,7 +2041,7 @@ std::string PassphraseRequiredReasonToString(
}
// Helper function to determine if initial sync had ended for types.
-bool InitialSyncEndedForTypes(syncable::ModelTypeSet types,
+bool InitialSyncEndedForTypes(syncable::ModelEnumSet types,
sync_api::UserShare* share) {
syncable::ScopedDirLookup lookup(share->dir_manager.get(),
share->name);
@@ -2050,33 +2050,33 @@ bool InitialSyncEndedForTypes(syncable::ModelTypeSet types,
return false;
}
- for (syncable::ModelTypeSet::const_iterator i = types.begin();
- i != types.end(); ++i) {
- if (!lookup->initial_sync_ended_for_type(*i))
+ for (syncable::ModelEnumSet::Iterator i = types.First();
+ i.Good(); i.Inc()) {
+ if (!lookup->initial_sync_ended_for_type(i.Get()))
return false;
}
return true;
}
-syncable::ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
- const syncable::ModelTypeSet types,
+syncable::ModelEnumSet GetTypesWithEmptyProgressMarkerToken(
+ syncable::ModelEnumSet types,
sync_api::UserShare* share) {
syncable::ScopedDirLookup lookup(share->dir_manager.get(),
share->name);
if (!lookup.good()) {
NOTREACHED() << "ScopedDirLookup failed for "
<< "GetTypesWithEmptyProgressMarkerToken";
- return syncable::ModelTypeSet();
+ return syncable::ModelEnumSet();
}
- syncable::ModelTypeSet result;
- for (syncable::ModelTypeSet::const_iterator i = types.begin();
- i != types.end(); ++i) {
+ syncable::ModelEnumSet result;
+ for (syncable::ModelEnumSet::Iterator i = types.First();
+ i.Good(); i.Inc()) {
sync_pb::DataTypeProgressMarker marker;
- lookup->GetDownloadProgress(*i, &marker);
+ lookup->GetDownloadProgress(i.Get(), &marker);
if (marker.token().empty())
- result.insert(*i);
+ result.Put(i.Get());
}
return result;
diff --git a/chrome/browser/sync/internal_api/sync_manager.h b/chrome/browser/sync/internal_api/sync_manager.h
index 138ec92..14f82e8 100644
--- a/chrome/browser/sync/internal_api/sync_manager.h
+++ b/chrome/browser/sync/internal_api/sync_manager.h
@@ -158,7 +158,7 @@ class SyncManager {
int useful_sync_cycles;
// Encryption related.
- syncable::ModelTypeSet encrypted_types;
+ syncable::ModelEnumSet encrypted_types;
bool cryptographer_ready;
bool crypto_has_pending_keys;
@@ -390,7 +390,7 @@ class SyncManager {
//
// Called from within a transaction.
virtual void OnEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) = 0;
// Called after we finish encrypting the current set of encrypted
@@ -559,12 +559,12 @@ class SyncManager {
// Gets the set of encrypted types from the cryptographer
// Note: opens a transaction. May be called from any thread.
- syncable::ModelTypeSet GetEncryptedDataTypesForTest() const;
+ syncable::ModelEnumSet GetEncryptedDataTypesForTest() const;
// Reads the nigori node to determine if any experimental types should be
// enabled.
// Note: opens a transaction. May be called on any thread.
- bool ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add) const;
+ bool ReceivedExperimentalTypes(syncable::ModelEnumSet* to_add) const;
// Uses a read-only transaction to determine if the directory being synced has
// any remaining unsynced items. May be called on any thread.
@@ -587,10 +587,10 @@ class SyncManager {
DISALLOW_COPY_AND_ASSIGN(SyncManager);
};
-bool InitialSyncEndedForTypes(syncable::ModelTypeSet types, UserShare* share);
+bool InitialSyncEndedForTypes(syncable::ModelEnumSet types, UserShare* share);
-syncable::ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
- const syncable::ModelTypeSet types,
+syncable::ModelEnumSet GetTypesWithEmptyProgressMarkerToken(
+ syncable::ModelEnumSet types,
sync_api::UserShare* share);
// Returns the string representation of a PassphraseRequiredReason value.
diff --git a/chrome/browser/sync/internal_api/syncapi_unittest.cc b/chrome/browser/sync/internal_api/syncapi_unittest.cc
index 0c3cd6f..86e2a83 100644
--- a/chrome/browser/sync/internal_api/syncapi_unittest.cc
+++ b/chrome/browser/sync/internal_api/syncapi_unittest.cc
@@ -46,6 +46,7 @@
#include "chrome/browser/sync/protocol/sync.pb.h"
#include "chrome/browser/sync/sessions/sync_session.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
+#include "chrome/browser/sync/syncable/model_type_test_util.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/sync/syncable/syncable_id.h"
#include "chrome/browser/sync/test/engine/test_user_share.h"
@@ -72,10 +73,9 @@ using browser_sync::ModelSafeWorkerRegistrar;
using browser_sync::sessions::SyncSessionSnapshot;
using browser_sync::WeakHandle;
using content::BrowserThread;
-using syncable::GetAllRealModelTypes;
using syncable::kEncryptedString;
+using syncable::ModelEnumSet;
using syncable::ModelType;
-using syncable::ModelTypeSet;
using test::ExpectDictStringValue;
using testing::_;
using testing::AnyNumber;
@@ -632,7 +632,7 @@ class SyncManagerObserverMock : public SyncManager::Observer {
MOCK_METHOD0(OnClearServerDataFailed, void()); // NOLINT
MOCK_METHOD0(OnClearServerDataSucceeded, void()); // NOLINT
MOCK_METHOD2(OnEncryptedTypesChanged,
- void(const ModelTypeSet&, bool)); // NOLINT
+ void(ModelEnumSet, bool)); // NOLINT
MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT
MOCK_METHOD1(OnActionableError,
void(const browser_sync::SyncProtocolError&)); // NOLINT
@@ -854,7 +854,7 @@ TEST_F(SyncManagerTest, UpdateEnabledTypes) {
}
TEST_F(SyncManagerTest, DoNotSyncTabsInNigoriNode) {
- syncable::ModelEnumSet encrypted_types(syncable::TYPED_URLS);
+ const syncable::ModelEnumSet encrypted_types(syncable::TYPED_URLS);
sync_manager_.MaybeSetSyncTabsInNigoriNode(encrypted_types);
ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
@@ -864,7 +864,7 @@ TEST_F(SyncManagerTest, DoNotSyncTabsInNigoriNode) {
}
TEST_F(SyncManagerTest, SyncTabsInNigoriNode) {
- syncable::ModelEnumSet encrypted_types(syncable::SESSIONS);
+ const syncable::ModelEnumSet encrypted_types(syncable::SESSIONS);
sync_manager_.MaybeSetSyncTabsInNigoriNode(encrypted_types);
ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
@@ -1159,7 +1159,8 @@ TEST_F(SyncManagerTest, OnIncomingNotification) {
StrictMock<MockJsEventHandler> event_handler;
const syncable::ModelEnumSet empty_model_types;
- syncable::ModelEnumSet model_types(syncable::BOOKMARKS, syncable::THEMES);
+ const syncable::ModelEnumSet model_types(
+ syncable::BOOKMARKS, syncable::THEMES);
// Build expected_args to have a single argument with the string
// equivalents of model_types.
@@ -1197,9 +1198,9 @@ TEST_F(SyncManagerTest, RefreshEncryptionReady) {
EXPECT_TRUE(SetUpEncryption(true));
EXPECT_CALL(observer_, OnEncryptionComplete());
sync_manager_.RefreshEncryption();
- syncable::ModelTypeSet encrypted_types =
+ const syncable::ModelEnumSet encrypted_types =
sync_manager_.GetEncryptedDataTypesForTest();
- EXPECT_EQ(1U, encrypted_types.count(syncable::PASSWORDS));
+ EXPECT_TRUE(encrypted_types.Has(syncable::PASSWORDS));
EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest());
{
ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
@@ -1217,9 +1218,9 @@ TEST_F(SyncManagerTest, RefreshEncryptionReady) {
TEST_F(SyncManagerTest, RefreshEncryptionNotReady) {
// Don't set up encryption (no nigori node created).
sync_manager_.RefreshEncryption(); // Should fail.
- syncable::ModelTypeSet encrypted_types =
+ const syncable::ModelEnumSet encrypted_types =
sync_manager_.GetEncryptedDataTypesForTest();
- EXPECT_EQ(1U, encrypted_types.count(syncable::PASSWORDS)); // Hardcoded.
+ EXPECT_TRUE(encrypted_types.Has(syncable::PASSWORDS)); // Hardcoded.
EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest());
}
@@ -1228,9 +1229,9 @@ TEST_F(SyncManagerTest, RefreshEncryptionEmptyNigori) {
EXPECT_TRUE(SetUpEncryption(false));
EXPECT_CALL(observer_, OnEncryptionComplete());
sync_manager_.RefreshEncryption(); // Should write to nigori.
- syncable::ModelTypeSet encrypted_types =
+ const syncable::ModelEnumSet encrypted_types =
sync_manager_.GetEncryptedDataTypesForTest();
- EXPECT_EQ(1U, encrypted_types.count(syncable::PASSWORDS)); // Hardcoded.
+ EXPECT_TRUE(encrypted_types.Has(syncable::PASSWORDS)); // Hardcoded.
EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest());
{
ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
@@ -1247,7 +1248,8 @@ TEST_F(SyncManagerTest, RefreshEncryptionEmptyNigori) {
TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) {
EXPECT_TRUE(SetUpEncryption(true));
EXPECT_CALL(observer_,
- OnEncryptedTypesChanged(GetAllRealModelTypes(), true));
+ OnEncryptedTypesChanged(
+ HasModelTypes(syncable::ModelEnumSet::All()), true));
EXPECT_CALL(observer_, OnEncryptionComplete());
sync_manager_.EnableEncryptEverything();
EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest());
@@ -1283,7 +1285,8 @@ TEST_F(SyncManagerTest, EncryptDataTypesWithData) {
{
ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
- EXPECT_EQ(Cryptographer::SensitiveTypes(), GetEncryptedTypes(&trans));
+ EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(
+ Cryptographer::SensitiveTypes()));
EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
trans.GetWrappedTrans(),
trans.GetCryptographer(),
@@ -1302,13 +1305,15 @@ TEST_F(SyncManagerTest, EncryptDataTypesWithData) {
}
EXPECT_CALL(observer_,
- OnEncryptedTypesChanged(GetAllRealModelTypes(), true));
+ OnEncryptedTypesChanged(
+ HasModelTypes(syncable::ModelEnumSet::All()), true));
EXPECT_CALL(observer_, OnEncryptionComplete());
sync_manager_.EnableEncryptEverything();
EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest());
{
ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
- EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans));
+ EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(
+ syncable::ModelEnumSet::All()));
EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
trans.GetWrappedTrans(),
trans.GetCryptographer(),
@@ -1334,7 +1339,8 @@ TEST_F(SyncManagerTest, EncryptDataTypesWithData) {
EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest());
{
ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
- EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans));
+ EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(
+ syncable::ModelEnumSet::All()));
EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
trans.GetWrappedTrans(),
trans.GetCryptographer(),
@@ -1494,14 +1500,16 @@ TEST_F(SyncManagerTest, EncryptBookmarksWithLegacyData) {
}
EXPECT_CALL(observer_,
- OnEncryptedTypesChanged(GetAllRealModelTypes(), true));
+ OnEncryptedTypesChanged(
+ HasModelTypes(syncable::ModelEnumSet::All()), true));
EXPECT_CALL(observer_, OnEncryptionComplete());
sync_manager_.EnableEncryptEverything();
EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest());
{
ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
- EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans));
+ EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(
+ syncable::ModelEnumSet::All()));
EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
trans.GetWrappedTrans(),
trans.GetCryptographer(),
diff --git a/chrome/browser/sync/internal_api/write_node.cc b/chrome/browser/sync/internal_api/write_node.cc
index b088dc1..c693eac 100644
--- a/chrome/browser/sync/internal_api/write_node.cc
+++ b/chrome/browser/sync/internal_api/write_node.cc
@@ -38,7 +38,8 @@ bool WriteNode::UpdateEntryWithEncryption(
syncable::MutableEntry* entry) {
syncable::ModelType type = syncable::GetModelTypeFromSpecifics(new_specifics);
DCHECK_GE(type, syncable::FIRST_REAL_MODEL_TYPE);
- syncable::ModelTypeSet encrypted_types = cryptographer->GetEncryptedTypes();
+ const syncable::ModelEnumSet encrypted_types =
+ cryptographer->GetEncryptedTypes();
sync_pb::EntitySpecifics generated_specifics;
if (!SpecificsNeedsEncryption(encrypted_types, new_specifics) ||
!cryptographer->is_initialized()) {
@@ -119,7 +120,7 @@ void WriteNode::SetTitle(const std::wstring& title) {
// Only set NON_UNIQUE_NAME to the title if we're not encrypted.
Cryptographer* cryptographer = GetTransaction()->GetCryptographer();
- if (cryptographer->GetEncryptedTypes().count(GetModelType()) > 0) {
+ if (cryptographer->GetEncryptedTypes().Has(GetModelType())) {
if (old_name != kEncryptedString)
entry_->Put(syncable::NON_UNIQUE_NAME, kEncryptedString);
} else {
diff --git a/chrome/browser/sync/js/js_sync_manager_observer.cc b/chrome/browser/sync/js/js_sync_manager_observer.cc
index 079a53d5..0a19ff9 100644
--- a/chrome/browser/sync/js/js_sync_manager_observer.cc
+++ b/chrome/browser/sync/js/js_sync_manager_observer.cc
@@ -81,14 +81,14 @@ void JsSyncManagerObserver::OnPassphraseAccepted(
}
void JsSyncManagerObserver::OnEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) {
if (!event_handler_.IsInitialized()) {
return;
}
DictionaryValue details;
details.Set("encryptedTypes",
- syncable::ModelTypeSetToValue(encrypted_types));
+ syncable::ModelEnumSetToValue(encrypted_types));
details.SetBoolean("encryptEverything", encrypt_everything);
HandleJsEvent(FROM_HERE,
"onEncryptedTypesChanged", JsEventDetails(&details));
diff --git a/chrome/browser/sync/js/js_sync_manager_observer.h b/chrome/browser/sync/js/js_sync_manager_observer.h
index 6d891c4..6a848f7 100644
--- a/chrome/browser/sync/js/js_sync_manager_observer.h
+++ b/chrome/browser/sync/js/js_sync_manager_observer.h
@@ -41,7 +41,7 @@ class JsSyncManagerObserver : public sync_api::SyncManager::Observer {
virtual void OnPassphraseAccepted(
const std::string& bootstrap_token) OVERRIDE;
virtual void OnEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) OVERRIDE;
virtual void OnEncryptionComplete() OVERRIDE;
virtual void OnInitializationComplete(
diff --git a/chrome/browser/sync/js/js_sync_manager_observer_unittest.cc b/chrome/browser/sync/js/js_sync_manager_observer_unittest.cc
index 8d0981b..b12af66 100644
--- a/chrome/browser/sync/js/js_sync_manager_observer_unittest.cc
+++ b/chrome/browser/sync/js/js_sync_manager_observer_unittest.cc
@@ -200,12 +200,12 @@ TEST_F(JsSyncManagerObserverTest, OnEncryptedTypesChanged) {
const bool encrypt_everything = false;
expected_details.Set("encryptedTypes", encrypted_type_values);
expected_details.SetBoolean("encryptEverything", encrypt_everything);
- syncable::ModelTypeSet encrypted_types;
+ syncable::ModelEnumSet encrypted_types;
for (int i = syncable::FIRST_REAL_MODEL_TYPE;
i < syncable::MODEL_TYPE_COUNT; ++i) {
syncable::ModelType type = syncable::ModelTypeFromInt(i);
- encrypted_types.insert(type);
+ encrypted_types.Put(type);
encrypted_type_values->Append(Value::CreateStringValue(
syncable::ModelTypeToString(type)));
}
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index 68010d0..a421d0f 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -4,7 +4,6 @@
#include "chrome/browser/sync/profile_sync_service.h"
-#include <algorithm>
#include <cstddef>
#include <map>
#include <set>
@@ -307,12 +306,12 @@ void ProfileSyncService::InitializeBackend(bool delete_stale_data) {
return;
}
- syncable::ModelTypeSet initial_types;
+ syncable::ModelEnumSet initial_types;
// If sync setup hasn't finished, we don't want to initialize routing info
// for any data types so that we don't download updates for types that the
// user chooses not to sync on the first DownloadUpdatesCommand.
if (HasSyncSetupCompleted()) {
- GetPreferredDataTypes(&initial_types);
+ initial_types = GetPreferredDataTypes();
}
SyncCredentials credentials = GetCredentials();
@@ -341,18 +340,10 @@ void ProfileSyncService::CreateBackend() {
bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
if (encryption_pending())
return true;
- syncable::ModelTypeSet preferred_types;
- GetPreferredDataTypes(&preferred_types);
- syncable::ModelTypeSet encrypted_types;
- GetEncryptedDataTypes(&encrypted_types);
- const syncable::ModelEnumSet preferred_types_enum_set =
- syncable::ModelTypeSetToEnumSet(preferred_types);
- const syncable::ModelEnumSet encrypted_types_enum_set =
- syncable::ModelTypeSetToEnumSet(encrypted_types);
- DCHECK(encrypted_types.count(syncable::PASSWORDS));
- return
- !Intersection(preferred_types_enum_set,
- encrypted_types_enum_set).Empty();
+ const syncable::ModelEnumSet preferred_types = GetPreferredDataTypes();
+ const syncable::ModelEnumSet encrypted_types = GetEncryptedDataTypes();
+ DCHECK(encrypted_types.Has(syncable::PASSWORDS));
+ return !Intersection(preferred_types, encrypted_types).Empty();
}
void ProfileSyncService::OnSyncConfigureDone(
@@ -639,7 +630,7 @@ void ProfileSyncService::OnSyncCycleCompleted() {
// TODO(sync): eventually support removing datatypes too.
void ProfileSyncService::OnDataTypesChanged(
- const syncable::ModelTypeSet& to_add) {
+ syncable::ModelEnumSet to_add) {
// If this is a first time sync for a client, this will be called before
// OnBackendInitialized() to ensure the new datatypes are available at sync
// setup. As a result, the migrator won't exist yet. This is fine because for
@@ -652,28 +643,25 @@ void ProfileSyncService::OnDataTypesChanged(
}
DVLOG(2) << "OnDataTypesChanged called with types: "
- << syncable::ModelTypeSetToString(to_add);
+ << syncable::ModelEnumSetToString(to_add);
- syncable::ModelTypeSet registered_types;
- GetRegisteredDataTypes(&registered_types);
+ const syncable::ModelEnumSet registered_types = GetRegisteredDataTypes();
- syncable::ModelTypeSet to_register;
- std::set_difference(to_add.begin(), to_add.end(),
- registered_types.begin(), registered_types.end(),
- std::inserter(to_register, to_register.end()));
+ const syncable::ModelEnumSet to_register =
+ Difference(to_add, registered_types);
- DVLOG(2) << "Enabling types: " << syncable::ModelTypeSetToString(to_register);
+ DVLOG(2) << "Enabling types: " << syncable::ModelEnumSetToString(to_register);
- for (syncable::ModelTypeSet::const_iterator it = to_register.begin();
- it != to_register.end(); ++it) {
+ for (syncable::ModelEnumSet::Iterator it = to_register.First();
+ it.Good(); it.Inc()) {
// Received notice to enable experimental type. Check if the type is
// registered, and if not register a new datatype controller.
- RegisterNewDataType(*it);
+ RegisterNewDataType(it.Get());
// Enable the about:flags switch for the experimental type so we don't have
// to always perform this reconfiguration. Once we set this, the type will
// remain registered on restart, so we will no longer go down this code
// path.
- std::string experiment_name = GetExperimentNameForDataType(*it);
+ std::string experiment_name = GetExperimentNameForDataType(it.Get());
if (experiment_name.empty())
continue;
about_flags::SetExperimentEnabled(g_browser_process->local_state(),
@@ -693,9 +681,9 @@ void ProfileSyncService::OnDataTypesChanged(
// Only automatically turn on types if we have already finished set up.
// Otherwise, just leave the experimental types on by default.
- if (!to_register.empty() && HasSyncSetupCompleted() && migrator_.get()) {
+ if (!to_register.Empty() && HasSyncSetupCompleted() && migrator_.get()) {
DVLOG(1) << "Dynamically enabling new datatypes: "
- << syncable::ModelTypeSetToString(to_register);
+ << syncable::ModelEnumSetToString(to_register);
OnMigrationNeededForTypes(to_register);
}
}
@@ -837,8 +825,7 @@ void ProfileSyncService::OnPassphraseAccepted() {
// Make sure the data types that depend on the passphrase are started at
// this time.
- syncable::ModelTypeSet types;
- GetPreferredDataTypes(&types);
+ const syncable::ModelEnumSet types = GetPreferredDataTypes();
if (data_type_manager_.get()) {
// Unblock the data type manager if necessary.
@@ -865,15 +852,15 @@ void ProfileSyncService::ResolvePassphraseRequired() {
}
void ProfileSyncService::OnEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) {
encrypted_types_ = encrypted_types;
encrypt_everything_ = encrypt_everything;
DVLOG(1) << "Encrypted types changed to "
- << syncable::ModelTypeSetToString(encrypted_types_)
+ << syncable::ModelEnumSetToString(encrypted_types_)
<< " (encrypt everything is set to "
<< (encrypt_everything_ ? "true" : "false") << ")";
- DCHECK_GT(encrypted_types_.count(syncable::PASSWORDS), 0u);
+ DCHECK(encrypted_types_.Has(syncable::PASSWORDS));
}
void ProfileSyncService::OnEncryptionComplete() {
@@ -890,7 +877,7 @@ void ProfileSyncService::OnEncryptionComplete() {
}
void ProfileSyncService::OnMigrationNeededForTypes(
- const syncable::ModelTypeSet& types) {
+ syncable::ModelEnumSet types) {
DCHECK(backend_initialized_);
DCHECK(data_type_manager_.get());
@@ -1110,7 +1097,7 @@ void ProfileSyncService::OnUserSubmittedOAuth(
}
void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything,
- const syncable::ModelTypeSet& chosen_types) {
+ syncable::ModelEnumSet chosen_types) {
if (!backend_.get() &&
unrecoverable_error_detected_ == false) {
NOTREACHED();
@@ -1150,17 +1137,12 @@ void ProfileSyncService::OnUserCancelledDialog() {
}
void ProfileSyncService::ChangePreferredDataTypes(
- const syncable::ModelTypeSet& preferred_types) {
+ syncable::ModelEnumSet preferred_types) {
DVLOG(1) << "ChangePreferredDataTypes invoked";
- syncable::ModelTypeSet registered_types;
- GetRegisteredDataTypes(&registered_types);
- syncable::ModelTypeSet registered_preferred_types;
- std::set_intersection(
- registered_types.begin(), registered_types.end(),
- preferred_types.begin(), preferred_types.end(),
- std::inserter(registered_preferred_types,
- registered_preferred_types.end()));
+ const syncable::ModelEnumSet registered_types = GetRegisteredDataTypes();
+ const syncable::ModelEnumSet registered_preferred_types =
+ Intersection(registered_types, preferred_types);
sync_prefs_.SetPreferredDataTypes(registered_types,
registered_preferred_types);
@@ -1168,31 +1150,25 @@ void ProfileSyncService::ChangePreferredDataTypes(
ReconfigureDatatypeManager();
}
-void ProfileSyncService::GetPreferredDataTypes(
- syncable::ModelTypeSet* preferred_types) const {
- syncable::ModelTypeSet registered_types;
- GetRegisteredDataTypes(&registered_types);
- *preferred_types = sync_prefs_.GetPreferredDataTypes(registered_types);
-
- syncable::ModelTypeSet failed_types =
+syncable::ModelEnumSet ProfileSyncService::GetPreferredDataTypes() const {
+ const syncable::ModelEnumSet registered_types = GetRegisteredDataTypes();
+ const syncable::ModelEnumSet preferred_types =
+ sync_prefs_.GetPreferredDataTypes(registered_types);
+ const syncable::ModelEnumSet failed_types =
failed_datatypes_handler_.GetFailedTypes();
- syncable::ModelTypeSet difference;
- std::set_difference(preferred_types->begin(), preferred_types->end(),
- failed_types.begin(), failed_types.end(),
- std::inserter(difference, difference.end()));
- std::swap(*preferred_types, difference);
+ return Difference(preferred_types, failed_types);
}
-void ProfileSyncService::GetRegisteredDataTypes(
- syncable::ModelTypeSet* registered_types) const {
- registered_types->clear();
+syncable::ModelEnumSet ProfileSyncService::GetRegisteredDataTypes() const {
+ syncable::ModelEnumSet registered_types;
// The data_type_controllers_ are determined by command-line flags; that's
// effectively what controls the values returned here.
for (DataTypeController::TypeMap::const_iterator it =
data_type_controllers_.begin();
it != data_type_controllers_.end(); ++it) {
- registered_types->insert((*it).first);
+ registered_types.Put(it->first);
}
+ return registered_types;
}
bool ProfileSyncService::IsUsingSecondaryPassphrase() const {
@@ -1239,8 +1215,7 @@ void ProfileSyncService::ConfigureDataTypeManager() {
this, data_type_manager_.get()));
}
- syncable::ModelTypeSet types;
- GetPreferredDataTypes(&types);
+ const syncable::ModelEnumSet types = GetPreferredDataTypes();
if (IsPassphraseRequiredForDecryption()) {
// We need a passphrase still. We don't bother to attempt to configure
// until we receive an OnPassphraseAccepted (which triggers a configure).
@@ -1354,13 +1329,11 @@ bool ProfileSyncService::EncryptEverythingEnabled() const {
return encrypt_everything_;
}
-void ProfileSyncService::GetEncryptedDataTypes(
- syncable::ModelTypeSet* encrypted_types) const {
- CHECK(encrypted_types);
+syncable::ModelEnumSet ProfileSyncService::GetEncryptedDataTypes() const {
+ DCHECK(encrypted_types_.Has(syncable::PASSWORDS));
// We may be called during the setup process before we're
// initialized. In this case, we default to the sensitive types.
- *encrypted_types = encrypted_types_;
- DCHECK_GT(encrypted_types->count(syncable::PASSWORDS), 0u);
+ return encrypted_types_;
}
void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) {
@@ -1571,9 +1544,7 @@ void ProfileSyncService::UnsuppressAndStart() {
}
void ProfileSyncService::AcknowledgeSyncedTypes() {
- syncable::ModelTypeSet registered_types;
- GetRegisteredDataTypes(&registered_types);
- sync_prefs_.AcknowledgeSyncedTypes(registered_types);
+ sync_prefs_.AcknowledgeSyncedTypes(GetRegisteredDataTypes());
}
void ProfileSyncService::ReconfigureDatatypeManager() {
diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h
index 06181d0..79e1a94 100644
--- a/chrome/browser/sync/profile_sync_service.h
+++ b/chrome/browser/sync/profile_sync_service.h
@@ -212,13 +212,13 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
sync_api::PassphraseRequiredReason reason) OVERRIDE;
virtual void OnPassphraseAccepted() OVERRIDE;
virtual void OnEncryptedTypesChanged(
- const syncable::ModelTypeSet& enncrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) OVERRIDE;
virtual void OnEncryptionComplete() OVERRIDE;
virtual void OnMigrationNeededForTypes(
- const syncable::ModelTypeSet& types) OVERRIDE;
+ syncable::ModelEnumSet types) OVERRIDE;
virtual void OnDataTypesChanged(
- const syncable::ModelTypeSet& to_add) OVERRIDE;
+ syncable::ModelEnumSet to_add) OVERRIDE;
virtual void OnActionableError(
const browser_sync::SyncProtocolError& error) OVERRIDE;
@@ -242,7 +242,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
// and all data types will be synced. |sync_everything| means "sync all
// current and future data types."
virtual void OnUserChoseDatatypes(bool sync_everything,
- const syncable::ModelTypeSet& chosen_types);
+ syncable::ModelEnumSet chosen_types);
// Called when a user cancels any setup dialog (login, etc).
virtual void OnUserCancelledDialog();
@@ -410,20 +410,18 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
// the sync backend so that exactly these datatypes are actively synced. See
// class comment for more on what it means for a datatype to be Preferred.
virtual void ChangePreferredDataTypes(
- const syncable::ModelTypeSet& preferred_types);
+ syncable::ModelEnumSet preferred_types);
// Get the set of currently enabled data types (as chosen or configured by
// the user). See class comment for more on what it means for a datatype
// to be Preferred.
- virtual void GetPreferredDataTypes(
- syncable::ModelTypeSet* preferred_types) const;
+ virtual syncable::ModelEnumSet GetPreferredDataTypes() const;
// Gets the set of all data types that could be allowed (the set that
// should be advertised to the user). These will typically only change
// via a command-line option. See class comment for more on what it means
// for a datatype to be Registered.
- virtual void GetRegisteredDataTypes(
- syncable::ModelTypeSet* registered_types) const;
+ virtual syncable::ModelEnumSet GetRegisteredDataTypes() const;
// Checks whether the Cryptographer is ready to encrypt and decrypt updates
// for sensitive data types. Caller must be holding a
@@ -458,8 +456,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
// Fills |encrypted_types| with the set of currently encrypted types. Does
// not account for types pending encryption.
- virtual void GetEncryptedDataTypes(
- syncable::ModelTypeSet* encrypted_types) const;
+ virtual syncable::ModelEnumSet GetEncryptedDataTypes() const;
// Returns true if the syncer is waiting for new datatypes to be encrypted.
virtual bool encryption_pending() const;
@@ -679,7 +676,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
// The current set of encrypted types. Always a superset of
// Cryptographer::SensitiveTypes().
- syncable::ModelTypeSet encrypted_types_;
+ syncable::ModelEnumSet encrypted_types_;
// Whether we want to encrypt everything.
bool encrypt_everything_;
diff --git a/chrome/browser/sync/profile_sync_service_harness.cc b/chrome/browser/sync/profile_sync_service_harness.cc
index 1b465a6..05bb5fe 100644
--- a/chrome/browser/sync/profile_sync_service_harness.cc
+++ b/chrome/browser/sync/profile_sync_service_harness.cc
@@ -4,8 +4,7 @@
#include "chrome/browser/sync/profile_sync_service_harness.h"
-#include <stddef.h>
-#include <algorithm>
+#include <cstddef>
#include <iterator>
#include <ostream>
#include <set>
@@ -138,12 +137,7 @@ bool ProfileSyncServiceHarness::IsSyncAlreadySetup() {
}
bool ProfileSyncServiceHarness::SetupSync() {
- syncable::ModelTypeSet synced_datatypes;
- for (int i = syncable::FIRST_REAL_MODEL_TYPE;
- i < syncable::MODEL_TYPE_COUNT; ++i) {
- synced_datatypes.insert(syncable::ModelTypeFromInt(i));
- }
- bool result = SetupSync(synced_datatypes);
+ bool result = SetupSync(syncable::ModelEnumSet::All());
if (result == false) {
std::string status = GetServiceStatus();
LOG(ERROR) << profile_debug_name_
@@ -155,7 +149,7 @@ bool ProfileSyncServiceHarness::SetupSync() {
}
bool ProfileSyncServiceHarness::SetupSync(
- const syncable::ModelTypeSet& synced_datatypes) {
+ syncable::ModelEnumSet synced_datatypes) {
// Initialize the sync client's profile sync service object.
service_ = profile_->GetProfileSyncService("");
if (service_ == NULL) {
@@ -180,8 +174,8 @@ bool ProfileSyncServiceHarness::SetupSync(
// Choose the datatypes to be synced. If all datatypes are to be synced,
// set sync_everything to true; otherwise, set it to false.
- bool sync_everything = (synced_datatypes.size() ==
- (syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE));
+ bool sync_everything =
+ synced_datatypes.Equals(syncable::ModelEnumSet::All());
service()->OnUserChoseDatatypes(sync_everything, synced_datatypes);
// Subscribe sync client to notifications from the backend migrator
@@ -454,31 +448,18 @@ void ProfileSyncServiceHarness::OnMigrationStateChange() {
if (HasPendingBackendMigration()) {
// Merge current pending migration types into
// |pending_migration_types_|.
- syncable::ModelTypeSet new_pending_migration_types =
+ pending_migration_types_.PutAll(
service()->GetBackendMigratorForTest()->
- GetPendingMigrationTypesForTest();
- syncable::ModelTypeSet temp;
- std::set_union(pending_migration_types_.begin(),
- pending_migration_types_.end(),
- new_pending_migration_types.begin(),
- new_pending_migration_types.end(),
- std::inserter(temp, temp.end()));
- std::swap(pending_migration_types_, temp);
+ GetPendingMigrationTypesForTest());
DVLOG(1) << profile_debug_name_ << ": new pending migration types "
- << syncable::ModelTypeSetToString(pending_migration_types_);
+ << syncable::ModelEnumSetToString(pending_migration_types_);
} else {
// Merge just-finished pending migration types into
// |migration_types_|.
- syncable::ModelTypeSet temp;
- std::set_union(pending_migration_types_.begin(),
- pending_migration_types_.end(),
- migrated_types_.begin(),
- migrated_types_.end(),
- std::inserter(temp, temp.end()));
- std::swap(migrated_types_, temp);
- pending_migration_types_.clear();
+ migrated_types_.PutAll(pending_migration_types_);
+ pending_migration_types_.Clear();
DVLOG(1) << profile_debug_name_ << ": new migrated types "
- << syncable::ModelTypeSetToString(migrated_types_);
+ << syncable::ModelEnumSetToString(migrated_types_);
}
RunStateChangeMachine();
}
@@ -643,19 +624,16 @@ bool ProfileSyncServiceHarness::AwaitActionableError() {
}
bool ProfileSyncServiceHarness::AwaitMigration(
- const syncable::ModelTypeSet& expected_migrated_types) {
+ syncable::ModelEnumSet expected_migrated_types) {
DVLOG(1) << GetClientInfoString("AwaitMigration");
DVLOG(1) << profile_debug_name_ << ": waiting until migration is done for "
- << syncable::ModelTypeSetToString(expected_migrated_types);
+ << syncable::ModelEnumSetToString(expected_migrated_types);
while (true) {
- bool migration_finished =
- std::includes(migrated_types_.begin(), migrated_types_.end(),
- expected_migrated_types.begin(),
- expected_migrated_types.end());
+ bool migration_finished = migrated_types_.HasAll(expected_migrated_types);
DVLOG(1) << "Migrated types "
- << syncable::ModelTypeSetToString(migrated_types_)
+ << syncable::ModelEnumSetToString(migrated_types_)
<< (migration_finished ? " contains " : " does not contain ")
- << syncable::ModelTypeSetToString(expected_migrated_types);
+ << syncable::ModelEnumSetToString(expected_migrated_types);
if (migration_finished) {
return true;
}
@@ -845,28 +823,24 @@ bool ProfileSyncServiceHarness::MatchesOtherClient(
// Only look for a match if we have at least one enabled datatype in
// common with the partner client.
- syncable::ModelTypeSet types, other_types, intersection_types;
- service()->GetPreferredDataTypes(&types);
- partner->service()->GetPreferredDataTypes(&other_types);
- std::set_intersection(types.begin(), types.end(), other_types.begin(),
- other_types.end(),
- inserter(intersection_types,
- intersection_types.begin()));
+ const syncable::ModelEnumSet common_types =
+ Intersection(service()->GetPreferredDataTypes(),
+ partner->service()->GetPreferredDataTypes());
DVLOG(2) << profile_debug_name_ << ", " << partner->profile_debug_name_
<< ": common types are "
- << syncable::ModelTypeSetToString(intersection_types);
+ << syncable::ModelEnumSetToString(common_types);
- if (!intersection_types.empty() && !partner->IsFullySynced()) {
+ if (!common_types.Empty() && !partner->IsFullySynced()) {
DVLOG(2) << "non-empty common types and "
<< partner->profile_debug_name_ << " isn't synced";
return false;
}
- for (syncable::ModelTypeSet::iterator i = intersection_types.begin();
- i != intersection_types.end(); ++i) {
- const std::string timestamp = GetUpdatedTimestamp(*i);
- const std::string partner_timestamp = partner->GetUpdatedTimestamp(*i);
+ for (syncable::ModelEnumSet::Iterator i = common_types.First();
+ i.Good(); i.Inc()) {
+ const std::string timestamp = GetUpdatedTimestamp(i.Get());
+ const std::string partner_timestamp = partner->GetUpdatedTimestamp(i.Get());
if (timestamp != partner_timestamp) {
if (VLOG_IS_ON(2)) {
std::string timestamp_base64, partner_timestamp_base64;
@@ -877,7 +851,7 @@ bool ProfileSyncServiceHarness::MatchesOtherClient(
partner_timestamp, &partner_timestamp_base64)) {
NOTREACHED();
}
- DVLOG(2) << syncable::ModelTypeToString(*i) << ": "
+ DVLOG(2) << syncable::ModelTypeToString(i.Get()) << ": "
<< profile_debug_name_ << " timestamp = "
<< timestamp_base64 << ", "
<< partner->profile_debug_name_
@@ -905,10 +879,8 @@ bool ProfileSyncServiceHarness::EnableSyncForDatatype(
"EnableSyncForDatatype("
+ std::string(syncable::ModelTypeToString(datatype)) + ")");
- syncable::ModelTypeSet synced_datatypes;
if (wait_state_ == SYNC_DISABLED) {
- synced_datatypes.insert(datatype);
- return SetupSync(synced_datatypes);
+ return SetupSync(syncable::ModelEnumSet(datatype));
}
if (service() == NULL) {
@@ -916,16 +888,16 @@ bool ProfileSyncServiceHarness::EnableSyncForDatatype(
return false;
}
- service()->GetPreferredDataTypes(&synced_datatypes);
- syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype);
- if (it != synced_datatypes.end()) {
+ syncable::ModelEnumSet synced_datatypes =
+ service()->GetPreferredDataTypes();
+ if (synced_datatypes.Has(datatype)) {
DVLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype "
<< syncable::ModelTypeToString(datatype)
<< " on " << profile_debug_name_ << ".";
return true;
}
- synced_datatypes.insert(syncable::ModelTypeFromInt(datatype));
+ synced_datatypes.Put(syncable::ModelTypeFromInt(datatype));
service()->OnUserChoseDatatypes(false, synced_datatypes);
if (AwaitFullSyncCompletion("Datatype configuration.")) {
DVLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype "
@@ -944,22 +916,21 @@ bool ProfileSyncServiceHarness::DisableSyncForDatatype(
"DisableSyncForDatatype("
+ std::string(syncable::ModelTypeToString(datatype)) + ")");
- syncable::ModelTypeSet synced_datatypes;
if (service() == NULL) {
LOG(ERROR) << "DisableSyncForDatatype(): service() is null.";
return false;
}
- service()->GetPreferredDataTypes(&synced_datatypes);
- syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype);
- if (it == synced_datatypes.end()) {
+ syncable::ModelEnumSet synced_datatypes =
+ service()->GetPreferredDataTypes();
+ if (!synced_datatypes.Has(datatype)) {
DVLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype "
<< syncable::ModelTypeToString(datatype)
<< " on " << profile_debug_name_ << ".";
return true;
}
- synced_datatypes.erase(it);
+ synced_datatypes.Remove(datatype);
service()->OnUserChoseDatatypes(false, synced_datatypes);
if (AwaitFullSyncCompletion("Datatype reconfiguration.")) {
DVLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype "
@@ -984,13 +955,7 @@ bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() {
return false;
}
- syncable::ModelTypeSet synced_datatypes;
- for (int i = syncable::FIRST_REAL_MODEL_TYPE;
- i < syncable::MODEL_TYPE_COUNT;
- ++i) {
- synced_datatypes.insert(syncable::ModelTypeFromInt(i));
- }
- service()->OnUserChoseDatatypes(true, synced_datatypes);
+ service()->OnUserChoseDatatypes(true, syncable::ModelEnumSet::All());
if (AwaitFullSyncCompletion("Datatype reconfiguration.")) {
DVLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes "
<< "on " << profile_debug_name_ << ".";
@@ -1066,20 +1031,19 @@ std::string ProfileSyncServiceHarness::GetClientInfoString(
// encryption for individual types but for all.
bool ProfileSyncServiceHarness::EnableEncryptionForType(
syncable::ModelType type) {
- syncable::ModelTypeSet encrypted_types;
- service_->GetEncryptedDataTypes(&encrypted_types);
- if (encrypted_types.count(type) > 0)
+ const syncable::ModelEnumSet encrypted_types =
+ service_->GetEncryptedDataTypes();
+ if (encrypted_types.Has(type))
return true;
service_->EnableEncryptEverything();
// In order to kick off the encryption we have to reconfigure. Just grab the
// currently synced types and use them.
- syncable::ModelTypeSet synced_datatypes;
- service_->GetPreferredDataTypes(&synced_datatypes);
- bool sync_everything = (synced_datatypes.size() ==
- (syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE));
- service_->OnUserChoseDatatypes(sync_everything,
- synced_datatypes);
+ const syncable::ModelEnumSet synced_datatypes =
+ service_->GetPreferredDataTypes();
+ bool sync_everything =
+ synced_datatypes.Equals(syncable::ModelEnumSet::All());
+ service_->OnUserChoseDatatypes(sync_everything, synced_datatypes);
// Wait some time to let the enryption finish.
return WaitForTypeEncryption(type);
@@ -1110,13 +1074,13 @@ bool ProfileSyncServiceHarness::WaitForTypeEncryption(
}
bool ProfileSyncServiceHarness::IsTypeEncrypted(syncable::ModelType type) {
- syncable::ModelTypeSet encrypted_types;
- service_->GetEncryptedDataTypes(&encrypted_types);
- bool is_type_encrypted = (encrypted_types.count(type) != 0);
+ const syncable::ModelEnumSet encrypted_types =
+ service_->GetEncryptedDataTypes();
+ bool is_type_encrypted = service_->GetEncryptedDataTypes().Has(type);
DVLOG(2) << syncable::ModelTypeToString(type) << " is "
<< (is_type_encrypted ? "" : "not ") << "encrypted; "
<< "encrypted types = "
- << syncable::ModelTypeSetToString(encrypted_types);
+ << syncable::ModelEnumSetToString(encrypted_types);
return is_type_encrypted;
}
@@ -1128,9 +1092,7 @@ bool ProfileSyncServiceHarness::IsTypeRunning(syncable::ModelType type) {
}
bool ProfileSyncServiceHarness::IsTypePreferred(syncable::ModelType type) {
- syncable::ModelTypeSet synced_types;
- service_->GetPreferredDataTypes(&synced_types);
- return (synced_types.count(type) != 0);
+ return service_->GetPreferredDataTypes().Has(type);
}
std::string ProfileSyncServiceHarness::GetServiceStatus() {
diff --git a/chrome/browser/sync/profile_sync_service_harness.h b/chrome/browser/sync/profile_sync_service_harness.h
index 4ac71c0..4317e34 100644
--- a/chrome/browser/sync/profile_sync_service_harness.h
+++ b/chrome/browser/sync/profile_sync_service_harness.h
@@ -59,7 +59,7 @@ class ProfileSyncServiceHarness
// Same as the above method, but enables sync only for the datatypes contained
// in |synced_datatypes|.
- bool SetupSync(const syncable::ModelTypeSet& synced_datatypes);
+ bool SetupSync(syncable::ModelEnumSet synced_datatypes);
// ProfileSyncServiceObserver implementation.
virtual void OnStateChanged() OVERRIDE;
@@ -102,7 +102,7 @@ class ProfileSyncServiceHarness
bool AwaitActionableError();
// Blocks until the given set of data types are migrated.
- bool AwaitMigration(const syncable::ModelTypeSet& expected_migrated_types);
+ bool AwaitMigration(syncable::ModelEnumSet expected_migrated_types);
// Blocks the caller until this harness has observed that the sync engine
// has downloaded all the changes seen by the |partner| harness's client.
@@ -335,11 +335,11 @@ class ProfileSyncServiceHarness
// The current set of data types pending migration. Used by
// AwaitMigration().
- syncable::ModelTypeSet pending_migration_types_;
+ syncable::ModelEnumSet pending_migration_types_;
// The set of data types that have undergone migration. Used by
// AwaitMigration().
- syncable::ModelTypeSet migrated_types_;
+ syncable::ModelEnumSet migrated_types_;
// Used for logging.
const std::string profile_debug_name_;
diff --git a/chrome/browser/sync/profile_sync_service_mock.h b/chrome/browser/sync/profile_sync_service_mock.h
index 23dcce2..49cd7b1 100644
--- a/chrome/browser/sync/profile_sync_service_mock.h
+++ b/chrome/browser/sync/profile_sync_service_mock.h
@@ -57,11 +57,9 @@ class ProfileSyncServiceMock : public ProfileSyncService {
MOCK_CONST_METHOD0(HasSyncSetupCompleted, bool());
MOCK_METHOD1(ChangePreferredDataTypes,
- void(const syncable::ModelTypeSet& preferred_types));
- MOCK_CONST_METHOD1(GetPreferredDataTypes,
- void(syncable::ModelTypeSet* preferred_types));
- MOCK_CONST_METHOD1(GetRegisteredDataTypes,
- void(syncable::ModelTypeSet* registered_types));
+ void(syncable::ModelEnumSet preferred_types));
+ MOCK_CONST_METHOD0(GetPreferredDataTypes, syncable::ModelEnumSet());
+ MOCK_CONST_METHOD0(GetRegisteredDataTypes, syncable::ModelEnumSet());
MOCK_CONST_METHOD0(GetLastSessionSnapshot,
const browser_sync::sessions::SyncSessionSnapshot*());
diff --git a/chrome/browser/sync/profile_sync_service_password_unittest.cc b/chrome/browser/sync/profile_sync_service_password_unittest.cc
index cfb4084..4ee02c4 100644
--- a/chrome/browser/sync/profile_sync_service_password_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_password_unittest.cc
@@ -215,9 +215,9 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest {
service_.reset(new PasswordTestProfileSyncService(
&factory_, &profile_, "test_user", false,
root_callback, node_callback));
- syncable::ModelTypeSet preferred_types;
- service_->GetPreferredDataTypes(&preferred_types);
- preferred_types.insert(syncable::PASSWORDS);
+ syncable::ModelEnumSet preferred_types =
+ service_->GetPreferredDataTypes();
+ preferred_types.Put(syncable::PASSWORDS);
service_->ChangePreferredDataTypes(preferred_types);
EXPECT_CALL(profile_, GetProfileSyncService()).WillRepeatedly(
Return(service_.get()));
diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
index 04ae1f9..b5a773b 100644
--- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
@@ -127,9 +127,8 @@ TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
profile_->GetTokenService()->IssueAuthTokenForTest(
GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
- syncable::ModelTypeSet set;
- set.insert(syncable::BOOKMARKS);
- service_->OnUserChoseDatatypes(false, set);
+ service_->OnUserChoseDatatypes(
+ false, syncable::ModelEnumSet(syncable::BOOKMARKS));
EXPECT_TRUE(service_->ShouldPushChanges());
}
@@ -278,7 +277,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartFailure) {
errors.push_back(error);
browser_sync::DataTypeManager::ConfigureResult result(
status,
- syncable::ModelTypeSet(),
+ syncable::ModelEnumSet(),
errors);
EXPECT_CALL(*data_type_manager, Configure(_, _)).
WillRepeatedly(
diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
index 0d2d0f7..82d5c64 100644
--- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
@@ -702,8 +702,8 @@ TEST_F(ProfileSyncServiceTypedUrlTest, FailWriteToHistoryBackend) {
WillRepeatedly(Return(false));
StartSyncService(base::Bind(&AddTypedUrlEntries, this, sync_entries));
ASSERT_TRUE(
- service_->failed_datatypes_handler().GetFailedTypes().count(
- syncable::TYPED_URLS) != 0);
- ASSERT_TRUE(
- service_->failed_datatypes_handler().GetFailedTypes().size() == 1);
+ service_->failed_datatypes_handler().GetFailedTypes().Has(
+ syncable::TYPED_URLS));
+ ASSERT_EQ(
+ 1u, service_->failed_datatypes_handler().GetFailedTypes().Size());
}
diff --git a/chrome/browser/sync/protocol/sync_protocol_error.h b/chrome/browser/sync/protocol/sync_protocol_error.h
index 0729989..9121ff0 100644
--- a/chrome/browser/sync/protocol/sync_protocol_error.h
+++ b/chrome/browser/sync/protocol/sync_protocol_error.h
@@ -68,7 +68,7 @@ struct SyncProtocolError {
std::string error_description;
std::string url;
ClientAction action;
- syncable::ModelTypeSet error_data_types;
+ syncable::ModelEnumSet error_data_types;
SyncProtocolError();
~SyncProtocolError();
DictionaryValue* ToValue() const;
diff --git a/chrome/browser/sync/sessions/sync_session_context.cc b/chrome/browser/sync/sessions/sync_session_context.cc
index 8a11c85..fdc9e7d 100644
--- a/chrome/browser/sync/sessions/sync_session_context.cc
+++ b/chrome/browser/sync/sessions/sync_session_context.cc
@@ -49,12 +49,11 @@ SyncSessionContext::~SyncSessionContext() {
}
}
-void SyncSessionContext::SetUnthrottleTime(const syncable::ModelTypeSet& types,
+void SyncSessionContext::SetUnthrottleTime(syncable::ModelEnumSet types,
const base::TimeTicks& time) {
- for (syncable::ModelTypeSet::const_iterator it = types.begin();
- it != types.end();
- ++it) {
- unthrottle_times_[*it] = time;
+ for (syncable::ModelEnumSet::Iterator it = types.First();
+ it.Good(); it.Inc()) {
+ unthrottle_times_[it.Get()] = time;
}
}
@@ -75,12 +74,12 @@ void SyncSessionContext::PruneUnthrottledTypes(const base::TimeTicks& time) {
// TODO(lipalani): Call this function and fill the return values in snapshot
// so it could be shown in the about:sync page.
-syncable::ModelTypeSet SyncSessionContext::GetThrottledTypes() const {
- syncable::ModelTypeSet types;
+syncable::ModelEnumSet SyncSessionContext::GetThrottledTypes() const {
+ syncable::ModelEnumSet types;
for (UnthrottleTimes::const_iterator it = unthrottle_times_.begin();
it != unthrottle_times_.end();
++it) {
- types.insert(it->first);
+ types.Put(it->first);
}
return types;
}
diff --git a/chrome/browser/sync/sessions/sync_session_context.h b/chrome/browser/sync/sessions/sync_session_context.h
index 1ca222e..a5324bc 100644
--- a/chrome/browser/sync/sessions/sync_session_context.h
+++ b/chrome/browser/sync/sessions/sync_session_context.h
@@ -110,7 +110,7 @@ class SyncSessionContext {
}
// This is virtual for unit tests.
- virtual void SetUnthrottleTime(const syncable::ModelTypeSet& types,
+ virtual void SetUnthrottleTime(syncable::ModelEnumSet types,
const base::TimeTicks& time);
// This prunes the |unthrottle_time_| map based on the |time| passed in. This
@@ -119,7 +119,7 @@ class SyncSessionContext {
// This returns the list of currently throttled types. Unless server returns
// new throttled types this will remain constant through out the sync cycle.
- syncable::ModelTypeSet GetThrottledTypes() const;
+ syncable::ModelEnumSet GetThrottledTypes() const;
private:
typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes;
diff --git a/chrome/browser/sync/sessions/sync_session_context_unittest.cc b/chrome/browser/sync/sessions/sync_session_context_unittest.cc
index db7eb77..4a43752 100644
--- a/chrome/browser/sync/sessions/sync_session_context_unittest.cc
+++ b/chrome/browser/sync/sessions/sync_session_context_unittest.cc
@@ -10,9 +10,8 @@
namespace browser_sync {
namespace sessions {
TEST(SyncSessionContextTest, AddUnthrottleTimeTest) {
- syncable::ModelTypeSet types;
- types.insert(syncable::BOOKMARKS);
- types.insert(syncable::PASSWORDS);
+ const syncable::ModelEnumSet types(
+ syncable::BOOKMARKS, syncable::PASSWORDS);
SyncSessionContext context;
base::TimeTicks now = base::TimeTicks::Now();
@@ -24,9 +23,8 @@ TEST(SyncSessionContextTest, AddUnthrottleTimeTest) {
}
TEST(SyncSessionContextTest, GetCurrentlyThrottledTypesTest) {
- syncable::ModelTypeSet types;
- types.insert(syncable::BOOKMARKS);
- types.insert(syncable::PASSWORDS);
+ const syncable::ModelEnumSet types(
+ syncable::BOOKMARKS, syncable::PASSWORDS);
SyncSessionContext context;
base::TimeTicks now = base::TimeTicks::Now();
@@ -35,12 +33,12 @@ TEST(SyncSessionContextTest, GetCurrentlyThrottledTypesTest) {
// now.
context.SetUnthrottleTime(types, now - base::TimeDelta::FromSeconds(10));
context.PruneUnthrottledTypes(base::TimeTicks::Now());
- EXPECT_EQ(context.GetThrottledTypes(), syncable::ModelTypeSet());
+ EXPECT_TRUE(context.GetThrottledTypes().Empty());
// Now update the throttled types with time set to 2 hours from now.
context.SetUnthrottleTime(types, now + base::TimeDelta::FromSeconds(1200));
context.PruneUnthrottledTypes(base::TimeTicks::Now());
- EXPECT_EQ(context.GetThrottledTypes(), types);
+ EXPECT_TRUE(context.GetThrottledTypes().Equals(types));
}
} // namespace sessions.
} // namespace browser_sync
diff --git a/chrome/browser/sync/sync_prefs.cc b/chrome/browser/sync/sync_prefs.cc
index e013bda..bbaa8ec 100644
--- a/chrome/browser/sync/sync_prefs.cc
+++ b/chrome/browser/sync/sync_prefs.cc
@@ -123,11 +123,11 @@ void SyncPrefs::SetKeepEverythingSynced(bool keep_everything_synced) {
pref_service_->ScheduleSavePersistentPrefs();
}
-syncable::ModelTypeSet SyncPrefs::GetPreferredDataTypes(
- const syncable::ModelTypeSet& registered_types) const {
+syncable::ModelEnumSet SyncPrefs::GetPreferredDataTypes(
+ syncable::ModelEnumSet registered_types) const {
DCHECK(non_thread_safe_.CalledOnValidThread());
if (!pref_service_) {
- return syncable::ModelTypeSet();
+ return syncable::ModelEnumSet();
}
if (pref_service_->GetBoolean(prefs::kSyncKeepEverythingSynced)) {
@@ -136,93 +136,92 @@ syncable::ModelTypeSet SyncPrefs::GetPreferredDataTypes(
// Remove autofill_profile since it's controlled by autofill, and
// search_engines since it's controlled by preferences (see code below).
- syncable::ModelTypeSet user_selectable_types(registered_types);
- DCHECK_EQ(user_selectable_types.count(syncable::NIGORI), 0u);
- user_selectable_types.erase(syncable::AUTOFILL_PROFILE);
- user_selectable_types.erase(syncable::SEARCH_ENGINES);
+ syncable::ModelEnumSet user_selectable_types(registered_types);
+ DCHECK(!user_selectable_types.Has(syncable::NIGORI));
+ user_selectable_types.Remove(syncable::AUTOFILL_PROFILE);
+ user_selectable_types.Remove(syncable::SEARCH_ENGINES);
// Remove app_notifications since it's controlled by apps (see
// code below).
// TODO(akalin): Centralize notion of all user selectable data types.
- user_selectable_types.erase(syncable::APP_NOTIFICATIONS);
+ user_selectable_types.Remove(syncable::APP_NOTIFICATIONS);
- syncable::ModelTypeSet preferred_types;
+ syncable::ModelEnumSet preferred_types;
- for (syncable::ModelTypeSet::const_iterator it =
- user_selectable_types.begin();
- it != user_selectable_types.end(); ++it) {
- if (GetDataTypePreferred(*it)) {
- preferred_types.insert(*it);
+ for (syncable::ModelEnumSet::Iterator it = user_selectable_types.First();
+ it.Good(); it.Inc()) {
+ if (GetDataTypePreferred(it.Get())) {
+ preferred_types.Put(it.Get());
}
}
// Group the enabled/disabled state of autofill_profile with autofill, and
// search_engines with preferences (since only autofill and preferences are
// shown on the UI).
- if (registered_types.count(syncable::AUTOFILL) &&
- registered_types.count(syncable::AUTOFILL_PROFILE) &&
+ if (registered_types.Has(syncable::AUTOFILL) &&
+ registered_types.Has(syncable::AUTOFILL_PROFILE) &&
GetDataTypePreferred(syncable::AUTOFILL)) {
- preferred_types.insert(syncable::AUTOFILL_PROFILE);
+ preferred_types.Put(syncable::AUTOFILL_PROFILE);
}
- if (registered_types.count(syncable::PREFERENCES) &&
- registered_types.count(syncable::SEARCH_ENGINES) &&
+ if (registered_types.Has(syncable::PREFERENCES) &&
+ registered_types.Has(syncable::SEARCH_ENGINES) &&
GetDataTypePreferred(syncable::PREFERENCES)) {
- preferred_types.insert(syncable::SEARCH_ENGINES);
+ preferred_types.Put(syncable::SEARCH_ENGINES);
}
// Set app_notifications to the same enabled/disabled state as
// apps (since only apps is shown on the UI).
- if (registered_types.count(syncable::APPS) &&
- registered_types.count(syncable::APP_NOTIFICATIONS) &&
+ if (registered_types.Has(syncable::APPS) &&
+ registered_types.Has(syncable::APP_NOTIFICATIONS) &&
GetDataTypePreferred(syncable::APPS)) {
- preferred_types.insert(syncable::APP_NOTIFICATIONS);
+ preferred_types.Put(syncable::APP_NOTIFICATIONS);
}
return preferred_types;
}
void SyncPrefs::SetPreferredDataTypes(
- const syncable::ModelTypeSet& registered_types,
- const syncable::ModelTypeSet& preferred_types) {
+ syncable::ModelEnumSet registered_types,
+ syncable::ModelEnumSet preferred_types) {
DCHECK(non_thread_safe_.CalledOnValidThread());
CHECK(pref_service_);
- DCHECK(std::includes(registered_types.begin(), registered_types.end(),
- preferred_types.begin(), preferred_types.end()));
- syncable::ModelTypeSet preferred_types_with_dependents(preferred_types);
+ DCHECK(registered_types.HasAll(preferred_types));
+ syncable::ModelEnumSet preferred_types_with_dependents(preferred_types);
// Set autofill_profile to the same enabled/disabled state as
// autofill (since only autofill is shown in the UI).
- if (registered_types.count(syncable::AUTOFILL) &&
- registered_types.count(syncable::AUTOFILL_PROFILE)) {
- if (preferred_types_with_dependents.count(syncable::AUTOFILL)) {
- preferred_types_with_dependents.insert(syncable::AUTOFILL_PROFILE);
+ if (registered_types.Has(syncable::AUTOFILL) &&
+ registered_types.Has(syncable::AUTOFILL_PROFILE)) {
+ if (preferred_types_with_dependents.Has(syncable::AUTOFILL)) {
+ preferred_types_with_dependents.Put(syncable::AUTOFILL_PROFILE);
} else {
- preferred_types_with_dependents.erase(syncable::AUTOFILL_PROFILE);
+ preferred_types_with_dependents.Remove(syncable::AUTOFILL_PROFILE);
}
}
// Set app_notifications to the same enabled/disabled state as
// apps (since only apps is shown in the UI).
- if (registered_types.count(syncable::APPS) &&
- registered_types.count(syncable::APP_NOTIFICATIONS)) {
- if (preferred_types_with_dependents.count(syncable::APPS)) {
- preferred_types_with_dependents.insert(syncable::APP_NOTIFICATIONS);
+ if (registered_types.Has(syncable::APPS) &&
+ registered_types.Has(syncable::APP_NOTIFICATIONS)) {
+ if (preferred_types_with_dependents.Has(syncable::APPS)) {
+ preferred_types_with_dependents.Put(syncable::APP_NOTIFICATIONS);
} else {
- preferred_types_with_dependents.erase(syncable::APP_NOTIFICATIONS);
+ preferred_types_with_dependents.Remove(syncable::APP_NOTIFICATIONS);
}
}
// Set search_engines to the same enabled/disabled state as
// preferences (since only preferences is shown in the UI).
- if (registered_types.count(syncable::PREFERENCES) &&
- registered_types.count(syncable::SEARCH_ENGINES)) {
- if (preferred_types_with_dependents.count(syncable::PREFERENCES)) {
- preferred_types_with_dependents.insert(syncable::SEARCH_ENGINES);
+ if (registered_types.Has(syncable::PREFERENCES) &&
+ registered_types.Has(syncable::SEARCH_ENGINES)) {
+ if (preferred_types_with_dependents.Has(syncable::PREFERENCES)) {
+ preferred_types_with_dependents.Put(syncable::SEARCH_ENGINES);
} else {
- preferred_types_with_dependents.erase(syncable::SEARCH_ENGINES);
+ preferred_types_with_dependents.Remove(syncable::SEARCH_ENGINES);
}
}
- for (syncable::ModelTypeSet::const_iterator it = registered_types.begin();
- it != registered_types.end(); ++it) {
- SetDataTypePreferred(*it, preferred_types_with_dependents.count(*it) > 0);
+ for (syncable::ModelEnumSet::Iterator it = registered_types.First();
+ it.Good(); it.Inc()) {
+ SetDataTypePreferred(
+ it.Get(), preferred_types_with_dependents.Has(it.Get()));
}
}
@@ -314,25 +313,18 @@ void SyncPrefs::SetMaxVersion(syncable::ModelType model_type,
}
void SyncPrefs::AcknowledgeSyncedTypes(
- const syncable::ModelTypeSet& types) {
+ syncable::ModelEnumSet types) {
DCHECK(non_thread_safe_.CalledOnValidThread());
CHECK(pref_service_);
- syncable::ModelTypeSet acknowledged_types =
- syncable::ModelTypeSetFromValue(
- *pref_service_->GetList(prefs::kSyncAcknowledgedSyncTypes));
-
// Add the types to the current set of acknowledged
// types, and then store the resulting set in prefs.
- {
- syncable::ModelTypeSet temp;
- std::set_union(acknowledged_types.begin(), acknowledged_types.end(),
- types.begin(), types.end(),
- std::inserter(temp, temp.end()));
- std::swap(acknowledged_types, temp);
- }
+ const syncable::ModelEnumSet acknowledged_types =
+ Union(types,
+ syncable::ModelEnumSetFromValue(
+ *pref_service_->GetList(prefs::kSyncAcknowledgedSyncTypes)));
scoped_ptr<ListValue> value(
- syncable::ModelTypeSetToValue(acknowledged_types));
+ syncable::ModelEnumSetToValue(acknowledged_types));
pref_service_->Set(prefs::kSyncAcknowledgedSyncTypes, *value);
pref_service_->ScheduleSavePersistentPrefs();
}
@@ -365,12 +357,12 @@ void SyncPrefs::SetManagedForTest(bool is_managed) {
pref_service_->ScheduleSavePersistentPrefs();
}
-syncable::ModelTypeSet SyncPrefs::GetAcknowledgeSyncedTypesForTest() const {
+syncable::ModelEnumSet SyncPrefs::GetAcknowledgeSyncedTypesForTest() const {
DCHECK(non_thread_safe_.CalledOnValidThread());
if (!pref_service_) {
- return syncable::ModelTypeSet();
+ return syncable::ModelEnumSet();
}
- return syncable::ModelTypeSetFromValue(
+ return syncable::ModelEnumSetFromValue(
*pref_service_->GetList(prefs::kSyncAcknowledgedSyncTypes));
}
diff --git a/chrome/browser/sync/sync_prefs.h b/chrome/browser/sync/sync_prefs.h
index 460633a..7369da2 100644
--- a/chrome/browser/sync/sync_prefs.h
+++ b/chrome/browser/sync/sync_prefs.h
@@ -80,8 +80,8 @@ class SyncPrefs : public base::SupportsWeakPtr<SyncPrefs>,
// The returned set is guaranteed to be a subset of
// |registered_types|. Returns |registered_types| directly if
// HasKeepEverythingSynced() is true.
- syncable::ModelTypeSet GetPreferredDataTypes(
- const syncable::ModelTypeSet& registered_types) const;
+ syncable::ModelEnumSet GetPreferredDataTypes(
+ syncable::ModelEnumSet registered_types) const;
// |preferred_types| should be a subset of |registered_types|. All
// types in |preferred_types| are marked preferred, and all types in
// |registered_types| \ |preferred_types| are marked not preferred.
@@ -89,8 +89,8 @@ class SyncPrefs : public base::SupportsWeakPtr<SyncPrefs>,
// HasKeepEverythingSynced() is true, but won't be visible until
// SetKeepEverythingSynced(false) is called.
void SetPreferredDataTypes(
- const syncable::ModelTypeSet& registered_types,
- const syncable::ModelTypeSet& preferred_types);
+ syncable::ModelEnumSet registered_types,
+ syncable::ModelEnumSet preferred_types);
// This pref is set outside of sync.
bool IsManaged() const;
@@ -105,7 +105,7 @@ class SyncPrefs : public base::SupportsWeakPtr<SyncPrefs>,
int64 max_version) OVERRIDE;
// Merges the given set of types with the set of acknowledged types.
- void AcknowledgeSyncedTypes(const syncable::ModelTypeSet& types);
+ void AcknowledgeSyncedTypes(syncable::ModelEnumSet types);
// content::NotificationObserver implementation.
virtual void Observe(int type,
@@ -115,7 +115,7 @@ class SyncPrefs : public base::SupportsWeakPtr<SyncPrefs>,
// For testing.
void SetManagedForTest(bool is_managed);
- syncable::ModelTypeSet GetAcknowledgeSyncedTypesForTest() const;
+ syncable::ModelEnumSet GetAcknowledgeSyncedTypesForTest() const;
private:
void RegisterPreferences();
diff --git a/chrome/browser/sync/sync_prefs_unittest.cc b/chrome/browser/sync/sync_prefs_unittest.cc
index eb752a8..21ceffa 100644
--- a/chrome/browser/sync/sync_prefs_unittest.cc
+++ b/chrome/browser/sync/sync_prefs_unittest.cc
@@ -27,23 +27,18 @@ class SyncPrefsTest : public testing::Test {
};
// Get all types with a user-facing component.
-syncable::ModelTypeSet GetNonPassiveTypes() {
- syncable::ModelTypeSet all_types;
- for (int i = syncable::FIRST_REAL_MODEL_TYPE;
- i < syncable::MODEL_TYPE_COUNT; ++i) {
- const syncable::ModelType type = syncable::ModelTypeFromInt(i);
- all_types.insert(type);
- }
- all_types.erase(syncable::NIGORI);
- return all_types;
+syncable::ModelEnumSet GetNonPassiveTypes() {
+ syncable::ModelEnumSet non_passive_types = syncable::ModelEnumSet::All();
+ non_passive_types.Remove(syncable::NIGORI);
+ return non_passive_types;
}
// Returns all types visible from the setup UI.
-syncable::ModelTypeSet GetUserVisibleTypes() {
- syncable::ModelTypeSet user_visible_types(GetNonPassiveTypes());
- user_visible_types.erase(syncable::AUTOFILL_PROFILE);
- user_visible_types.erase(syncable::SEARCH_ENGINES);
- user_visible_types.erase(syncable::APP_NOTIFICATIONS);
+syncable::ModelEnumSet GetUserVisibleTypes() {
+ syncable::ModelEnumSet user_visible_types(GetNonPassiveTypes());
+ user_visible_types.Remove(syncable::AUTOFILL_PROFILE);
+ user_visible_types.Remove(syncable::SEARCH_ENGINES);
+ user_visible_types.Remove(syncable::APP_NOTIFICATIONS);
return user_visible_types;
}
@@ -81,17 +76,17 @@ TEST_F(SyncPrefsTest, PreferredTypesKeepEverythingSynced) {
EXPECT_TRUE(sync_prefs.HasKeepEverythingSynced());
- const syncable::ModelTypeSet& non_passive_types = GetNonPassiveTypes();
- EXPECT_EQ(non_passive_types,
- sync_prefs.GetPreferredDataTypes(non_passive_types));
- const syncable::ModelTypeSet& user_visible_types = GetUserVisibleTypes();
- for (syncable::ModelTypeSet::const_iterator it = user_visible_types.begin();
- it != user_visible_types.end(); ++it) {
- syncable::ModelTypeSet preferred_types;
- preferred_types.insert(*it);
+ const syncable::ModelEnumSet non_passive_types = GetNonPassiveTypes();
+ EXPECT_TRUE(non_passive_types.Equals(
+ sync_prefs.GetPreferredDataTypes(non_passive_types)));
+ const syncable::ModelEnumSet user_visible_types = GetUserVisibleTypes();
+ for (syncable::ModelEnumSet::Iterator it = user_visible_types.First();
+ it.Good(); it.Inc()) {
+ syncable::ModelEnumSet preferred_types;
+ preferred_types.Put(it.Get());
sync_prefs.SetPreferredDataTypes(non_passive_types, preferred_types);
- EXPECT_EQ(non_passive_types,
- sync_prefs.GetPreferredDataTypes(non_passive_types));
+ EXPECT_TRUE(non_passive_types.Equals(
+ sync_prefs.GetPreferredDataTypes(non_passive_types)));
}
}
@@ -100,27 +95,27 @@ TEST_F(SyncPrefsTest, PreferredTypesNotKeepEverythingSynced) {
sync_prefs.SetKeepEverythingSynced(false);
- const syncable::ModelTypeSet& non_passive_types = GetNonPassiveTypes();
- EXPECT_EQ(non_passive_types,
- sync_prefs.GetPreferredDataTypes(non_passive_types));
- const syncable::ModelTypeSet& user_visible_types = GetUserVisibleTypes();
- for (syncable::ModelTypeSet::const_iterator it = user_visible_types.begin();
- it != user_visible_types.end(); ++it) {
- syncable::ModelTypeSet preferred_types;
- preferred_types.insert(*it);
- syncable::ModelTypeSet expected_preferred_types(preferred_types);
- if (*it == syncable::AUTOFILL) {
- expected_preferred_types.insert(syncable::AUTOFILL_PROFILE);
+ const syncable::ModelEnumSet non_passive_types = GetNonPassiveTypes();
+ EXPECT_TRUE(non_passive_types.Equals(
+ sync_prefs.GetPreferredDataTypes(non_passive_types)));
+ const syncable::ModelEnumSet user_visible_types = GetUserVisibleTypes();
+ for (syncable::ModelEnumSet::Iterator it = user_visible_types.First();
+ it.Good(); it.Inc()) {
+ syncable::ModelEnumSet preferred_types;
+ preferred_types.Put(it.Get());
+ syncable::ModelEnumSet expected_preferred_types(preferred_types);
+ if (it.Get() == syncable::AUTOFILL) {
+ expected_preferred_types.Put(syncable::AUTOFILL_PROFILE);
}
- if (*it == syncable::PREFERENCES) {
- expected_preferred_types.insert(syncable::SEARCH_ENGINES);
+ if (it.Get() == syncable::PREFERENCES) {
+ expected_preferred_types.Put(syncable::SEARCH_ENGINES);
}
- if (*it == syncable::APPS) {
- expected_preferred_types.insert(syncable::APP_NOTIFICATIONS);
+ if (it.Get() == syncable::APPS) {
+ expected_preferred_types.Put(syncable::APP_NOTIFICATIONS);
}
sync_prefs.SetPreferredDataTypes(non_passive_types, preferred_types);
- EXPECT_EQ(expected_preferred_types,
- sync_prefs.GetPreferredDataTypes(non_passive_types));
+ EXPECT_TRUE(expected_preferred_types.Equals(
+ sync_prefs.GetPreferredDataTypes(non_passive_types)));
}
}
@@ -175,17 +170,16 @@ TEST_F(SyncPrefsTest, ObservedPrefs) {
TEST_F(SyncPrefsTest, AcknowledgeSyncedTypes) {
SyncPrefs sync_prefs(&pref_service_);
- syncable::ModelTypeSet expected_acknowledge_synced_types =
+ syncable::ModelEnumSet expected_acknowledge_synced_types =
sync_prefs.GetAcknowledgeSyncedTypesForTest();
for (int i = syncable::EXTENSION_SETTINGS;
i < syncable::MODEL_TYPE_COUNT; ++i) {
const syncable::ModelType type = syncable::ModelTypeFromInt(i);
- syncable::ModelTypeSet acknowledge_synced_types;
- acknowledge_synced_types.insert(type);
- expected_acknowledge_synced_types.insert(type);
+ syncable::ModelEnumSet acknowledge_synced_types(type);
+ expected_acknowledge_synced_types.Put(type);
sync_prefs.AcknowledgeSyncedTypes(acknowledge_synced_types);
- EXPECT_EQ(expected_acknowledge_synced_types,
- sync_prefs.GetAcknowledgeSyncedTypesForTest());
+ EXPECT_TRUE(expected_acknowledge_synced_types.Equals(
+ sync_prefs.GetAcknowledgeSyncedTypesForTest()));
}
}
@@ -226,8 +220,8 @@ TEST_F(SyncPrefsTest, NullPrefService) {
EXPECT_FALSE(sync_prefs.IsStartSuppressed());
EXPECT_EQ(base::Time(), sync_prefs.GetLastSyncedTime());
EXPECT_FALSE(sync_prefs.HasKeepEverythingSynced());
- const syncable::ModelTypeSet& non_passive_types = GetNonPassiveTypes();
- EXPECT_TRUE(sync_prefs.GetPreferredDataTypes(non_passive_types).empty());
+ const syncable::ModelEnumSet non_passive_types = GetNonPassiveTypes();
+ EXPECT_TRUE(sync_prefs.GetPreferredDataTypes(non_passive_types).Empty());
EXPECT_FALSE(sync_prefs.IsManaged());
EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty());
EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty());
diff --git a/chrome/browser/sync/sync_setup_flow.cc b/chrome/browser/sync/sync_setup_flow.cc
index e15bf73..a08bab1 100644
--- a/chrome/browser/sync/sync_setup_flow.cc
+++ b/chrome/browser/sync/sync_setup_flow.cc
@@ -29,9 +29,8 @@ namespace {
// Helper function to disable password sync.
void DisablePasswordSync(ProfileSyncService* service) {
- syncable::ModelTypeSet types;
- service->GetPreferredDataTypes(&types);
- types.erase(syncable::PASSWORDS);
+ syncable::ModelEnumSet types = service->GetPreferredDataTypes();
+ types.Remove(syncable::PASSWORDS);
service->OnUserChoseDatatypes(false, types);
}
@@ -124,40 +123,40 @@ void SyncSetupFlow::GetArgsForConfigure(ProfileSyncService* service,
// Bookmarks, Preferences, and Themes are launched for good, there's no
// going back now. Check if the other data types are registered though.
- syncable::ModelTypeSet registered_types;
- service->GetRegisteredDataTypes(&registered_types);
- syncable::ModelTypeSet preferred_types;
- service->GetPreferredDataTypes(&preferred_types);
+ const syncable::ModelEnumSet registered_types =
+ service->GetRegisteredDataTypes();
+ const syncable::ModelEnumSet preferred_types =
+ service->GetPreferredDataTypes();
args->SetBoolean("passwordsRegistered",
- registered_types.count(syncable::PASSWORDS) > 0);
+ registered_types.Has(syncable::PASSWORDS));
args->SetBoolean("autofillRegistered",
- registered_types.count(syncable::AUTOFILL) > 0);
+ registered_types.Has(syncable::AUTOFILL));
args->SetBoolean("extensionsRegistered",
- registered_types.count(syncable::EXTENSIONS) > 0);
+ registered_types.Has(syncable::EXTENSIONS));
args->SetBoolean("typedUrlsRegistered",
- registered_types.count(syncable::TYPED_URLS) > 0);
+ registered_types.Has(syncable::TYPED_URLS));
args->SetBoolean("appsRegistered",
- registered_types.count(syncable::APPS) > 0);
+ registered_types.Has(syncable::APPS));
args->SetBoolean("sessionsRegistered",
- registered_types.count(syncable::SESSIONS) > 0);
+ registered_types.Has(syncable::SESSIONS));
args->SetBoolean("syncBookmarks",
- preferred_types.count(syncable::BOOKMARKS) > 0);
+ preferred_types.Has(syncable::BOOKMARKS));
args->SetBoolean("syncPreferences",
- preferred_types.count(syncable::PREFERENCES) > 0);
+ preferred_types.Has(syncable::PREFERENCES));
args->SetBoolean("syncThemes",
- preferred_types.count(syncable::THEMES) > 0);
+ preferred_types.Has(syncable::THEMES));
args->SetBoolean("syncPasswords",
- preferred_types.count(syncable::PASSWORDS) > 0);
+ preferred_types.Has(syncable::PASSWORDS));
args->SetBoolean("syncAutofill",
- preferred_types.count(syncable::AUTOFILL) > 0);
+ preferred_types.Has(syncable::AUTOFILL));
args->SetBoolean("syncExtensions",
- preferred_types.count(syncable::EXTENSIONS) > 0);
+ preferred_types.Has(syncable::EXTENSIONS));
args->SetBoolean("syncSessions",
- preferred_types.count(syncable::SESSIONS) > 0);
+ preferred_types.Has(syncable::SESSIONS));
args->SetBoolean("syncTypedUrls",
- preferred_types.count(syncable::TYPED_URLS) > 0);
+ preferred_types.Has(syncable::TYPED_URLS));
args->SetBoolean("syncApps",
- preferred_types.count(syncable::APPS) > 0);
+ preferred_types.Has(syncable::APPS));
args->SetBoolean("encryptionEnabled",
!CommandLine::ForCurrentProcess()->HasSwitch(
diff --git a/chrome/browser/sync/sync_setup_flow.h b/chrome/browser/sync/sync_setup_flow.h
index 4fb9a93..712df92 100644
--- a/chrome/browser/sync/sync_setup_flow.h
+++ b/chrome/browser/sync/sync_setup_flow.h
@@ -30,7 +30,7 @@ struct SyncConfiguration {
bool encrypt_all;
bool sync_everything;
- syncable::ModelTypeSet data_types;
+ syncable::ModelEnumSet data_types;
// We pass a separate |set_xxxxx_passphrase| flag because sometimes the UI
// wants to set an empty gaia/secondary passphrase (for example, when the user
// doesn't enter a passphrase, but we still want the ProfileSyncService to
diff --git a/chrome/browser/sync/sync_setup_wizard_unittest.cc b/chrome/browser/sync/sync_setup_wizard_unittest.cc
index ba48588..879f465 100644
--- a/chrome/browser/sync/sync_setup_wizard_unittest.cc
+++ b/chrome/browser/sync/sync_setup_wizard_unittest.cc
@@ -81,7 +81,7 @@ class ProfileSyncServiceForWizardTest : public ProfileSyncService {
}
virtual void OnUserChoseDatatypes(bool sync_everything,
- const syncable::ModelTypeSet& chosen_types) {
+ syncable::ModelEnumSet chosen_types) {
user_chose_data_types_ = true;
chosen_data_types_ = chosen_types;
}
@@ -141,7 +141,7 @@ class ProfileSyncServiceForWizardTest : public ProfileSyncService {
user_cancelled_dialog_ = false;
user_chose_data_types_ = false;
keep_everything_synced_ = false;
- chosen_data_types_.clear();
+ chosen_data_types_.Clear();
}
// Use this to have the service act as if it were running under CrOS.
@@ -169,7 +169,7 @@ class ProfileSyncServiceForWizardTest : public ProfileSyncService {
bool keep_everything_synced_;
bool is_using_secondary_passphrase_;
bool encrypt_everything_;
- syncable::ModelTypeSet chosen_data_types_;
+ syncable::ModelEnumSet chosen_data_types_;
std::string passphrase_;
private:
@@ -342,15 +342,15 @@ TEST_F(SyncSetupWizardTest, ChooseDataTypesSetsPrefs) {
// DONE state and closed the UI.
EXPECT_FALSE(wizard_->IsVisible());
EXPECT_FALSE(service_->keep_everything_synced_);
- EXPECT_EQ(1U, service_->chosen_data_types_.count(syncable::BOOKMARKS));
- EXPECT_EQ(1U, service_->chosen_data_types_.count(syncable::PREFERENCES));
- EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::THEMES));
- EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::PASSWORDS));
- EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::AUTOFILL));
- EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::EXTENSIONS));
- EXPECT_EQ(1U, service_->chosen_data_types_.count(syncable::TYPED_URLS));
- EXPECT_EQ(1U, service_->chosen_data_types_.count(syncable::APPS));
- EXPECT_EQ(0U, service_->chosen_data_types_.count(
+ EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::BOOKMARKS));
+ EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::PREFERENCES));
+ EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::THEMES));
+ EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::PASSWORDS));
+ EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::AUTOFILL));
+ EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::EXTENSIONS));
+ EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::TYPED_URLS));
+ EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::APPS));
+ EXPECT_FALSE(service_->chosen_data_types_.Has(
syncable::APP_NOTIFICATIONS));
}
diff --git a/chrome/browser/sync/sync_ui_util.cc b/chrome/browser/sync/sync_ui_util.cc
index 7cc2091..6e4ae48 100644
--- a/chrome/browser/sync/sync_ui_util.cc
+++ b/chrome/browser/sync/sync_ui_util.cc
@@ -613,7 +613,7 @@ void ConstructAboutInformation(ProfileSyncService* service,
full_status.crypto_has_pending_keys);
sync_ui_util::AddStringSyncDetails(details,
"Encrypted Types",
- syncable::ModelTypeSetToString(full_status.encrypted_types));
+ syncable::ModelEnumSetToString(full_status.encrypted_types));
const browser_sync::sessions::SyncSessionSnapshot* snapshot =
service->sync_initialized() ?
diff --git a/chrome/browser/sync/syncable/model_type.cc b/chrome/browser/sync/syncable/model_type.cc
index b7e147c..4bbadbf 100644
--- a/chrome/browser/sync/syncable/model_type.cc
+++ b/chrome/browser/sync/syncable/model_type.cc
@@ -287,17 +287,6 @@ StringValue* ModelTypeToValue(ModelType model_type) {
return Value::CreateStringValue("");
}
-std::string ModelTypeSetToString(const ModelTypeSet& model_types) {
- std::string result;
- for (ModelTypeSet::const_iterator iter = model_types.begin();
- iter != model_types.end();) {
- result += ModelTypeToString(*iter);
- if (++iter != model_types.end())
- result += ", ";
- }
- return result;
-}
-
ModelType ModelTypeFromValue(const Value& value) {
if (value.IsType(Value::TYPE_STRING)) {
std::string result;
@@ -361,23 +350,6 @@ std::string ModelEnumSetToString(ModelEnumSet model_types) {
return result;
}
-ModelTypeSet ModelEnumSetToSet(ModelEnumSet enum_set) {
- ModelTypeSet model_type_set;
- for (ModelEnumSet::Iterator it = enum_set.First(); it.Good(); it.Inc()) {
- model_type_set.insert(it.Get());
- }
- return model_type_set;
-}
-
-ModelEnumSet ModelTypeSetToEnumSet(const ModelTypeSet& model_type_set) {
- ModelEnumSet enum_set;
- for (ModelTypeSet::const_iterator it = model_type_set.begin();
- it != model_type_set.end(); ++it) {
- enum_set.Put(*it);
- }
- return enum_set;
-}
-
base::ListValue* ModelEnumSetToValue(ModelEnumSet model_types) {
ListValue* value = new ListValue();
for (ModelEnumSet::Iterator it = model_types.First(); it.Good(); it.Inc()) {
@@ -387,23 +359,6 @@ base::ListValue* ModelEnumSetToValue(ModelEnumSet model_types) {
return value;
}
-ListValue* ModelTypeSetToValue(const ModelTypeSet& model_types) {
- ListValue* value = new ListValue();
- for (ModelTypeSet::const_iterator i = model_types.begin();
- i != model_types.end(); ++i) {
- value->Append(Value::CreateStringValue(ModelTypeToString(*i)));
- }
- return value;
-}
-
-ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value) {
- ModelTypeSet result;
- for (ListValue::const_iterator i = value.begin(); i != value.end(); ++i) {
- result.insert(ModelTypeFromValue(**i));
- }
- return result;
-}
-
ModelEnumSet ModelEnumSetFromValue(const base::ListValue& value) {
ModelEnumSet result;
for (ListValue::const_iterator i = value.begin(); i != value.end(); ++i) {
@@ -656,14 +611,6 @@ bool NotificationTypeToRealModelType(const std::string& notification_type,
}
}
-ModelTypeSet GetAllRealModelTypes() {
- ModelTypeSet all_types;
- for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
- all_types.insert(ModelTypeFromInt(i));
- }
- return all_types;
-}
-
bool IsRealDataType(ModelType model_type) {
return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT;
}
diff --git a/chrome/browser/sync/syncable/model_type.h b/chrome/browser/sync/syncable/model_type.h
index f31c377..a532e02 100644
--- a/chrome/browser/sync/syncable/model_type.h
+++ b/chrome/browser/sync/syncable/model_type.h
@@ -85,7 +85,6 @@ enum ModelType {
MODEL_TYPE_COUNT,
};
-typedef std::set<ModelType> ModelTypeSet;
typedef browser_sync::EnumSet<
ModelType, FIRST_REAL_MODEL_TYPE, LAST_REAL_MODEL_TYPE> ModelEnumSet;
typedef browser_sync::EnumSet<
@@ -137,25 +136,14 @@ base::StringValue* ModelTypeToValue(ModelType model_type);
// Converts a Value into a ModelType - complement to ModelTypeToValue().
ModelType ModelTypeFromValue(const base::Value& value);
-std::string ModelTypeSetToString(const ModelTypeSet& model_types);
-
// Returns the ModelType corresponding to the name |model_type_string|.
ModelType ModelTypeFromString(const std::string& model_type_string);
std::string ModelEnumSetToString(ModelEnumSet model_types);
-ModelTypeSet ModelEnumSetToSet(ModelEnumSet enum_set);
-
-ModelEnumSet ModelTypeSetToEnumSet(const ModelTypeSet& model_type_set);
-
// Caller takes ownership of returned list.
base::ListValue* ModelEnumSetToValue(ModelEnumSet model_types);
-// Caller takes ownership of returned list.
-base::ListValue* ModelTypeSetToValue(const ModelTypeSet& model_types);
-
-ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value);
-
ModelEnumSet ModelEnumSetFromValue(const base::ListValue& value);
// Returns a string corresponding to the syncable tag for this datatype.
@@ -178,9 +166,6 @@ bool RealModelTypeToNotificationType(ModelType model_type,
bool NotificationTypeToRealModelType(const std::string& notification_type,
ModelType* model_type);
-// Returns a ModelTypeSet with all real model types.
-ModelTypeSet GetAllRealModelTypes();
-
// Returns true if |model_type| is a real datatype
bool IsRealDataType(ModelType model_type);
diff --git a/chrome/browser/sync/syncable/model_type_unittest.cc b/chrome/browser/sync/syncable/model_type_unittest.cc
index 2db0ab9..c5b9196 100644
--- a/chrome/browser/sync/syncable/model_type_unittest.cc
+++ b/chrome/browser/sync/syncable/model_type_unittest.cc
@@ -38,12 +38,10 @@ TEST_F(ModelTypeTest, ModelTypeFromValue) {
}
}
-TEST_F(ModelTypeTest, ModelTypeSetToValue) {
- ModelTypeSet model_types;
- model_types.insert(syncable::BOOKMARKS);
- model_types.insert(syncable::APPS);
+TEST_F(ModelTypeTest, ModelEnumSetToValue) {
+ const ModelEnumSet model_types(syncable::BOOKMARKS, syncable::APPS);
- scoped_ptr<ListValue> value(ModelTypeSetToValue(model_types));
+ scoped_ptr<ListValue> value(ModelEnumSetToValue(model_types));
EXPECT_EQ(2u, value->GetSize());
std::string types[2];
EXPECT_TRUE(value->GetString(0, &types[0]));
@@ -52,26 +50,17 @@ TEST_F(ModelTypeTest, ModelTypeSetToValue) {
EXPECT_EQ("Apps", types[1]);
}
-TEST_F(ModelTypeTest, ModelTypeSetFromValue) {
+TEST_F(ModelTypeTest, ModelEnumSetFromValue) {
// Try empty set first.
- ModelTypeSet model_types;
- scoped_ptr<ListValue> value(ModelTypeSetToValue(model_types));
- EXPECT_EQ(model_types, ModelTypeSetFromValue(*value));
+ ModelEnumSet model_types;
+ scoped_ptr<ListValue> value(ModelEnumSetToValue(model_types));
+ EXPECT_TRUE(model_types.Equals(ModelEnumSetFromValue(*value)));
// Now try with a few random types.
- model_types.insert(BOOKMARKS);
- model_types.insert(APPS);
- value.reset(ModelTypeSetToValue(model_types));
- EXPECT_EQ(model_types, ModelTypeSetFromValue(*value));
-}
-
-TEST_F(ModelTypeTest, GetAllRealModelTypes) {
- const ModelTypeSet& all_types = GetAllRealModelTypes();
- for (int i = 0; i < MODEL_TYPE_COUNT; ++i) {
- ModelType type = ModelTypeFromInt(i);
- EXPECT_EQ(IsRealDataType(type), all_types.count(type) > 0u);
- }
- EXPECT_EQ(0u, all_types.count(MODEL_TYPE_COUNT));
+ model_types.Put(BOOKMARKS);
+ model_types.Put(APPS);
+ value.reset(ModelEnumSetToValue(model_types));
+ EXPECT_TRUE(model_types.Equals(ModelEnumSetFromValue(*value)));
}
TEST_F(ModelTypeTest, IsRealDataType) {
diff --git a/chrome/browser/sync/test/integration/enable_disable_test.cc b/chrome/browser/sync/test/integration/enable_disable_test.cc
index fd4363d..7acbfb6 100644
--- a/chrome/browser/sync/test/integration/enable_disable_test.cc
+++ b/chrome/browser/sync/test/integration/enable_disable_test.cc
@@ -43,25 +43,25 @@ IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, EnableOneAtATime) {
DisableNotifications();
// Setup sync with no enabled types.
- ASSERT_TRUE(GetClient(0)->SetupSync(syncable::ModelTypeSet()));
+ ASSERT_TRUE(GetClient(0)->SetupSync(syncable::ModelEnumSet()));
- syncable::ModelTypeSet registered_types;
- GetClient(0)->service()->GetRegisteredDataTypes(&registered_types);
+ const syncable::ModelEnumSet registered_types =
+ GetClient(0)->service()->GetRegisteredDataTypes();
sync_api::UserShare* user_share = GetClient(0)->service()->GetUserShare();
- for (syncable::ModelTypeSet::const_iterator it = registered_types.begin();
- it != registered_types.end(); ++it) {
- ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(*it));
+ for (syncable::ModelEnumSet::Iterator it = registered_types.First();
+ it.Good(); it.Inc()) {
+ ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(it.Get()));
// AUTOFILL_PROFILE is lumped together with AUTOFILL.
- if (*it == syncable::AUTOFILL_PROFILE) {
+ if (it.Get() == syncable::AUTOFILL_PROFILE) {
continue;
}
- ASSERT_TRUE(DoesTopLevelNodeExist(user_share, *it))
- << syncable::ModelTypeToString(*it);
+ ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get()))
+ << syncable::ModelTypeToString(it.Get());
// AUTOFILL_PROFILE is lumped together with AUTOFILL.
- if (*it == syncable::AUTOFILL) {
+ if (it.Get() == syncable::AUTOFILL) {
ASSERT_TRUE(DoesTopLevelNodeExist(user_share,
syncable::AUTOFILL_PROFILE));
}
@@ -78,34 +78,34 @@ IN_PROC_BROWSER_TEST_F(EnableDisableSingleClientTest, DisableOneAtATime) {
// Setup sync with no disabled types.
ASSERT_TRUE(GetClient(0)->SetupSync());
- syncable::ModelTypeSet registered_types;
- GetClient(0)->service()->GetRegisteredDataTypes(&registered_types);
+ const syncable::ModelEnumSet registered_types =
+ GetClient(0)->service()->GetRegisteredDataTypes();
sync_api::UserShare* user_share = GetClient(0)->service()->GetUserShare();
// Make sure all top-level nodes exist first.
- for (syncable::ModelTypeSet::const_iterator it = registered_types.begin();
- it != registered_types.end(); ++it) {
- ASSERT_TRUE(DoesTopLevelNodeExist(user_share, *it));
+ for (syncable::ModelEnumSet::Iterator it = registered_types.First();
+ it.Good(); it.Inc()) {
+ ASSERT_TRUE(DoesTopLevelNodeExist(user_share, it.Get()));
}
- for (syncable::ModelTypeSet::const_iterator it = registered_types.begin();
- it != registered_types.end(); ++it) {
- ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(*it));
+ for (syncable::ModelEnumSet::Iterator it = registered_types.First();
+ it.Good(); it.Inc()) {
+ ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(it.Get()));
// AUTOFILL_PROFILE is lumped together with AUTOFILL.
- if (*it == syncable::AUTOFILL_PROFILE) {
+ if (it.Get() == syncable::AUTOFILL_PROFILE) {
continue;
}
sync_api::UserShare* user_share =
GetClient(0)->service()->GetUserShare();
- ASSERT_FALSE(DoesTopLevelNodeExist(user_share, *it))
- << syncable::ModelTypeToString(*it);
+ ASSERT_FALSE(DoesTopLevelNodeExist(user_share, it.Get()))
+ << syncable::ModelTypeToString(it.Get());
// AUTOFILL_PROFILE is lumped together with AUTOFILL.
- if (*it == syncable::AUTOFILL) {
+ if (it.Get() == syncable::AUTOFILL) {
ASSERT_FALSE(DoesTopLevelNodeExist(user_share,
syncable::AUTOFILL_PROFILE));
}
diff --git a/chrome/browser/sync/test/integration/migration_errors_test.cc b/chrome/browser/sync/test/integration/migration_errors_test.cc
index 32a5944..1034da2 100644
--- a/chrome/browser/sync/test/integration/migration_errors_test.cc
+++ b/chrome/browser/sync/test/integration/migration_errors_test.cc
@@ -74,16 +74,15 @@ class MigrationTest : public SyncTest {
enum TriggerMethod { MODIFY_PREF, MODIFY_BOOKMARK, TRIGGER_NOTIFICATION };
syncable::ModelEnumSet GetPreferredDataTypes() {
- syncable::ModelTypeSet preferred_data_types;
- GetClient(0)->service()->GetPreferredDataTypes(&preferred_data_types);
+ const syncable::ModelEnumSet preferred_data_types =
+ GetClient(0)->service()->GetPreferredDataTypes();
// Make sure all clients have the same preferred data types.
for (int i = 1; i < num_clients(); ++i) {
- syncable::ModelTypeSet other_preferred_data_types;
- GetClient(i)->service()->GetPreferredDataTypes(
- &other_preferred_data_types);
- EXPECT_EQ(preferred_data_types, other_preferred_data_types);
+ const syncable::ModelEnumSet other_preferred_data_types =
+ GetClient(i)->service()->GetPreferredDataTypes();
+ EXPECT_TRUE(preferred_data_types.Equals(other_preferred_data_types));
}
- return syncable::ModelTypeSetToEnumSet(preferred_data_types);
+ return preferred_data_types;
}
// Returns a MigrationList with every enabled data type in its own
@@ -126,10 +125,8 @@ class MigrationTest : public SyncTest {
// Block until all clients have completed migration for the given
// types.
void AwaitMigration(syncable::ModelEnumSet migrate_types) {
- const syncable::ModelTypeSet& migrate_types_set =
- syncable::ModelEnumSetToSet(migrate_types);
for (int i = 0; i < num_clients(); ++i) {
- ASSERT_TRUE(GetClient(i)->AwaitMigration(migrate_types_set));
+ ASSERT_TRUE(GetClient(i)->AwaitMigration(migrate_types));
}
}
diff --git a/chrome/browser/sync/util/cryptographer.cc b/chrome/browser/sync/util/cryptographer.cc
index 59e9610..0f04a01 100644
--- a/chrome/browser/sync/util/cryptographer.cc
+++ b/chrome/browser/sync/util/cryptographer.cc
@@ -22,10 +22,8 @@ Cryptographer::Observer::~Observer() {}
Cryptographer::Cryptographer()
: default_nigori_(NULL),
- encrypt_everything_(false) {
- syncable::ModelTypeSet sensitive_types = SensitiveTypes();
- encrypted_types_.insert(sensitive_types.begin(), sensitive_types.end());
-}
+ encrypted_types_(SensitiveTypes()),
+ encrypt_everything_(false) {}
Cryptographer::~Cryptographer() {}
@@ -275,12 +273,12 @@ Cryptographer::UpdateResult Cryptographer::Update(
}
// Static
-syncable::ModelTypeSet Cryptographer::SensitiveTypes() {
- syncable::ModelTypeSet types;
+syncable::ModelEnumSet Cryptographer::SensitiveTypes() {
// Both of these have their own encryption schemes, but we include them
// anyways.
- types.insert(syncable::PASSWORDS);
- types.insert(syncable::NIGORI);
+ syncable::ModelEnumSet types;
+ types.Put(syncable::PASSWORDS);
+ types.Put(syncable::NIGORI);
return types;
}
@@ -291,39 +289,39 @@ void Cryptographer::UpdateEncryptedTypesFromNigori(
return;
}
- syncable::ModelTypeSet encrypted_types(SensitiveTypes());
+ syncable::ModelEnumSet encrypted_types(SensitiveTypes());
if (nigori.encrypt_bookmarks())
- encrypted_types.insert(syncable::BOOKMARKS);
+ encrypted_types.Put(syncable::BOOKMARKS);
if (nigori.encrypt_preferences())
- encrypted_types.insert(syncable::PREFERENCES);
+ encrypted_types.Put(syncable::PREFERENCES);
if (nigori.encrypt_autofill_profile())
- encrypted_types.insert(syncable::AUTOFILL_PROFILE);
+ encrypted_types.Put(syncable::AUTOFILL_PROFILE);
if (nigori.encrypt_autofill())
- encrypted_types.insert(syncable::AUTOFILL);
+ encrypted_types.Put(syncable::AUTOFILL);
if (nigori.encrypt_themes())
- encrypted_types.insert(syncable::THEMES);
+ encrypted_types.Put(syncable::THEMES);
if (nigori.encrypt_typed_urls())
- encrypted_types.insert(syncable::TYPED_URLS);
+ encrypted_types.Put(syncable::TYPED_URLS);
if (nigori.encrypt_extension_settings())
- encrypted_types.insert(syncable::EXTENSION_SETTINGS);
+ encrypted_types.Put(syncable::EXTENSION_SETTINGS);
if (nigori.encrypt_extensions())
- encrypted_types.insert(syncable::EXTENSIONS);
+ encrypted_types.Put(syncable::EXTENSIONS);
if (nigori.encrypt_search_engines())
- encrypted_types.insert(syncable::SEARCH_ENGINES);
+ encrypted_types.Put(syncable::SEARCH_ENGINES);
if (nigori.encrypt_sessions())
- encrypted_types.insert(syncable::SESSIONS);
+ encrypted_types.Put(syncable::SESSIONS);
if (nigori.encrypt_app_settings())
- encrypted_types.insert(syncable::APP_SETTINGS);
+ encrypted_types.Put(syncable::APP_SETTINGS);
if (nigori.encrypt_apps())
- encrypted_types.insert(syncable::APPS);
+ encrypted_types.Put(syncable::APPS);
if (nigori.encrypt_app_notifications())
- encrypted_types.insert(syncable::APP_NOTIFICATIONS);
+ encrypted_types.Put(syncable::APP_NOTIFICATIONS);
// Note: the initial version with encryption did not support the
// encrypt_everything field. If anything more than the sensitive types were
// encrypted, it meant we were encrypting everything.
if (!nigori.has_encrypt_everything() &&
- encrypted_types.size() > SensitiveTypes().size()) {
+ !Difference(encrypted_types, SensitiveTypes()).Empty()) {
set_encrypt_everything();
return;
}
@@ -335,38 +333,38 @@ void Cryptographer::UpdateNigoriFromEncryptedTypes(
sync_pb::NigoriSpecifics* nigori) const {
nigori->set_encrypt_everything(encrypt_everything_);
nigori->set_encrypt_bookmarks(
- encrypted_types_.count(syncable::BOOKMARKS) > 0);
+ encrypted_types_.Has(syncable::BOOKMARKS));
nigori->set_encrypt_preferences(
- encrypted_types_.count(syncable::PREFERENCES) > 0);
+ encrypted_types_.Has(syncable::PREFERENCES));
nigori->set_encrypt_autofill_profile(
- encrypted_types_.count(syncable::AUTOFILL_PROFILE) > 0);
- nigori->set_encrypt_autofill(encrypted_types_.count(syncable::AUTOFILL) > 0);
- nigori->set_encrypt_themes(encrypted_types_.count(syncable::THEMES) > 0);
+ encrypted_types_.Has(syncable::AUTOFILL_PROFILE));
+ nigori->set_encrypt_autofill(encrypted_types_.Has(syncable::AUTOFILL));
+ nigori->set_encrypt_themes(encrypted_types_.Has(syncable::THEMES));
nigori->set_encrypt_typed_urls(
- encrypted_types_.count(syncable::TYPED_URLS) > 0);
+ encrypted_types_.Has(syncable::TYPED_URLS));
nigori->set_encrypt_extension_settings(
- encrypted_types_.count(syncable::EXTENSION_SETTINGS) > 0);
+ encrypted_types_.Has(syncable::EXTENSION_SETTINGS));
nigori->set_encrypt_extensions(
- encrypted_types_.count(syncable::EXTENSIONS) > 0);
+ encrypted_types_.Has(syncable::EXTENSIONS));
nigori->set_encrypt_search_engines(
- encrypted_types_.count(syncable::SEARCH_ENGINES) > 0);
- nigori->set_encrypt_sessions(encrypted_types_.count(syncable::SESSIONS) > 0);
+ encrypted_types_.Has(syncable::SEARCH_ENGINES));
+ nigori->set_encrypt_sessions(encrypted_types_.Has(syncable::SESSIONS));
nigori->set_encrypt_app_settings(
- encrypted_types_.count(syncable::APP_SETTINGS) > 0);
- nigori->set_encrypt_apps(encrypted_types_.count(syncable::APPS) > 0);
+ encrypted_types_.Has(syncable::APP_SETTINGS));
+ nigori->set_encrypt_apps(encrypted_types_.Has(syncable::APPS));
nigori->set_encrypt_app_notifications(
- encrypted_types_.count(syncable::APP_NOTIFICATIONS) > 0);
+ encrypted_types_.Has(syncable::APP_NOTIFICATIONS));
}
void Cryptographer::set_encrypt_everything() {
if (encrypt_everything_) {
- DCHECK(encrypted_types_ == syncable::GetAllRealModelTypes());
+ DCHECK(encrypted_types_.Equals(syncable::ModelEnumSet::All()));
return;
}
encrypt_everything_ = true;
// Change |encrypted_types_| directly to avoid sending more than one
// notification.
- encrypted_types_ = syncable::GetAllRealModelTypes();
+ encrypted_types_ = syncable::ModelEnumSet::All();
EmitEncryptedTypesChangedNotification();
}
@@ -374,19 +372,18 @@ bool Cryptographer::encrypt_everything() const {
return encrypt_everything_;
}
-syncable::ModelTypeSet Cryptographer::GetEncryptedTypes() const {
+syncable::ModelEnumSet Cryptographer::GetEncryptedTypes() const {
return encrypted_types_;
}
void Cryptographer::MergeEncryptedTypesForTest(
- const syncable::ModelTypeSet& encrypted_types) {
+ syncable::ModelEnumSet encrypted_types) {
MergeEncryptedTypes(encrypted_types);
}
void Cryptographer::MergeEncryptedTypes(
- const syncable::ModelTypeSet& encrypted_types) {
- if (std::includes(encrypted_types_.begin(), encrypted_types_.end(),
- encrypted_types.begin(), encrypted_types.end())) {
+ syncable::ModelEnumSet encrypted_types) {
+ if (encrypted_types_.HasAll(encrypted_types)) {
return;
}
encrypted_types_ = encrypted_types;
diff --git a/chrome/browser/sync/util/cryptographer.h b/chrome/browser/sync/util/cryptographer.h
index 992c443..b370296 100644
--- a/chrome/browser/sync/util/cryptographer.h
+++ b/chrome/browser/sync/util/cryptographer.h
@@ -62,7 +62,7 @@ class Cryptographer {
// set of encrypted types is SensitiveTypes() and that the encrypt
// everything flag is false.
virtual void OnEncryptedTypesChanged(
- const syncable::ModelTypeSet& encrypted_types,
+ syncable::ModelEnumSet encrypted_types,
bool encrypt_everything) = 0;
protected:
@@ -163,7 +163,7 @@ class Cryptographer {
UpdateResult Update(const sync_pb::NigoriSpecifics& nigori);
// The set of types that are always encrypted.
- static syncable::ModelTypeSet SensitiveTypes();
+ static syncable::ModelEnumSet SensitiveTypes();
// Reset our set of encrypted types based on the contents of the nigori
// specifics.
@@ -180,11 +180,11 @@ class Cryptographer {
bool encrypt_everything() const;
// Return the set of encrypted types.
- syncable::ModelTypeSet GetEncryptedTypes() const;
+ syncable::ModelEnumSet GetEncryptedTypes() const;
// Forwards to MergeEncryptedTypes.
void MergeEncryptedTypesForTest(
- const syncable::ModelTypeSet& encrypted_types);
+ syncable::ModelEnumSet encrypted_types);
private:
FRIEND_TEST_ALL_PREFIXES(CryptographerTest, PackUnpack);
@@ -192,7 +192,7 @@ class Cryptographer {
// Merges the given set of encrypted types with the existing set and emits a
// notification if necessary.
- void MergeEncryptedTypes(const syncable::ModelTypeSet& encrypted_types);
+ void MergeEncryptedTypes(syncable::ModelEnumSet encrypted_types);
void EmitEncryptedTypesChangedNotification();
@@ -216,7 +216,7 @@ class Cryptographer {
scoped_ptr<sync_pb::EncryptedData> pending_keys_;
- syncable::ModelTypeSet encrypted_types_;
+ syncable::ModelEnumSet encrypted_types_;
bool encrypt_everything_;
DISALLOW_COPY_AND_ASSIGN(Cryptographer);
diff --git a/chrome/browser/sync/util/cryptographer_unittest.cc b/chrome/browser/sync/util/cryptographer_unittest.cc
index 73e3891..b596c11 100644
--- a/chrome/browser/sync/util/cryptographer_unittest.cc
+++ b/chrome/browser/sync/util/cryptographer_unittest.cc
@@ -11,21 +11,23 @@
#include "chrome/browser/password_manager/encryptor.h"
#include "chrome/browser/sync/protocol/nigori_specifics.pb.h"
#include "chrome/browser/sync/protocol/password_specifics.pb.h"
+#include "chrome/browser/sync/syncable/model_type_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace browser_sync {
+using ::testing::_;
using ::testing::Mock;
using ::testing::StrictMock;
-using syncable::ModelTypeSet;
+using syncable::ModelEnumSet;
namespace {
class MockObserver : public Cryptographer::Observer {
public:
MOCK_METHOD2(OnEncryptedTypesChanged,
- void(const syncable::ModelTypeSet&, bool));
+ void(syncable::ModelEnumSet, bool));
};
} // namespace
@@ -206,41 +208,43 @@ TEST(CryptographerTest, NigoriEncryptionTypes) {
// Just set the sensitive types (shouldn't trigger any
// notifications).
- ModelTypeSet encrypted_types(Cryptographer::SensitiveTypes());
+ ModelEnumSet encrypted_types(Cryptographer::SensitiveTypes());
cryptographer.MergeEncryptedTypesForTest(encrypted_types);
cryptographer.UpdateNigoriFromEncryptedTypes(&nigori);
cryptographer2.UpdateEncryptedTypesFromNigori(nigori);
- EXPECT_EQ(encrypted_types, cryptographer.GetEncryptedTypes());
- EXPECT_EQ(encrypted_types, cryptographer2.GetEncryptedTypes());
+ EXPECT_TRUE(encrypted_types.Equals(cryptographer.GetEncryptedTypes()));
+ EXPECT_TRUE(encrypted_types.Equals(cryptographer2.GetEncryptedTypes()));
Mock::VerifyAndClearExpectations(&observer);
Mock::VerifyAndClearExpectations(&observer2);
EXPECT_CALL(observer,
- OnEncryptedTypesChanged(syncable::GetAllRealModelTypes(),
- false));
+ OnEncryptedTypesChanged(
+ HasModelTypes(syncable::ModelEnumSet::All()),
+ false));
EXPECT_CALL(observer2,
- OnEncryptedTypesChanged(syncable::GetAllRealModelTypes(),
- false));
+ OnEncryptedTypesChanged(
+ HasModelTypes(syncable::ModelEnumSet::All()),
+ false));
// Set all encrypted types
- encrypted_types = syncable::GetAllRealModelTypes();
+ encrypted_types = syncable::ModelEnumSet::All();
cryptographer.MergeEncryptedTypesForTest(encrypted_types);
cryptographer.UpdateNigoriFromEncryptedTypes(&nigori);
cryptographer2.UpdateEncryptedTypesFromNigori(nigori);
- EXPECT_EQ(encrypted_types, cryptographer.GetEncryptedTypes());
- EXPECT_EQ(encrypted_types, cryptographer2.GetEncryptedTypes());
+ EXPECT_TRUE(encrypted_types.Equals(cryptographer.GetEncryptedTypes()));
+ EXPECT_TRUE(encrypted_types.Equals(cryptographer2.GetEncryptedTypes()));
// Receiving an empty nigori should not reset any encrypted types or trigger
// an observer notification.
Mock::VerifyAndClearExpectations(&observer);
nigori = sync_pb::NigoriSpecifics();
cryptographer.UpdateEncryptedTypesFromNigori(nigori);
- EXPECT_EQ(encrypted_types, cryptographer.GetEncryptedTypes());
+ EXPECT_TRUE(encrypted_types.Equals(cryptographer.GetEncryptedTypes()));
}
TEST(CryptographerTest, EncryptEverythingExplicit) {
- ModelTypeSet real_types = syncable::GetAllRealModelTypes();
+ ModelEnumSet real_types = syncable::ModelEnumSet::All();
sync_pb::NigoriSpecifics specifics;
specifics.set_encrypt_everything(true);
@@ -249,28 +253,26 @@ TEST(CryptographerTest, EncryptEverythingExplicit) {
cryptographer.AddObserver(&observer);
EXPECT_CALL(observer,
- OnEncryptedTypesChanged(syncable::GetAllRealModelTypes(),
- true));
+ OnEncryptedTypesChanged(
+ HasModelTypes(syncable::ModelEnumSet::All()), true));
EXPECT_FALSE(cryptographer.encrypt_everything());
- ModelTypeSet encrypted_types = cryptographer.GetEncryptedTypes();
- for (ModelTypeSet::iterator iter = real_types.begin();
- iter != real_types.end();
- ++iter) {
- if (*iter == syncable::PASSWORDS || *iter == syncable::NIGORI)
- EXPECT_EQ(1U, encrypted_types.count(*iter));
+ ModelEnumSet encrypted_types = cryptographer.GetEncryptedTypes();
+ for (ModelEnumSet::Iterator iter = real_types.First();
+ iter.Good(); iter.Inc()) {
+ if (iter.Get() == syncable::PASSWORDS || iter.Get() == syncable::NIGORI)
+ EXPECT_TRUE(encrypted_types.Has(iter.Get()));
else
- EXPECT_EQ(0U, encrypted_types.count(*iter));
+ EXPECT_FALSE(encrypted_types.Has(iter.Get()));
}
cryptographer.UpdateEncryptedTypesFromNigori(specifics);
EXPECT_TRUE(cryptographer.encrypt_everything());
encrypted_types = cryptographer.GetEncryptedTypes();
- for (ModelTypeSet::iterator iter = real_types.begin();
- iter != real_types.end();
- ++iter) {
- EXPECT_EQ(1U, encrypted_types.count(*iter));
+ for (ModelEnumSet::Iterator iter = real_types.First();
+ iter.Good(); iter.Inc()) {
+ EXPECT_TRUE(encrypted_types.Has(iter.Get()));
}
// Shouldn't trigger another notification.
@@ -280,7 +282,7 @@ TEST(CryptographerTest, EncryptEverythingExplicit) {
}
TEST(CryptographerTest, EncryptEverythingImplicit) {
- ModelTypeSet real_types = syncable::GetAllRealModelTypes();
+ ModelEnumSet real_types = syncable::ModelEnumSet::All();
sync_pb::NigoriSpecifics specifics;
specifics.set_encrypt_bookmarks(true); // Non-passwords = encrypt everything
@@ -289,28 +291,26 @@ TEST(CryptographerTest, EncryptEverythingImplicit) {
cryptographer.AddObserver(&observer);
EXPECT_CALL(observer,
- OnEncryptedTypesChanged(syncable::GetAllRealModelTypes(),
- true));
+ OnEncryptedTypesChanged(
+ HasModelTypes(syncable::ModelEnumSet::All()), true));
EXPECT_FALSE(cryptographer.encrypt_everything());
- ModelTypeSet encrypted_types = cryptographer.GetEncryptedTypes();
- for (ModelTypeSet::iterator iter = real_types.begin();
- iter != real_types.end();
- ++iter) {
- if (*iter == syncable::PASSWORDS || *iter == syncable::NIGORI)
- EXPECT_EQ(1U, encrypted_types.count(*iter));
+ ModelEnumSet encrypted_types = cryptographer.GetEncryptedTypes();
+ for (ModelEnumSet::Iterator iter = real_types.First();
+ iter.Good(); iter.Inc()) {
+ if (iter.Get() == syncable::PASSWORDS || iter.Get() == syncable::NIGORI)
+ EXPECT_TRUE(encrypted_types.Has(iter.Get()));
else
- EXPECT_EQ(0U, encrypted_types.count(*iter));
+ EXPECT_FALSE(encrypted_types.Has(iter.Get()));
}
cryptographer.UpdateEncryptedTypesFromNigori(specifics);
EXPECT_TRUE(cryptographer.encrypt_everything());
encrypted_types = cryptographer.GetEncryptedTypes();
- for (ModelTypeSet::iterator iter = real_types.begin();
- iter != real_types.end();
- ++iter) {
- EXPECT_EQ(1U, encrypted_types.count(*iter));
+ for (ModelEnumSet::Iterator iter = real_types.First();
+ iter.Good(); iter.Inc()) {
+ EXPECT_TRUE(encrypted_types.Has(iter.Get()));
}
// Shouldn't trigger another notification.
@@ -320,7 +320,7 @@ TEST(CryptographerTest, EncryptEverythingImplicit) {
}
TEST(CryptographerTest, UnknownSensitiveTypes) {
- ModelTypeSet real_types = syncable::GetAllRealModelTypes();
+ ModelEnumSet real_types = syncable::ModelEnumSet::All();
sync_pb::NigoriSpecifics specifics;
// Explicitly setting encrypt everything should override logic for implicit
// encrypt everything.
@@ -331,38 +331,36 @@ TEST(CryptographerTest, UnknownSensitiveTypes) {
StrictMock<MockObserver> observer;
cryptographer.AddObserver(&observer);
- syncable::ModelTypeSet expected_encrypted_types =
+ syncable::ModelEnumSet expected_encrypted_types =
Cryptographer::SensitiveTypes();
- expected_encrypted_types.insert(syncable::BOOKMARKS);
+ expected_encrypted_types.Put(syncable::BOOKMARKS);
EXPECT_CALL(observer,
- OnEncryptedTypesChanged(expected_encrypted_types,
- false));
+ OnEncryptedTypesChanged(
+ HasModelTypes(expected_encrypted_types), false));
EXPECT_FALSE(cryptographer.encrypt_everything());
- ModelTypeSet encrypted_types = cryptographer.GetEncryptedTypes();
- for (ModelTypeSet::iterator iter = real_types.begin();
- iter != real_types.end();
- ++iter) {
- if (*iter == syncable::PASSWORDS || *iter == syncable::NIGORI)
- EXPECT_EQ(1U, encrypted_types.count(*iter));
+ ModelEnumSet encrypted_types = cryptographer.GetEncryptedTypes();
+ for (ModelEnumSet::Iterator iter = real_types.First();
+ iter.Good(); iter.Inc()) {
+ if (iter.Get() == syncable::PASSWORDS || iter.Get() == syncable::NIGORI)
+ EXPECT_TRUE(encrypted_types.Has(iter.Get()));
else
- EXPECT_EQ(0U, encrypted_types.count(*iter));
+ EXPECT_FALSE(encrypted_types.Has(iter.Get()));
}
cryptographer.UpdateEncryptedTypesFromNigori(specifics);
EXPECT_FALSE(cryptographer.encrypt_everything());
encrypted_types = cryptographer.GetEncryptedTypes();
- for (ModelTypeSet::iterator iter = real_types.begin();
- iter != real_types.end();
- ++iter) {
- if (*iter == syncable::PASSWORDS ||
- *iter == syncable::NIGORI ||
- *iter == syncable::BOOKMARKS)
- EXPECT_EQ(1U, encrypted_types.count(*iter));
+ for (ModelEnumSet::Iterator iter = real_types.First();
+ iter.Good(); iter.Inc()) {
+ if (iter.Get() == syncable::PASSWORDS ||
+ iter.Get() == syncable::NIGORI ||
+ iter.Get() == syncable::BOOKMARKS)
+ EXPECT_TRUE(encrypted_types.Has(iter.Get()));
else
- EXPECT_EQ(0U, encrypted_types.count(*iter));
+ EXPECT_FALSE(encrypted_types.Has(iter.Get()));
}
cryptographer.RemoveObserver(&observer);
diff --git a/chrome/browser/ui/webui/sync_setup_handler.cc b/chrome/browser/ui/webui/sync_setup_handler.cc
index 60a92ae..c15b4f8 100644
--- a/chrome/browser/ui/webui/sync_setup_handler.cc
+++ b/chrome/browser/ui/webui/sync_setup_handler.cc
@@ -89,58 +89,58 @@ bool GetConfiguration(const std::string& json, SyncConfiguration* config) {
if (!result->GetBoolean("syncBookmarks", &sync_bookmarks))
return false;
if (sync_bookmarks)
- config->data_types.insert(syncable::BOOKMARKS);
+ config->data_types.Put(syncable::BOOKMARKS);
bool sync_preferences;
if (!result->GetBoolean("syncPreferences", &sync_preferences))
return false;
if (sync_preferences)
- config->data_types.insert(syncable::PREFERENCES);
+ config->data_types.Put(syncable::PREFERENCES);
bool sync_themes;
if (!result->GetBoolean("syncThemes", &sync_themes))
return false;
if (sync_themes)
- config->data_types.insert(syncable::THEMES);
+ config->data_types.Put(syncable::THEMES);
bool sync_passwords;
if (!result->GetBoolean("syncPasswords", &sync_passwords))
return false;
if (sync_passwords)
- config->data_types.insert(syncable::PASSWORDS);
+ config->data_types.Put(syncable::PASSWORDS);
bool sync_autofill;
if (!result->GetBoolean("syncAutofill", &sync_autofill))
return false;
if (sync_autofill)
- config->data_types.insert(syncable::AUTOFILL);
+ config->data_types.Put(syncable::AUTOFILL);
bool sync_extensions;
if (!result->GetBoolean("syncExtensions", &sync_extensions))
return false;
if (sync_extensions) {
- config->data_types.insert(syncable::EXTENSIONS);
- config->data_types.insert(syncable::EXTENSION_SETTINGS);
+ config->data_types.Put(syncable::EXTENSIONS);
+ config->data_types.Put(syncable::EXTENSION_SETTINGS);
}
bool sync_typed_urls;
if (!result->GetBoolean("syncTypedUrls", &sync_typed_urls))
return false;
if (sync_typed_urls)
- config->data_types.insert(syncable::TYPED_URLS);
+ config->data_types.Put(syncable::TYPED_URLS);
bool sync_sessions;
if (!result->GetBoolean("syncSessions", &sync_sessions))
return false;
if (sync_sessions)
- config->data_types.insert(syncable::SESSIONS);
+ config->data_types.Put(syncable::SESSIONS);
bool sync_apps;
if (!result->GetBoolean("syncApps", &sync_apps))
return false;
if (sync_apps) {
- config->data_types.insert(syncable::APPS);
- config->data_types.insert(syncable::APP_SETTINGS);
+ config->data_types.Put(syncable::APPS);
+ config->data_types.Put(syncable::APP_SETTINGS);
}
// Encryption settings.
@@ -202,24 +202,24 @@ bool HasConfigurationChanged(const SyncConfiguration& config,
// Only check the data types that are explicitly listed on the sync
// preferences page.
- const syncable::ModelTypeSet& types = config.data_types;
- if (((types.find(syncable::BOOKMARKS) != types.end()) !=
+ const syncable::ModelEnumSet types = config.data_types;
+ if (((types.Has(syncable::BOOKMARKS)) !=
pref_service->GetBoolean(prefs::kSyncBookmarks)) ||
- ((types.find(syncable::PREFERENCES) != types.end()) !=
+ ((types.Has(syncable::PREFERENCES)) !=
pref_service->GetBoolean(prefs::kSyncPreferences)) ||
- ((types.find(syncable::THEMES) != types.end()) !=
+ ((types.Has(syncable::THEMES)) !=
pref_service->GetBoolean(prefs::kSyncThemes)) ||
- ((types.find(syncable::PASSWORDS) != types.end()) !=
+ ((types.Has(syncable::PASSWORDS)) !=
pref_service->GetBoolean(prefs::kSyncPasswords)) ||
- ((types.find(syncable::AUTOFILL) != types.end()) !=
+ ((types.Has(syncable::AUTOFILL)) !=
pref_service->GetBoolean(prefs::kSyncAutofill)) ||
- ((types.find(syncable::EXTENSIONS) != types.end()) !=
+ ((types.Has(syncable::EXTENSIONS)) !=
pref_service->GetBoolean(prefs::kSyncExtensions)) ||
- ((types.find(syncable::TYPED_URLS) != types.end()) !=
+ ((types.Has(syncable::TYPED_URLS)) !=
pref_service->GetBoolean(prefs::kSyncTypedUrls)) ||
- ((types.find(syncable::SESSIONS) != types.end()) !=
+ ((types.Has(syncable::SESSIONS)) !=
pref_service->GetBoolean(prefs::kSyncSessions)) ||
- ((types.find(syncable::APPS) != types.end()) !=
+ ((types.Has(syncable::APPS)) !=
pref_service->GetBoolean(prefs::kSyncApps)))
return true;
@@ -580,32 +580,32 @@ void SyncSetupHandler::HandleConfigure(const ListValue* args) {
if (!configuration.sync_everything) {
// Only log the data types that are explicitly listed on the sync
// preferences page.
- const syncable::ModelTypeSet& types = configuration.data_types;
- if (types.find(syncable::BOOKMARKS) != types.end())
+ const syncable::ModelEnumSet types = configuration.data_types;
+ if (types.Has(syncable::BOOKMARKS))
UMA_HISTOGRAM_ENUMERATION(
"Sync.CustomSync", BOOKMARKS, SELECTABLE_DATATYPE_COUNT + 1);
- if (types.find(syncable::PREFERENCES) != types.end())
+ if (types.Has(syncable::PREFERENCES))
UMA_HISTOGRAM_ENUMERATION(
"Sync.CustomSync", PREFERENCES, SELECTABLE_DATATYPE_COUNT + 1);
- if (types.find(syncable::PASSWORDS) != types.end())
+ if (types.Has(syncable::PASSWORDS))
UMA_HISTOGRAM_ENUMERATION(
"Sync.CustomSync", PASSWORDS, SELECTABLE_DATATYPE_COUNT + 1);
- if (types.find(syncable::AUTOFILL) != types.end())
+ if (types.Has(syncable::AUTOFILL))
UMA_HISTOGRAM_ENUMERATION(
"Sync.CustomSync", AUTOFILL, SELECTABLE_DATATYPE_COUNT + 1);
- if (types.find(syncable::THEMES) != types.end())
+ if (types.Has(syncable::THEMES))
UMA_HISTOGRAM_ENUMERATION(
"Sync.CustomSync", THEMES, SELECTABLE_DATATYPE_COUNT + 1);
- if (types.find(syncable::TYPED_URLS) != types.end())
+ if (types.Has(syncable::TYPED_URLS))
UMA_HISTOGRAM_ENUMERATION(
"Sync.CustomSync", TYPED_URLS, SELECTABLE_DATATYPE_COUNT + 1);
- if (types.find(syncable::EXTENSIONS) != types.end())
+ if (types.Has(syncable::EXTENSIONS))
UMA_HISTOGRAM_ENUMERATION(
"Sync.CustomSync", EXTENSIONS, SELECTABLE_DATATYPE_COUNT + 1);
- if (types.find(syncable::SESSIONS) != types.end())
+ if (types.Has(syncable::SESSIONS))
UMA_HISTOGRAM_ENUMERATION(
"Sync.CustomSync", SESSIONS, SELECTABLE_DATATYPE_COUNT + 1);
- if (types.find(syncable::APPS) != types.end())
+ if (types.Has(syncable::APPS))
UMA_HISTOGRAM_ENUMERATION(
"Sync.CustomSync", APPS, SELECTABLE_DATATYPE_COUNT + 1);
COMPILE_ASSERT(17 == syncable::MODEL_TYPE_COUNT,