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

Side by Side Diff: chrome/browser/extensions/settings/syncable_settings_storage.cc

Issue 8587025: Extension settings API: force through changes that come from sync (ignoring (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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/extensions/settings/syncable_settings_storage.h" 5 #include "chrome/browser/extensions/settings/syncable_settings_storage.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/extensions/settings/settings_sync_util.h" 8 #include "chrome/browser/extensions/settings/settings_sync_util.h"
9 #include "chrome/browser/sync/api/sync_data.h" 9 #include "chrome/browser/sync/api/sync_data.h"
10 #include "chrome/browser/sync/protocol/extension_setting_specifics.pb.h" 10 #include "chrome/browser/sync/protocol/extension_setting_specifics.pb.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
43 return delegate_->Get(keys); 43 return delegate_->Get(keys);
44 } 44 }
45 45
46 SettingsStorage::ReadResult SyncableSettingsStorage::Get() { 46 SettingsStorage::ReadResult SyncableSettingsStorage::Get() {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
48 return delegate_->Get(); 48 return delegate_->Get();
49 } 49 }
50 50
51 SettingsStorage::WriteResult SyncableSettingsStorage::Set( 51 SettingsStorage::WriteResult SyncableSettingsStorage::Set(
52 const std::string& key, const Value& value) { 52 WriteOptions options, const std::string& key, const Value& value) {
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
54 WriteResult result = delegate_->Set(key, value); 54 WriteResult result = delegate_->Set(options, key, value);
55 if (result.HasError()) { 55 if (result.HasError()) {
56 return result; 56 return result;
57 } 57 }
58 if (sync_processor_ && !result.changes().empty()) { 58 if (sync_processor_ && !result.changes().empty()) {
59 SendChangesToSync(result.changes()); 59 SendChangesToSync(result.changes());
60 } 60 }
61 return result; 61 return result;
62 } 62 }
63 63
64 SettingsStorage::WriteResult SyncableSettingsStorage::Set( 64 SettingsStorage::WriteResult SyncableSettingsStorage::Set(
65 const DictionaryValue& values) { 65 WriteOptions options, const DictionaryValue& values) {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
67 WriteResult result = delegate_->Set(values); 67 WriteResult result = delegate_->Set(options, values);
68 if (result.HasError()) { 68 if (result.HasError()) {
69 return result; 69 return result;
70 } 70 }
71 if (sync_processor_ && !result.changes().empty()) { 71 if (sync_processor_ && !result.changes().empty()) {
72 SendChangesToSync(result.changes()); 72 SendChangesToSync(result.changes());
73 } 73 }
74 return result; 74 return result;
75 } 75 }
76 76
77 SettingsStorage::WriteResult SyncableSettingsStorage::Remove( 77 SettingsStorage::WriteResult SyncableSettingsStorage::Remove(
78 const std::string& key) { 78 WriteOptions options, const std::string& key) {
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
80 WriteResult result = delegate_->Remove(key); 80 WriteResult result = delegate_->Remove(options, key);
81 if (result.HasError()) { 81 if (result.HasError()) {
82 return result; 82 return result;
83 } 83 }
84 if (sync_processor_ && !result.changes().empty()) { 84 if (sync_processor_ && !result.changes().empty()) {
85 SendChangesToSync(result.changes()); 85 SendChangesToSync(result.changes());
86 } 86 }
87 return result; 87 return result;
88 } 88 }
89 89
90 SettingsStorage::WriteResult SyncableSettingsStorage::Remove( 90 SettingsStorage::WriteResult SyncableSettingsStorage::Remove(
91 const std::vector<std::string>& keys) { 91 WriteOptions options, const std::vector<std::string>& keys) {
92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
93 WriteResult result = delegate_->Remove(keys); 93 WriteResult result = delegate_->Remove(options, keys);
94 if (result.HasError()) { 94 if (result.HasError()) {
95 return result; 95 return result;
96 } 96 }
97 if (sync_processor_ && !result.changes().empty()) { 97 if (sync_processor_ && !result.changes().empty()) {
98 SendChangesToSync(result.changes()); 98 SendChangesToSync(result.changes());
99 } 99 }
100 return result; 100 return result;
101 } 101 }
102 102
103 SettingsStorage::WriteResult 103 SettingsStorage::WriteResult SyncableSettingsStorage::Clear(
104 SyncableSettingsStorage::Clear() { 104 WriteOptions options) {
105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
106 WriteResult result = delegate_->Clear(); 106 WriteResult result = delegate_->Clear(options);
107 if (result.HasError()) { 107 if (result.HasError()) {
108 return result; 108 return result;
109 } 109 }
110 if (sync_processor_ && !result.changes().empty()) { 110 if (sync_processor_ && !result.changes().empty()) {
111 SendChangesToSync(result.changes()); 111 SendChangesToSync(result.changes());
112 } 112 }
113 return result; 113 return result;
114 } 114 }
115 115
116 // Sync-related methods. 116 // Sync-related methods.
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 synced_keys_.erase(*it); 389 synced_keys_.erase(*it);
390 } 390 }
391 } 391 }
392 392
393 SyncError SyncableSettingsStorage::OnSyncAdd( 393 SyncError SyncableSettingsStorage::OnSyncAdd(
394 const std::string& key, 394 const std::string& key,
395 Value* new_value, 395 Value* new_value,
396 SettingChangeList* changes) { 396 SettingChangeList* changes) {
397 DCHECK(new_value); 397 DCHECK(new_value);
398 synced_keys_.insert(key); 398 synced_keys_.insert(key);
399 WriteResult result = delegate_->Set(key, *new_value); 399 WriteResult result = delegate_->Set(FORCE, key, *new_value);
not at google - send to devlin 2011/11/17 07:02:53 Change #5: forcing changes that come from sync (he
400 if (result.HasError()) { 400 if (result.HasError()) {
401 return SyncError( 401 return SyncError(
402 FROM_HERE, 402 FROM_HERE,
403 std::string("Error pushing sync add to local settings: ") + 403 std::string("Error pushing sync add to local settings: ") +
404 result.error(), 404 result.error(),
405 sync_type_); 405 sync_type_);
406 } 406 }
407 changes->push_back(SettingChange(key, NULL, new_value)); 407 changes->push_back(SettingChange(key, NULL, new_value));
408 return SyncError(); 408 return SyncError();
409 } 409 }
410 410
411 SyncError SyncableSettingsStorage::OnSyncUpdate( 411 SyncError SyncableSettingsStorage::OnSyncUpdate(
412 const std::string& key, 412 const std::string& key,
413 Value* old_value, 413 Value* old_value,
414 Value* new_value, 414 Value* new_value,
415 SettingChangeList* changes) { 415 SettingChangeList* changes) {
416 DCHECK(old_value); 416 DCHECK(old_value);
417 DCHECK(new_value); 417 DCHECK(new_value);
418 WriteResult result = delegate_->Set(key, *new_value); 418 WriteResult result = delegate_->Set(FORCE, key, *new_value);
419 if (result.HasError()) { 419 if (result.HasError()) {
420 return SyncError( 420 return SyncError(
421 FROM_HERE, 421 FROM_HERE,
422 std::string("Error pushing sync update to local settings: ") + 422 std::string("Error pushing sync update to local settings: ") +
423 result.error(), 423 result.error(),
424 sync_type_); 424 sync_type_);
425 } 425 }
426 changes->push_back(SettingChange(key, old_value, new_value)); 426 changes->push_back(SettingChange(key, old_value, new_value));
427 return SyncError(); 427 return SyncError();
428 } 428 }
429 429
430 SyncError SyncableSettingsStorage::OnSyncDelete( 430 SyncError SyncableSettingsStorage::OnSyncDelete(
431 const std::string& key, 431 const std::string& key,
432 Value* old_value, 432 Value* old_value,
433 SettingChangeList* changes) { 433 SettingChangeList* changes) {
434 DCHECK(old_value); 434 DCHECK(old_value);
435 synced_keys_.erase(key); 435 synced_keys_.erase(key);
436 WriteResult result = delegate_->Remove(key); 436 WriteResult result = delegate_->Remove(FORCE, key);
437 if (result.HasError()) { 437 if (result.HasError()) {
438 return SyncError( 438 return SyncError(
439 FROM_HERE, 439 FROM_HERE,
440 std::string("Error pushing sync remove to local settings: ") + 440 std::string("Error pushing sync remove to local settings: ") +
441 result.error(), 441 result.error(),
442 sync_type_); 442 sync_type_);
443 } 443 }
444 changes->push_back(SettingChange(key, old_value, NULL)); 444 changes->push_back(SettingChange(key, old_value, NULL));
445 return SyncError(); 445 return SyncError();
446 } 446 }
447 447
448 } // namespace extensions 448 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698