OLD | NEW |
1 // Copyright (c) 2011 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) { |
11 // my_string_.Init(prefs::kHomePage, prefs, NULL /* no observer */); | 11 // my_string_.Init(prefs::kHomePage, prefs, NULL /* no observer */); |
(...skipping 10 matching lines...) Expand all Loading... |
22 // will not be notified. | 22 // will not be notified. |
23 | 23 |
24 #ifndef CHROME_BROWSER_PREFS_PREF_MEMBER_H_ | 24 #ifndef CHROME_BROWSER_PREFS_PREF_MEMBER_H_ |
25 #define CHROME_BROWSER_PREFS_PREF_MEMBER_H_ | 25 #define CHROME_BROWSER_PREFS_PREF_MEMBER_H_ |
26 #pragma once | 26 #pragma once |
27 | 27 |
28 #include <string> | 28 #include <string> |
29 | 29 |
30 #include "base/basictypes.h" | 30 #include "base/basictypes.h" |
31 #include "base/file_path.h" | 31 #include "base/file_path.h" |
| 32 #include "base/logging.h" |
32 #include "base/memory/ref_counted.h" | 33 #include "base/memory/ref_counted.h" |
33 #include "base/values.h" | 34 #include "base/values.h" |
34 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/notification_observer.h" | 36 #include "content/public/browser/notification_observer.h" |
36 | 37 |
37 class PrefService; | 38 class PrefService; |
38 | 39 |
39 namespace subtle { | 40 namespace subtle { |
40 | 41 |
41 class PrefMemberBase : public content::NotificationObserver { | 42 class PrefMemberBase : public content::NotificationObserver { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // Verifies the preference name, and lazily loads the preference value if | 109 // Verifies the preference name, and lazily loads the preference value if |
109 // it hasn't been loaded yet. | 110 // it hasn't been loaded yet. |
110 void VerifyPref() const; | 111 void VerifyPref() const; |
111 | 112 |
112 const std::string& pref_name() const { return pref_name_; } | 113 const std::string& pref_name() const { return pref_name_; } |
113 PrefService* prefs() { return prefs_; } | 114 PrefService* prefs() { return prefs_; } |
114 const PrefService* prefs() const { return prefs_; } | 115 const PrefService* prefs() const { return prefs_; } |
115 | 116 |
116 virtual Internal* internal() const = 0; | 117 virtual Internal* internal() const = 0; |
117 | 118 |
118 // Ordered the members to compact the class instance. | |
119 private: | 119 private: |
| 120 // Ordered the members to compact the class instance. |
120 std::string pref_name_; | 121 std::string pref_name_; |
121 content::NotificationObserver* observer_; | 122 content::NotificationObserver* observer_; |
122 PrefService* prefs_; | 123 PrefService* prefs_; |
123 | 124 |
124 protected: | 125 protected: |
125 bool setting_value_; | 126 bool setting_value_; |
126 }; | 127 }; |
127 | 128 |
128 } // namespace subtle | 129 } // namespace subtle |
129 | 130 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 DISALLOW_COPY_AND_ASSIGN(PrefMember); | 240 DISALLOW_COPY_AND_ASSIGN(PrefMember); |
240 }; | 241 }; |
241 | 242 |
242 typedef PrefMember<bool> BooleanPrefMember; | 243 typedef PrefMember<bool> BooleanPrefMember; |
243 typedef PrefMember<int> IntegerPrefMember; | 244 typedef PrefMember<int> IntegerPrefMember; |
244 typedef PrefMember<double> DoublePrefMember; | 245 typedef PrefMember<double> DoublePrefMember; |
245 typedef PrefMember<std::string> StringPrefMember; | 246 typedef PrefMember<std::string> StringPrefMember; |
246 typedef PrefMember<FilePath> FilePathPrefMember; | 247 typedef PrefMember<FilePath> FilePathPrefMember; |
247 | 248 |
248 #endif // CHROME_BROWSER_PREFS_PREF_MEMBER_H_ | 249 #endif // CHROME_BROWSER_PREFS_PREF_MEMBER_H_ |
OLD | NEW |