diff options
Diffstat (limited to 'base/prefs/scoped_user_pref_update.cc')
-rw-r--r-- | base/prefs/scoped_user_pref_update.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/base/prefs/scoped_user_pref_update.cc b/base/prefs/scoped_user_pref_update.cc new file mode 100644 index 0000000..c86b163 --- /dev/null +++ b/base/prefs/scoped_user_pref_update.cc @@ -0,0 +1,36 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/prefs/scoped_user_pref_update.h" + +#include "base/logging.h" +#include "base/prefs/pref_notifier.h" +#include "base/prefs/pref_service.h" + +namespace subtle { + +ScopedUserPrefUpdateBase::ScopedUserPrefUpdateBase(PrefService* service, + const char* path) + : service_(service), + path_(path), + value_(NULL) {} + +ScopedUserPrefUpdateBase::~ScopedUserPrefUpdateBase() { + Notify(); +} + +Value* ScopedUserPrefUpdateBase::GetValueOfType(base::Value::Type type) { + if (!value_) + value_ = service_->GetMutableUserPref(path_.c_str(), type); + return value_; +} + +void ScopedUserPrefUpdateBase::Notify() { + if (value_) { + service_->ReportUserPrefChanged(path_); + value_ = NULL; + } +} + +} // namespace subtle |