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

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

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

Powered by Google App Engine
This is Rietveld 408576698