sync: Introduce control data types

The Nigori node has always been treated specially.  It is downloaded
during early sync initialization.  It has custom encryption, update
application, and conflict resolution logic.  It is not user-selectable,
but is instead always implicitly enabled.

This patch replaces a lot of if (NIGORI)' code branches and creates the
infrastructure we will need to support other data types that have these
properties.  These types will be used to store metadata required for the
normal operation of the syncer.

Notable changes include:
- Introduce mutually exclusive lists of control types and user types in
  model_type.cc.
- Create an ApplyControlDataUpdates() function, which will be used to
  apply changes and resolve conflicts for control data types.
- Add some if statements to skip processing of control data updates in
  the regular conflict resolution code path.  
- Move around some code to accomodate the above changes.  Introduce
  apply_control_data_updates_unittest.cc and conflict_util.cc
- Have SyncBackendHost download all control types during init, not just
  the NIGORI.
- Introduce a PurgeForMigration() function on the DataTypeManagerImpl
  class to support migration of control data types.  This replaces
  ConfigureWithoutNigori(), which would not have scaled well as
  additional control data types were addded.
- Modify the encryption logic so that only user types may be set to be
  encrypted.  The Nigori is no longer expected to be in the set of
  encrypted types, though it is no less encrypted than it was before
  this change.
- Use the list of user types to help calculate the list of registered
  sync prefs.

BUG=122825,111297

Review URL: https://chromiumcodereview.appspot.com/10832286

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154522 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/sync/backend_migrator_unittest.cc b/chrome/browser/sync/backend_migrator_unittest.cc
index 7331072..bc28fcb8 100644
--- a/chrome/browser/sync/backend_migrator_unittest.cc
+++ b/chrome/browser/sync/backend_migrator_unittest.cc
@@ -130,8 +130,12 @@
 
   EXPECT_CALL(*manager(), state())
       .WillOnce(Return(DataTypeManager::CONFIGURED));
-  EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION))
-      .Times(2);
+  EXPECT_CALL(
+      *manager(),
+      PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
+  EXPECT_CALL(
+      *manager(),
+      Configure(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
 
   migrator()->MigrateTypes(to_migrate);
   EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
@@ -158,7 +162,7 @@
   EXPECT_CALL(*manager(), state())
       .WillOnce(Return(DataTypeManager::CONFIGURED));
 
-  EXPECT_CALL(*manager(), ConfigureWithoutNigori(_,
+  EXPECT_CALL(*manager(), PurgeForMigration(_,
       syncer::CONFIGURE_REASON_MIGRATION));
 
   migrator()->MigrateTypes(to_migrate);
@@ -189,7 +193,8 @@
   Mock::VerifyAndClearExpectations(manager());
   EXPECT_CALL(*manager(), state())
       .WillOnce(Return(DataTypeManager::CONFIGURED));
-  EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION));
+  EXPECT_CALL(*manager(),
+              PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION));
   SetUnsyncedTypes(syncer::ModelTypeSet());
   SendConfigureDone(DataTypeManager::OK, syncer::ModelTypeSet());
 
@@ -208,8 +213,9 @@
 
   EXPECT_CALL(*manager(), state())
       .WillOnce(Return(DataTypeManager::CONFIGURED));
-  EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION))
-              .Times(2);
+  EXPECT_CALL(
+      *manager(),
+      PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(2);
   migrator()->MigrateTypes(to_migrate1);
 
   EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
@@ -219,8 +225,11 @@
       Difference(preferred_types(), to_migrate1);
 
   Mock::VerifyAndClearExpectations(manager());
+  EXPECT_CALL(
+      *manager(),
+      PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
   EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION))
-      .Times(2);
+      .Times(1);
   SetUnsyncedTypes(to_migrate1);
   SendConfigureDone(DataTypeManager::OK, difference1);
   EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
@@ -241,13 +250,13 @@
 
   EXPECT_CALL(*manager(), state())
       .WillOnce(Return(DataTypeManager::CONFIGURED));
-  EXPECT_CALL(*manager(), Configure(HasModelTypes(difference),
+  EXPECT_CALL(*manager(), PurgeForMigration(HasModelTypes(to_migrate),
       syncer::CONFIGURE_REASON_MIGRATION));
   migrator()->MigrateTypes(to_migrate);
   EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
 
   Mock::VerifyAndClearExpectations(manager());
-  EXPECT_CALL(*manager(), Configure(HasModelTypes(difference),
+  EXPECT_CALL(*manager(), PurgeForMigration(HasModelTypes(to_migrate),
       syncer::CONFIGURE_REASON_MIGRATION));
   SetUnsyncedTypes(syncer::ModelTypeSet());
   SendConfigureDone(DataTypeManager::OK, preferred_types());
@@ -266,8 +275,12 @@
 
   EXPECT_CALL(*manager(), state())
       .WillOnce(Return(DataTypeManager::CONFIGURED));
-  EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION))
-      .Times(2);
+  EXPECT_CALL(
+      *manager(),
+      PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
+  EXPECT_CALL(
+      *manager(),
+      Configure(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
 
   migrator()->MigrateTypes(to_migrate);
   EXPECT_EQ(BackendMigrator::DISABLING_TYPES, migrator()->state());
@@ -292,8 +305,12 @@
 
   EXPECT_CALL(*manager(), state())
       .WillOnce(Return(DataTypeManager::CONFIGURED));
-  EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION))
-      .Times(2);
+  EXPECT_CALL(
+      *manager(),
+      PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
+  EXPECT_CALL(
+      *manager(),
+      Configure(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
   migrator()->MigrateTypes(to_migrate);
 
   RemovePreferredType(syncer::PREFERENCES);
@@ -311,8 +328,9 @@
 
   EXPECT_CALL(*manager(), state())
       .WillOnce(Return(DataTypeManager::CONFIGURED));
-  EXPECT_CALL(*manager(), Configure(_, syncer::CONFIGURE_REASON_MIGRATION))
-              .Times(1);
+  EXPECT_CALL(
+      *manager(),
+      PurgeForMigration(_, syncer::CONFIGURE_REASON_MIGRATION)).Times(1);
   migrator()->MigrateTypes(to_migrate);
   SetUnsyncedTypes(syncer::ModelTypeSet());
   SendConfigureDone(DataTypeManager::ABORTED, syncer::ModelTypeSet());