OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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) { |
11 // my_string_.Init(prefs::kHomePage, prefs, NULL /* no observer */); | 11 // my_string_.Init(prefs::kHomePage, prefs, NULL /* no observer */); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 185 } |
186 | 186 |
187 // Set the value of the member variable if it is not managed. | 187 // Set the value of the member variable if it is not managed. |
188 // This method should only be called on the UI thread. | 188 // This method should only be called on the UI thread. |
189 void SetValueIfNotManaged(const ValueType& value) { | 189 void SetValueIfNotManaged(const ValueType& value) { |
190 if (!IsManaged()) { | 190 if (!IsManaged()) { |
191 SetValue(value); | 191 SetValue(value); |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
| 195 // Returns the pref name. |
| 196 const std::string& GetPrefName() const { |
| 197 return pref_name(); |
| 198 } |
| 199 |
195 private: | 200 private: |
196 class Internal : public subtle::PrefMemberBase::Internal { | 201 class Internal : public subtle::PrefMemberBase::Internal { |
197 public: | 202 public: |
198 Internal() : value_(ValueType()) {} | 203 Internal() : value_(ValueType()) {} |
199 | 204 |
200 ValueType value() { | 205 ValueType value() { |
201 CheckOnCorrectThread(); | 206 CheckOnCorrectThread(); |
202 return value_; | 207 return value_; |
203 } | 208 } |
204 | 209 |
(...skipping 22 matching lines...) Expand all Loading... |
227 DISALLOW_COPY_AND_ASSIGN(PrefMember); | 232 DISALLOW_COPY_AND_ASSIGN(PrefMember); |
228 }; | 233 }; |
229 | 234 |
230 typedef PrefMember<bool> BooleanPrefMember; | 235 typedef PrefMember<bool> BooleanPrefMember; |
231 typedef PrefMember<int> IntegerPrefMember; | 236 typedef PrefMember<int> IntegerPrefMember; |
232 typedef PrefMember<double> DoublePrefMember; | 237 typedef PrefMember<double> DoublePrefMember; |
233 typedef PrefMember<std::string> StringPrefMember; | 238 typedef PrefMember<std::string> StringPrefMember; |
234 typedef PrefMember<FilePath> FilePathPrefMember; | 239 typedef PrefMember<FilePath> FilePathPrefMember; |
235 | 240 |
236 #endif // CHROME_BROWSER_PREFS_PREF_MEMBER_H_ | 241 #endif // CHROME_BROWSER_PREFS_PREF_MEMBER_H_ |
OLD | NEW |