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

Side by Side Diff: base/prefs/pref_member.h

Issue 1113953002: Revert of base: Remove use of MessageLoopProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « base/prefs/json_pref_store_unittest.cc ('k') | base/prefs/pref_member.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) 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 Internal(); 58 Internal();
59 59
60 // Update the value, either by calling |UpdateValueInternal| directly 60 // Update the value, either by calling |UpdateValueInternal| directly
61 // or by dispatching to the right thread. 61 // or by dispatching to the right thread.
62 // Takes ownership of |value|. 62 // Takes ownership of |value|.
63 void UpdateValue(base::Value* value, 63 void UpdateValue(base::Value* value,
64 bool is_managed, 64 bool is_managed,
65 bool is_user_modifiable, 65 bool is_user_modifiable,
66 const base::Closure& callback) const; 66 const base::Closure& callback) const;
67 67
68 void MoveToThread(scoped_refptr<base::SingleThreadTaskRunner> task_runner); 68 void MoveToThread(
69 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
69 70
70 // See PrefMember<> for description. 71 // See PrefMember<> for description.
71 bool IsManaged() const { 72 bool IsManaged() const {
72 return is_managed_; 73 return is_managed_;
73 } 74 }
74 75
75 bool IsUserModifiable() const { 76 bool IsUserModifiable() const {
76 return is_user_modifiable_; 77 return is_user_modifiable_;
77 } 78 }
78 79
79 protected: 80 protected:
80 friend class base::RefCountedThreadSafe<Internal>; 81 friend class base::RefCountedThreadSafe<Internal>;
81 virtual ~Internal(); 82 virtual ~Internal();
82 83
83 void CheckOnCorrectThread() const { 84 void CheckOnCorrectThread() const {
84 DCHECK(IsOnCorrectThread()); 85 DCHECK(IsOnCorrectThread());
85 } 86 }
86 87
87 private: 88 private:
88 // This method actually updates the value. It should only be called from 89 // This method actually updates the value. It should only be called from
89 // the thread the PrefMember is on. 90 // the thread the PrefMember is on.
90 virtual bool UpdateValueInternal(const base::Value& value) const = 0; 91 virtual bool UpdateValueInternal(const base::Value& value) const = 0;
91 92
92 bool IsOnCorrectThread() const; 93 bool IsOnCorrectThread() const;
93 94
94 scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner_; 95 scoped_refptr<base::SingleThreadTaskRunner> thread_loop_;
95 mutable bool is_managed_; 96 mutable bool is_managed_;
96 mutable bool is_user_modifiable_; 97 mutable bool is_user_modifiable_;
97 98
98 DISALLOW_COPY_AND_ASSIGN(Internal); 99 DISALLOW_COPY_AND_ASSIGN(Internal);
99 }; 100 };
100 101
101 PrefMemberBase(); 102 PrefMemberBase();
102 virtual ~PrefMemberBase(); 103 virtual ~PrefMemberBase();
103 104
104 // See PrefMember<> for description. 105 // See PrefMember<> for description.
105 void Init(const std::string& pref_name, 106 void Init(const std::string& pref_name,
106 PrefService* prefs, 107 PrefService* prefs,
107 const NamedChangeCallback& observer); 108 const NamedChangeCallback& observer);
108 void Init(const std::string& pref_name, PrefService* prefs); 109 void Init(const std::string& pref_name, PrefService* prefs);
109 110
110 virtual void CreateInternal() const = 0; 111 virtual void CreateInternal() const = 0;
111 112
112 // See PrefMember<> for description. 113 // See PrefMember<> for description.
113 void Destroy(); 114 void Destroy();
114 115
115 void MoveToThread(scoped_refptr<base::SingleThreadTaskRunner> task_runner); 116 void MoveToThread(
117 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
116 118
117 // PrefObserver 119 // PrefObserver
118 void OnPreferenceChanged(PrefService* service, 120 void OnPreferenceChanged(PrefService* service,
119 const std::string& pref_name) override; 121 const std::string& pref_name) override;
120 122
121 void VerifyValuePrefName() const { 123 void VerifyValuePrefName() const {
122 DCHECK(!pref_name_.empty()); 124 DCHECK(!pref_name_.empty());
123 } 125 }
124 126
125 // This method is used to do the actual sync with the preference. 127 // This method is used to do the actual sync with the preference.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // This method should only be called on the UI thread. 194 // This method should only be called on the UI thread.
193 void Destroy() { 195 void Destroy() {
194 subtle::PrefMemberBase::Destroy(); 196 subtle::PrefMemberBase::Destroy();
195 } 197 }
196 198
197 // Moves the PrefMember to another thread, allowing read accesses from there. 199 // Moves the PrefMember to another thread, allowing read accesses from there.
198 // Changes from the PrefService will be propagated asynchronously 200 // Changes from the PrefService will be propagated asynchronously
199 // via PostTask. 201 // via PostTask.
200 // This method should only be used from the thread the PrefMember is currently 202 // This method should only be used from the thread the PrefMember is currently
201 // on, which is the UI thread by default. 203 // on, which is the UI thread by default.
202 void MoveToThread(scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 204 void MoveToThread(
205 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {
203 subtle::PrefMemberBase::MoveToThread(task_runner); 206 subtle::PrefMemberBase::MoveToThread(task_runner);
204 } 207 }
205 208
206 // Check whether the pref is managed, i.e. controlled externally through 209 // Check whether the pref is managed, i.e. controlled externally through
207 // enterprise configuration management (e.g. windows group policy). Returns 210 // enterprise configuration management (e.g. windows group policy). Returns
208 // false for unknown prefs. 211 // false for unknown prefs.
209 // This method should only be used from the thread the PrefMember is currently 212 // This method should only be used from the thread the PrefMember is currently
210 // on, which is the UI thread unless changed by |MoveToThread|. 213 // on, which is the UI thread unless changed by |MoveToThread|.
211 bool IsManaged() const { 214 bool IsManaged() const {
212 VerifyPref(); 215 VerifyPref();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 349
347 typedef PrefMember<bool> BooleanPrefMember; 350 typedef PrefMember<bool> BooleanPrefMember;
348 typedef PrefMember<int> IntegerPrefMember; 351 typedef PrefMember<int> IntegerPrefMember;
349 typedef PrefMember<double> DoublePrefMember; 352 typedef PrefMember<double> DoublePrefMember;
350 typedef PrefMember<std::string> StringPrefMember; 353 typedef PrefMember<std::string> StringPrefMember;
351 typedef PrefMember<base::FilePath> FilePathPrefMember; 354 typedef PrefMember<base::FilePath> FilePathPrefMember;
352 // This preference member is expensive for large string arrays. 355 // This preference member is expensive for large string arrays.
353 typedef PrefMember<std::vector<std::string> > StringListPrefMember; 356 typedef PrefMember<std::vector<std::string> > StringListPrefMember;
354 357
355 #endif // BASE_PREFS_PREF_MEMBER_H_ 358 #endif // BASE_PREFS_PREF_MEMBER_H_
OLDNEW
« no previous file with comments | « base/prefs/json_pref_store_unittest.cc ('k') | base/prefs/pref_member.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698