blob: 7871c75ce3783ab84156d188fd58b087927e2cfd [file] [log] [blame]
[email protected]9eec53fe2013-10-30 20:21:171// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]dd8fa1a992010-04-05 23:56:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]9eec53fe2013-10-30 20:21:175#include "base/prefs/scoped_user_pref_update.h"
[email protected]dd8fa1a992010-04-05 23:56:166
[email protected]26418b72011-03-30 14:07:397#include "base/logging.h"
[email protected]03b9b4e2012-10-22 20:01:528#include "base/prefs/pref_notifier.h"
[email protected]3853a4c2013-02-11 17:15:579#include "base/prefs/pref_service.h"
[email protected]ee91666a2010-09-21 02:40:0010
[email protected]26418b72011-03-30 14:07:3911namespace subtle {
12
13ScopedUserPrefUpdateBase::ScopedUserPrefUpdateBase(PrefService* service,
14 const char* path)
15 : service_(service),
16 path_(path),
[email protected]86bb4e652014-07-10 17:09:5117 value_(NULL) {
18 DCHECK(service_->CalledOnValidThread());
19}
[email protected]26418b72011-03-30 14:07:3920
21ScopedUserPrefUpdateBase::~ScopedUserPrefUpdateBase() {
22 Notify();
23}
24
[email protected]a644f1e22013-12-24 15:31:2125base::Value* ScopedUserPrefUpdateBase::GetValueOfType(base::Value::Type type) {
[email protected]86bb4e652014-07-10 17:09:5126 DCHECK(CalledOnValidThread());
[email protected]26418b72011-03-30 14:07:3927 if (!value_)
28 value_ = service_->GetMutableUserPref(path_.c_str(), type);
29 return value_;
30}
31
32void ScopedUserPrefUpdateBase::Notify() {
33 if (value_) {
34 service_->ReportUserPrefChanged(path_);
35 value_ = NULL;
36 }
37}
38
39} // namespace subtle