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

Side by Side Diff: chrome/browser/extensions/extension_settings_storage.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: sync 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "chrome/browser/extensions/extension_settings_storage.h" 6 #include "chrome/browser/extensions/extension_settings_storage.h"
7 7
8 // Implementation of ExtensionSettingsStorage::Result 8 // Implementation of ExtensionSettingsStorage::Result
9 9
10 ExtensionSettingsStorage::Result::Result( 10 ExtensionSettingsStorage::Result::Result(
11 DictionaryValue* settings, std::set<std::string>* changed_keys) 11 DictionaryValue* settings,
12 : inner_(new Inner(settings, changed_keys, std::string())) {} 12 DictionaryValue* old_settings,
13 std::set<std::string>* changed_keys)
14 : inner_(new Inner(settings, old_settings, changed_keys, std::string())) {}
13 15
14 ExtensionSettingsStorage::Result::Result(const std::string& error) 16 ExtensionSettingsStorage::Result::Result(const std::string& error)
15 : inner_(new Inner(NULL, new std::set<std::string>(), error)) { 17 : inner_(new Inner(NULL, NULL, new std::set<std::string>(), error)) {
16 DCHECK(!error.empty()); 18 DCHECK(!error.empty());
17 } 19 }
18 20
19 ExtensionSettingsStorage::Result::~Result() {} 21 ExtensionSettingsStorage::Result::~Result() {}
20 22
21 DictionaryValue* ExtensionSettingsStorage::Result::GetSettings() const { 23 const DictionaryValue* ExtensionSettingsStorage::Result::GetSettings() const {
22 DCHECK(!HasError()); 24 DCHECK(!HasError());
23 return inner_->settings_.get(); 25 return inner_->settings_.get();
24 } 26 }
25 27
26 std::set<std::string>* 28 const std::set<std::string>*
27 ExtensionSettingsStorage::Result::GetChangedKeys() const { 29 ExtensionSettingsStorage::Result::GetChangedKeys() const {
28 DCHECK(!HasError()); 30 DCHECK(!HasError());
29 return inner_->changed_keys_.get(); 31 return inner_->changed_keys_.get();
30 } 32 }
31 33
34 const Value* ExtensionSettingsStorage::Result::GetOldValue(
35 const std::string& key) const {
36 DCHECK(!HasError());
37 if (!inner_->changed_keys_.get()) {
38 return NULL;
39 }
40 Value* old_value = NULL;
41 if (inner_->changed_keys_->count(key)) {
42 inner_->old_settings_->GetWithoutPathExpansion(key, &old_value);
43 } else if (inner_->settings_.get()) {
44 inner_->settings_->GetWithoutPathExpansion(key, &old_value);
45 }
46 return old_value;
47 }
48
49 const Value* ExtensionSettingsStorage::Result::GetNewValue(
50 const std::string& key) const {
51 DCHECK(!HasError());
52 if (!inner_->changed_keys_.get()) {
53 return NULL;
54 }
55 Value* new_value = NULL;
56 if (inner_->settings_.get()) {
57 inner_->settings_->GetWithoutPathExpansion(key, &new_value);
58 }
59 return new_value;
60 }
61
32 bool ExtensionSettingsStorage::Result::HasError() const { 62 bool ExtensionSettingsStorage::Result::HasError() const {
33 return !inner_->error_.empty(); 63 return !inner_->error_.empty();
34 } 64 }
35 65
36 const std::string& ExtensionSettingsStorage::Result::GetError() const { 66 const std::string& ExtensionSettingsStorage::Result::GetError() const {
37 DCHECK(HasError()); 67 DCHECK(HasError());
38 return inner_->error_; 68 return inner_->error_;
39 } 69 }
40 70
41 ExtensionSettingsStorage::Result::Inner::Inner( 71 ExtensionSettingsStorage::Result::Inner::Inner(
42 DictionaryValue* settings, 72 DictionaryValue* settings,
73 DictionaryValue* old_settings,
43 std::set<std::string>* changed_keys, 74 std::set<std::string>* changed_keys,
44 const std::string& error) 75 const std::string& error)
45 : settings_(settings), changed_keys_(changed_keys), error_(error) {} 76 : settings_(settings),
77 old_settings_(old_settings),
78 changed_keys_(changed_keys),
79 error_(error) {}
46 80
47 ExtensionSettingsStorage::Result::Inner::~Inner() {} 81 ExtensionSettingsStorage::Result::Inner::~Inner() {}
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_settings_storage.h ('k') | chrome/browser/extensions/extension_settings_storage_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698