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

Side by Side Diff: chrome/browser/prefs/pref_model_associator.cc

Issue 7453014: [Sync] Refactor sync datatype error handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and really really fix compile Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/prefs/pref_model_associator.h" 5 #include "chrome/browser/prefs/pref_model_associator.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/tracked.h" 10 #include "base/tracked.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 // Make sure we add it to our list of synced preferences so we know what 113 // Make sure we add it to our list of synced preferences so we know what
114 // the server is aware of. 114 // the server is aware of.
115 synced_preferences_.insert(pref_name); 115 synced_preferences_.insert(pref_name);
116 return; 116 return;
117 } 117 }
118 118
119 bool PrefModelAssociator::MergeDataAndStartSyncing( 119 bool PrefModelAssociator::MergeDataAndStartSyncing(
120 syncable::ModelType type, 120 syncable::ModelType type,
121 const SyncDataList& initial_sync_data, 121 const SyncDataList& initial_sync_data,
122 SyncChangeProcessor* sync_processor) { 122 SyncChangeProcessor* sync_processor,
123 SyncError* error) {
123 DCHECK_EQ(type, PREFERENCES); 124 DCHECK_EQ(type, PREFERENCES);
124 DCHECK(CalledOnValidThread()); 125 DCHECK(CalledOnValidThread());
125 DCHECK(!sync_processor_); 126 DCHECK(!sync_processor_);
126 sync_processor_ = sync_processor; 127 sync_processor_ = sync_processor;
127 128
128 SyncChangeList new_changes; 129 SyncChangeList new_changes;
129 std::set<std::string> remaining_preferences = registered_preferences_; 130 std::set<std::string> remaining_preferences = registered_preferences_;
130 131
131 // Go through and check for all preferences we care about that sync already 132 // Go through and check for all preferences we care about that sync already
132 // knows about. 133 // knows about.
(...skipping 18 matching lines...) Expand all
151 152
152 // Go through and build sync data for any remaining preferences. 153 // Go through and build sync data for any remaining preferences.
153 for (std::set<std::string>::iterator pref_name_iter = 154 for (std::set<std::string>::iterator pref_name_iter =
154 remaining_preferences.begin(); 155 remaining_preferences.begin();
155 pref_name_iter != remaining_preferences.end(); 156 pref_name_iter != remaining_preferences.end();
156 ++pref_name_iter) { 157 ++pref_name_iter) {
157 InitPrefAndAssociate(SyncData(), *pref_name_iter, &new_changes); 158 InitPrefAndAssociate(SyncData(), *pref_name_iter, &new_changes);
158 } 159 }
159 160
160 // Push updates to sync. 161 // Push updates to sync.
161 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); 162 if (!sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes, error)) {
162 models_associated_ = true; 163 return false;
163 return true; 164 } else {
165 models_associated_ = true;
166 return true;
167 }
164 } 168 }
165 169
166 void PrefModelAssociator::StopSyncing(syncable::ModelType type) { 170 void PrefModelAssociator::StopSyncing(syncable::ModelType type) {
167 DCHECK_EQ(type, PREFERENCES); 171 DCHECK_EQ(type, PREFERENCES);
168 models_associated_ = false; 172 models_associated_ = false;
169 sync_processor_ = NULL; 173 sync_processor_ = NULL;
170 } 174 }
171 175
172 Value* PrefModelAssociator::MergePreference( 176 Value* PrefModelAssociator::MergePreference(
173 const PrefService::Preference& local_pref, 177 const PrefService::Preference& local_pref,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 continue; // This is not data we care about. 303 continue; // This is not data we care about.
300 // TODO(zea): plumb a way to read the user controlled value. 304 // TODO(zea): plumb a way to read the user controlled value.
301 SyncData sync_data; 305 SyncData sync_data;
302 if (!CreatePrefSyncData(name, *pref->GetValue(), &sync_data)) 306 if (!CreatePrefSyncData(name, *pref->GetValue(), &sync_data))
303 continue; 307 continue;
304 current_data.push_back(sync_data); 308 current_data.push_back(sync_data);
305 } 309 }
306 return current_data; 310 return current_data;
307 } 311 }
308 312
309 void PrefModelAssociator::ProcessSyncChanges( 313 bool PrefModelAssociator::ProcessSyncChanges(
310 const tracked_objects::Location& from_here, 314 const tracked_objects::Location& from_here,
311 const SyncChangeList& change_list) { 315 const SyncChangeList& change_list,
312 if (!models_associated_) 316 SyncError* error) {
313 return; 317 if (!models_associated_) {
318 error->Reset(FROM_HERE,
319 "Models not yet associated.",
320 PREFERENCES);
321 return false;
322 }
314 AutoReset<bool> processing_changes(&processing_syncer_changes_, true); 323 AutoReset<bool> processing_changes(&processing_syncer_changes_, true);
315 SyncChangeList::const_iterator iter; 324 SyncChangeList::const_iterator iter;
316 for (iter = change_list.begin(); iter != change_list.end(); ++iter) { 325 for (iter = change_list.begin(); iter != change_list.end(); ++iter) {
317 DCHECK_EQ(PREFERENCES, iter->sync_data().GetDataType()); 326 DCHECK_EQ(PREFERENCES, iter->sync_data().GetDataType());
318 327
319 std::string name; 328 std::string name;
320 sync_pb::PreferenceSpecifics pref_specifics = 329 sync_pb::PreferenceSpecifics pref_specifics =
321 iter->sync_data().GetSpecifics().GetExtension(sync_pb::preference); 330 iter->sync_data().GetSpecifics().GetExtension(sync_pb::preference);
322 scoped_ptr<Value> value(ReadPreferenceSpecifics(pref_specifics, 331 scoped_ptr<Value> value(ReadPreferenceSpecifics(pref_specifics,
323 &name)); 332 &name));
(...skipping 28 matching lines...) Expand all
352 // policy controlled. 361 // policy controlled.
353 pref_service_->Set(pref_name, *value); 362 pref_service_->Set(pref_name, *value);
354 363
355 // Keep track of any newly synced preferences. 364 // Keep track of any newly synced preferences.
356 if (iter->change_type() == SyncChange::ACTION_ADD) { 365 if (iter->change_type() == SyncChange::ACTION_ADD) {
357 synced_preferences_.insert(name); 366 synced_preferences_.insert(name);
358 } 367 }
359 368
360 SendUpdateNotificationsIfNecessary(name); 369 SendUpdateNotificationsIfNecessary(name);
361 } 370 }
371 return true;
362 } 372 }
363 373
364 Value* PrefModelAssociator::ReadPreferenceSpecifics( 374 Value* PrefModelAssociator::ReadPreferenceSpecifics(
365 const sync_pb::PreferenceSpecifics& preference, 375 const sync_pb::PreferenceSpecifics& preference,
366 std::string* name) { 376 std::string* name) {
367 base::JSONReader reader; 377 base::JSONReader reader;
368 scoped_ptr<Value> value(reader.JsonToValue(preference.value(), false, false)); 378 scoped_ptr<Value> value(reader.JsonToValue(preference.value(), false, false));
369 if (!value.get()) { 379 if (!value.get()) {
370 std::string err = "Failed to deserialize preference value: " + 380 std::string err = "Failed to deserialize preference value: " +
371 reader.GetErrorMessage(); 381 reader.GetErrorMessage();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 InitPrefAndAssociate(SyncData(), name, &changes); 435 InitPrefAndAssociate(SyncData(), name, &changes);
426 } else { 436 } else {
427 // We are already syncing this preference, just update it's sync node. 437 // We are already syncing this preference, just update it's sync node.
428 SyncData sync_data; 438 SyncData sync_data;
429 if (!CreatePrefSyncData(name, *preference->GetValue(), &sync_data)) { 439 if (!CreatePrefSyncData(name, *preference->GetValue(), &sync_data)) {
430 LOG(ERROR) << "Failed to update preference."; 440 LOG(ERROR) << "Failed to update preference.";
431 return; 441 return;
432 } 442 }
433 changes.push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); 443 changes.push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data));
434 } 444 }
435 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); 445
446 SyncError error;
447 if (!sync_processor_->ProcessSyncChanges(FROM_HERE, changes, &error))
448 StopSyncing(PREFERENCES);
436 } 449 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698