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

Side by Side Diff: chrome/browser/api/prefs/pref_member.cc

Issue 11345008: Remove content::NotificationObserver dependency from most Prefs code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head for commit Created 8 years, 1 month 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
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 #include "chrome/browser/api/prefs/pref_member.h" 5 #include "chrome/browser/api/prefs/pref_member.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/prefs/public/pref_service_base.h" 9 #include "base/prefs/public/pref_service_base.h"
10 #include "base/value_conversions.h" 10 #include "base/value_conversions.h"
11 #include "chrome/common/chrome_notification_types.h"
12 11
13 using base::MessageLoopProxy; 12 using base::MessageLoopProxy;
14 13
15 namespace subtle { 14 namespace subtle {
16 15
17 PrefMemberBase::PrefMemberBase() 16 PrefMemberBase::PrefMemberBase()
18 : observer_(NULL), 17 : observer_(NULL),
19 prefs_(NULL), 18 prefs_(NULL),
20 setting_value_(false) { 19 setting_value_(false) {
21 } 20 }
22 21
23 PrefMemberBase::~PrefMemberBase() { 22 PrefMemberBase::~PrefMemberBase() {
24 Destroy(); 23 Destroy();
25 } 24 }
26 25
27 void PrefMemberBase::Init(const char* pref_name, 26 void PrefMemberBase::Init(const char* pref_name,
28 PrefServiceBase* prefs, 27 PrefServiceBase* prefs,
29 content::NotificationObserver* observer) { 28 PrefObserver* observer) {
30 DCHECK(pref_name); 29 DCHECK(pref_name);
31 DCHECK(prefs); 30 DCHECK(prefs);
32 DCHECK(pref_name_.empty()); // Check that Init is only called once. 31 DCHECK(pref_name_.empty()); // Check that Init is only called once.
33 observer_ = observer; 32 observer_ = observer;
34 prefs_ = prefs; 33 prefs_ = prefs;
35 pref_name_ = pref_name; 34 pref_name_ = pref_name;
36 // Check that the preference is registered. 35 // Check that the preference is registered.
37 DCHECK(prefs_->FindPreference(pref_name_.c_str())) 36 DCHECK(prefs_->FindPreference(pref_name_.c_str()))
38 << pref_name << " not registered."; 37 << pref_name << " not registered.";
39 38
(...skipping 10 matching lines...) Expand all
50 49
51 void PrefMemberBase::MoveToThread( 50 void PrefMemberBase::MoveToThread(
52 const scoped_refptr<MessageLoopProxy>& message_loop) { 51 const scoped_refptr<MessageLoopProxy>& message_loop) {
53 VerifyValuePrefName(); 52 VerifyValuePrefName();
54 // Load the value from preferences if it hasn't been loaded so far. 53 // Load the value from preferences if it hasn't been loaded so far.
55 if (!internal()) 54 if (!internal())
56 UpdateValueFromPref(); 55 UpdateValueFromPref();
57 internal()->MoveToThread(message_loop); 56 internal()->MoveToThread(message_loop);
58 } 57 }
59 58
60 void PrefMemberBase::Observe(int type, 59 void PrefMemberBase::OnPreferenceChanged(PrefServiceBase* service,
61 const content::NotificationSource& source, 60 const std::string& pref_name) {
62 const content::NotificationDetails& details) {
63 VerifyValuePrefName(); 61 VerifyValuePrefName();
64 DCHECK(chrome::NOTIFICATION_PREF_CHANGED == type);
65 UpdateValueFromPref(); 62 UpdateValueFromPref();
66 if (!setting_value_ && observer_) 63 if (!setting_value_ && observer_)
67 observer_->Observe(type, source, details); 64 observer_->OnPreferenceChanged(service, pref_name);
68 } 65 }
69 66
70 void PrefMemberBase::UpdateValueFromPref() const { 67 void PrefMemberBase::UpdateValueFromPref() const {
71 VerifyValuePrefName(); 68 VerifyValuePrefName();
72 const PrefServiceBase::Preference* pref = 69 const PrefServiceBase::Preference* pref =
73 prefs_->FindPreference(pref_name_.c_str()); 70 prefs_->FindPreference(pref_name_.c_str());
74 DCHECK(pref); 71 DCHECK(pref);
75 if (!internal()) 72 if (!internal())
76 CreateInternal(); 73 CreateInternal();
77 internal()->UpdateValue(pref->GetValue()->DeepCopy(), 74 internal()->UpdateValue(pref->GetValue()->DeepCopy(),
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 ListValue list_value; 197 ListValue list_value;
201 list_value.AppendStrings(value); 198 list_value.AppendStrings(value);
202 prefs()->Set(pref_name().c_str(), list_value); 199 prefs()->Set(pref_name().c_str(), list_value);
203 } 200 }
204 201
205 template <> 202 template <>
206 bool PrefMember<std::vector<std::string> >::Internal::UpdateValueInternal( 203 bool PrefMember<std::vector<std::string> >::Internal::UpdateValueInternal(
207 const Value& value) const { 204 const Value& value) const {
208 return subtle::PrefMemberVectorStringUpdate(value, &value_); 205 return subtle::PrefMemberVectorStringUpdate(value, &value_);
209 } 206 }
OLDNEW
« no previous file with comments | « chrome/browser/api/prefs/pref_member.h ('k') | chrome/browser/api/prefs/pref_member_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698