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

Side by Side Diff: chrome/browser/extensions/extension_settings_storage_cache.cc

Issue 8177022: Add onChanged events to the extension settings API, both from sync and between (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 2 months 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/extension_settings_storage_cache.h" 5 #include "chrome/browser/extensions/extension_settings_storage_cache.h"
6 6
7 ExtensionSettingsStorageCache::ExtensionSettingsStorageCache( 7 ExtensionSettingsStorageCache::ExtensionSettingsStorageCache(
8 ExtensionSettingsStorage* delegate) : delegate_(delegate) {} 8 ExtensionSettingsStorage* delegate) : delegate_(delegate) {}
9 9
10 ExtensionSettingsStorageCache::~ExtensionSettingsStorageCache() {} 10 ExtensionSettingsStorageCache::~ExtensionSettingsStorageCache() {}
11 11
12 ExtensionSettingsStorage::Result ExtensionSettingsStorageCache::Get( 12 ExtensionSettingsStorage::Result ExtensionSettingsStorageCache::Get(
13 const std::string& key) { 13 const std::string& key) {
14 Value *value; 14 Value *value;
15 if (GetFromCache(key, &value)) { 15 if (GetFromCache(key, &value)) {
16 DictionaryValue* settings = new DictionaryValue(); 16 DictionaryValue* settings = new DictionaryValue();
17 settings->SetWithoutPathExpansion(key, value); 17 settings->SetWithoutPathExpansion(key, value);
18 return Result(settings, NULL); 18 return Result(settings, NULL, NULL);
19 } 19 }
20 20
21 Result result = delegate_->Get(key); 21 Result result = delegate_->Get(key);
22 if (result.HasError()) { 22 if (result.HasError()) {
23 return result; 23 return result;
24 } 24 }
25 25
26 cache_.MergeDictionary(result.GetSettings()); 26 cache_.MergeDictionary(result.GetSettings());
27 return result; 27 return result;
28 } 28 }
29 29
30 ExtensionSettingsStorage::Result ExtensionSettingsStorageCache::Get( 30 ExtensionSettingsStorage::Result ExtensionSettingsStorageCache::Get(
31 const std::vector<std::string>& keys) { 31 const std::vector<std::string>& keys) {
32 scoped_ptr<DictionaryValue> from_cache(new DictionaryValue()); 32 scoped_ptr<DictionaryValue> from_cache(new DictionaryValue());
33 std::vector<std::string> missing_keys; 33 std::vector<std::string> missing_keys;
34 34
35 for (std::vector<std::string>::const_iterator it = keys.begin(); 35 for (std::vector<std::string>::const_iterator it = keys.begin();
36 it != keys.end(); ++it) { 36 it != keys.end(); ++it) {
37 Value *value; 37 Value *value;
38 if (GetFromCache(*it, &value)) { 38 if (GetFromCache(*it, &value)) {
39 from_cache->SetWithoutPathExpansion(*it, value); 39 from_cache->SetWithoutPathExpansion(*it, value);
40 } else { 40 } else {
41 missing_keys.push_back(*it); 41 missing_keys.push_back(*it);
42 } 42 }
43 } 43 }
44 44
45 if (missing_keys.empty()) { 45 if (missing_keys.empty()) {
46 return Result(from_cache.release(), NULL); 46 return Result(from_cache.release(), NULL, NULL);
47 } 47 }
48 48
49 Result result = delegate_->Get(keys); 49 Result result = delegate_->Get(keys);
50 if (result.HasError()) { 50 if (result.HasError()) {
51 return result; 51 return result;
52 } 52 }
53 53
54 cache_.MergeDictionary(result.GetSettings()); 54 cache_.MergeDictionary(result.GetSettings());
55 result.GetSettings()->MergeDictionary(from_cache.get()); 55 result.GetSettings()->MergeDictionary(from_cache.get());
56 return result; 56 return result;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 bool ExtensionSettingsStorageCache::GetFromCache( 128 bool ExtensionSettingsStorageCache::GetFromCache(
129 const std::string& key, Value** value) { 129 const std::string& key, Value** value) {
130 Value* cached_value; 130 Value* cached_value;
131 if (!cache_.GetWithoutPathExpansion(key, &cached_value)) { 131 if (!cache_.GetWithoutPathExpansion(key, &cached_value)) {
132 return false; 132 return false;
133 } 133 }
134 134
135 *value = cached_value->DeepCopy(); 135 *value = cached_value->DeepCopy();
136 return true; 136 return true;
137 } 137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698