Add callback list to PrefModelAssociator after sync data is loaded

This is a follow up CL of https://codereview.chromium.org/1895993003. The
migrated settings will be synced back because sync process happens after the
construction of HostContentSettingsMap.

In this CL, a callback list is added to PrefModelAssociator, which will gets
registered with the migration code after construction of HostContentSettingsMap,
and gets executed at the end of PrefModelAssociator::MergeDataAndStartSyncing.

The follow up CL of this is https://codereview.chromium.org/2075103002.

BUG=604612

Review-Url: https://codereview.chromium.org/2078893002
Cr-Commit-Position: refs/heads/master@{#405669}
diff --git a/components/syncable_prefs/pref_model_associator.cc b/components/syncable_prefs/pref_model_associator.cc
index 4cbdd558..dd9d71494 100644
--- a/components/syncable_prefs/pref_model_associator.cc
+++ b/components/syncable_prefs/pref_model_associator.cc
@@ -157,6 +157,14 @@
   // we'll send the new user controlled value to the syncer.
 }
 
+void PrefModelAssociator::RegisterMergeDataFinishedCallback(
+    const base::Closure& callback) {
+  if (!models_associated_)
+    callback_list_.push_back(callback);
+  else
+    callback.Run();
+}
+
 syncer::SyncMergeResult PrefModelAssociator::MergeDataAndStartSyncing(
     syncer::ModelType type,
     const syncer::SyncDataList& initial_sync_data,
@@ -213,6 +221,10 @@
   if (merge_result.error().IsSet())
     return merge_result;
 
+  for (const auto& callback : callback_list_)
+    callback.Run();
+  callback_list_.clear();
+
   models_associated_ = true;
   pref_service_->OnIsSyncingChanged();
   return merge_result;