scoped_user_pref_update.cc revision ddb351dbec246cf1fab5ec20d2d5520909041de1
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
3// found in the LICENSE file.
4
5#include "chrome/browser/prefs/scoped_user_pref_update.h"
6
7#include "base/logging.h"
8#include "chrome/browser/prefs/pref_notifier.h"
9#include "chrome/browser/prefs/pref_service.h"
10
11namespace subtle {
12
13ScopedUserPrefUpdateBase::ScopedUserPrefUpdateBase(PrefService* service,
14                                                   const char* path)
15    : service_(service),
16      path_(path),
17      value_(NULL) {}
18
19ScopedUserPrefUpdateBase::~ScopedUserPrefUpdateBase() {
20  Notify();
21}
22
23Value* ScopedUserPrefUpdateBase::Get(Value::ValueType type) {
24  if (!value_)
25    value_ = service_->GetMutableUserPref(path_.c_str(), type);
26  return value_;
27}
28
29void ScopedUserPrefUpdateBase::Notify() {
30  if (value_) {
31    service_->ReportUserPrefChanged(path_);
32    value_ = NULL;
33  }
34}
35
36}  // namespace subtle
37