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

Side by Side Diff: chrome/browser/prefs/pref_notifier_impl.cc

Issue 7838030: WIP: Introduce per-TabContents PrefService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/prefs/pref_notifier_impl.h" 5 #include "chrome/browser/prefs/pref_notifier_impl.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "chrome/browser/prefs/pref_model_associator.h"
8 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/common/chrome_notification_types.h" 10 #include "chrome/common/chrome_notification_types.h"
10 #include "content/common/notification_observer.h" 11 #include "content/common/notification_observer.h"
11 #include "content/common/notification_service.h" 12 #include "content/common/notification_service.h"
12 13
13 PrefNotifierImpl::PrefNotifierImpl(PrefService* service) 14 PrefNotifierImpl::PrefNotifierImpl()
14 : pref_service_(service) { 15 : pref_service_(NULL),
16 pref_model_associator_(NULL) {
15 } 17 }
16 18
17 PrefNotifierImpl::~PrefNotifierImpl() { 19 PrefNotifierImpl::~PrefNotifierImpl() {
18 DCHECK(CalledOnValidThread()); 20 DCHECK(CalledOnValidThread());
19 21
20 // Verify that there are no pref observers when we shut down. 22 // Verify that there are no pref observers when we shut down.
21 for (PrefObserverMap::iterator it = pref_observers_.begin(); 23 for (PrefObserverMap::iterator it = pref_observers_.begin();
22 it != pref_observers_.end(); ++it) { 24 it != pref_observers_.end(); ++it) {
23 NotificationObserverList::Iterator obs_iterator(*(it->second)); 25 NotificationObserverList::Iterator obs_iterator(*(it->second));
24 if (obs_iterator.GetNext()) { 26 if (obs_iterator.GetNext()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 const PrefObserverMap::iterator observer_iterator = 66 const PrefObserverMap::iterator observer_iterator =
65 pref_observers_.find(path); 67 pref_observers_.find(path);
66 if (observer_iterator == pref_observers_.end()) { 68 if (observer_iterator == pref_observers_.end()) {
67 return; 69 return;
68 } 70 }
69 71
70 NotificationObserverList* observer_list = observer_iterator->second; 72 NotificationObserverList* observer_list = observer_iterator->second;
71 observer_list->RemoveObserver(obs); 73 observer_list->RemoveObserver(obs);
72 } 74 }
73 75
76 void PrefNotifierImpl::SetSource(PrefService* pref_service) {
77 pref_service_ = pref_service;
78 }
79
80 void PrefNotifierImpl::SetPrefModelAssociator(PrefModelAssociator* associator) {
81 pref_model_associator_ = associator;
82 }
83
74 void PrefNotifierImpl::OnPreferenceChanged(const std::string& path) { 84 void PrefNotifierImpl::OnPreferenceChanged(const std::string& path) {
75 FireObservers(path); 85 FireObservers(path);
76 } 86 }
77 87
78 void PrefNotifierImpl::OnInitializationCompleted(bool succeeded) { 88 void PrefNotifierImpl::OnInitializationCompleted(bool succeeded) {
79 DCHECK(CalledOnValidThread()); 89 DCHECK(CalledOnValidThread());
80 90
81 NotificationService::current()->Notify( 91 NotificationService::current()->Notify(
82 chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, 92 chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED,
83 Source<PrefService>(pref_service_), 93 Source<PrefService>(pref_service_),
84 Details<bool>(&succeeded)); 94 Details<bool>(&succeeded));
85 } 95 }
86 96
87 void PrefNotifierImpl::FireObservers(const std::string& path) { 97 void PrefNotifierImpl::FireObservers(const std::string& path) {
88 DCHECK(CalledOnValidThread()); 98 DCHECK(CalledOnValidThread());
89 99
90 // Only send notifications for registered preferences. 100 // Only send notifications for registered preferences.
91 if (!pref_service_->FindPreference(path.c_str())) 101 if (!pref_service_ || !pref_service_->FindPreference(path.c_str()))
92 return; 102 return;
93 103
104 // Notify the associator.
105 if (pref_model_associator_)
106 pref_model_associator_->ProcessPrefChange(path);
107
94 const PrefObserverMap::iterator observer_iterator = 108 const PrefObserverMap::iterator observer_iterator =
95 pref_observers_.find(path); 109 pref_observers_.find(path);
96 if (observer_iterator == pref_observers_.end()) 110 if (observer_iterator == pref_observers_.end())
97 return; 111 return;
98 112
99 NotificationObserverList::Iterator it(*(observer_iterator->second)); 113 NotificationObserverList::Iterator it(*(observer_iterator->second));
100 NotificationObserver* observer; 114 NotificationObserver* observer;
101 while ((observer = it.GetNext()) != NULL) { 115 while ((observer = it.GetNext()) != NULL) {
102 observer->Observe(chrome::NOTIFICATION_PREF_CHANGED, 116 observer->Observe(chrome::NOTIFICATION_PREF_CHANGED,
103 Source<PrefService>(pref_service_), 117 Source<PrefService>(pref_service_),
104 Details<const std::string>(&path)); 118 Details<const std::string>(&path));
105 } 119 }
106 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698