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

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

Issue 8539037: Extension Settings API: make it so that when changes received from Sync fail to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments, sync 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/settings/in_memory_settings_storage.h"
6
7 #include "base/logging.h"
8
9 namespace extensions {
10
11 namespace {
12
13 std::vector<std::string> CreateVector(const std::string& string) {
14 std::vector<std::string> strings;
15 strings.push_back(string);
16 return strings;
17 }
18
19 } // namespace
20
21 SettingsStorage::ReadResult InMemorySettingsStorage::Get(
22 const std::string& key) {
23 return Get(CreateVector(key));
24 }
25
26 SettingsStorage::ReadResult InMemorySettingsStorage::Get(
27 const std::vector<std::string>& keys) {
28 DictionaryValue* settings = new DictionaryValue();
29 for (std::vector<std::string>::const_iterator it = keys.begin();
30 it != keys.end(); ++it) {
31 Value* value = NULL;
32 if (storage_.GetWithoutPathExpansion(*it, &value)) {
33 settings->SetWithoutPathExpansion(*it, value->DeepCopy());
34 }
35 }
36 return ReadResult(settings);
37 }
38
39 SettingsStorage::ReadResult InMemorySettingsStorage::Get() {
40 return ReadResult(storage_.DeepCopy());
41 }
42
43 SettingsStorage::WriteResult InMemorySettingsStorage::Set(
44 const std::string& key, const Value& value) {
45 DictionaryValue settings;
46 settings.SetWithoutPathExpansion(key, value.DeepCopy());
47 return Set(settings);
48 }
49
50 SettingsStorage::WriteResult InMemorySettingsStorage::Set(
51 const DictionaryValue& settings) {
52 scoped_ptr<SettingChangeList> changes(
53 new SettingChangeList());
54 for (DictionaryValue::Iterator it(settings); it.HasNext(); it.Advance()) {
55 Value* old_value = NULL;
56 storage_.GetWithoutPathExpansion(it.key(), &old_value);
57 if (!old_value || !old_value->Equals(&it.value())) {
58 changes->push_back(
59 SettingChange(
60 it.key(),
61 old_value ? old_value->DeepCopy() : old_value,
62 it.value().DeepCopy()));
63 storage_.SetWithoutPathExpansion(it.key(), it.value().DeepCopy());
64 }
65 }
66 return WriteResult(changes.release());
67 }
68
69 SettingsStorage::WriteResult InMemorySettingsStorage::Remove(
70 const std::string& key) {
71 return Remove(CreateVector(key));
72 }
73
74 SettingsStorage::WriteResult InMemorySettingsStorage::Remove(
75 const std::vector<std::string>& keys) {
76 scoped_ptr<SettingChangeList> changes(
77 new SettingChangeList());
78 for (std::vector<std::string>::const_iterator it = keys.begin();
79 it != keys.end(); ++it) {
80 Value* old_value = NULL;
81 if (storage_.RemoveWithoutPathExpansion(*it, &old_value)) {
82 changes->push_back(SettingChange(*it, old_value, NULL));
83 }
84 }
85 return WriteResult(changes.release());
86 }
87
88 SettingsStorage::WriteResult
89 InMemorySettingsStorage::Clear() {
90 std::vector<std::string> keys;
91 for (DictionaryValue::Iterator it(storage_); it.HasNext(); it.Advance()) {
92 keys.push_back(it.key());
93 }
94 return Remove(keys);
95 }
96
97 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698