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

Unified 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: . 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_settings_storage.cc
diff --git a/chrome/browser/extensions/extension_settings_storage.cc b/chrome/browser/extensions/extension_settings_storage.cc
index 882efe83e72268923482ae77ca8029b589eb93fc..42e5209d568a2cb6cec131dbe08bfdc5fe4cd6b7 100644
--- a/chrome/browser/extensions/extension_settings_storage.cc
+++ b/chrome/browser/extensions/extension_settings_storage.cc
@@ -8,11 +8,13 @@
// Implementation of ExtensionSettingsStorage::Result
ExtensionSettingsStorage::Result::Result(
- DictionaryValue* settings, std::set<std::string>* changed_keys)
- : inner_(new Inner(settings, changed_keys, std::string())) {}
+ DictionaryValue* settings,
+ DictionaryValue* old_settings,
+ std::set<std::string>* changed_keys)
+ : inner_(new Inner(settings, old_settings, changed_keys, std::string())) {}
ExtensionSettingsStorage::Result::Result(const std::string& error)
- : inner_(new Inner(NULL, new std::set<std::string>(), error)) {
+ : inner_(new Inner(NULL, NULL, new std::set<std::string>(), error)) {
DCHECK(!error.empty());
}
@@ -29,6 +31,36 @@ ExtensionSettingsStorage::Result::GetChangedKeys() const {
return inner_->changed_keys_.get();
}
+bool ExtensionSettingsStorage::Result::GetOldValue(
+ const std::string& key, Value** old_value) const {
+ DCHECK(!HasError());
+ DCHECK(old_value);
+ if (!inner_->changed_keys_.get()) {
+ return false;
+ }
+ if (!inner_->changed_keys_->count(key)) {
+ return inner_->settings_->GetWithoutPathExpansion(key, old_value);
+ }
+ *old_value = NULL;
+ inner_->old_settings_->GetWithoutPathExpansion(key, old_value);
+ return true;
+}
+
+bool ExtensionSettingsStorage::Result::GetNewValue(
+ const std::string& key, Value** new_value) const {
+ DCHECK(!HasError());
+ DCHECK(new_value);
+ if (!inner_->changed_keys_.get()) {
+ return false;
+ }
+ *new_value = NULL;
+ if (!inner_->settings_.get()) {
+ return true;
+ }
+ inner_->settings_->GetWithoutPathExpansion(key, new_value);
+ return true;
+}
+
bool ExtensionSettingsStorage::Result::HasError() const {
return !inner_->error_.empty();
}
@@ -40,8 +72,12 @@ const std::string& ExtensionSettingsStorage::Result::GetError() const {
ExtensionSettingsStorage::Result::Inner::Inner(
DictionaryValue* settings,
+ DictionaryValue* old_settings,
std::set<std::string>* changed_keys,
const std::string& error)
- : settings_(settings), changed_keys_(changed_keys), error_(error) {}
+ : settings_(settings),
+ old_settings_(old_settings),
+ changed_keys_(changed_keys),
+ error_(error) {}
ExtensionSettingsStorage::Result::Inner::~Inner() {}

Powered by Google App Engine
This is Rietveld 408576698