Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: components/syncable_prefs/pref_model_associator.cc

Issue 2078893002: Add callback list to PrefModelAssociator after sync data is loaded (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@migrate_domain_scoped_settings
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/syncable_prefs/pref_model_associator.h" 5 #include "components/syncable_prefs/pref_model_associator.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 sync_data)); 150 sync_data));
151 synced_preferences_.insert(pref_name); 151 synced_preferences_.insert(pref_name);
152 } 152 }
153 153
154 // Else this pref does not have a sync value but also does not have a user 154 // Else this pref does not have a sync value but also does not have a user
155 // controlled value (either it's a default value or it's policy controlled, 155 // controlled value (either it's a default value or it's policy controlled,
156 // either way it's not interesting). We can ignore it. Once it gets changed, 156 // either way it's not interesting). We can ignore it. Once it gets changed,
157 // we'll send the new user controlled value to the syncer. 157 // we'll send the new user controlled value to the syncer.
158 } 158 }
159 159
160 void PrefModelAssociator::RegisterMergeDataFinishedCallback(
raymes 2016/06/29 03:50:01 Did you look into whether we should use PrefServic
lshang 2016/06/30 05:03:36 PrefServiceSyncableObserver will get called in Mer
161 const base::Closure& callback) {
162 callback_list_.push_back(callback);
raymes 2016/06/29 03:50:01 We should make sure that we only add this if we ex
lshang 2016/06/30 05:03:36 Done.
163 }
164
160 syncer::SyncMergeResult PrefModelAssociator::MergeDataAndStartSyncing( 165 syncer::SyncMergeResult PrefModelAssociator::MergeDataAndStartSyncing(
161 syncer::ModelType type, 166 syncer::ModelType type,
162 const syncer::SyncDataList& initial_sync_data, 167 const syncer::SyncDataList& initial_sync_data,
163 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor, 168 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor,
164 std::unique_ptr<syncer::SyncErrorFactory> sync_error_factory) { 169 std::unique_ptr<syncer::SyncErrorFactory> sync_error_factory) {
165 DCHECK_EQ(type_, type); 170 DCHECK_EQ(type_, type);
166 DCHECK(CalledOnValidThread()); 171 DCHECK(CalledOnValidThread());
167 DCHECK(pref_service_); 172 DCHECK(pref_service_);
168 DCHECK(!sync_processor_.get()); 173 DCHECK(!sync_processor_.get());
169 DCHECK(sync_processor.get()); 174 DCHECK(sync_processor.get());
(...skipping 30 matching lines...) Expand all
200 } 205 }
201 206
202 // Go through and build sync data for any remaining preferences. 207 // Go through and build sync data for any remaining preferences.
203 for (std::set<std::string>::iterator pref_name_iter = 208 for (std::set<std::string>::iterator pref_name_iter =
204 remaining_preferences.begin(); 209 remaining_preferences.begin();
205 pref_name_iter != remaining_preferences.end(); 210 pref_name_iter != remaining_preferences.end();
206 ++pref_name_iter) { 211 ++pref_name_iter) {
207 InitPrefAndAssociate(syncer::SyncData(), *pref_name_iter, &new_changes); 212 InitPrefAndAssociate(syncer::SyncData(), *pref_name_iter, &new_changes);
208 } 213 }
209 214
215 for (const auto& callback : callback_list_)
216 callback.Run();
217 callback_list_.clear();
218
210 // Push updates to sync. 219 // Push updates to sync.
211 merge_result.set_error( 220 merge_result.set_error(
212 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes)); 221 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes));
213 if (merge_result.error().IsSet()) 222 if (merge_result.error().IsSet())
214 return merge_result; 223 return merge_result;
215 224
216 models_associated_ = true; 225 models_associated_ = true;
217 pref_service_->OnIsSyncingChanged(); 226 pref_service_->OnIsSyncingChanged();
218 return merge_result; 227 return merge_result;
219 } 228 }
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 SyncedPrefObserverMap::const_iterator observer_iter = 540 SyncedPrefObserverMap::const_iterator observer_iter =
532 synced_pref_observers_.find(path); 541 synced_pref_observers_.find(path);
533 if (observer_iter == synced_pref_observers_.end()) 542 if (observer_iter == synced_pref_observers_.end())
534 return; 543 return;
535 SyncedPrefObserverList* observers = observer_iter->second; 544 SyncedPrefObserverList* observers = observer_iter->second;
536 FOR_EACH_OBSERVER(SyncedPrefObserver, *observers, 545 FOR_EACH_OBSERVER(SyncedPrefObserver, *observers,
537 OnSyncedPrefChanged(path, from_sync)); 546 OnSyncedPrefChanged(path, from_sync));
538 } 547 }
539 548
540 } // namespace syncable_prefs 549 } // namespace syncable_prefs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698