summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prefs/scoped_user_pref_update.cc
diff options
context:
space:
mode:
authorbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 14:07:39 +0000
committerbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 14:07:39 +0000
commit26418b737e8f2058e35d03e25ec39926e2e2830b (patch)
tree0b475b14654631f6ba38482f42223d04f2501be6 /chrome/browser/prefs/scoped_user_pref_update.cc
parent16eee4e22ca134972a23b667102f1b019a44aa85 (diff)
downloadchromium_src-26418b737e8f2058e35d03e25ec39926e2e2830b.zip
chromium_src-26418b737e8f2058e35d03e25ec39926e2e2830b.tar.gz
chromium_src-26418b737e8f2058e35d03e25ec39926e2e2830b.tar.bz2
Introduce a new way of using ScopedUserPrefUpdate that ensures notifications are sent.
This new ScopedUserPrefUpdate class should subsitute access to GetMutableList() and GetMutableDictionary() in PrefService. It ensures that update notifications are sent. BUG=none TEST=none Review URL: http://codereview.chromium.org/6757011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79821 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/prefs/scoped_user_pref_update.cc')
-rw-r--r--chrome/browser/prefs/scoped_user_pref_update.cc32
1 files changed, 30 insertions, 2 deletions
diff --git a/chrome/browser/prefs/scoped_user_pref_update.cc b/chrome/browser/prefs/scoped_user_pref_update.cc
index 3ef0029..bc033f1 100644
--- a/chrome/browser/prefs/scoped_user_pref_update.cc
+++ b/chrome/browser/prefs/scoped_user_pref_update.cc
@@ -4,11 +4,39 @@
#include "chrome/browser/prefs/scoped_user_pref_update.h"
+#include "base/logging.h"
#include "chrome/browser/prefs/pref_notifier.h"
#include "chrome/browser/prefs/pref_service.h"
-ScopedUserPrefUpdate::ScopedUserPrefUpdate(
- PrefService* service, const char* path)
+namespace subtle {
+
+ScopedUserPrefUpdateBase::ScopedUserPrefUpdateBase(PrefService* service,
+ const char* path)
+ : service_(service),
+ path_(path),
+ value_(NULL) {}
+
+ScopedUserPrefUpdateBase::~ScopedUserPrefUpdateBase() {
+ Notify();
+}
+
+Value* ScopedUserPrefUpdateBase::Get(Value::ValueType type) {
+ if (!value_)
+ value_ = service_->GetMutableUserPref(path_.c_str(), type);
+ return value_;
+}
+
+void ScopedUserPrefUpdateBase::Notify() {
+ if (value_) {
+ service_->ReportUserPrefChanged(path_);
+ value_ = NULL;
+ }
+}
+
+} // namespace subtle
+
+ScopedUserPrefUpdate::ScopedUserPrefUpdate(PrefService* service,
+ const char* path)
: service_(service),
path_(path) {}