OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/prefs/scoped_user_pref_update.h" | 5 #include "base/prefs/scoped_user_pref_update.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/prefs/pref_notifier.h" | 8 #include "base/prefs/pref_notifier.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 | 10 |
11 namespace subtle { | 11 namespace subtle { |
12 | 12 |
13 ScopedUserPrefUpdateBase::ScopedUserPrefUpdateBase(PrefService* service, | 13 ScopedUserPrefUpdateBase::ScopedUserPrefUpdateBase(PrefService* service, |
14 const char* path) | 14 const std::string& path) |
15 : service_(service), | 15 : service_(service), path_(path), value_(NULL) { |
16 path_(path), | |
17 value_(NULL) { | |
18 DCHECK(service_->CalledOnValidThread()); | 16 DCHECK(service_->CalledOnValidThread()); |
19 } | 17 } |
20 | 18 |
21 ScopedUserPrefUpdateBase::~ScopedUserPrefUpdateBase() { | 19 ScopedUserPrefUpdateBase::~ScopedUserPrefUpdateBase() { |
22 Notify(); | 20 Notify(); |
23 } | 21 } |
24 | 22 |
25 base::Value* ScopedUserPrefUpdateBase::GetValueOfType(base::Value::Type type) { | 23 base::Value* ScopedUserPrefUpdateBase::GetValueOfType(base::Value::Type type) { |
26 DCHECK(CalledOnValidThread()); | 24 DCHECK(CalledOnValidThread()); |
27 if (!value_) | 25 if (!value_) |
28 value_ = service_->GetMutableUserPref(path_.c_str(), type); | 26 value_ = service_->GetMutableUserPref(path_, type); |
29 return value_; | 27 return value_; |
30 } | 28 } |
31 | 29 |
32 void ScopedUserPrefUpdateBase::Notify() { | 30 void ScopedUserPrefUpdateBase::Notify() { |
33 if (value_) { | 31 if (value_) { |
34 service_->ReportUserPrefChanged(path_); | 32 service_->ReportUserPrefChanged(path_); |
35 value_ = NULL; | 33 value_ = NULL; |
36 } | 34 } |
37 } | 35 } |
38 | 36 |
39 } // namespace subtle | 37 } // namespace subtle |
OLD | NEW |