OLD | NEW |
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 virtual void CreateInternal() const = 0; | 110 virtual void CreateInternal() const = 0; |
111 | 111 |
112 // See PrefMember<> for description. | 112 // See PrefMember<> for description. |
113 void Destroy(); | 113 void Destroy(); |
114 | 114 |
115 void MoveToThread(const scoped_refptr<base::MessageLoopProxy>& message_loop); | 115 void MoveToThread(const scoped_refptr<base::MessageLoopProxy>& message_loop); |
116 | 116 |
117 // PrefObserver | 117 // PrefObserver |
118 virtual void OnPreferenceChanged(PrefService* service, | 118 virtual void OnPreferenceChanged(PrefService* service, |
119 const std::string& pref_name) OVERRIDE; | 119 const std::string& pref_name) OVERRIDE; |
| 120 // TODO(battre): Remove function (debugging tool for crbug.com/373435). |
| 121 virtual void SetPrefServiceDestructionTrace( |
| 122 const std::string& stacktrace) OVERRIDE; |
120 | 123 |
121 void VerifyValuePrefName() const { | 124 void VerifyValuePrefName() const { |
122 DCHECK(!pref_name_.empty()); | 125 DCHECK(!pref_name_.empty()); |
123 } | 126 } |
124 | 127 |
125 // This method is used to do the actual sync with the preference. | 128 // This method is used to do the actual sync with the preference. |
126 // Note: it is logically const, because it doesn't modify the state | 129 // Note: it is logically const, because it doesn't modify the state |
127 // seen by the outside world. It is just doing a lazy load behind the scenes. | 130 // seen by the outside world. It is just doing a lazy load behind the scenes. |
128 void UpdateValueFromPref(const base::Closure& callback) const; | 131 void UpdateValueFromPref(const base::Closure& callback) const; |
129 | 132 |
130 // Verifies the preference name, and lazily loads the preference value if | 133 // Verifies the preference name, and lazily loads the preference value if |
131 // it hasn't been loaded yet. | 134 // it hasn't been loaded yet. |
132 void VerifyPref() const; | 135 void VerifyPref() const; |
133 | 136 |
134 const std::string& pref_name() const { return pref_name_; } | 137 const std::string& pref_name() const { return pref_name_; } |
135 | 138 |
136 virtual Internal* internal() const = 0; | 139 virtual Internal* internal() const = 0; |
137 | 140 |
138 // Used to allow registering plain base::Closure callbacks. | 141 // Used to allow registering plain base::Closure callbacks. |
139 static void InvokeUnnamedCallback(const base::Closure& callback, | 142 static void InvokeUnnamedCallback(const base::Closure& callback, |
140 const std::string& pref_name); | 143 const std::string& pref_name); |
141 | 144 |
142 private: | 145 private: |
143 // Ordered the members to compact the class instance. | 146 // Ordered the members to compact the class instance. |
144 std::string pref_name_; | 147 std::string pref_name_; |
145 NamedChangeCallback observer_; | 148 NamedChangeCallback observer_; |
146 PrefService* prefs_; | 149 PrefService* prefs_; |
| 150 // TODO(battre): Remove attribute (debugging tool for crbug.com/373435). |
| 151 std::string pref_service_destruction_; |
147 | 152 |
148 protected: | 153 protected: |
149 bool setting_value_; | 154 bool setting_value_; |
150 }; | 155 }; |
151 | 156 |
152 // This function implements StringListPrefMember::UpdateValue(). | 157 // This function implements StringListPrefMember::UpdateValue(). |
153 // It is exposed here for testing purposes. | 158 // It is exposed here for testing purposes. |
154 bool BASE_PREFS_EXPORT PrefMemberVectorStringUpdate( | 159 bool BASE_PREFS_EXPORT PrefMemberVectorStringUpdate( |
155 const base::Value& value, | 160 const base::Value& value, |
156 std::vector<std::string>* string_vector); | 161 std::vector<std::string>* string_vector); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 | 348 |
344 typedef PrefMember<bool> BooleanPrefMember; | 349 typedef PrefMember<bool> BooleanPrefMember; |
345 typedef PrefMember<int> IntegerPrefMember; | 350 typedef PrefMember<int> IntegerPrefMember; |
346 typedef PrefMember<double> DoublePrefMember; | 351 typedef PrefMember<double> DoublePrefMember; |
347 typedef PrefMember<std::string> StringPrefMember; | 352 typedef PrefMember<std::string> StringPrefMember; |
348 typedef PrefMember<base::FilePath> FilePathPrefMember; | 353 typedef PrefMember<base::FilePath> FilePathPrefMember; |
349 // This preference member is expensive for large string arrays. | 354 // This preference member is expensive for large string arrays. |
350 typedef PrefMember<std::vector<std::string> > StringListPrefMember; | 355 typedef PrefMember<std::vector<std::string> > StringListPrefMember; |
351 | 356 |
352 #endif // BASE_PREFS_PREF_MEMBER_H_ | 357 #endif // BASE_PREFS_PREF_MEMBER_H_ |
OLD | NEW |