Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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( | |
| 161 const base::Closure& callback) { | |
| 162 if (!models_associated_) | |
| 163 callback_list_.push_back(callback); | |
| 164 else | |
| 165 callback.Run(); | |
| 166 } | |
| 167 | |
| 160 syncer::SyncMergeResult PrefModelAssociator::MergeDataAndStartSyncing( | 168 syncer::SyncMergeResult PrefModelAssociator::MergeDataAndStartSyncing( |
| 161 syncer::ModelType type, | 169 syncer::ModelType type, |
| 162 const syncer::SyncDataList& initial_sync_data, | 170 const syncer::SyncDataList& initial_sync_data, |
| 163 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor, | 171 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 164 std::unique_ptr<syncer::SyncErrorFactory> sync_error_factory) { | 172 std::unique_ptr<syncer::SyncErrorFactory> sync_error_factory) { |
| 165 DCHECK_EQ(type_, type); | 173 DCHECK_EQ(type_, type); |
| 166 DCHECK(CalledOnValidThread()); | 174 DCHECK(CalledOnValidThread()); |
| 167 DCHECK(pref_service_); | 175 DCHECK(pref_service_); |
| 168 DCHECK(!sync_processor_.get()); | 176 DCHECK(!sync_processor_.get()); |
| 169 DCHECK(sync_processor.get()); | 177 DCHECK(sync_processor.get()); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 200 } | 208 } |
| 201 | 209 |
| 202 // Go through and build sync data for any remaining preferences. | 210 // Go through and build sync data for any remaining preferences. |
| 203 for (std::set<std::string>::iterator pref_name_iter = | 211 for (std::set<std::string>::iterator pref_name_iter = |
| 204 remaining_preferences.begin(); | 212 remaining_preferences.begin(); |
| 205 pref_name_iter != remaining_preferences.end(); | 213 pref_name_iter != remaining_preferences.end(); |
| 206 ++pref_name_iter) { | 214 ++pref_name_iter) { |
| 207 InitPrefAndAssociate(syncer::SyncData(), *pref_name_iter, &new_changes); | 215 InitPrefAndAssociate(syncer::SyncData(), *pref_name_iter, &new_changes); |
| 208 } | 216 } |
| 209 | 217 |
| 218 for (const auto& callback : callback_list_) | |
| 219 callback.Run(); | |
| 220 callback_list_.clear(); | |
|
pavely
2016/07/06 22:11:56
I think it is possible that MergeDataAndStartSynci
lshang
2016/07/07 08:26:05
I think in this case even though the migration cod
| |
| 221 | |
| 210 // Push updates to sync. | 222 // Push updates to sync. |
| 211 merge_result.set_error( | 223 merge_result.set_error( |
| 212 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes)); | 224 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes)); |
| 213 if (merge_result.error().IsSet()) | 225 if (merge_result.error().IsSet()) |
| 214 return merge_result; | 226 return merge_result; |
| 215 | 227 |
|
pavely
2016/07/06 22:11:55
If you want to call a callback only for successful
lshang
2016/07/07 08:26:05
Done.
| |
| 216 models_associated_ = true; | 228 models_associated_ = true; |
| 217 pref_service_->OnIsSyncingChanged(); | 229 pref_service_->OnIsSyncingChanged(); |
| 218 return merge_result; | 230 return merge_result; |
| 219 } | 231 } |
| 220 | 232 |
| 221 void PrefModelAssociator::StopSyncing(syncer::ModelType type) { | 233 void PrefModelAssociator::StopSyncing(syncer::ModelType type) { |
| 222 DCHECK_EQ(type_, type); | 234 DCHECK_EQ(type_, type); |
| 223 models_associated_ = false; | 235 models_associated_ = false; |
| 224 sync_processor_.reset(); | 236 sync_processor_.reset(); |
| 225 sync_error_factory_.reset(); | 237 sync_error_factory_.reset(); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 SyncedPrefObserverMap::const_iterator observer_iter = | 543 SyncedPrefObserverMap::const_iterator observer_iter = |
| 532 synced_pref_observers_.find(path); | 544 synced_pref_observers_.find(path); |
| 533 if (observer_iter == synced_pref_observers_.end()) | 545 if (observer_iter == synced_pref_observers_.end()) |
| 534 return; | 546 return; |
| 535 SyncedPrefObserverList* observers = observer_iter->second; | 547 SyncedPrefObserverList* observers = observer_iter->second; |
| 536 FOR_EACH_OBSERVER(SyncedPrefObserver, *observers, | 548 FOR_EACH_OBSERVER(SyncedPrefObserver, *observers, |
| 537 OnSyncedPrefChanged(path, from_sync)); | 549 OnSyncedPrefChanged(path, from_sync)); |
| 538 } | 550 } |
| 539 | 551 |
| 540 } // namespace syncable_prefs | 552 } // namespace syncable_prefs |
| OLD | NEW |