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

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

Issue 8568019: Introduce per-tab preferences service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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) 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/public/browser/notification_observer.h" 11 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 content::NotificationService::current()->Notify( 83 content::NotificationService::current()->Notify(
82 chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, 84 chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED,
83 content::Source<PrefService>(pref_service_), 85 content::Source<PrefService>(pref_service_),
84 content::Details<bool>(&succeeded)); 86 content::Details<bool>(&succeeded));
85 } 87 }
86 88
87 void PrefNotifierImpl::FireObservers(const std::string& path) { 89 void PrefNotifierImpl::FireObservers(const std::string& path) {
88 DCHECK(CalledOnValidThread()); 90 DCHECK(CalledOnValidThread());
89 91
90 // Only send notifications for registered preferences. 92 // Only send notifications for registered preferences.
91 if (!pref_service_->FindPreference(path.c_str())) 93 if (!pref_service_ || !pref_service_->FindPreference(path.c_str()))
92 return; 94 return;
93 95
96 if (pref_model_associator_)
97 pref_model_associator_->ProcessPrefChange(path);
Mattias Nissler (ping if slow) 2011/11/16 12:08:04 Seems like this now duplicates the same thing in P
mnaganov (inactive) 2011/11/17 16:50:58 Right. I haven't understood that from your change.
98
94 const PrefObserverMap::iterator observer_iterator = 99 const PrefObserverMap::iterator observer_iterator =
95 pref_observers_.find(path); 100 pref_observers_.find(path);
96 if (observer_iterator == pref_observers_.end()) 101 if (observer_iterator == pref_observers_.end())
97 return; 102 return;
98 103
99 NotificationObserverList::Iterator it(*(observer_iterator->second)); 104 NotificationObserverList::Iterator it(*(observer_iterator->second));
100 content::NotificationObserver* observer; 105 content::NotificationObserver* observer;
101 while ((observer = it.GetNext()) != NULL) { 106 while ((observer = it.GetNext()) != NULL) {
102 observer->Observe(chrome::NOTIFICATION_PREF_CHANGED, 107 observer->Observe(chrome::NOTIFICATION_PREF_CHANGED,
103 content::Source<PrefService>(pref_service_), 108 content::Source<PrefService>(pref_service_),
104 content::Details<const std::string>(&path)); 109 content::Details<const std::string>(&path));
105 } 110 }
106 } 111 }
112
113 void PrefNotifierImpl::SetPrefModelAssociator(
114 PrefModelAssociator* pref_model_associator) {
115 DCHECK(pref_model_associator_ == NULL);
116 pref_model_associator_ = pref_model_associator;
117 }
118
119 void PrefNotifierImpl::SetPrefService(PrefService* pref_service) {
120 DCHECK(pref_service_ == NULL);
121 pref_service_ = pref_service;
122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698