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

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

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: Removed all calls to c_str() in prefs. 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
« no previous file with comments | « base/prefs/pref_change_registrar_unittest.cc ('k') | base/prefs/pref_member.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // A helper class that stays in sync with a preference (bool, int, real, 5 // A helper class that stays in sync with a preference (bool, int, real,
6 // string or filepath). For example: 6 // string or filepath). For example:
7 // 7 //
8 // class MyClass { 8 // class MyClass {
9 // public: 9 // public:
10 // MyClass(PrefService* prefs) { 10 // MyClass(PrefService* prefs) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 mutable bool is_managed_; 96 mutable bool is_managed_;
97 mutable bool is_user_modifiable_; 97 mutable bool is_user_modifiable_;
98 98
99 DISALLOW_COPY_AND_ASSIGN(Internal); 99 DISALLOW_COPY_AND_ASSIGN(Internal);
100 }; 100 };
101 101
102 PrefMemberBase(); 102 PrefMemberBase();
103 virtual ~PrefMemberBase(); 103 virtual ~PrefMemberBase();
104 104
105 // See PrefMember<> for description. 105 // See PrefMember<> for description.
106 void Init(const char* pref_name, PrefService* prefs, 106 void Init(const std::string& pref_name,
107 PrefService* prefs,
107 const NamedChangeCallback& observer); 108 const NamedChangeCallback& observer);
108 void Init(const char* pref_name, PrefService* prefs); 109 void Init(const std::string& pref_name, PrefService* prefs);
109 110
110 virtual void CreateInternal() const = 0; 111 virtual void CreateInternal() const = 0;
111 112
112 // See PrefMember<> for description. 113 // See PrefMember<> for description.
113 void Destroy(); 114 void Destroy();
114 115
115 void MoveToThread( 116 void MoveToThread(
116 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); 117 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
117 118
118 // PrefObserver 119 // PrefObserver
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 class PrefMember : public subtle::PrefMemberBase { 163 class PrefMember : public subtle::PrefMemberBase {
163 public: 164 public:
164 // Defer initialization to an Init method so it's easy to make this class be 165 // Defer initialization to an Init method so it's easy to make this class be
165 // a member variable. 166 // a member variable.
166 PrefMember() {} 167 PrefMember() {}
167 virtual ~PrefMember() {} 168 virtual ~PrefMember() {}
168 169
169 // Do the actual initialization of the class. Use the two-parameter 170 // Do the actual initialization of the class. Use the two-parameter
170 // version if you don't want any notifications of changes. This 171 // version if you don't want any notifications of changes. This
171 // method should only be called on the UI thread. 172 // method should only be called on the UI thread.
172 void Init(const char* pref_name, PrefService* prefs, 173 void Init(const std::string& pref_name,
174 PrefService* prefs,
173 const NamedChangeCallback& observer) { 175 const NamedChangeCallback& observer) {
174 subtle::PrefMemberBase::Init(pref_name, prefs, observer); 176 subtle::PrefMemberBase::Init(pref_name, prefs, observer);
175 } 177 }
176 void Init(const char* pref_name, PrefService* prefs, 178 void Init(const std::string& pref_name,
179 PrefService* prefs,
177 const base::Closure& observer) { 180 const base::Closure& observer) {
178 subtle::PrefMemberBase::Init( 181 subtle::PrefMemberBase::Init(
179 pref_name, prefs, 182 pref_name, prefs,
180 base::Bind(&PrefMemberBase::InvokeUnnamedCallback, observer)); 183 base::Bind(&PrefMemberBase::InvokeUnnamedCallback, observer));
181 } 184 }
182 void Init(const char* pref_name, PrefService* prefs) { 185 void Init(const std::string& pref_name, PrefService* prefs) {
183 subtle::PrefMemberBase::Init(pref_name, prefs); 186 subtle::PrefMemberBase::Init(pref_name, prefs);
184 } 187 }
185 188
186 // Unsubscribes the PrefMember from the PrefService. After calling this 189 // Unsubscribes the PrefMember from the PrefService. After calling this
187 // function, the PrefMember may not be used any more on the UI thread. 190 // function, the PrefMember may not be used any more on the UI thread.
188 // Assuming |MoveToThread| was previously called, |GetValue|, |IsManaged|, 191 // Assuming |MoveToThread| was previously called, |GetValue|, |IsManaged|,
189 // and |IsUserModifiable| can still be called from the other thread but 192 // and |IsUserModifiable| can still be called from the other thread but
190 // the results will no longer update from the PrefService. 193 // the results will no longer update from the PrefService.
191 // This method should only be called on the UI thread. 194 // This method should only be called on the UI thread.
192 void Destroy() { 195 void Destroy() {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 348
346 typedef PrefMember<bool> BooleanPrefMember; 349 typedef PrefMember<bool> BooleanPrefMember;
347 typedef PrefMember<int> IntegerPrefMember; 350 typedef PrefMember<int> IntegerPrefMember;
348 typedef PrefMember<double> DoublePrefMember; 351 typedef PrefMember<double> DoublePrefMember;
349 typedef PrefMember<std::string> StringPrefMember; 352 typedef PrefMember<std::string> StringPrefMember;
350 typedef PrefMember<base::FilePath> FilePathPrefMember; 353 typedef PrefMember<base::FilePath> FilePathPrefMember;
351 // This preference member is expensive for large string arrays. 354 // This preference member is expensive for large string arrays.
352 typedef PrefMember<std::vector<std::string> > StringListPrefMember; 355 typedef PrefMember<std::vector<std::string> > StringListPrefMember;
353 356
354 #endif // BASE_PREFS_PREF_MEMBER_H_ 357 #endif // BASE_PREFS_PREF_MEMBER_H_
OLDNEW
« no previous file with comments | « base/prefs/pref_change_registrar_unittest.cc ('k') | base/prefs/pref_member.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698