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/extension_settings_storage_cache.h" | 5 #include "chrome/browser/extensions/extension_settings_storage_cache.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 std::string key; | 142 std::string key; |
143 DictionaryValue* settings = new DictionaryValue(); | 143 DictionaryValue* settings = new DictionaryValue(); |
144 ListValue missing_keys; | 144 ListValue missing_keys; |
145 | 145 |
146 for (ListValue::const_iterator it = keys.begin(); it != keys.end(); ++it) { | 146 for (ListValue::const_iterator it = keys.begin(); it != keys.end(); ++it) { |
147 if ((*it)->GetAsString(&key)) { | 147 if ((*it)->GetAsString(&key)) { |
148 Value *value; | 148 Value *value; |
149 if (GetFromCache(key, &value)) { | 149 if (GetFromCache(key, &value)) { |
150 settings->Set(key, value); | 150 settings->Set(key, value); |
151 } else { | 151 } else { |
152 missing_keys.Append(Value::CreateStringValue(key)); | 152 missing_keys.Append(base::StringValue::New(key)); |
153 } | 153 } |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 if (missing_keys.empty()) { | 157 if (missing_keys.empty()) { |
158 MessageLoop::current()->PostTask( | 158 MessageLoop::current()->PostTask( |
159 FROM_HERE, | 159 FROM_HERE, |
160 base::Bind( | 160 base::Bind( |
161 &ExtensionSettingsStorageCache::Callback::OnSuccess, | 161 &ExtensionSettingsStorageCache::Callback::OnSuccess, |
162 base::Unretained(callback), | 162 base::Unretained(callback), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 void ExtensionSettingsStorageCache::Remove( | 214 void ExtensionSettingsStorageCache::Remove( |
215 const std::string& key, | 215 const std::string& key, |
216 ExtensionSettingsStorageCache::Callback *callback) { | 216 ExtensionSettingsStorageCache::Callback *callback) { |
217 // Invalidate the cached entry first, in case the remove fails. | 217 // Invalidate the cached entry first, in case the remove fails. |
218 // We will also need to do if after the callback, to avoid race conditions | 218 // We will also need to do if after the callback, to avoid race conditions |
219 // whether other API calls fill the cache on the UI thread. | 219 // whether other API calls fill the cache on the UI thread. |
220 // This would be a good time to use structured cloning... | 220 // This would be a good time to use structured cloning... |
221 cache_.Remove(key, NULL); | 221 cache_.Remove(key, NULL); |
222 ListValue* key_list = new ListValue(); | 222 ListValue* key_list = new ListValue(); |
223 key_list->Append(Value::CreateStringValue(key)); | 223 key_list->Append(base::StringValue::New(key)); |
224 delegate_->Remove( | 224 delegate_->Remove( |
225 key, | 225 key, |
226 CacheModifyingCallback::Create( | 226 CacheModifyingCallback::Create( |
227 callback, | 227 callback, |
228 cache_ptr_factory_.GetWeakPtr(), | 228 cache_ptr_factory_.GetWeakPtr(), |
229 key_list)); | 229 key_list)); |
230 } | 230 } |
231 | 231 |
232 void ExtensionSettingsStorageCache::Remove( | 232 void ExtensionSettingsStorageCache::Remove( |
233 const ListValue& keys, | 233 const ListValue& keys, |
(...skipping 22 matching lines...) Expand all Loading... |
256 | 256 |
257 bool ExtensionSettingsStorageCache::GetFromCache( | 257 bool ExtensionSettingsStorageCache::GetFromCache( |
258 const std::string& key, Value** value) { | 258 const std::string& key, Value** value) { |
259 Value* cached_value; | 259 Value* cached_value; |
260 if (!cache_.Get(key, &cached_value)) { | 260 if (!cache_.Get(key, &cached_value)) { |
261 return false; | 261 return false; |
262 } | 262 } |
263 *value = cached_value->DeepCopy(); | 263 *value = cached_value->DeepCopy(); |
264 return true; | 264 return true; |
265 } | 265 } |
OLD | NEW |