Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: base/prefs/pref_member.cc

Issue 753603002: Change preference APIs to take std::string instead of const char*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverted changed to values.cc. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/pref_member.h" 5 #include "base/prefs/pref_member.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/value_conversions.h" 12 #include "base/value_conversions.h"
13 13
14 using base::MessageLoopProxy; 14 using base::MessageLoopProxy;
15 using base::SingleThreadTaskRunner; 15 using base::SingleThreadTaskRunner;
16 16
17 namespace subtle { 17 namespace subtle {
18 18
19 PrefMemberBase::PrefMemberBase() 19 PrefMemberBase::PrefMemberBase()
20 : prefs_(NULL), 20 : prefs_(NULL),
21 setting_value_(false) { 21 setting_value_(false) {
22 } 22 }
23 23
24 PrefMemberBase::~PrefMemberBase() { 24 PrefMemberBase::~PrefMemberBase() {
25 Destroy(); 25 Destroy();
26 } 26 }
27 27
28 void PrefMemberBase::Init(const char* pref_name, 28 void PrefMemberBase::Init(const std::string& pref_name,
29 PrefService* prefs, 29 PrefService* prefs,
30 const NamedChangeCallback& observer) { 30 const NamedChangeCallback& observer) {
31 observer_ = observer; 31 observer_ = observer;
32 Init(pref_name, prefs); 32 Init(pref_name, prefs);
33 } 33 }
34 34
35 void PrefMemberBase::Init(const char* pref_name, 35 void PrefMemberBase::Init(const std::string& pref_name, PrefService* prefs) {
36 PrefService* prefs) {
37 DCHECK(pref_name);
38 DCHECK(prefs); 36 DCHECK(prefs);
39 DCHECK(pref_name_.empty()); // Check that Init is only called once. 37 DCHECK(pref_name_.empty()); // Check that Init is only called once.
40 prefs_ = prefs; 38 prefs_ = prefs;
41 pref_name_ = pref_name; 39 pref_name_ = pref_name;
42 // Check that the preference is registered. 40 // Check that the preference is registered.
43 DCHECK(prefs_->FindPreference(pref_name_.c_str())) 41 DCHECK(prefs_->FindPreference(pref_name_.c_str()))
gab 2014/12/01 21:13:01 Once again, another example, picked at random whil
Georges Khalil 2014/12/02 17:57:00 Done.
44 << pref_name << " not registered."; 42 << pref_name << " not registered.";
45 43
46 // Add ourselves as a pref observer so we can keep our local value in sync. 44 // Add ourselves as a pref observer so we can keep our local value in sync.
47 prefs_->AddPrefObserver(pref_name, this); 45 prefs_->AddPrefObserver(pref_name, this);
48 } 46 }
49 47
50 void PrefMemberBase::Destroy() { 48 void PrefMemberBase::Destroy() {
51 if (prefs_ && !pref_name_.empty()) { 49 if (prefs_ && !pref_name_.empty()) {
52 prefs_->RemovePrefObserver(pref_name_.c_str(), this); 50 prefs_->RemovePrefObserver(pref_name_.c_str(), this);
53 prefs_ = NULL; 51 prefs_ = NULL;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 base::ListValue list_value; 217 base::ListValue list_value;
220 list_value.AppendStrings(value); 218 list_value.AppendStrings(value);
221 prefs()->Set(pref_name().c_str(), list_value); 219 prefs()->Set(pref_name().c_str(), list_value);
222 } 220 }
223 221
224 template <> 222 template <>
225 bool PrefMember<std::vector<std::string> >::Internal::UpdateValueInternal( 223 bool PrefMember<std::vector<std::string> >::Internal::UpdateValueInternal(
226 const base::Value& value) const { 224 const base::Value& value) const {
227 return subtle::PrefMemberVectorStringUpdate(value, &value_); 225 return subtle::PrefMemberVectorStringUpdate(value, &value_);
228 } 226 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698