| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 setting_value_ = false; | 133 setting_value_ = false; |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Set the value of the member variable if it is not managed. | 136 // Set the value of the member variable if it is not managed. |
| 137 void SetValueIfNotManaged(const ValueType& value) { | 137 void SetValueIfNotManaged(const ValueType& value) { |
| 138 if (!IsManaged()) { | 138 if (!IsManaged()) { |
| 139 SetValue(value); | 139 SetValue(value); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 | 142 |
| 143 // Returns the pref name. |
| 144 const std::string& GetPrefName() const { |
| 145 return pref_name(); |
| 146 } |
| 147 |
| 143 protected: | 148 protected: |
| 144 // This methods is used to do the actual sync with pref of the specified type. | 149 // This methods is used to do the actual sync with pref of the specified type. |
| 145 virtual void UpdatePref(const ValueType& value) = 0; | 150 virtual void UpdatePref(const ValueType& value) = 0; |
| 146 | 151 |
| 147 // We cache the value of the pref so we don't have to keep walking the pref | 152 // We cache the value of the pref so we don't have to keep walking the pref |
| 148 // tree. | 153 // tree. |
| 149 mutable ValueType value_; | 154 mutable ValueType value_; |
| 150 }; | 155 }; |
| 151 | 156 |
| 152 /////////////////////////////////////////////////////////////////////////////// | 157 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 216 |
| 212 protected: | 217 protected: |
| 213 virtual void UpdateValueFromPref() const; | 218 virtual void UpdateValueFromPref() const; |
| 214 virtual void UpdatePref(const FilePath& value); | 219 virtual void UpdatePref(const FilePath& value); |
| 215 | 220 |
| 216 private: | 221 private: |
| 217 DISALLOW_COPY_AND_ASSIGN(FilePathPrefMember); | 222 DISALLOW_COPY_AND_ASSIGN(FilePathPrefMember); |
| 218 }; | 223 }; |
| 219 | 224 |
| 220 #endif // CHROME_BROWSER_PREFS_PREF_MEMBER_H_ | 225 #endif // CHROME_BROWSER_PREFS_PREF_MEMBER_H_ |
| OLD | NEW |