OLD | NEW |
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/settings_storage_cache.h" | 5 #include "chrome/browser/extensions/settings/settings_storage_cache.h" |
6 | 6 |
7 namespace extensions { | 7 namespace extensions { |
8 | 8 |
9 SettingsStorageCache::SettingsStorageCache( | 9 SettingsStorageCache::SettingsStorageCache( |
10 SettingsStorage* delegate) : delegate_(delegate) {} | 10 SettingsStorage* delegate) : delegate_(delegate) {} |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 SettingsStorage::ReadResult SettingsStorageCache::Get() { | 61 SettingsStorage::ReadResult SettingsStorageCache::Get() { |
62 ReadResult result = delegate_->Get(); | 62 ReadResult result = delegate_->Get(); |
63 if (!result.HasError()) { | 63 if (!result.HasError()) { |
64 cache_.MergeDictionary(&result.settings()); | 64 cache_.MergeDictionary(&result.settings()); |
65 } | 65 } |
66 return result; | 66 return result; |
67 } | 67 } |
68 | 68 |
69 SettingsStorage::WriteResult SettingsStorageCache::Set( | 69 SettingsStorage::WriteResult SettingsStorageCache::Set( |
70 const std::string& key, const Value& value) { | 70 WriteOptions options, const std::string& key, const Value& value) { |
71 WriteResult result = delegate_->Set(key, value); | 71 WriteResult result = delegate_->Set(options, key, value); |
72 if (!result.HasError()) { | 72 if (!result.HasError()) { |
73 cache_.SetWithoutPathExpansion(key, value.DeepCopy()); | 73 cache_.SetWithoutPathExpansion(key, value.DeepCopy()); |
74 } | 74 } |
75 return result; | 75 return result; |
76 } | 76 } |
77 | 77 |
78 SettingsStorage::WriteResult SettingsStorageCache::Set( | 78 SettingsStorage::WriteResult SettingsStorageCache::Set( |
79 const DictionaryValue& settings) { | 79 WriteOptions options, const DictionaryValue& settings) { |
80 WriteResult result = delegate_->Set(settings); | 80 WriteResult result = delegate_->Set(options, settings); |
81 if (result.HasError()) { | 81 if (result.HasError()) { |
82 return result; | 82 return result; |
83 } | 83 } |
84 | 84 |
85 for (SettingChangeList::const_iterator it = result.changes().begin(); | 85 for (SettingChangeList::const_iterator it = result.changes().begin(); |
86 it != result.changes().end(); ++it) { | 86 it != result.changes().end(); ++it) { |
87 DCHECK(it->new_value()); | 87 DCHECK(it->new_value()); |
88 cache_.SetWithoutPathExpansion(it->key(), it->new_value()->DeepCopy()); | 88 cache_.SetWithoutPathExpansion(it->key(), it->new_value()->DeepCopy()); |
89 } | 89 } |
90 | 90 |
91 return result; | 91 return result; |
92 } | 92 } |
93 | 93 |
94 SettingsStorage::WriteResult SettingsStorageCache::Remove( | 94 SettingsStorage::WriteResult SettingsStorageCache::Remove( |
95 const std::string& key) { | 95 WriteOptions options, const std::string& key) { |
96 WriteResult result = delegate_->Remove(key); | 96 WriteResult result = delegate_->Remove(options, key); |
97 if (!result.HasError()) { | 97 if (!result.HasError()) { |
98 cache_.RemoveWithoutPathExpansion(key, NULL); | 98 cache_.RemoveWithoutPathExpansion(key, NULL); |
99 } | 99 } |
100 return result; | 100 return result; |
101 } | 101 } |
102 | 102 |
103 SettingsStorage::WriteResult SettingsStorageCache::Remove( | 103 SettingsStorage::WriteResult SettingsStorageCache::Remove( |
104 const std::vector<std::string>& keys) { | 104 WriteOptions options, const std::vector<std::string>& keys) { |
105 WriteResult result = delegate_->Remove(keys); | 105 WriteResult result = delegate_->Remove(options, keys); |
106 if (result.HasError()) { | 106 if (result.HasError()) { |
107 return result; | 107 return result; |
108 } | 108 } |
109 | 109 |
110 for (SettingChangeList::const_iterator it = result.changes().begin(); | 110 for (SettingChangeList::const_iterator it = result.changes().begin(); |
111 it != result.changes().end(); ++it) { | 111 it != result.changes().end(); ++it) { |
112 cache_.RemoveWithoutPathExpansion(it->key(), NULL); | 112 cache_.RemoveWithoutPathExpansion(it->key(), NULL); |
113 } | 113 } |
114 | 114 |
115 return result; | 115 return result; |
116 } | 116 } |
117 | 117 |
118 SettingsStorage::WriteResult SettingsStorageCache::Clear() { | 118 SettingsStorage::WriteResult SettingsStorageCache::Clear(WriteOptions options) { |
119 WriteResult result = delegate_->Clear(); | 119 WriteResult result = delegate_->Clear(options); |
120 if (!result.HasError()) { | 120 if (!result.HasError()) { |
121 cache_.Clear(); | 121 cache_.Clear(); |
122 } | 122 } |
123 return result; | 123 return result; |
124 } | 124 } |
125 | 125 |
126 bool SettingsStorageCache::GetFromCache( | 126 bool SettingsStorageCache::GetFromCache( |
127 const std::string& key, Value** value) { | 127 const std::string& key, Value** value) { |
128 Value* cached_value; | 128 Value* cached_value; |
129 if (!cache_.GetWithoutPathExpansion(key, &cached_value)) { | 129 if (!cache_.GetWithoutPathExpansion(key, &cached_value)) { |
130 return false; | 130 return false; |
131 } | 131 } |
132 | 132 |
133 *value = cached_value->DeepCopy(); | 133 *value = cached_value->DeepCopy(); |
134 return true; | 134 return true; |
135 } | 135 } |
136 | 136 |
137 } // namespace extensions | 137 } // namespace extensions |
OLD | NEW |