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

Side by Side Diff: chrome/browser/extensions/api/storage/syncable_settings_storage.cc

Issue 24021002: Propagate more information about ValueStore errors to callers, notably an (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add Pass*() Created 7 years, 3 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) 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 "chrome/browser/extensions/api/storage/syncable_settings_storage.h" 5 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h"
6 6
7 #include "base/strings/stringprintf.h"
7 #include "chrome/browser/extensions/api/storage/settings_namespace.h" 8 #include "chrome/browser/extensions/api/storage/settings_namespace.h"
8 #include "chrome/browser/extensions/api/storage/settings_sync_processor.h" 9 #include "chrome/browser/extensions/api/storage/settings_sync_processor.h"
9 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" 10 #include "chrome/browser/extensions/api/storage/settings_sync_util.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
11 #include "sync/api/sync_data.h" 12 #include "sync/api/sync_data.h"
12 #include "sync/protocol/extension_setting_specifics.pb.h" 13 #include "sync/protocol/extension_setting_specifics.pb.h"
13 14
14 namespace extensions { 15 namespace extensions {
15 16
16 using content::BrowserThread; 17 using content::BrowserThread;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 DCHECK(!sync_processor_.get()); 136 DCHECK(!sync_processor_.get());
136 137
137 sync_processor_ = sync_processor.Pass(); 138 sync_processor_ = sync_processor.Pass();
138 sync_processor_->Init(sync_state); 139 sync_processor_->Init(sync_state);
139 140
140 ReadResult maybe_settings = delegate_->Get(); 141 ReadResult maybe_settings = delegate_->Get();
141 if (maybe_settings->HasError()) { 142 if (maybe_settings->HasError()) {
142 return syncer::SyncError( 143 return syncer::SyncError(
143 FROM_HERE, 144 FROM_HERE,
144 syncer::SyncError::DATATYPE_ERROR, 145 syncer::SyncError::DATATYPE_ERROR,
145 std::string("Failed to get settings: ") + maybe_settings->error(), 146 base::StringPrintf("Failed to get settings: %s",
147 maybe_settings->error().message.c_str()),
146 sync_processor_->type()); 148 sync_processor_->type());
147 } 149 }
148 150
149 const base::DictionaryValue& settings = *maybe_settings->settings().get(); 151 const base::DictionaryValue& settings = maybe_settings->settings();
150 if (sync_state.empty()) 152 return sync_state.empty() ?
151 return SendLocalSettingsToSync(settings); 153 SendLocalSettingsToSync(settings) :
152 else 154 OverwriteLocalSettingsWithSync(sync_state, settings);
153 return OverwriteLocalSettingsWithSync(sync_state, settings);
154 } 155 }
155 156
156 syncer::SyncError SyncableSettingsStorage::SendLocalSettingsToSync( 157 syncer::SyncError SyncableSettingsStorage::SendLocalSettingsToSync(
157 const base::DictionaryValue& settings) { 158 const base::DictionaryValue& settings) {
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
159 160
160 ValueStoreChangeList changes; 161 ValueStoreChangeList changes;
161 for (base::DictionaryValue::Iterator i(settings); !i.IsAtEnd(); i.Advance()) { 162 for (base::DictionaryValue::Iterator i(settings); !i.IsAtEnd(); i.Advance()) {
162 changes.push_back(ValueStoreChange(i.key(), NULL, i.value().DeepCopy())); 163 changes.push_back(ValueStoreChange(i.key(), NULL, i.value().DeepCopy()));
163 } 164 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 const std::string& key = it->key(); 255 const std::string& key = it->key();
255 const Value& value = it->value(); 256 const Value& value = it->value();
256 257
257 scoped_ptr<Value> current_value; 258 scoped_ptr<Value> current_value;
258 { 259 {
259 ReadResult maybe_settings = Get(it->key()); 260 ReadResult maybe_settings = Get(it->key());
260 if (maybe_settings->HasError()) { 261 if (maybe_settings->HasError()) {
261 errors.push_back(syncer::SyncError( 262 errors.push_back(syncer::SyncError(
262 FROM_HERE, 263 FROM_HERE,
263 syncer::SyncError::DATATYPE_ERROR, 264 syncer::SyncError::DATATYPE_ERROR,
264 std::string("Error getting current sync state for ") + 265 base::StringPrintf("Error getting current sync state for %s/%s: %s",
265 extension_id_ + "/" + key + ": " + maybe_settings->error(), 266 extension_id_.c_str(), key.c_str(),
267 maybe_settings->error().message.c_str()),
266 sync_processor_->type())); 268 sync_processor_->type()));
267 continue; 269 continue;
268 } 270 }
269 Value* value = NULL; 271 maybe_settings->settings().RemoveWithoutPathExpansion(key,
270 if (maybe_settings->settings()->GetWithoutPathExpansion(key, &value)) { 272 &current_value);
271 current_value.reset(value->DeepCopy());
272 }
273 } 273 }
274 274
275 syncer::SyncError error; 275 syncer::SyncError error;
276 276
277 switch (it->change_type()) { 277 switch (it->change_type()) {
278 case syncer::SyncChange::ACTION_ADD: 278 case syncer::SyncChange::ACTION_ADD:
279 if (!current_value.get()) { 279 if (!current_value.get()) {
280 error = OnSyncAdd(key, value.DeepCopy(), &changes); 280 error = OnSyncAdd(key, value.DeepCopy(), &changes);
281 } else { 281 } else {
282 // Already a value; hopefully a local change has beaten sync in a 282 // Already a value; hopefully a local change has beaten sync in a
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 syncer::SyncError SyncableSettingsStorage::OnSyncAdd( 334 syncer::SyncError SyncableSettingsStorage::OnSyncAdd(
335 const std::string& key, 335 const std::string& key,
336 Value* new_value, 336 Value* new_value,
337 ValueStoreChangeList* changes) { 337 ValueStoreChangeList* changes) {
338 DCHECK(new_value); 338 DCHECK(new_value);
339 WriteResult result = delegate_->Set(IGNORE_QUOTA, key, *new_value); 339 WriteResult result = delegate_->Set(IGNORE_QUOTA, key, *new_value);
340 if (result->HasError()) { 340 if (result->HasError()) {
341 return syncer::SyncError( 341 return syncer::SyncError(
342 FROM_HERE, 342 FROM_HERE,
343 syncer::SyncError::DATATYPE_ERROR, 343 syncer::SyncError::DATATYPE_ERROR,
344 std::string("Error pushing sync add to local settings: ") + 344 base::StringPrintf("Error pushing sync add to local settings: %s",
345 result->error(), 345 result->error().message.c_str()),
346 sync_processor_->type()); 346 sync_processor_->type());
347 } 347 }
348 changes->push_back(ValueStoreChange(key, NULL, new_value)); 348 changes->push_back(ValueStoreChange(key, NULL, new_value));
349 return syncer::SyncError(); 349 return syncer::SyncError();
350 } 350 }
351 351
352 syncer::SyncError SyncableSettingsStorage::OnSyncUpdate( 352 syncer::SyncError SyncableSettingsStorage::OnSyncUpdate(
353 const std::string& key, 353 const std::string& key,
354 Value* old_value, 354 Value* old_value,
355 Value* new_value, 355 Value* new_value,
356 ValueStoreChangeList* changes) { 356 ValueStoreChangeList* changes) {
357 DCHECK(old_value); 357 DCHECK(old_value);
358 DCHECK(new_value); 358 DCHECK(new_value);
359 WriteResult result = delegate_->Set(IGNORE_QUOTA, key, *new_value); 359 WriteResult result = delegate_->Set(IGNORE_QUOTA, key, *new_value);
360 if (result->HasError()) { 360 if (result->HasError()) {
361 return syncer::SyncError( 361 return syncer::SyncError(
362 FROM_HERE, 362 FROM_HERE,
363 syncer::SyncError::DATATYPE_ERROR, 363 syncer::SyncError::DATATYPE_ERROR,
364 std::string("Error pushing sync update to local settings: ") + 364 base::StringPrintf("Error pushing sync update to local settings: %s",
365 result->error(), 365 result->error().message.c_str()),
366 sync_processor_->type()); 366 sync_processor_->type());
367 } 367 }
368 changes->push_back(ValueStoreChange(key, old_value, new_value)); 368 changes->push_back(ValueStoreChange(key, old_value, new_value));
369 return syncer::SyncError(); 369 return syncer::SyncError();
370 } 370 }
371 371
372 syncer::SyncError SyncableSettingsStorage::OnSyncDelete( 372 syncer::SyncError SyncableSettingsStorage::OnSyncDelete(
373 const std::string& key, 373 const std::string& key,
374 Value* old_value, 374 Value* old_value,
375 ValueStoreChangeList* changes) { 375 ValueStoreChangeList* changes) {
376 DCHECK(old_value); 376 DCHECK(old_value);
377 WriteResult result = delegate_->Remove(key); 377 WriteResult result = delegate_->Remove(key);
378 if (result->HasError()) { 378 if (result->HasError()) {
379 return syncer::SyncError( 379 return syncer::SyncError(
380 FROM_HERE, 380 FROM_HERE,
381 syncer::SyncError::DATATYPE_ERROR, 381 syncer::SyncError::DATATYPE_ERROR,
382 std::string("Error pushing sync remove to local settings: ") + 382 base::StringPrintf("Error pushing sync remove to local settings: %s",
383 result->error(), 383 result->error().message.c_str()),
384 sync_processor_->type()); 384 sync_processor_->type());
385 } 385 }
386 changes->push_back(ValueStoreChange(key, old_value, NULL)); 386 changes->push_back(ValueStoreChange(key, old_value, NULL));
387 return syncer::SyncError(); 387 return syncer::SyncError();
388 } 388 }
389 389
390 } // namespace extensions 390 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698