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

Side by Side Diff: chrome/browser/extensions/settings/testing_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/testing_settings_storage.h" 5 #include "chrome/browser/extensions/settings/testing_settings_storage.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace extensions { 9 namespace extensions {
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 61
62 SettingsStorage::ReadResult TestingSettingsStorage::Get() { 62 SettingsStorage::ReadResult TestingSettingsStorage::Get() {
63 if (fail_all_requests_) { 63 if (fail_all_requests_) {
64 return ReadResultError(); 64 return ReadResultError();
65 } 65 }
66 return ReadResult(storage_.DeepCopy()); 66 return ReadResult(storage_.DeepCopy());
67 } 67 }
68 68
69 SettingsStorage::WriteResult TestingSettingsStorage::Set( 69 SettingsStorage::WriteResult TestingSettingsStorage::Set(
70 const std::string& key, const Value& value) { 70 WriteOptions options, const std::string& key, const Value& value) {
71 DictionaryValue settings; 71 DictionaryValue settings;
72 settings.SetWithoutPathExpansion(key, value.DeepCopy()); 72 settings.SetWithoutPathExpansion(key, value.DeepCopy());
73 return Set(settings); 73 return Set(options, settings);
74 } 74 }
75 75
76 SettingsStorage::WriteResult TestingSettingsStorage::Set( 76 SettingsStorage::WriteResult TestingSettingsStorage::Set(
77 const DictionaryValue& settings) { 77 WriteOptions options, const DictionaryValue& settings) {
78 if (fail_all_requests_) { 78 if (fail_all_requests_) {
79 return WriteResultError(); 79 return WriteResultError();
80 } 80 }
81 81
82 scoped_ptr<SettingChangeList> changes(new SettingChangeList()); 82 scoped_ptr<SettingChangeList> changes(new SettingChangeList());
83 for (DictionaryValue::Iterator it(settings); it.HasNext(); it.Advance()) { 83 for (DictionaryValue::Iterator it(settings); it.HasNext(); it.Advance()) {
84 Value* old_value = NULL; 84 Value* old_value = NULL;
85 storage_.GetWithoutPathExpansion(it.key(), &old_value); 85 storage_.GetWithoutPathExpansion(it.key(), &old_value);
86 if (!old_value || !old_value->Equals(&it.value())) { 86 if (!old_value || !old_value->Equals(&it.value())) {
87 changes->push_back( 87 changes->push_back(
88 SettingChange( 88 SettingChange(
89 it.key(), 89 it.key(),
90 old_value ? old_value->DeepCopy() : old_value, 90 old_value ? old_value->DeepCopy() : old_value,
91 it.value().DeepCopy())); 91 it.value().DeepCopy()));
92 storage_.SetWithoutPathExpansion(it.key(), it.value().DeepCopy()); 92 storage_.SetWithoutPathExpansion(it.key(), it.value().DeepCopy());
93 } 93 }
94 } 94 }
95 return WriteResult(changes.release()); 95 return WriteResult(changes.release());
96 } 96 }
97 97
98 SettingsStorage::WriteResult TestingSettingsStorage::Remove( 98 SettingsStorage::WriteResult TestingSettingsStorage::Remove(
99 const std::string& key) { 99 WriteOptions options, const std::string& key) {
100 return Remove(CreateVector(key)); 100 return Remove(options, CreateVector(key));
101 } 101 }
102 102
103 SettingsStorage::WriteResult TestingSettingsStorage::Remove( 103 SettingsStorage::WriteResult TestingSettingsStorage::Remove(
104 const std::vector<std::string>& keys) { 104 WriteOptions options, const std::vector<std::string>& keys) {
105 if (fail_all_requests_) { 105 if (fail_all_requests_) {
106 return WriteResultError(); 106 return WriteResultError();
107 } 107 }
108 108
109 scoped_ptr<SettingChangeList> changes( 109 scoped_ptr<SettingChangeList> changes(
110 new SettingChangeList()); 110 new SettingChangeList());
111 for (std::vector<std::string>::const_iterator it = keys.begin(); 111 for (std::vector<std::string>::const_iterator it = keys.begin();
112 it != keys.end(); ++it) { 112 it != keys.end(); ++it) {
113 Value* old_value = NULL; 113 Value* old_value = NULL;
114 if (storage_.RemoveWithoutPathExpansion(*it, &old_value)) { 114 if (storage_.RemoveWithoutPathExpansion(*it, &old_value)) {
115 changes->push_back(SettingChange(*it, old_value, NULL)); 115 changes->push_back(SettingChange(*it, old_value, NULL));
116 } 116 }
117 } 117 }
118 return WriteResult(changes.release()); 118 return WriteResult(changes.release());
119 } 119 }
120 120
121 SettingsStorage::WriteResult TestingSettingsStorage::Clear() { 121 SettingsStorage::WriteResult TestingSettingsStorage::Clear(
122 WriteOptions options) {
122 if (fail_all_requests_) { 123 if (fail_all_requests_) {
123 return WriteResultError(); 124 return WriteResultError();
124 } 125 }
125 126
126 std::vector<std::string> keys; 127 std::vector<std::string> keys;
127 for (DictionaryValue::Iterator it(storage_); it.HasNext(); it.Advance()) { 128 for (DictionaryValue::Iterator it(storage_); it.HasNext(); it.Advance()) {
128 keys.push_back(it.key()); 129 keys.push_back(it.key());
129 } 130 }
130 return Remove(keys); 131 return Remove(options, keys);
131 } 132 }
132 133
133 } // namespace extensions 134 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698