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

Side by Side Diff: chrome/common/pref_member.h

Issue 2929: Some initial work on compiling chrome/common/ on Linux.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/libxml_utils.cc ('k') | chrome/common/slide_animation.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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, or 5 // A helper class that stays in sync with a preference (bool, int, real, or
6 // string). For example: 6 // string). For example:
7 // 7 //
8 // class MyClass { 8 // class MyClass {
9 // public: 9 // public:
10 // MyClass(PrefService* prefs) { 10 // MyClass(PrefService* prefs) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 const NotificationDetails& details); 46 const NotificationDetails& details);
47 47
48 void VerifyValuePrefName(); 48 void VerifyValuePrefName();
49 49
50 // This methods is used to do the actual sync with pref of the specified type. 50 // This methods is used to do the actual sync with pref of the specified type.
51 virtual void UpdateValueFromPref() = 0; 51 virtual void UpdateValueFromPref() = 0;
52 52
53 const std::wstring& pref_name() const { return pref_name_; } 53 const std::wstring& pref_name() const { return pref_name_; }
54 PrefService* prefs() { return prefs_; } 54 PrefService* prefs() { return prefs_; }
55 55
56 // Ordered the members to compact the class instance.
57 private:
58 std::wstring pref_name_;
59 NotificationObserver* observer_;
60 PrefService* prefs_;
61
56 protected: 62 protected:
57 bool is_synced_; 63 bool is_synced_;
58 bool setting_value_; 64 bool setting_value_;
59
60 private:
61 std::wstring pref_name_;
62 PrefService* prefs_;
63 NotificationObserver* observer_;
64 }; 65 };
65 66
66 } // namespace subtle 67 } // namespace subtle
67 68
68 69
69 template <typename ValueType> 70 template <typename ValueType>
70 class PrefMember : public subtle::PrefMemberBase { 71 class PrefMember : public subtle::PrefMemberBase {
71 public: 72 public:
72 // Defer initialization to an Init method so it's easy to make this class be 73 // Defer initialization to an Init method so it's easy to make this class be
73 // a member variable. 74 // a member variable.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // We cache the value of the pref so we don't have to keep walking the pref 114 // We cache the value of the pref so we don't have to keep walking the pref
114 // tree. 115 // tree.
115 ValueType value_; 116 ValueType value_;
116 }; 117 };
117 118
118 /////////////////////////////////////////////////////////////////////////////// 119 ///////////////////////////////////////////////////////////////////////////////
119 // Implementations of Boolean, Integer, Real, and String PrefMember below. 120 // Implementations of Boolean, Integer, Real, and String PrefMember below.
120 121
121 class BooleanPrefMember : public PrefMember<bool> { 122 class BooleanPrefMember : public PrefMember<bool> {
122 public: 123 public:
123 BooleanPrefMember() : PrefMember() { } 124 BooleanPrefMember() : PrefMember<bool>() { }
124 virtual ~BooleanPrefMember() { } 125 virtual ~BooleanPrefMember() { }
125 126
126 protected: 127 protected:
127 virtual void UpdateValueFromPref(); 128 virtual void UpdateValueFromPref();
128 virtual void UpdatePref(const bool& value); 129 virtual void UpdatePref(const bool& value);
129 130
130 private: 131 private:
131 DISALLOW_COPY_AND_ASSIGN(BooleanPrefMember); 132 DISALLOW_COPY_AND_ASSIGN(BooleanPrefMember);
132 }; 133 };
133 134
134 class IntegerPrefMember : public PrefMember<int> { 135 class IntegerPrefMember : public PrefMember<int> {
135 public: 136 public:
136 IntegerPrefMember() : PrefMember() { } 137 IntegerPrefMember() : PrefMember<int>() { }
137 virtual ~IntegerPrefMember() { } 138 virtual ~IntegerPrefMember() { }
138 139
139 protected: 140 protected:
140 virtual void UpdateValueFromPref(); 141 virtual void UpdateValueFromPref();
141 virtual void UpdatePref(const int& value); 142 virtual void UpdatePref(const int& value);
142 143
143 private: 144 private:
144 DISALLOW_COPY_AND_ASSIGN(IntegerPrefMember); 145 DISALLOW_COPY_AND_ASSIGN(IntegerPrefMember);
145 }; 146 };
146 147
147 class RealPrefMember : public PrefMember<double> { 148 class RealPrefMember : public PrefMember<double> {
148 public: 149 public:
149 RealPrefMember() : PrefMember() { } 150 RealPrefMember() : PrefMember<double>() { }
150 virtual ~RealPrefMember() { } 151 virtual ~RealPrefMember() { }
151 152
152 protected: 153 protected:
153 virtual void UpdateValueFromPref(); 154 virtual void UpdateValueFromPref();
154 virtual void UpdatePref(const double& value); 155 virtual void UpdatePref(const double& value);
155 156
156 private: 157 private:
157 DISALLOW_COPY_AND_ASSIGN(RealPrefMember); 158 DISALLOW_COPY_AND_ASSIGN(RealPrefMember);
158 }; 159 };
159 160
160 class StringPrefMember : public PrefMember<std::wstring> { 161 class StringPrefMember : public PrefMember<std::wstring> {
161 public: 162 public:
162 StringPrefMember() : PrefMember() { } 163 StringPrefMember() : PrefMember<std::wstring>() { }
163 virtual ~StringPrefMember() { } 164 virtual ~StringPrefMember() { }
164 165
165 protected: 166 protected:
166 virtual void UpdateValueFromPref(); 167 virtual void UpdateValueFromPref();
167 virtual void UpdatePref(const std::wstring& value); 168 virtual void UpdatePref(const std::wstring& value);
168 169
169 private: 170 private:
170 DISALLOW_COPY_AND_ASSIGN(StringPrefMember); 171 DISALLOW_COPY_AND_ASSIGN(StringPrefMember);
171 }; 172 };
172 173
173 #endif // CHROME_COMMON_PREF_MEMBER_H_ 174 #endif // CHROME_COMMON_PREF_MEMBER_H_
174 175
OLDNEW
« no previous file with comments | « chrome/common/libxml_utils.cc ('k') | chrome/common/slide_animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698