diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-01 17:24:18 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-01 17:24:18 +0000 |
commit | a6a7ced56b518de42dab6d3ac18de490fb494696 (patch) | |
tree | b89d63fe26927a79e9d6d07519fa1983a5466f5a | |
parent | 38d455b3bc1ab2a7b9efc58d78c7ba9ec5067001 (diff) | |
download | chromium_src-a6a7ced56b518de42dab6d3ac18de490fb494696.zip chromium_src-a6a7ced56b518de42dab6d3ac18de490fb494696.tar.gz chromium_src-a6a7ced56b518de42dab6d3ac18de490fb494696.tar.bz2 |
Remove content::NotificationObserver dependency from most Prefs code.
Instead of using content::NotificationObserver, introduce specific
type-safe observer classes and update users to use them. In a very
large number of cases this was the users' only reason for being a
content::NotificationObserver and they would have a lot of
boiler-plate code such as a DCHECK on the notification type and
unpacking of the generic NotificationDetails types, so this change
removes a bunch of boilerplate and introduces more type safety.
This is part of enabling more of the Prefs code to live in
base/prefs/.
TBR=ben@chromium.org,brettw@chromium.org
BUG=155525
Review URL: https://chromiumcodereview.appspot.com/11345008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165414 0039d316-1c4b-4281-b951-d872f2087c98
194 files changed, 1437 insertions, 1516 deletions
diff --git a/base/base.gyp b/base/base.gyp index 699fe46..14460d4 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -329,6 +329,7 @@ 'prefs/pref_value_map.h', 'prefs/public/pref_change_registrar.cc', 'prefs/public/pref_change_registrar.h', + 'prefs/public/pref_observer.h', 'prefs/public/pref_service_base.h', 'prefs/value_map_pref_store.cc', 'prefs/value_map_pref_store.h', diff --git a/base/prefs/public/pref_change_registrar.cc b/base/prefs/public/pref_change_registrar.cc index e7a9791..3f94b04 100644 --- a/base/prefs/public/pref_change_registrar.cc +++ b/base/prefs/public/pref_change_registrar.cc @@ -22,8 +22,7 @@ void PrefChangeRegistrar::Init(PrefServiceBase* service) { service_ = service; } -void PrefChangeRegistrar::Add(const char* path, - content::NotificationObserver* obs) { +void PrefChangeRegistrar::Add(const char* path, PrefObserver* obs) { if (!service_) { NOTREACHED(); return; @@ -37,8 +36,7 @@ void PrefChangeRegistrar::Add(const char* path, service_->AddPrefObserver(path, obs); } -void PrefChangeRegistrar::Remove(const char* path, - content::NotificationObserver* obs) { +void PrefChangeRegistrar::Remove(const char* path, PrefObserver* obs) { if (!service_) { NOTREACHED(); return; diff --git a/base/prefs/public/pref_change_registrar.h b/base/prefs/public/pref_change_registrar.h index a7e1eab..f3abd98 100644 --- a/base/prefs/public/pref_change_registrar.h +++ b/base/prefs/public/pref_change_registrar.h @@ -11,12 +11,9 @@ #include "base/basictypes.h" #include "base/prefs/base_prefs_export.h" +class PrefObserver; class PrefServiceBase; -namespace content { -class NotificationObserver; -} - // Automatically manages the registration of one or more pref change observers // with a PrefStore. Functions much like NotificationRegistrar, but specifically // manages observers of preference changes. When the Registrar is destroyed, @@ -34,13 +31,11 @@ class BASE_PREFS_EXPORT PrefChangeRegistrar { // object. All registered observers will be automatically unregistered // when the registrar's destructor is called unless the observer has been // explicitly removed by a call to Remove beforehand. - void Add(const char* path, - content::NotificationObserver* obs); + void Add(const char* path, PrefObserver* obs); // Removes a preference observer that has previously been added with a call to // Add. - void Remove(const char* path, - content::NotificationObserver* obs); + void Remove(const char* path, PrefObserver* obs); // Removes all observers that have been previously added with a call to Add. void RemoveAll(); @@ -55,8 +50,7 @@ class BASE_PREFS_EXPORT PrefChangeRegistrar { bool IsManaged(); private: - typedef std::pair<std::string, content::NotificationObserver*> - ObserverRegistration; + typedef std::pair<std::string, PrefObserver*> ObserverRegistration; std::set<ObserverRegistration> observers_; PrefServiceBase* service_; diff --git a/base/prefs/public/pref_change_registrar_unittest.cc b/base/prefs/public/pref_change_registrar_unittest.cc index 491d7db..f860602 100644 --- a/base/prefs/public/pref_change_registrar_unittest.cc +++ b/base/prefs/public/pref_change_registrar_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_pref_service.h" @@ -18,6 +19,14 @@ using testing::Eq; namespace { +// TODO(joi): Use PrefObserverMock once it moves to base/prefs/. +class MockPrefObserver : public PrefObserver { + public: + virtual ~MockPrefObserver() {} + + MOCK_METHOD2(OnPreferenceChanged, void(PrefServiceBase*, const std::string&)); +}; + // A mock provider that allows us to capture pref observer changes. class MockPrefService : public TestingPrefService { public: @@ -25,9 +34,9 @@ class MockPrefService : public TestingPrefService { virtual ~MockPrefService() {} MOCK_METHOD2(AddPrefObserver, - void(const char*, content::NotificationObserver*)); + void(const char*, PrefObserver*)); MOCK_METHOD2(RemovePrefObserver, - void(const char*, content::NotificationObserver*)); + void(const char*, PrefObserver*)); }; } // namespace @@ -40,17 +49,17 @@ class PrefChangeRegistrarTest : public testing::Test { protected: virtual void SetUp(); - content::NotificationObserver* observer() const { return observer_.get(); } + PrefObserver* observer() const { return observer_.get(); } MockPrefService* service() const { return service_.get(); } private: scoped_ptr<MockPrefService> service_; - scoped_ptr<content::MockNotificationObserver> observer_; + scoped_ptr<MockPrefObserver> observer_; }; void PrefChangeRegistrarTest::SetUp() { service_.reset(new MockPrefService()); - observer_.reset(new content::MockNotificationObserver()); + observer_.reset(new MockPrefObserver()); } TEST_F(PrefChangeRegistrarTest, AddAndRemove) { @@ -137,7 +146,7 @@ class ObserveSetOfPreferencesTest : public testing::Test { } PrefChangeRegistrar* CreatePrefChangeRegistrar( - content::NotificationObserver* observer) { + PrefObserver* observer) { PrefChangeRegistrar* pref_set = new PrefChangeRegistrar(); pref_set->Init(pref_service_.get()); pref_set->Add(prefs::kHomePage, observer); @@ -180,27 +189,23 @@ TEST_F(ObserveSetOfPreferencesTest, Observe) { using testing::_; using testing::Mock; - content::MockNotificationObserver observer; + MockPrefObserver observer; scoped_ptr<PrefChangeRegistrar> pref_set( CreatePrefChangeRegistrar(&observer)); - EXPECT_CALL(observer, - Observe(int(chrome::NOTIFICATION_PREF_CHANGED), - content::Source<PrefService>(pref_service_.get()), - PrefNameDetails(prefs::kHomePage))); + EXPECT_CALL(observer, OnPreferenceChanged(pref_service_.get(), + prefs::kHomePage)); pref_service_->SetUserPref(prefs::kHomePage, Value::CreateStringValue("http://crbug.com")); Mock::VerifyAndClearExpectations(&observer); - EXPECT_CALL(observer, - Observe(int(chrome::NOTIFICATION_PREF_CHANGED), - content::Source<PrefService>(pref_service_.get()), - PrefNameDetails(prefs::kHomePageIsNewTabPage))); + EXPECT_CALL(observer, OnPreferenceChanged(pref_service_.get(), + prefs::kHomePageIsNewTabPage)); pref_service_->SetUserPref(prefs::kHomePageIsNewTabPage, Value::CreateBooleanValue(true)); Mock::VerifyAndClearExpectations(&observer); - EXPECT_CALL(observer, Observe(_, _, _)).Times(0); + EXPECT_CALL(observer, OnPreferenceChanged(_, _)).Times(0); pref_service_->SetUserPref(prefs::kApplicationLocale, Value::CreateStringValue("en_US.utf8")); Mock::VerifyAndClearExpectations(&observer); diff --git a/base/prefs/public/pref_observer.h b/base/prefs/public/pref_observer.h new file mode 100644 index 0000000..2692243 --- /dev/null +++ b/base/prefs/public/pref_observer.h @@ -0,0 +1,19 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_PREFS_PUBLIC_PREF_OBSERVER_H_ +#define BASE_PREFS_PUBLIC_PREF_OBSERVER_H_ + +#include <string> + +class PrefServiceBase; + +// TODO(joi): Switch to base::Callback and remove this. +class PrefObserver { + public: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) = 0; +}; + +#endif // BASE_PREFS_PUBLIC_PREF_OBSERVER_H_ diff --git a/base/prefs/public/pref_service_base.h b/base/prefs/public/pref_service_base.h index aa5b3fd..131d221 100644 --- a/base/prefs/public/pref_service_base.h +++ b/base/prefs/public/pref_service_base.h @@ -20,7 +20,6 @@ namespace content { class BrowserContext; -class NotificationObserver; } namespace subtle { @@ -28,6 +27,7 @@ class PrefMemberBase; } class FilePath; +class PrefObserver; class Profile; class TabContents; @@ -259,14 +259,12 @@ class PrefServiceBase { // These are protected so they can only be accessed by the friend // classes listed above. // - // If the pref at the given path changes, we call the observer's Observe - // method with PREF_CHANGED. Note that observers should not call these methods - // directly but rather use a PrefChangeRegistrar to make sure the observer - // gets cleaned up properly. - virtual void AddPrefObserver(const char* path, - content::NotificationObserver* obs) = 0; - virtual void RemovePrefObserver(const char* path, - content::NotificationObserver* obs) = 0; + // If the pref at the given path changes, we call the observer's + // OnPreferenceChanged method. Note that observers should not call + // these methods directly but rather use a PrefChangeRegistrar to + // make sure the observer gets cleaned up properly. + virtual void AddPrefObserver(const char* path, PrefObserver* obs) = 0; + virtual void RemovePrefObserver(const char* path, PrefObserver* obs) = 0; }; #endif // BASE_PREFS_PUBLIC_PREF_SERVICE_BASE_H_ diff --git a/chrome/browser/api/prefs/pref_member.cc b/chrome/browser/api/prefs/pref_member.cc index 46f2aa6..e81b13a 100644 --- a/chrome/browser/api/prefs/pref_member.cc +++ b/chrome/browser/api/prefs/pref_member.cc @@ -8,7 +8,6 @@ #include "base/location.h" #include "base/prefs/public/pref_service_base.h" #include "base/value_conversions.h" -#include "chrome/common/chrome_notification_types.h" using base::MessageLoopProxy; @@ -26,7 +25,7 @@ PrefMemberBase::~PrefMemberBase() { void PrefMemberBase::Init(const char* pref_name, PrefServiceBase* prefs, - content::NotificationObserver* observer) { + PrefObserver* observer) { DCHECK(pref_name); DCHECK(prefs); DCHECK(pref_name_.empty()); // Check that Init is only called once. @@ -57,14 +56,12 @@ void PrefMemberBase::MoveToThread( internal()->MoveToThread(message_loop); } -void PrefMemberBase::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void PrefMemberBase::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { VerifyValuePrefName(); - DCHECK(chrome::NOTIFICATION_PREF_CHANGED == type); UpdateValueFromPref(); if (!setting_value_ && observer_) - observer_->Observe(type, source, details); + observer_->OnPreferenceChanged(service, pref_name); } void PrefMemberBase::UpdateValueFromPref() const { diff --git a/chrome/browser/api/prefs/pref_member.h b/chrome/browser/api/prefs/pref_member.h index 18a2129..7843693 100644 --- a/chrome/browser/api/prefs/pref_member.h +++ b/chrome/browser/api/prefs/pref_member.h @@ -32,14 +32,14 @@ #include "base/logging.h" #include "base/memory/ref_counted.h" #include "base/message_loop_proxy.h" +#include "base/prefs/public/pref_observer.h" #include "base/values.h" -#include "content/public/browser/notification_observer.h" class PrefServiceBase; namespace subtle { -class PrefMemberBase : public content::NotificationObserver { +class PrefMemberBase : public PrefObserver { protected: class Internal : public base::RefCountedThreadSafe<Internal> { public: @@ -91,7 +91,7 @@ class PrefMemberBase : public content::NotificationObserver { // See PrefMember<> for description. void Init(const char* pref_name, PrefServiceBase* prefs, - content::NotificationObserver* observer); + PrefObserver* observer); virtual void CreateInternal() const = 0; @@ -100,10 +100,9 @@ class PrefMemberBase : public content::NotificationObserver { void MoveToThread(const scoped_refptr<base::MessageLoopProxy>& message_loop); - // content::NotificationObserver - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; void VerifyValuePrefName() const { DCHECK(!pref_name_.empty()); @@ -127,7 +126,7 @@ class PrefMemberBase : public content::NotificationObserver { private: // Ordered the members to compact the class instance. std::string pref_name_; - content::NotificationObserver* observer_; + PrefObserver* observer_; PrefServiceBase* prefs_; protected: @@ -153,7 +152,7 @@ class PrefMember : public subtle::PrefMemberBase { // don't want any notifications of changes. // This method should only be called on the UI thread. void Init(const char* pref_name, PrefServiceBase* prefs, - content::NotificationObserver* observer) { + PrefObserver* observer) { subtle::PrefMemberBase::Init(pref_name, prefs, observer); } diff --git a/chrome/browser/api/prefs/pref_member_unittest.cc b/chrome/browser/api/prefs/pref_member_unittest.cc index 67a5159..3539322 100644 --- a/chrome/browser/api/prefs/pref_member_unittest.cc +++ b/chrome/browser/api/prefs/pref_member_unittest.cc @@ -77,21 +77,17 @@ class GetPrefValueCallback bool value_; }; -class PrefMemberTestClass : public content::NotificationObserver { +class PrefMemberTestClass : public PrefObserver { public: explicit PrefMemberTestClass(PrefService* prefs) : observe_cnt_(0), prefs_(prefs) { str_.Init(kStringPref, prefs, this); } - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK(chrome::NOTIFICATION_PREF_CHANGED == type); - PrefService* prefs_in = content::Source<PrefService>(source).ptr(); - EXPECT_EQ(prefs_in, prefs_); - std::string* pref_name_in = content::Details<std::string>(details).ptr(); - EXPECT_EQ(*pref_name_in, kStringPref); + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE { + EXPECT_EQ(service, prefs_); + EXPECT_EQ(pref_name, kStringPref); EXPECT_EQ(str_.GetValue(), prefs_->GetString(kStringPref)); ++observe_cnt_; } diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc index f9dfd82..132d4ce 100644 --- a/chrome/browser/autofill/autofill_manager.cc +++ b/chrome/browser/autofill/autofill_manager.cc @@ -290,14 +290,10 @@ void AutofillManager::RenderViewCreated(content::RenderViewHost* host) { UpdatePasswordGenerationState(host, true); } -void AutofillManager::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void AutofillManager::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - std::string* pref = content::Details<std::string>(details).ptr(); - DCHECK(prefs::kPasswordGenerationEnabled == *pref); + DCHECK(prefs::kPasswordGenerationEnabled == pref_name); UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(), false); } diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h index 4be3a4f5..af42fbe 100644 --- a/chrome/browser/autofill/autofill_manager.h +++ b/chrome/browser/autofill/autofill_manager.h @@ -18,6 +18,7 @@ #include "base/memory/scoped_vector.h" #include "base/memory/weak_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/string16.h" #include "base/time.h" #include "chrome/browser/api/sync/profile_sync_service_observer.h" @@ -25,7 +26,6 @@ #include "chrome/browser/autofill/autofill_download.h" #include "chrome/browser/autofill/field_types.h" #include "chrome/browser/autofill/form_structure.h" -#include "content/public/browser/notification_observer.h" #include "content/public/browser/web_contents_observer.h" class AutofillExternalDelegate; @@ -64,10 +64,10 @@ class Message; // Manages saving and restoring the user's personal information entered into web // forms. -class AutofillManager : public content::NotificationObserver, - public content::WebContentsObserver, +class AutofillManager : public content::WebContentsObserver, public AutofillDownloadManager::Observer, public ProfileSyncServiceObserver, + public PrefObserver, public base::RefCounted<AutofillManager> { public: static void CreateForWebContentsAndDelegate( @@ -191,10 +191,9 @@ class AutofillManager : public content::NotificationObserver, // Register as an observer with the sync service. void RegisterWithSyncService(); - // content::NotificationObserver override - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // Determines what the current state of password generation is, and if it has // changed from |password_generation_enabled_|. If it has changed or if diff --git a/chrome/browser/background/background_mode_manager.cc b/chrome/browser/background/background_mode_manager.cc index 4fd087c..b77ba7e 100644 --- a/chrome/browser/background/background_mode_manager.cc +++ b/chrome/browser/background/background_mode_manager.cc @@ -284,11 +284,6 @@ void BackgroundModeManager::Observe( const content::NotificationSource& source, const content::NotificationDetails& details) { switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: - DCHECK(*content::Details<std::string>(details).ptr() == - prefs::kBackgroundModeEnabled); - OnBackgroundModeEnabledPrefChanged(); - break; case chrome::NOTIFICATION_EXTENSIONS_READY: // Extensions are loaded, so we don't need to manually keep the browser // process alive any more when running in no-startup-window mode. @@ -341,6 +336,12 @@ void BackgroundModeManager::Observe( } } +void BackgroundModeManager::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK(pref_name == prefs::kBackgroundModeEnabled); + OnBackgroundModeEnabledPrefChanged(); +} + void BackgroundModeManager::OnBackgroundModeEnabledPrefChanged() { if (IsBackgroundModePrefEnabled()) EnableBackgroundMode(); diff --git a/chrome/browser/background/background_mode_manager.h b/chrome/browser/background/background_mode_manager.h index 5a3db331..2cb8a78 100644 --- a/chrome/browser/background/background_mode_manager.h +++ b/chrome/browser/background/background_mode_manager.h @@ -9,6 +9,7 @@ #include "base/gtest_prod_util.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/background/background_application_list_model.h" #include "chrome/browser/profiles/profile_info_cache_observer.h" #include "chrome/browser/profiles/profile_keyed_service.h" @@ -47,6 +48,7 @@ class BackgroundModeManager : public content::NotificationObserver, public BackgroundApplicationListModel::Observer, public ProfileInfoCacheObserver, + public PrefObserver, public ui::SimpleMenuModel::Delegate { public: BackgroundModeManager(CommandLine* command_line, @@ -158,6 +160,10 @@ class BackgroundModeManager const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Called when the kBackgroundModeEnabled preference changes. void OnBackgroundModeEnabledPrefChanged(); diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 7cb72c1..aacfea08 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -610,20 +610,14 @@ safe_browsing::ClientSideDetectionService* return NULL; } -void BrowserProcessImpl::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - std::string* pref = content::Details<std::string>(details).ptr(); - if (*pref == prefs::kDefaultBrowserSettingEnabled) { - ApplyDefaultBrowserPolicy(); - } else if (*pref == prefs::kDisabledSchemes) { - ApplyDisabledSchemesPolicy(); - } else if (*pref == prefs::kAllowCrossOriginAuthPrompt) { - ApplyAllowCrossOriginAuthPromptPolicy(); - } - } else { - NOTREACHED(); +void BrowserProcessImpl::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref) { + if (pref == prefs::kDefaultBrowserSettingEnabled) { + ApplyDefaultBrowserPolicy(); + } else if (pref == prefs::kDisabledSchemes) { + ApplyDisabledSchemesPolicy(); + } else if (pref == prefs::kAllowCrossOriginAuthPrompt) { + ApplyAllowCrossOriginAuthPromptPolicy(); } } diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h index 304cd7a..5f18e62 100644 --- a/chrome/browser/browser_process_impl.h +++ b/chrome/browser/browser_process_impl.h @@ -17,10 +17,10 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/threading/non_thread_safe.h" #include "base/timer.h" #include "chrome/browser/browser_process.h" -#include "content/public/browser/notification_observer.h" class ChromeNetLog; class ChromeResourceDispatcherHostDelegate; @@ -43,7 +43,7 @@ class PolicyService; // Real implementation of BrowserProcess that creates and returns the services. class BrowserProcessImpl : public BrowserProcess, public base::NonThreadSafe, - public content::NotificationObserver { + public PrefObserver { public: // |local_state_task_runner| must be a shutdown-blocking task runner. BrowserProcessImpl(base::SequencedTaskRunner* local_state_task_runner, @@ -120,10 +120,9 @@ class BrowserProcessImpl : public BrowserProcess, virtual CRLSetFetcher* crl_set_fetcher() OVERRIDE; virtual BookmarkPromptController* bookmark_prompt_controller() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; private: void CreateMetricsService(); diff --git a/chrome/browser/captive_portal/captive_portal_service.cc b/chrome/browser/captive_portal/captive_portal_service.cc index d6a013c..b2cce55 100644 --- a/chrome/browser/captive_portal/captive_portal_service.cc +++ b/chrome/browser/captive_portal/captive_portal_service.cc @@ -271,14 +271,10 @@ void CaptivePortalService::OnPortalDetectionCompleted( OnResult(result); } -void CaptivePortalService::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void CaptivePortalService::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { DCHECK(CalledOnValidThread()); - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - DCHECK_EQ(std::string(prefs::kAlternateErrorPagesEnabled), - *content::Details<std::string>(details).ptr()); + DCHECK_EQ(std::string(prefs::kAlternateErrorPagesEnabled), pref_name); UpdateEnabledState(); } diff --git a/chrome/browser/captive_portal/captive_portal_service.h b/chrome/browser/captive_portal/captive_portal_service.h index 82b3d71..35badc4 100644 --- a/chrome/browser/captive_portal/captive_portal_service.h +++ b/chrome/browser/captive_portal/captive_portal_service.h @@ -7,13 +7,13 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "base/threading/non_thread_safe.h" #include "base/time.h" #include "base/timer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/captive_portal/captive_portal_detector.h" #include "chrome/browser/profiles/profile_keyed_service.h" -#include "content/public/browser/notification_observer.h" #include "googleurl/src/gurl.h" #include "net/base/backoff_entry.h" @@ -29,7 +29,7 @@ namespace captive_portal { // be accessed on the UI thread. // Design doc: https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlUdlUdoW9WRaEmfM/edit class CaptivePortalService : public ProfileKeyedService, - public content::NotificationObserver, + public PrefObserver, public base::NonThreadSafe { public: enum TestingState { @@ -116,11 +116,9 @@ class CaptivePortalService : public ProfileKeyedService, void OnPortalDetectionCompleted( const CaptivePortalDetector::Results& results); - // content::NotificationObserver: - virtual void Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // ProfileKeyedService: virtual void Shutdown() OVERRIDE; diff --git a/chrome/browser/chromeos/audio/audio_handler.cc b/chrome/browser/chromeos/audio/audio_handler.cc index f9d9999..f78657f 100644 --- a/chrome/browser/chromeos/audio/audio_handler.cc +++ b/chrome/browser/chromeos/audio/audio_handler.cc @@ -19,7 +19,6 @@ #include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_service.h" using std::max; using std::min; @@ -161,18 +160,11 @@ void AudioHandler::RemoveVolumeObserver(VolumeObserver* observer) { volume_observers_.RemoveObserver(observer); } -void AudioHandler::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - std::string* pref_name = content::Details<std::string>(details).ptr(); - if (*pref_name == prefs::kAudioOutputAllowed || - *pref_name == prefs::kAudioCaptureAllowed) { - ApplyAudioPolicy(); - } - } else { - NOTREACHED() << "Unexpected notification type : " << type; - } +void AudioHandler::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK(pref_name == prefs::kAudioOutputAllowed || + pref_name == prefs::kAudioCaptureAllowed); + ApplyAudioPolicy(); } AudioHandler::AudioHandler(AudioMixer* mixer) diff --git a/chrome/browser/chromeos/audio/audio_handler.h b/chrome/browser/chromeos/audio/audio_handler.h index ecb9f57a..1b77f9f 100644 --- a/chrome/browser/chromeos/audio/audio_handler.h +++ b/chrome/browser/chromeos/audio/audio_handler.h @@ -9,11 +9,8 @@ #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/threading/thread.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" -#include "content/public/browser/notification_source.h" template <typename T> struct DefaultSingletonTraits; @@ -24,7 +21,7 @@ namespace chromeos { class AudioMixer; -class AudioHandler : public content::NotificationObserver { +class AudioHandler : public PrefObserver { public: class VolumeObserver { public: @@ -76,10 +73,9 @@ class AudioHandler : public content::NotificationObserver { void AddVolumeObserver(VolumeObserver* observer); void RemoveVolumeObserver(VolumeObserver* observer); - // Overridden from content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // Overridden from PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; private: // Defines the delete on exit Singleton traits we like. Best to have this @@ -107,7 +103,6 @@ class AudioHandler : public content::NotificationObserver { PrefService* local_state_; // not owned PrefChangeRegistrar pref_change_registrar_; - content::NotificationRegistrar registrar_; DISALLOW_COPY_AND_ASSIGN(AudioHandler); }; diff --git a/chrome/browser/chromeos/drive/drive_file_system.cc b/chrome/browser/chromeos/drive/drive_file_system.cc index 94aedf8..98cd149 100644 --- a/chrome/browser/chromeos/drive/drive_file_system.cc +++ b/chrome/browser/chromeos/drive/drive_file_system.cc @@ -2140,21 +2140,14 @@ DriveFileSystemMetadata DriveFileSystem::GetMetadata() const { return metadata; } -void DriveFileSystem::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void DriveFileSystem::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(pref_name == prefs::kDisableDriveHostedFiles); - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - PrefService* pref_service = profile_->GetPrefs(); - std::string* pref_name = content::Details<std::string>(details).ptr(); - if (*pref_name == prefs::kDisableDriveHostedFiles) { - SetHideHostedDocuments( - pref_service->GetBoolean(prefs::kDisableDriveHostedFiles)); - } - } else { - NOTREACHED(); - } + PrefService* pref_service = profile_->GetPrefs(); + SetHideHostedDocuments( + pref_service->GetBoolean(prefs::kDisableDriveHostedFiles)); } void DriveFileSystem::SetHideHostedDocuments(bool hide) { diff --git a/chrome/browser/chromeos/drive/drive_file_system.h b/chrome/browser/chromeos/drive/drive_file_system.h index 98de02b..c8f05eb 100644 --- a/chrome/browser/chromeos/drive/drive_file_system.h +++ b/chrome/browser/chromeos/drive/drive_file_system.h @@ -11,6 +11,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/observer_list.h" +#include "base/prefs/public/pref_observer.h" #include "base/timer.h" #include "chrome/browser/chromeos/drive/drive_cache.h" #include "chrome/browser/chromeos/drive/drive_feed_loader_observer.h" @@ -18,7 +19,6 @@ #include "chrome/browser/chromeos/drive/file_system/drive_operations.h" #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" #include "chrome/browser/google_apis/gdata_errorcode.h" -#include "content/public/browser/notification_observer.h" class PrefChangeRegistrar; @@ -53,7 +53,7 @@ class RemoveOperation; class DriveFileSystem : public DriveFileSystemInterface, public DriveFeedLoaderObserver, public file_system::OperationObserver, - public content::NotificationObserver { + public PrefObserver { public: DriveFileSystem(Profile* profile, DriveCache* cache, @@ -143,10 +143,9 @@ class DriveFileSystem : public DriveFileSystemInterface, virtual DriveFileSystemMetadata GetMetadata() const OVERRIDE; virtual void Reload() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // file_system::OperationObserver overrides. virtual void OnDirectoryChangedByOperation( diff --git a/chrome/browser/chromeos/drive/drive_sync_client.cc b/chrome/browser/chromeos/drive/drive_sync_client.cc index 04d43cd..6de15df 100644 --- a/chrome/browser/chromeos/drive/drive_sync_client.cc +++ b/chrome/browser/chromeos/drive/drive_sync_client.cc @@ -430,9 +430,8 @@ void DriveSyncClient::OnUploadFileComplete(const std::string& resource_id, DoSyncLoop(); } -void DriveSyncClient::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void DriveSyncClient::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // Resume the sync loop if gdata preferences are changed. Note that we diff --git a/chrome/browser/chromeos/drive/drive_sync_client.h b/chrome/browser/chromeos/drive/drive_sync_client.h index f0694e1..410b50e 100644 --- a/chrome/browser/chromeos/drive/drive_sync_client.h +++ b/chrome/browser/chromeos/drive/drive_sync_client.h @@ -11,12 +11,12 @@ #include "base/callback_forward.h" #include "base/memory/weak_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "base/time.h" #include "chrome/browser/chromeos/drive/drive_cache.h" #include "chrome/browser/chromeos/drive/drive_cache_observer.h" #include "chrome/browser/chromeos/drive/drive_file_system_observer.h" #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" -#include "content/public/browser/notification_observer.h" #include "net/base/network_change_notifier.h" class Profile; @@ -45,7 +45,7 @@ class DriveSyncClientObserver; class DriveSyncClient : public DriveFileSystemObserver, public DriveCacheObserver, - public content::NotificationObserver, + public PrefObserver, public net::NetworkChangeNotifier::ConnectionTypeObserver { public: // Types of sync tasks. @@ -178,10 +178,9 @@ class DriveSyncClient void OnUploadFileComplete(const std::string& resource_id, DriveFileError error); - // content::NotificationObserver override. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver override. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // net::NetworkChangeNotifier::ConnectionTypeObserver override. virtual void OnConnectionTypeChanged( diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.cc b/chrome/browser/chromeos/extensions/file_browser_event_router.cc index 430e6f4..c4304333 100644 --- a/chrome/browser/chromeos/extensions/file_browser_event_router.cc +++ b/chrome/browser/chromeos/extensions/file_browser_event_router.cc @@ -385,41 +385,37 @@ void FileBrowserEventRouter::OnNetworkManagerChanged( scoped_ptr<ListValue>(new ListValue()), NULL, GURL()); } -void FileBrowserEventRouter::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void FileBrowserEventRouter::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { if (!profile_ || !extensions::ExtensionSystem::Get(profile_)->event_router()) { NOTREACHED(); return; } - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - std::string* pref_name = content::Details<std::string>(details).ptr(); - // If the policy just got disabled we have to unmount every device currently - // mounted. The opposite is fine - we can let the user re-plug her device to - // make it available. - if (*pref_name == prefs::kExternalStorageDisabled && - profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { - DiskMountManager* manager = DiskMountManager::GetInstance(); - DiskMountManager::MountPointMap mounts(manager->mount_points()); - for (DiskMountManager::MountPointMap::const_iterator it = mounts.begin(); - it != mounts.end(); ++it) { - LOG(INFO) << "Unmounting " << it->second.mount_path - << " because of policy."; - manager->UnmountPath(it->second.mount_path, - chromeos::UNMOUNT_OPTIONS_NONE); - } - return; - } else if (*pref_name == prefs::kDisableDriveOverCellular || - *pref_name == prefs::kDisableDriveHostedFiles || - *pref_name == prefs::kDisableDrive || - *pref_name == prefs::kUse24HourClock) { - extensions::ExtensionSystem::Get(profile_)->event_router()-> - DispatchEventToRenderers( - extensions::event_names::kOnFileBrowserPreferencesChanged, - scoped_ptr<ListValue>(new ListValue()), NULL, GURL()); + + // If the policy just got disabled we have to unmount every device currently + // mounted. The opposite is fine - we can let the user re-plug her device to + // make it available. + if (pref_name == prefs::kExternalStorageDisabled && + profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { + DiskMountManager* manager = DiskMountManager::GetInstance(); + DiskMountManager::MountPointMap mounts(manager->mount_points()); + for (DiskMountManager::MountPointMap::const_iterator it = mounts.begin(); + it != mounts.end(); ++it) { + LOG(INFO) << "Unmounting " << it->second.mount_path + << " because of policy."; + manager->UnmountPath(it->second.mount_path, + chromeos::UNMOUNT_OPTIONS_NONE); } + return; + } else if (pref_name == prefs::kDisableDriveOverCellular || + pref_name == prefs::kDisableDriveHostedFiles || + pref_name == prefs::kDisableDrive || + pref_name == prefs::kUse24HourClock) { + extensions::ExtensionSystem::Get(profile_)->event_router()-> + DispatchEventToRenderers( + extensions::event_names::kOnFileBrowserPreferencesChanged, + scoped_ptr<ListValue>(new ListValue()), NULL, GURL()); } } diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.h b/chrome/browser/chromeos/extensions/file_browser_event_router.h index 0313434..e2d926b 100644 --- a/chrome/browser/chromeos/extensions/file_browser_event_router.h +++ b/chrome/browser/chromeos/extensions/file_browser_event_router.h @@ -12,6 +12,7 @@ #include "base/files/file_path_watcher.h" #include "base/memory/linked_ptr.h" #include "base/memory/scoped_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "base/string16.h" #include "base/synchronization/lock.h" #include "chrome/browser/chromeos/cros/network_library.h" @@ -22,9 +23,6 @@ #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" #include "chrome/browser/profiles/refcounted_profile_keyed_service_factory.h" #include "chromeos/disks/disk_mount_manager.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_source.h" class FileBrowserNotifications; class PrefChangeRegistrar; @@ -41,7 +39,7 @@ class FileBrowserEventRouter : public RefcountedProfileKeyedService, public chromeos::disks::DiskMountManager::Observer, public chromeos::NetworkLibrary::NetworkManagerObserver, - public content::NotificationObserver, + public PrefObserver, public drive::DriveFileSystemObserver, public google_apis::DriveServiceObserver { public: @@ -79,10 +77,9 @@ class FileBrowserEventRouter virtual void OnNetworkManagerChanged( chromeos::NetworkLibrary* network_library) OVERRIDE; - // Overridden from content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // Overridden from PrefObserver. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // drive::DriveServiceObserver overrides. virtual void OnProgressUpdate( diff --git a/chrome/browser/chromeos/input_method/browser_state_monitor.cc b/chrome/browser/chromeos/input_method/browser_state_monitor.cc index 3de50d3..0b2a8a2 100644 --- a/chrome/browser/chromeos/input_method/browser_state_monitor.cc +++ b/chrome/browser/chromeos/input_method/browser_state_monitor.cc @@ -153,9 +153,6 @@ void BrowserStateMonitor::Observe( InputMethodManager::STATE_BROWSER_SCREEN); break; } - case chrome::NOTIFICATION_PREF_CHANGED: { - break; // just ignore the notification. - } default: { NOTREACHED(); break; diff --git a/chrome/browser/chromeos/input_method/browser_state_monitor_unittest.cc b/chrome/browser/chromeos/input_method/browser_state_monitor_unittest.cc index 3746b80..b73b05a 100644 --- a/chrome/browser/chromeos/input_method/browser_state_monitor_unittest.cc +++ b/chrome/browser/chromeos/input_method/browser_state_monitor_unittest.cc @@ -237,22 +237,6 @@ TEST(BrowserStateMonitorTest, TestObserveAppTerminating) { EXPECT_EQ(0, monitor.update_user_pref_count()); } -TEST(BrowserStateMonitorTest, TestObservePrefChanged) { - TestingPrefService prefs; - RegisterTestPrefs(&prefs); - MockInputMethodManager mock_manager; - TestableBrowserStateMonitor monitor(&mock_manager); - monitor.SetPrefServiceForTesting(&prefs); - - EXPECT_EQ(1, mock_manager.set_state_count_); - monitor.Observe(chrome::NOTIFICATION_PREF_CHANGED, - content::NotificationService::AllSources(), - content::NotificationService::NoDetails()); - - // NOTIFICATION_PREF_CHANGED should be ignored. - EXPECT_EQ(1, mock_manager.set_state_count_); -} - TEST(BrowserStateMonitorTest, TestUpdatePrefOnLoginScreen) { TestingPrefService prefs; RegisterTestPrefs(&prefs); diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc index 793c7f9..091369f 100644 --- a/chrome/browser/chromeos/preferences.cc +++ b/chrome/browser/chromeos/preferences.cc @@ -30,8 +30,6 @@ #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_source.h" #include "googleurl/src/gurl.h" #include "ui/base/events/event_constants.h" #include "unicode/timezone.h" @@ -393,11 +391,9 @@ void Preferences::SetInputMethodListForTesting() { SetInputMethodList(); } -void Preferences::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) - NotifyPrefChanged(content::Details<std::string>(details).ptr()); +void Preferences::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + NotifyPrefChanged(&pref_name); } void Preferences::NotifyPrefChanged(const std::string* pref_name) { diff --git a/chrome/browser/chromeos/preferences.h b/chrome/browser/chromeos/preferences.h index d14acfc..4c27fd3 100644 --- a/chrome/browser/chromeos/preferences.h +++ b/chrome/browser/chromeos/preferences.h @@ -9,9 +9,9 @@ #include <vector> #include "base/compiler_specific.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/chromeos/language_preferences.h" -#include "content/public/browser/notification_observer.h" class PrefService; @@ -24,7 +24,7 @@ class InputMethodManager; // is first initialized, it will initialize the OS settings to what's stored in // the preferences. These include touchpad settings, etc. // When the preferences change, we change the settings to reflect the new value. -class Preferences : public content::NotificationObserver { +class Preferences : public PrefObserver { public: Preferences(); explicit Preferences( @@ -37,10 +37,9 @@ class Preferences : public content::NotificationObserver { // This method will initialize Chrome OS settings to values in user prefs. void Init(PrefService* prefs); - // Overridden from content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // Overridden from PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; void InitUserPrefsForTesting(PrefService* prefs); void SetInputMethodListForTesting(); diff --git a/chrome/browser/chromeos/proxy_config_service_impl.cc b/chrome/browser/chromeos/proxy_config_service_impl.cc index 3b20231..5eca442 100644 --- a/chrome/browser/chromeos/proxy_config_service_impl.cc +++ b/chrome/browser/chromeos/proxy_config_service_impl.cc @@ -586,29 +586,26 @@ void ProxyConfigServiceImpl::RegisterPrefs(PrefService* pref_service) { //------------------ ProxyConfigServiceImpl: private methods ------------------- -void ProxyConfigServiceImpl::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED && - *(content::Details<std::string>(details).ptr()) == - prefs::kUseSharedProxies) { - if (content::Source<PrefService>(source).ptr() == prefs()) { - VLOG(1) << "New use-shared-proxies = " << GetUseSharedProxies(); - // Determine new proxy config which may have changed because of new - // use-shared-proxies. If necessary, activate it. - Network* network = NULL; - if (!active_network_.empty()) { - network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( - active_network_); - if (!network) - LOG(WARNING) << "Can't find requested network " << active_network_; - } - DetermineEffectiveConfig(network, true); +void ProxyConfigServiceImpl::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK(service == prefs()); + VLOG(1) << "New use-shared-proxies = " << GetUseSharedProxies(); + + if (pref_name == prefs::kUseSharedProxies) { + // Determine new proxy config which may have changed because of new + // use-shared-proxies. If necessary, activate it. + Network* network = NULL; + if (!active_network_.empty()) { + network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( + active_network_); + if (!network) + LOG(WARNING) << "Can't find requested network " << active_network_; } + DetermineEffectiveConfig(network, true); return; } - PrefProxyConfigTrackerImpl::Observe(type, source, details); + + PrefProxyConfigTrackerImpl::OnPreferenceChanged(service, pref_name); } void ProxyConfigServiceImpl::OnUISetProxyConfig() { diff --git a/chrome/browser/chromeos/proxy_config_service_impl.h b/chrome/browser/chromeos/proxy_config_service_impl.h index 92df0d0..78026ba 100644 --- a/chrome/browser/chromeos/proxy_config_service_impl.h +++ b/chrome/browser/chromeos/proxy_config_service_impl.h @@ -9,6 +9,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/prefs/public/pref_observer.h" #include "base/values.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/chromeos/cros/network_library.h" @@ -213,10 +214,9 @@ class ProxyConfigServiceImpl #endif // defined(UNIT_TEST) private: - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // Called from the various UISetProxyConfigTo*. void OnUISetProxyConfig(); diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc index a62883e8..cc6930c 100644 --- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc +++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc @@ -26,6 +26,7 @@ #include "base/chromeos/chromeos_version.h" #include "base/logging.h" #include "base/memory/weak_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chromeos/accessibility/accessibility_util.h" @@ -151,6 +152,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, public NetworkLibrary::NetworkManagerObserver, public NetworkLibrary::NetworkObserver, public NetworkLibrary::CellularDataPlanObserver, + public PrefObserver, public google_apis::DriveServiceObserver, public content::NotificationObserver, public input_method::InputMethodManager::Observer, @@ -1088,26 +1090,6 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, ObserveGDataUpdates(); break; } - case chrome::NOTIFICATION_PREF_CHANGED: { - std::string pref = *content::Details<std::string>(details).ptr(); - PrefService* service = content::Source<PrefService>(source).ptr(); - if (pref == prefs::kUse24HourClock) { - UpdateClockType(service); - } else if (pref == prefs::kLanguageRemapSearchKeyTo) { - search_key_mapped_to_ = - service->GetInteger(prefs::kLanguageRemapSearchKeyTo); - } else if (pref == prefs::kSpokenFeedbackEnabled) { - ash::AccessibilityObserver* observer = - tray_->accessibility_observer(); - if (observer) { - observer->OnAccessibilityModeChanged( - service->GetBoolean(prefs::kSpokenFeedbackEnabled)); - } - } else { - NOTREACHED(); - } - break; - } case chrome::NOTIFICATION_PROFILE_CREATED: { SetProfile(content::Source<Profile>(source).ptr()); registrar_.Remove(this, @@ -1126,6 +1108,25 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, } } + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref) OVERRIDE { + if (pref == prefs::kUse24HourClock) { + UpdateClockType(static_cast<PrefService*>(service)); + } else if (pref == prefs::kLanguageRemapSearchKeyTo) { + search_key_mapped_to_ = + service->GetInteger(prefs::kLanguageRemapSearchKeyTo); + } else if (pref == prefs::kSpokenFeedbackEnabled) { + ash::AccessibilityObserver* observer = + tray_->accessibility_observer(); + if (observer) { + observer->OnAccessibilityModeChanged( + service->GetBoolean(prefs::kSpokenFeedbackEnabled)); + } + } else { + NOTREACHED(); + } + } + // Overridden from InputMethodManager::Observer. virtual void InputMethodChanged( input_method::InputMethodManager* manager, bool show_message) OVERRIDE { diff --git a/chrome/browser/content_settings/content_settings_default_provider.cc b/chrome/browser/content_settings/content_settings_default_provider.cc index 97e6b55..ca56f7a 100644 --- a/chrome/browser/content_settings/content_settings_default_provider.cc +++ b/chrome/browser/content_settings/content_settings_default_provider.cc @@ -276,17 +276,13 @@ void DefaultProvider::ShutdownOnUIThread() { prefs_ = NULL; } -void DefaultProvider::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void DefaultProvider::OnPreferenceChanged(PrefServiceBase* service, + const std::string& name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - DCHECK_EQ(content::Source<PrefService>(source).ptr(), prefs_); - + DCHECK_EQ(prefs_, service); if (updating_preferences_) return; - const std::string& name = *content::Details<std::string>(details).ptr(); if (name == prefs::kDefaultContentSettings) { ReadDefaultSettings(true); } else if (name == prefs::kGeolocationDefaultContentSetting) { diff --git a/chrome/browser/content_settings/content_settings_default_provider.h b/chrome/browser/content_settings/content_settings_default_provider.h index 2e5d96a..9235293 100644 --- a/chrome/browser/content_settings/content_settings_default_provider.h +++ b/chrome/browser/content_settings/content_settings_default_provider.h @@ -12,10 +12,9 @@ #include "base/basictypes.h" #include "base/memory/linked_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/synchronization/lock.h" #include "chrome/browser/content_settings/content_settings_observable_provider.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" class PrefService; @@ -25,7 +24,7 @@ namespace content_settings { // user prefs. If no default values are set by the user we use the hard coded // default values. class DefaultProvider : public ObservableProvider, - public content::NotificationObserver { + public PrefObserver { public: static void RegisterUserPrefs(PrefService* prefs); @@ -51,10 +50,9 @@ class DefaultProvider : public ObservableProvider, virtual void ShutdownOnUIThread() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; private: // Sets the fields of |settings| based on the values in |dictionary|. diff --git a/chrome/browser/content_settings/content_settings_policy_provider.cc b/chrome/browser/content_settings/content_settings_policy_provider.cc index cb24bfd..0160b51 100644 --- a/chrome/browser/content_settings/content_settings_policy_provider.cc +++ b/chrome/browser/content_settings/content_settings_policy_provider.cc @@ -422,14 +422,11 @@ void PolicyProvider::ShutdownOnUIThread() { prefs_ = NULL; } -void PolicyProvider::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void PolicyProvider::OnPreferenceChanged(PrefServiceBase* service, + const std::string& name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - DCHECK_EQ(content::Source<PrefService>(source).ptr(), prefs_); + DCHECK_EQ(prefs_, service); - const std::string& name = *content::Details<std::string>(details).ptr(); if (name == prefs::kManagedDefaultCookiesSetting) { UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES); } else if (name == prefs::kManagedDefaultImagesSetting) { @@ -462,10 +459,8 @@ void PolicyProvider::Observe(int type, name == prefs::kManagedNotificationsBlockedForUrls) { ReadManagedContentSettings(true); ReadManagedDefaultSettings(); - } else { - NOTREACHED(); - return; } + NotifyObservers(ContentSettingsPattern(), ContentSettingsPattern(), CONTENT_SETTINGS_TYPE_DEFAULT, diff --git a/chrome/browser/content_settings/content_settings_policy_provider.h b/chrome/browser/content_settings/content_settings_policy_provider.h index 586a4d40..096c09b 100644 --- a/chrome/browser/content_settings/content_settings_policy_provider.h +++ b/chrome/browser/content_settings/content_settings_policy_provider.h @@ -11,10 +11,10 @@ #include "base/basictypes.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/synchronization/lock.h" #include "chrome/browser/content_settings/content_settings_observable_provider.h" #include "chrome/browser/content_settings/content_settings_origin_identifier_value_map.h" -#include "content/public/browser/notification_observer.h" class PrefService; @@ -22,7 +22,7 @@ namespace content_settings { // PolicyProvider that provides managed content-settings. class PolicyProvider : public ObservableProvider, - public content::NotificationObserver { + public PrefObserver { public: explicit PolicyProvider(PrefService* prefs); virtual ~PolicyProvider(); @@ -46,10 +46,10 @@ class PolicyProvider : public ObservableProvider, virtual void ShutdownOnUIThread() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + private: // Reads the policy managed default settings. void ReadManagedDefaultSettings(); diff --git a/chrome/browser/content_settings/content_settings_pref_provider.cc b/chrome/browser/content_settings/content_settings_pref_provider.cc index 8b4887e..e5ad337 100644 --- a/chrome/browser/content_settings/content_settings_pref_provider.cc +++ b/chrome/browser/content_settings/content_settings_pref_provider.cc @@ -217,15 +217,11 @@ void PrefProvider::ClearAllContentSettingsRules( std::string()); } -void PrefProvider::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void PrefProvider::OnPreferenceChanged(PrefServiceBase* service, + const std::string& name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - DCHECK_EQ(content::Source<PrefService>(source).ptr(), prefs_); - DCHECK_EQ(std::string(prefs::kContentSettingsPatternPairs), - *content::Details<std::string>(details).ptr()); + DCHECK_EQ(prefs_, service); + DCHECK_EQ(std::string(prefs::kContentSettingsPatternPairs), name); if (updating_preferences_) return; diff --git a/chrome/browser/content_settings/content_settings_pref_provider.h b/chrome/browser/content_settings/content_settings_pref_provider.h index 9595de7..1efc5ccb 100644 --- a/chrome/browser/content_settings/content_settings_pref_provider.h +++ b/chrome/browser/content_settings/content_settings_pref_provider.h @@ -11,12 +11,11 @@ #include "base/basictypes.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/synchronization/lock.h" #include "chrome/browser/content_settings/content_settings_observable_provider.h" #include "chrome/browser/content_settings/content_settings_origin_identifier_value_map.h" #include "chrome/browser/content_settings/content_settings_utils.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" class PrefService; @@ -29,7 +28,7 @@ namespace content_settings { // Content settings provider that provides content settings from the user // preference. class PrefProvider : public ObservableProvider, - public content::NotificationObserver { + public PrefObserver { public: static void RegisterUserPrefs(PrefService* prefs); @@ -55,10 +54,9 @@ class PrefProvider : public ObservableProvider, virtual void ShutdownOnUIThread() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; private: friend class DeadlockCheckerThread; // For testing. diff --git a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc index 3d9de68..c61b4a5 100644 --- a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc +++ b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc @@ -11,6 +11,7 @@ #include "base/prefs/default_pref_store.h" #include "base/prefs/overlay_user_pref_store.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/prefs/testing_pref_store.h" #include "base/threading/platform_thread.h" #include "base/values.h" @@ -20,13 +21,11 @@ #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_service_mock_builder.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" -#include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/testing_pref_service.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/browser/notification_observer.h" #include "content/public/test/test_browser_thread.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" @@ -54,7 +53,7 @@ class DeadlockCheckerThread : public base::PlatformThread::Delegate { // A helper for observing an preference changes and testing whether // |PrefProvider| holds a lock when the preferences change. -class DeadlockCheckerObserver : public content::NotificationObserver { +class DeadlockCheckerObserver : public PrefObserver { public: // |DeadlockCheckerObserver| doesn't take the ownership of |prefs| or // ||provider|. @@ -66,12 +65,10 @@ class DeadlockCheckerObserver : public content::NotificationObserver { } virtual ~DeadlockCheckerObserver() {} - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - ASSERT_EQ(type, chrome::NOTIFICATION_PREF_CHANGED); - // Check whether |provider_| holds its lock. For this, we need a separate - // thread. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + // Check whether |provider_| holds its lock. For this, we need a + // separate thread. DeadlockCheckerThread thread(provider_); base::PlatformThreadHandle handle = base::kNullThreadHandle; ASSERT_TRUE(base::PlatformThread::Create(0, &thread, &handle)); diff --git a/chrome/browser/content_settings/cookie_settings.cc b/chrome/browser/content_settings/cookie_settings.cc index 9407cbc..aed029e 100644 --- a/chrome/browser/content_settings/cookie_settings.cc +++ b/chrome/browser/content_settings/cookie_settings.cc @@ -155,20 +155,14 @@ void CookieSettings::ResetCookieSetting( CONTENT_SETTING_DEFAULT); } -void CookieSettings::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void CookieSettings::OnPreferenceChanged(PrefServiceBase* prefs, + const std::string& name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - DCHECK_EQ(std::string(prefs::kBlockThirdPartyCookies), - *content::Details<std::string>(details).ptr()); - - PrefService* prefs = content::Source<PrefService>(source).ptr(); - { - base::AutoLock auto_lock(lock_); - block_third_party_cookies_ = prefs->GetBoolean( - prefs::kBlockThirdPartyCookies); - } + DCHECK_EQ(std::string(prefs::kBlockThirdPartyCookies), name); + + base::AutoLock auto_lock(lock_); + block_third_party_cookies_ = prefs->GetBoolean( + prefs::kBlockThirdPartyCookies); } void CookieSettings::ShutdownOnUIThread() { diff --git a/chrome/browser/content_settings/cookie_settings.h b/chrome/browser/content_settings/cookie_settings.h index f1aba03..853f1df 100644 --- a/chrome/browser/content_settings/cookie_settings.h +++ b/chrome/browser/content_settings/cookie_settings.h @@ -11,12 +11,12 @@ #include "base/memory/ref_counted.h" #include "base/memory/singleton.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/synchronization/lock.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" #include "chrome/browser/profiles/refcounted_profile_keyed_service_factory.h" #include "chrome/common/content_settings.h" -#include "content/public/browser/notification_observer.h" class ContentSettingsPattern; class CookieSettingsWrapper; @@ -29,7 +29,7 @@ class Profile; // thread and read on any thread. One instance per profile. class CookieSettings - : public content::NotificationObserver, + : public PrefObserver, public RefcountedProfileKeyedService { public: CookieSettings( @@ -91,10 +91,9 @@ class CookieSettings void ResetCookieSetting(const ContentSettingsPattern& primary_pattern, const ContentSettingsPattern& secondary_pattern); - // |NotificationObserver| implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // |PrefObserver| implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // Detaches the |CookieSettings| from all |Profile|-related objects like // |PrefService|. This methods needs to be called before destroying the diff --git a/chrome/browser/extensions/api/font_settings/font_settings_api.cc b/chrome/browser/extensions/api/font_settings/font_settings_api.cc index 88a1149..053e417 100644 --- a/chrome/browser/extensions/api/font_settings/font_settings_api.cc +++ b/chrome/browser/extensions/api/font_settings/font_settings_api.cc @@ -87,7 +87,7 @@ std::string MaybeGetLocalizedFontName(const std::string& font_name) { // Registers |obs| to observe per-script font prefs under the path |map_name|. void RegisterFontFamilyMapObserver(PrefChangeRegistrar* registrar, const char* map_name, - content::NotificationObserver* obs) { + PrefObserver* obs) { for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; std::string pref_name = base::StringPrintf("%s.%s", map_name, script); @@ -132,24 +132,18 @@ void FontSettingsEventRouter::Init() { } void FontSettingsEventRouter::AddPrefToObserve(const char* pref_name, - const char* event_name, - const char* key) { + const char* event_name, + const char* key) { registrar_.Add(pref_name, this); pref_event_map_[pref_name] = std::make_pair(event_name, key); } -void FontSettingsEventRouter::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - - PrefService* pref_service = content::Source<PrefService>(source).ptr(); +void FontSettingsEventRouter::OnPreferenceChanged( + PrefServiceBase* pref_service, + const std::string& pref_name) { bool incognito = (pref_service != profile_->GetPrefs()); // We're only observing pref changes on the regular profile. DCHECK(!incognito); - const std::string& pref_name = - *content::Details<const std::string>(details).ptr(); PrefEventMap::iterator iter = pref_event_map_.find(pref_name); if (iter != pref_event_map_.end()) { @@ -172,12 +166,12 @@ void FontSettingsEventRouter::Observe( } void FontSettingsEventRouter::OnFontNamePrefChanged( - PrefService* pref_service, + PrefServiceBase* pref_service, const std::string& pref_name, const std::string& generic_family, const std::string& script, bool incognito) { - const PrefService::Preference* pref = pref_service->FindPreference( + const PrefServiceBase::Preference* pref = pref_service->FindPreference( pref_name.c_str()); CHECK(pref); @@ -205,12 +199,12 @@ void FontSettingsEventRouter::OnFontNamePrefChanged( } void FontSettingsEventRouter::OnFontPrefChanged( - PrefService* pref_service, + PrefServiceBase* pref_service, const std::string& pref_name, const std::string& event_name, const std::string& key, bool incognito) { - const PrefService::Preference* pref = pref_service->FindPreference( + const PrefServiceBase::Preference* pref = pref_service->FindPreference( pref_name.c_str()); CHECK(pref); diff --git a/chrome/browser/extensions/api/font_settings/font_settings_api.h b/chrome/browser/extensions/api/font_settings/font_settings_api.h index 9c73cf0..266b962 100644 --- a/chrome/browser/extensions/api/font_settings/font_settings_api.h +++ b/chrome/browser/extensions/api/font_settings/font_settings_api.h @@ -13,6 +13,7 @@ #include <utility> #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/extensions/extension_function.h" #include "chrome/browser/prefs/pref_service.h" @@ -20,7 +21,7 @@ namespace extensions { // This class observes pref changed events on a profile and dispatches the // corresponding extension API events to extensions. -class FontSettingsEventRouter : public content::NotificationObserver { +class FontSettingsEventRouter : public PrefObserver { public: // Constructor for observing pref changed events on |profile|. Stores a // pointer to |profile| but does not take ownership. |profile| must be @@ -48,17 +49,16 @@ class FontSettingsEventRouter : public content::NotificationObserver { const char* event_name, const char* key); - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // Dispatches a changed event for the font setting for |generic_family| and // |script| to extensions. The new value of the setting is the value of // browser pref |pref_name|. If the pref changed on the incognito profile, // |incognito| must be set to true for extensions to get the appropriate // event. - void OnFontNamePrefChanged(PrefService* pref_service, + void OnFontNamePrefChanged(PrefServiceBase* pref_service, const std::string& pref_name, const std::string& generic_family, const std::string& script, @@ -70,7 +70,7 @@ class FontSettingsEventRouter : public content::NotificationObserver { // under the key |key|. If the pref changed on the incognito profile, // |incognito| must be set to true for extensions to get the appropriate // event. - void OnFontPrefChanged(PrefService* pref_service, + void OnFontPrefChanged(PrefServiceBase* pref_service, const std::string& pref_name, const std::string& event_name, const std::string& key, diff --git a/chrome/browser/extensions/api/managed_mode/managed_mode_api.cc b/chrome/browser/extensions/api/managed_mode/managed_mode_api.cc index 82be3b6..2be512c 100644 --- a/chrome/browser/extensions/api/managed_mode/managed_mode_api.cc +++ b/chrome/browser/extensions/api/managed_mode/managed_mode_api.cc @@ -51,13 +51,9 @@ void ExtensionManagedModeEventRouter::Init() { ExtensionManagedModeEventRouter::~ExtensionManagedModeEventRouter() { } -void ExtensionManagedModeEventRouter::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - const std::string& pref_name = - *content::Details<std::string>(details).ptr(); +void ExtensionManagedModeEventRouter::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { DCHECK_EQ(std::string(prefs::kInManagedMode), pref_name); DictionaryValue* dict = new DictionaryValue(); diff --git a/chrome/browser/extensions/api/managed_mode/managed_mode_api.h b/chrome/browser/extensions/api/managed_mode/managed_mode_api.h index 8c3245a..e85a75a 100644 --- a/chrome/browser/extensions/api/managed_mode/managed_mode_api.h +++ b/chrome/browser/extensions/api/managed_mode/managed_mode_api.h @@ -9,6 +9,7 @@ #define CHROME_BROWSER_EXTENSIONS_API_MANAGED_MODE_MANAGED_MODE_API_H_ #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/extensions/extension_function.h" #include "content/public/browser/notification_observer.h" @@ -16,17 +17,16 @@ class Profile; namespace extensions { -class ExtensionManagedModeEventRouter : public content::NotificationObserver { +class ExtensionManagedModeEventRouter : public PrefObserver { public: explicit ExtensionManagedModeEventRouter(Profile* profile); virtual ~ExtensionManagedModeEventRouter(); void Init(); - // content::NotificationObserver implementation: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; private: PrefChangeRegistrar registrar_; diff --git a/chrome/browser/extensions/api/preference/preference_api.cc b/chrome/browser/extensions/api/preference/preference_api.cc index a555e36..46e6751 100644 --- a/chrome/browser/extensions/api/preference/preference_api.cc +++ b/chrome/browser/extensions/api/preference/preference_api.cc @@ -253,16 +253,12 @@ PreferenceEventRouter::PreferenceEventRouter(Profile* profile) PreferenceEventRouter::~PreferenceEventRouter() { } -void PreferenceEventRouter::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - OnPrefChanged(content::Source<PrefService>(source).ptr(), - *content::Details<const std::string>(details).ptr()); +void PreferenceEventRouter::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + OnPrefChanged(service, pref_name); } -void PreferenceEventRouter::OnPrefChanged(PrefService* pref_service, +void PreferenceEventRouter::OnPrefChanged(PrefServiceBase* pref_service, const std::string& browser_pref) { bool incognito = (pref_service != profile_->GetPrefs()); @@ -275,7 +271,7 @@ void PreferenceEventRouter::OnPrefChanged(PrefService* pref_service, ListValue args; DictionaryValue* dict = new DictionaryValue(); args.Append(dict); - const PrefService::Preference* pref = + const PrefServiceBase::Preference* pref = pref_service->FindPreference(browser_pref.c_str()); CHECK(pref); ExtensionService* extension_service = profile_->GetExtensionService(); diff --git a/chrome/browser/extensions/api/preference/preference_api.h b/chrome/browser/extensions/api/preference/preference_api.h index 7bf67cd..c6e7f4b 100644 --- a/chrome/browser/extensions/api/preference/preference_api.h +++ b/chrome/browser/extensions/api/preference/preference_api.h @@ -8,6 +8,7 @@ #include <string> #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/extensions/extension_function.h" #include "content/public/browser/notification_observer.h" @@ -19,18 +20,18 @@ class Value; namespace extensions { -class PreferenceEventRouter : public content::NotificationObserver { +class PreferenceEventRouter : public PrefObserver { public: explicit PreferenceEventRouter(Profile* profile); virtual ~PreferenceEventRouter(); private: - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; - void OnPrefChanged(PrefService* pref_service, const std::string& pref_key); + void OnPrefChanged(PrefServiceBase* pref_service, + const std::string& pref_key); // This method dispatches events to the extension message service. void DispatchEvent(const std::string& extension_id, diff --git a/chrome/browser/extensions/component_loader.cc b/chrome/browser/extensions/component_loader.cc index e7e5b16..51f0acf 100644 --- a/chrome/browser/extensions/component_loader.cc +++ b/chrome/browser/extensions/component_loader.cc @@ -407,13 +407,9 @@ void ComponentLoader::AddDefaultComponentExtensions() { AddScriptBubble(); } -void ComponentLoader::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - DCHECK_EQ(std::string(prefs::kEnterpriseWebStoreURL), - *content::Details<const std::string>(details).ptr()); +void ComponentLoader::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK_EQ(std::string(prefs::kEnterpriseWebStoreURL), pref_name); AddOrReloadEnterpriseWebStore(); } diff --git a/chrome/browser/extensions/component_loader.h b/chrome/browser/extensions/component_loader.h index 8c68775..beb2e6b 100644 --- a/chrome/browser/extensions/component_loader.h +++ b/chrome/browser/extensions/component_loader.h @@ -11,8 +11,8 @@ #include "base/file_path.h" #include "base/gtest_prod_util.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/values.h" -#include "content/public/browser/notification_observer.h" class ExtensionServiceInterface; class PrefService; @@ -22,7 +22,7 @@ namespace extensions { class Extension; // For registering, loading, and unloading component extensions. -class ComponentLoader : public content::NotificationObserver { +class ComponentLoader : public PrefObserver { public: ComponentLoader(ExtensionServiceInterface* extension_service, PrefService* prefs, @@ -69,10 +69,9 @@ class ComponentLoader : public content::NotificationObserver { // Adds the default component extensions. void AddDefaultComponentExtensions(); - // content::NotificationObserver implementation - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; static void RegisterUserPrefs(PrefService* prefs); diff --git a/chrome/browser/extensions/extension_prefs_unittest.cc b/chrome/browser/extensions/extension_prefs_unittest.cc index 22a8c50..67eb2a1 100644 --- a/chrome/browser/extensions/extension_prefs_unittest.cc +++ b/chrome/browser/extensions/extension_prefs_unittest.cc @@ -15,6 +15,7 @@ #include "chrome/browser/extensions/extension_pref_value_map.h" #include "chrome/browser/extensions/extension_prefs.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" +#include "chrome/browser/prefs/pref_observer_mock.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/extension_manifest_constants.h" #include "chrome/common/extensions/permissions/permission_set.h" @@ -1052,60 +1053,60 @@ class ExtensionPrefsNotifyWhenNeeded : public ExtensionPrefsPrepopulatedTest { using testing::Mock; using testing::StrEq; - content::MockNotificationObserver observer; + PrefObserverMock observer; PrefChangeRegistrar registrar; registrar.Init(prefs()->pref_service()); registrar.Add(kPref1, &observer); - content::MockNotificationObserver incognito_observer; + PrefObserverMock incognito_observer; scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); PrefChangeRegistrar incognito_registrar; incognito_registrar.Init(incog_prefs.get()); incognito_registrar.Add(kPref1, &incognito_observer); // Write value and check notification. - EXPECT_CALL(observer, Observe(_, _, _)); - EXPECT_CALL(incognito_observer, Observe(_, _, _)); + EXPECT_CALL(observer, OnPreferenceChanged(_, _)); + EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("https://www.chromium.org")); Mock::VerifyAndClearExpectations(&observer); Mock::VerifyAndClearExpectations(&incognito_observer); // Write same value. - EXPECT_CALL(observer, Observe(_, _, _)).Times(0); - EXPECT_CALL(incognito_observer, Observe(_, _, _)).Times(0); + EXPECT_CALL(observer, OnPreferenceChanged(_, _)).Times(0); + EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)).Times(0); InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("https://www.chromium.org")); Mock::VerifyAndClearExpectations(&observer); Mock::VerifyAndClearExpectations(&incognito_observer); // Change value. - EXPECT_CALL(observer, Observe(_, _, _)); - EXPECT_CALL(incognito_observer, Observe(_, _, _)); + EXPECT_CALL(observer, OnPreferenceChanged(_, _)); + EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("chrome://newtab")); Mock::VerifyAndClearExpectations(&observer); Mock::VerifyAndClearExpectations(&incognito_observer); // Change only incognito persistent value. - EXPECT_CALL(observer, Observe(_, _, _)).Times(0); - EXPECT_CALL(incognito_observer, Observe(_, _, _)); + EXPECT_CALL(observer, OnPreferenceChanged(_, _)).Times(0); + EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); InstallExtControlledPrefIncognito(ext1_, kPref1, Value::CreateStringValue("chrome://newtab2")); Mock::VerifyAndClearExpectations(&observer); Mock::VerifyAndClearExpectations(&incognito_observer); // Change only incognito session-only value. - EXPECT_CALL(observer, Observe(_, _, _)).Times(0); - EXPECT_CALL(incognito_observer, Observe(_, _, _)); + EXPECT_CALL(observer, OnPreferenceChanged(_, _)).Times(0); + EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); InstallExtControlledPrefIncognito(ext1_, kPref1, Value::CreateStringValue("chrome://newtab3")); Mock::VerifyAndClearExpectations(&observer); Mock::VerifyAndClearExpectations(&incognito_observer); // Uninstall. - EXPECT_CALL(observer, Observe(_, _, _)); - EXPECT_CALL(incognito_observer, Observe(_, _, _)); + EXPECT_CALL(observer, OnPreferenceChanged(_, _)); + EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); UninstallExtension(ext1_->id()); Mock::VerifyAndClearExpectations(&observer); Mock::VerifyAndClearExpectations(&incognito_observer); diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index eb41d52..ffb8152 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -2582,16 +2582,6 @@ void ExtensionService::Observe(int type, process->GetID())); break; } - case chrome::NOTIFICATION_PREF_CHANGED: { - const std::string& pref_name = - *content::Details<std::string>(details).ptr(); - DCHECK(pref_name == prefs::kExtensionInstallAllowList || - pref_name == prefs::kExtensionInstallDenyList) - << "Unexpected preference name " << pref_name; - IdentifyAlertableExtensions(); - CheckManagementPolicy(); - break; - } case chrome::NOTIFICATION_IMPORT_FINISHED: { InitAfterImport(); break; @@ -2602,6 +2592,15 @@ void ExtensionService::Observe(int type, } } +void ExtensionService::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK(pref_name == prefs::kExtensionInstallAllowList || + pref_name == prefs::kExtensionInstallDenyList) + << "Unexpected preference name " << pref_name; + IdentifyAlertableExtensions(); + CheckManagementPolicy(); +} + bool ExtensionService::HasApps() const { return !GetAppIds().empty(); } diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h index 49f029b..7b4e044 100644 --- a/chrome/browser/extensions/extension_service.h +++ b/chrome/browser/extensions/extension_service.h @@ -17,6 +17,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/string16.h" #include "chrome/browser/extensions/app_shortcut_manager.h" #include "chrome/browser/extensions/app_sync_bundle.h" @@ -140,7 +141,8 @@ class ExtensionServiceInterface : public syncer::SyncableService { class ExtensionService : public ExtensionServiceInterface, public extensions::ExternalProviderInterface::VisitorInterface, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: // The name of the directory inside the profile where extensions are // installed to. @@ -621,6 +623,10 @@ class ExtensionService const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Whether there are any apps installed. Component apps are not included. bool HasApps() const; diff --git a/chrome/browser/extensions/external_policy_loader.cc b/chrome/browser/extensions/external_policy_loader.cc index 5a3cbf9..79ddb8d 100644 --- a/chrome/browser/extensions/external_policy_loader.cc +++ b/chrome/browser/extensions/external_policy_loader.cc @@ -79,25 +79,20 @@ void ExternalPolicyLoader::Observe( const content::NotificationSource& source, const content::NotificationDetails& details) { if (profile_ == NULL) return; - switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: { - if (content::Source<PrefService>(source).ptr() == profile_->GetPrefs()) { - DCHECK_EQ(std::string(prefs::kExtensionInstallForceList), - *content::Details<std::string>(details).ptr()); - StartLoading(); - } - break; - } - case chrome::NOTIFICATION_PROFILE_DESTROYED: { - if (content::Source<Profile>(source).ptr() == profile_) { - notification_registrar_.RemoveAll(); - pref_change_registrar_.RemoveAll(); - profile_ = NULL; - } - break; - } - default: - NOTREACHED() << "Unexpected notification type."; + DCHECK(type == chrome::NOTIFICATION_PROFILE_DESTROYED) << + "Unexpected notification type."; + if (content::Source<Profile>(source).ptr() == profile_) { + notification_registrar_.RemoveAll(); + pref_change_registrar_.RemoveAll(); + profile_ = NULL; + } +} + +void ExternalPolicyLoader::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (service == profile_->GetPrefs()) { + DCHECK_EQ(std::string(prefs::kExtensionInstallForceList), pref_name); + StartLoading(); } } diff --git a/chrome/browser/extensions/external_policy_loader.h b/chrome/browser/extensions/external_policy_loader.h index bd0f5f5..44f9f1b 100644 --- a/chrome/browser/extensions/external_policy_loader.h +++ b/chrome/browser/extensions/external_policy_loader.h @@ -9,6 +9,7 @@ #include "base/compiler_specific.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -21,7 +22,8 @@ namespace extensions { // registered. class ExternalPolicyLoader : public ExternalLoader, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: explicit ExternalPolicyLoader(Profile* profile); @@ -30,6 +32,10 @@ class ExternalPolicyLoader const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + protected: virtual void StartLoading() OVERRIDE; diff --git a/chrome/browser/media_gallery/media_file_system_registry.cc b/chrome/browser/media_gallery/media_file_system_registry.cc index bd1ece3..030cb4b 100644 --- a/chrome/browser/media_gallery/media_file_system_registry.cc +++ b/chrome/browser/media_gallery/media_file_system_registry.cc @@ -35,6 +35,7 @@ #include "chrome/common/pref_names.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_details.h" +#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_source.h" #include "content/public/browser/notification_types.h" @@ -678,17 +679,12 @@ MediaFileSystemRegistry::~MediaFileSystemRegistry() { system_monitor->RemoveDevicesChangedObserver(this); } -void MediaFileSystemRegistry::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - const std::string& pref_name = - *content::Details<std::string>(details).ptr(); +void MediaFileSystemRegistry::OnPreferenceChanged( + PrefServiceBase* prefs, + const std::string& pref_name) { DCHECK_EQ(std::string(prefs::kMediaGalleriesRememberedGalleries), pref_name); // Find the Profile that contains the source PrefService. - PrefService* prefs = content::Source<PrefService>(source).ptr(); PrefChangeRegistrarMap::iterator pref_change_it = pref_change_registrar_map_.begin(); for (; pref_change_it != pref_change_registrar_map_.end(); ++pref_change_it) { diff --git a/chrome/browser/media_gallery/media_file_system_registry.h b/chrome/browser/media_gallery/media_file_system_registry.h index 28825b9..bfc266d 100644 --- a/chrome/browser/media_gallery/media_file_system_registry.h +++ b/chrome/browser/media_gallery/media_file_system_registry.h @@ -19,8 +19,8 @@ #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/system_monitor/system_monitor.h" -#include "content/public/browser/notification_observer.h" #include "webkit/fileapi/media/mtp_device_file_system_config.h" class Profile; @@ -81,7 +81,7 @@ typedef base::Callback<void(const std::vector<MediaFileSystemInfo>&)> class MediaFileSystemRegistry : public base::SystemMonitor::DevicesChangedObserver, - public content::NotificationObserver { + public PrefObserver { public: // The instance is lazily created per browser process. static MediaFileSystemRegistry* GetInstance(); @@ -131,10 +131,9 @@ class MediaFileSystemRegistry MediaFileSystemRegistry(); virtual ~MediaFileSystemRegistry(); - // NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) // Returns ScopedMtpDeviceMapEntry object for the given |device_location|. diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 8cb7c51..3130ed2 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -295,37 +295,29 @@ void ChromeURLRequestContextGetter::CleanupOnUIThread() { registrar_.RemoveAll(); } -// content::NotificationObserver implementation. -void ChromeURLRequestContextGetter::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void ChromeURLRequestContextGetter::OnPreferenceChanged( + PrefServiceBase* prefs, + const std::string& pref_name_in) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (chrome::NOTIFICATION_PREF_CHANGED == type) { - std::string* pref_name_in = content::Details<std::string>(details).ptr(); - PrefService* prefs = content::Source<PrefService>(source).ptr(); - DCHECK(pref_name_in && prefs); - if (*pref_name_in == prefs::kAcceptLanguages) { - std::string accept_language = - prefs->GetString(prefs::kAcceptLanguages); - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind( - &ChromeURLRequestContextGetter::OnAcceptLanguageChange, - this, - accept_language)); - } else if (*pref_name_in == prefs::kDefaultCharset) { - std::string default_charset = prefs->GetString(prefs::kDefaultCharset); - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind( - &ChromeURLRequestContextGetter::OnDefaultCharsetChange, - this, - default_charset)); - } - } else { - NOTREACHED(); + DCHECK(prefs); + if (pref_name_in == prefs::kAcceptLanguages) { + std::string accept_language = + prefs->GetString(prefs::kAcceptLanguages); + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind( + &ChromeURLRequestContextGetter::OnAcceptLanguageChange, + this, + accept_language)); + } else if (pref_name_in == prefs::kDefaultCharset) { + std::string default_charset = prefs->GetString(prefs::kDefaultCharset); + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind( + &ChromeURLRequestContextGetter::OnDefaultCharsetChange, + this, + default_charset)); } } diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index 93398e1..90ee941 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -9,8 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_job_factory.h" @@ -100,7 +99,7 @@ class ChromeURLRequestContext : public net::URLRequestContext { // Most methods are expected to be called on the UI thread, except for // the destructor and GetURLRequestContext(). class ChromeURLRequestContextGetter : public net::URLRequestContextGetter, - public content::NotificationObserver { + public PrefObserver { public: // Constructs a ChromeURLRequestContextGetter that will use |factory| to // create the ChromeURLRequestContext. If |profile| is non-NULL, then the @@ -181,10 +180,9 @@ class ChromeURLRequestContextGetter : public net::URLRequestContextGetter, // thread before the instance is deleted on the IO thread. void CleanupOnUIThread(); - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; private: // Must be called on the IO thread. diff --git a/chrome/browser/net/http_server_properties_manager.cc b/chrome/browser/net/http_server_properties_manager.cc index 94e4e02..02a173f 100644 --- a/chrome/browser/net/http_server_properties_manager.cc +++ b/chrome/browser/net/http_server_properties_manager.cc @@ -636,16 +636,12 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI( setting_prefs_ = false; } -void HttpServerPropertiesManager::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void HttpServerPropertiesManager::OnPreferenceChanged( + PrefServiceBase* prefs, + const std::string& pref_name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); - PrefService* prefs = content::Source<PrefService>(source).ptr(); DCHECK(prefs == pref_service_); - std::string* pref_name = content::Details<std::string>(details).ptr(); - if (*pref_name == prefs::kHttpServerProperties) { + if (pref_name == prefs::kHttpServerProperties) { if (!setting_prefs_) ScheduleUpdateCacheOnUI(); } else { diff --git a/chrome/browser/net/http_server_properties_manager.h b/chrome/browser/net/http_server_properties_manager.h index 43ee740..dc6a3a8 100644 --- a/chrome/browser/net/http_server_properties_manager.h +++ b/chrome/browser/net/http_server_properties_manager.h @@ -12,9 +12,9 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/timer.h" #include "base/values.h" -#include "content/public/browser/notification_observer.h" #include "net/base/host_port_pair.h" #include "net/http/http_pipelined_host_capability.h" #include "net/http/http_server_properties.h" @@ -48,7 +48,7 @@ namespace chrome_browser_net { // the actual update starts, and grab a WeakPtr. class HttpServerPropertiesManager : public net::HttpServerProperties, - public content::NotificationObserver { + public PrefObserver { public: // Create an instance of the HttpServerPropertiesManager. The lifetime of the // PrefService objects must be longer than that of the @@ -187,9 +187,8 @@ class HttpServerPropertiesManager private: // Callback for preference changes. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // --------- // UI thread diff --git a/chrome/browser/net/net_pref_observer.cc b/chrome/browser/net/net_pref_observer.cc index 4ccf194..e985609 100644 --- a/chrome/browser/net/net_pref_observer.cc +++ b/chrome/browser/net/net_pref_observer.cc @@ -34,10 +34,8 @@ NetPrefObserver::~NetPrefObserver() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } -void NetPrefObserver::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(type, chrome::NOTIFICATION_PREF_CHANGED); +void NetPrefObserver::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { ApplySettings(); } diff --git a/chrome/browser/net/net_pref_observer.h b/chrome/browser/net/net_pref_observer.h index 5f3157e..1d2f577 100644 --- a/chrome/browser/net/net_pref_observer.h +++ b/chrome/browser/net/net_pref_observer.h @@ -6,8 +6,8 @@ #define CHROME_BROWSER_NET_NET_PREF_OBSERVER_H_ #include "base/basictypes.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" -#include "content/public/browser/notification_observer.h" namespace chrome_browser_net { class Predictor; @@ -22,7 +22,7 @@ class PrefService; // Monitors network-related preferences for changes and applies them. // The supplied PrefService must outlive this NetPrefObserver. // Must be used only on the UI thread. -class NetPrefObserver : public content::NotificationObserver { +class NetPrefObserver : public PrefObserver { public: // |prefs| must be non-NULL and |*prefs| must outlive this. // |prerender_manager| may be NULL. If not, |*prerender_manager| must @@ -32,10 +32,9 @@ class NetPrefObserver : public content::NotificationObserver { chrome_browser_net::Predictor* predictor); virtual ~NetPrefObserver(); - // content::NotificationObserver - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; static void RegisterPrefs(PrefService* prefs); diff --git a/chrome/browser/net/pref_proxy_config_tracker_impl.cc b/chrome/browser/net/pref_proxy_config_tracker_impl.cc index 9760f02..50398ab 100644 --- a/chrome/browser/net/pref_proxy_config_tracker_impl.cc +++ b/chrome/browser/net/pref_proxy_config_tracker_impl.cc @@ -287,13 +287,11 @@ bool PrefProxyConfigTrackerImpl::PrefConfigToNetConfig( return false; } -void PrefProxyConfigTrackerImpl::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void PrefProxyConfigTrackerImpl::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (type == chrome::NOTIFICATION_PREF_CHANGED && - content::Source<PrefService>(source).ptr() == pref_service_) { + if (service == pref_service_) { net::ProxyConfig new_config; ProxyPrefs::ConfigState config_state = ReadPrefConfig(&new_config); if (config_state_ != config_state || @@ -307,7 +305,7 @@ void PrefProxyConfigTrackerImpl::Observe( if (update_pending_) OnProxyConfigChanged(config_state, new_config); } else { - NOTREACHED() << "Unexpected notification of type " << type; + NOTREACHED() << "Unexpected PrefService."; } } diff --git a/chrome/browser/net/pref_proxy_config_tracker_impl.h b/chrome/browser/net/pref_proxy_config_tracker_impl.h index 6df5c75..7ec829e 100644 --- a/chrome/browser/net/pref_proxy_config_tracker_impl.h +++ b/chrome/browser/net/pref_proxy_config_tracker_impl.h @@ -10,8 +10,8 @@ #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/prefs/proxy_config_dictionary.h" -#include "content/public/browser/notification_observer.h" #include "net/proxy/proxy_config.h" #include "net/proxy/proxy_config_service.h" @@ -78,7 +78,7 @@ class ChromeProxyConfigService // A class that tracks proxy preferences. It translates the configuration // to net::ProxyConfig and pushes the result over to the IO thread for // ChromeProxyConfigService::UpdateProxyConfig to use. -class PrefProxyConfigTrackerImpl : public content::NotificationObserver { +class PrefProxyConfigTrackerImpl : public PrefObserver { public: explicit PrefProxyConfigTrackerImpl(PrefService* pref_service); virtual ~PrefProxyConfigTrackerImpl(); @@ -132,10 +132,9 @@ class PrefProxyConfigTrackerImpl : public content::NotificationObserver { virtual void OnProxyConfigChanged(ProxyPrefs::ConfigState config_state, const net::ProxyConfig& config); - // content::NotificationObserver implementation: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; const PrefService* prefs() const { return pref_service_; } diff --git a/chrome/browser/net/ssl_config_service_manager_pref.cc b/chrome/browser/net/ssl_config_service_manager_pref.cc index 86cc792..28d769c 100644 --- a/chrome/browser/net/ssl_config_service_manager_pref.cc +++ b/chrome/browser/net/ssl_config_service_manager_pref.cc @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "base/bind.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/content_settings/content_settings_utils.h" #include "chrome/browser/prefs/pref_service.h" @@ -17,8 +18,6 @@ #include "chrome/common/content_settings.h" #include "chrome/common/pref_names.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_source.h" #include "net/base/ssl_cipher_suite_names.h" #include "net/base/ssl_config_service.h" @@ -145,7 +144,7 @@ void SSLConfigServicePref::SetNewSSLConfig( // The manager for holding and updating an SSLConfigServicePref instance. class SSLConfigServiceManagerPref : public SSLConfigServiceManager, - public content::NotificationObserver { + public PrefObserver { public: SSLConfigServiceManagerPref(PrefService* local_state, PrefService* user_prefs); @@ -159,9 +158,8 @@ class SSLConfigServiceManagerPref private: // Callback for preference changes. This will post the changes to the IO // thread with SetNewSSLConfig. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details); + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // Store SSL config settings in |config|, directly from the preferences. Must // only be called from UI thread. @@ -169,10 +167,10 @@ class SSLConfigServiceManagerPref // Processes changes to the disabled cipher suites preference, updating the // cached list of parsed SSL/TLS cipher suites that are disabled. - void OnDisabledCipherSuitesChange(PrefService* local_state); + void OnDisabledCipherSuitesChange(PrefServiceBase* local_state); // Processes changes to the default cookie settings. - void OnDefaultContentSettingsChange(PrefService* user_prefs); + void OnDefaultContentSettingsChange(PrefServiceBase* user_prefs); PrefChangeRegistrar local_state_change_registrar_; PrefChangeRegistrar user_prefs_change_registrar_; @@ -255,33 +253,28 @@ net::SSLConfigService* SSLConfigServiceManagerPref::Get() { return ssl_config_service_; } -void SSLConfigServiceManagerPref::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - std::string* pref_name_in = content::Details<std::string>(details).ptr(); - PrefService* prefs = content::Source<PrefService>(source).ptr(); - DCHECK(pref_name_in && prefs); - if (*pref_name_in == prefs::kCipherSuiteBlacklist) - OnDisabledCipherSuitesChange(prefs); - else if (*pref_name_in == prefs::kDefaultContentSettings) - OnDefaultContentSettingsChange(prefs); - - net::SSLConfig new_config; - GetSSLConfigFromPrefs(&new_config); - - // Post a task to |io_loop| with the new configuration, so it can - // update |cached_config_|. - BrowserThread::PostTask( - BrowserThread::IO, - FROM_HERE, - base::Bind( - &SSLConfigServicePref::SetNewSSLConfig, - ssl_config_service_.get(), - new_config)); - } +void SSLConfigServiceManagerPref::OnPreferenceChanged( + PrefServiceBase* prefs, + const std::string& pref_name_in) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(prefs); + if (pref_name_in == prefs::kCipherSuiteBlacklist) + OnDisabledCipherSuitesChange(prefs); + else if (pref_name_in == prefs::kDefaultContentSettings) + OnDefaultContentSettingsChange(prefs); + + net::SSLConfig new_config; + GetSSLConfigFromPrefs(&new_config); + + // Post a task to |io_loop| with the new configuration, so it can + // update |cached_config_|. + BrowserThread::PostTask( + BrowserThread::IO, + FROM_HERE, + base::Bind( + &SSLConfigServicePref::SetNewSSLConfig, + ssl_config_service_.get(), + new_config)); } void SSLConfigServiceManagerPref::GetSSLConfigFromPrefs( @@ -318,13 +311,13 @@ void SSLConfigServiceManagerPref::GetSSLConfigFromPrefs( } void SSLConfigServiceManagerPref::OnDisabledCipherSuitesChange( - PrefService* local_state) { + PrefServiceBase* local_state) { const ListValue* value = local_state->GetList(prefs::kCipherSuiteBlacklist); disabled_cipher_suites_ = ParseCipherSuites(ListValueToStringVector(value)); } void SSLConfigServiceManagerPref::OnDefaultContentSettingsChange( - PrefService* user_prefs) { + PrefServiceBase* user_prefs) { const DictionaryValue* value = user_prefs->GetDictionary( prefs::kDefaultContentSettings); int default_cookie_settings = -1; diff --git a/chrome/browser/notifications/notification_ui_manager_impl.cc b/chrome/browser/notifications/notification_ui_manager_impl.cc index f02b0f5..bf096c3 100644 --- a/chrome/browser/notifications/notification_ui_manager_impl.cc +++ b/chrome/browser/notifications/notification_ui_manager_impl.cc @@ -233,13 +233,17 @@ void NotificationUIManagerImpl::Observe( const content::NotificationDetails& details) { if (type == chrome::NOTIFICATION_APP_TERMINATING) { CancelAll(); - } else if (type == chrome::NOTIFICATION_PREF_CHANGED) { - std::string* name = content::Details<std::string>(details).ptr(); - if (*name == prefs::kDesktopNotificationPosition) - balloon_collection_->SetPositionPreference( - static_cast<BalloonCollection::PositionPreference>( - position_pref_.GetValue())); } else { NOTREACHED(); } } + +void NotificationUIManagerImpl::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kDesktopNotificationPosition) { + balloon_collection_->SetPositionPreference( + static_cast<BalloonCollection::PositionPreference>( + position_pref_.GetValue())); + } +} diff --git a/chrome/browser/notifications/notification_ui_manager_impl.h b/chrome/browser/notifications/notification_ui_manager_impl.h index e313622..0adebdf 100644 --- a/chrome/browser/notifications/notification_ui_manager_impl.h +++ b/chrome/browser/notifications/notification_ui_manager_impl.h @@ -11,6 +11,7 @@ #include "base/id_map.h" #include "base/memory/scoped_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "base/timer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/notifications/balloon.h" @@ -31,7 +32,8 @@ class NotificationUIManagerImpl : public NotificationUIManager, public NotificationPrefsManager, public BalloonCollection::BalloonSpaceChangeListener, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: explicit NotificationUIManagerImpl(PrefService* local_state); virtual ~NotificationUIManagerImpl(); @@ -63,6 +65,10 @@ class NotificationUIManagerImpl const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver override. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Attempts to display notifications from the show_queue if the user // is active. void CheckAndShowNotifications(); diff --git a/chrome/browser/plugins/plugin_prefs.cc b/chrome/browser/plugins/plugin_prefs.cc index ecb63d1..d8ee038 100644 --- a/chrome/browser/plugins/plugin_prefs.cc +++ b/chrome/browser/plugins/plugin_prefs.cc @@ -274,26 +274,19 @@ bool PluginPrefs::IsPluginEnabled(const webkit::WebPluginInfo& plugin) const { return true; } -void PluginPrefs::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - const std::string* pref_name = content::Details<std::string>(details).ptr(); - if (!pref_name) { - NOTREACHED(); - return; - } - DCHECK_EQ(prefs_, content::Source<PrefService>(source).ptr()); - if (*pref_name == prefs::kPluginsDisabledPlugins) { +void PluginPrefs::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK_EQ(prefs_, service); + if (pref_name == prefs::kPluginsDisabledPlugins) { base::AutoLock auto_lock(lock_); ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins), &policy_disabled_plugin_patterns_); - } else if (*pref_name == prefs::kPluginsDisabledPluginsExceptions) { + } else if (pref_name == prefs::kPluginsDisabledPluginsExceptions) { base::AutoLock auto_lock(lock_); ListValueToStringSet( prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions), &policy_disabled_plugin_exception_patterns_); - } else if (*pref_name == prefs::kPluginsEnabledPlugins) { + } else if (pref_name == prefs::kPluginsEnabledPlugins) { base::AutoLock auto_lock(lock_); ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins), &policy_enabled_plugin_patterns_); diff --git a/chrome/browser/plugins/plugin_prefs.h b/chrome/browser/plugins/plugin_prefs.h index 95fe301..594e3d3 100644 --- a/chrome/browser/plugins/plugin_prefs.h +++ b/chrome/browser/plugins/plugin_prefs.h @@ -12,11 +12,11 @@ #include "base/basictypes.h" #include "base/file_path.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/synchronization/lock.h" #include "chrome/browser/plugins/plugin_finder.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" -#include "content/public/browser/notification_observer.h" class Profile; @@ -35,7 +35,7 @@ class PluginList; // enabled or disabled. // Except where otherwise noted, it can be used on every thread. class PluginPrefs : public RefcountedProfileKeyedService, - public content::NotificationObserver { + public PrefObserver { public: enum PolicyStatus { NO_POLICY = 0, // Neither enabled or disabled by policy. @@ -85,10 +85,9 @@ class PluginPrefs : public RefcountedProfileKeyedService, // RefCountedProfileKeyedBase method override. virtual void ShutdownOnUIThread() OVERRIDE; - // content::NotificationObserver method override. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver method override. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; private: friend class base::RefCountedThreadSafe<PluginPrefs>; diff --git a/chrome/browser/plugins/plugin_status_pref_setter.cc b/chrome/browser/plugins/plugin_status_pref_setter.cc index dc3a91a..2de8547 100644 --- a/chrome/browser/plugins/plugin_status_pref_setter.cc +++ b/chrome/browser/plugins/plugin_status_pref_setter.cc @@ -28,7 +28,7 @@ PluginStatusPrefSetter::~PluginStatusPrefSetter() { } void PluginStatusPrefSetter::Init(Profile* profile, - content::NotificationObserver* observer) { + PrefObserver* observer) { clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, profile->GetPrefs(), observer); pepper_flash_settings_enabled_.Init(prefs::kPepperFlashSettingsEnabled, diff --git a/chrome/browser/plugins/plugin_status_pref_setter.h b/chrome/browser/plugins/plugin_status_pref_setter.h index ab406ae..915a820 100644 --- a/chrome/browser/plugins/plugin_status_pref_setter.h +++ b/chrome/browser/plugins/plugin_status_pref_setter.h @@ -9,6 +9,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -34,8 +35,7 @@ class PluginStatusPrefSetter : public content::NotificationObserver { // any value changes. // This asynchronously calls the PluginService to get the list of installed // plug-ins. - void Init(Profile* profile, - content::NotificationObserver* observer); + void Init(Profile* profile, PrefObserver* observer); bool IsClearPluginLSODataEnabled() const { return clear_plugin_lso_data_enabled_.GetValue(); diff --git a/chrome/browser/policy/cloud_policy_refresh_scheduler.cc b/chrome/browser/policy/cloud_policy_refresh_scheduler.cc index a0d9821..6397f8e 100644 --- a/chrome/browser/policy/cloud_policy_refresh_scheduler.cc +++ b/chrome/browser/policy/cloud_policy_refresh_scheduler.cc @@ -99,13 +99,10 @@ void CloudPolicyRefreshScheduler::OnStoreError(CloudPolicyStore* store) { // error is required. NB: Changes to is_managed fire OnStoreLoaded(). } -void CloudPolicyRefreshScheduler::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - DCHECK_EQ(refresh_delay_.GetPrefName(), - *content::Details<std::string>(details).ptr()); +void CloudPolicyRefreshScheduler::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { + DCHECK_EQ(refresh_delay_.GetPrefName(), pref_name); ScheduleRefresh(); } diff --git a/chrome/browser/policy/cloud_policy_refresh_scheduler.h b/chrome/browser/policy/cloud_policy_refresh_scheduler.h index 2b4ea13..aaba6c1 100644 --- a/chrome/browser/policy/cloud_policy_refresh_scheduler.h +++ b/chrome/browser/policy/cloud_policy_refresh_scheduler.h @@ -10,11 +10,11 @@ #include "base/basictypes.h" #include "base/cancelable_callback.h" #include "base/memory/ref_counted.h" +#include "base/prefs/public/pref_observer.h" #include "base/time.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/policy/cloud_policy_client.h" #include "chrome/browser/policy/cloud_policy_store.h" -#include "content/public/browser/notification_observer.h" #include "net/base/network_change_notifier.h" class PrefService; @@ -30,7 +30,7 @@ namespace policy { class CloudPolicyRefreshScheduler : public CloudPolicyClient::Observer, public CloudPolicyStore::Observer, - public content::NotificationObserver, + public PrefObserver, public net::NetworkChangeNotifier::IPAddressObserver { public: // Refresh constants. @@ -60,10 +60,9 @@ class CloudPolicyRefreshScheduler virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; - // content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // net::NetworkChangeNotifier::IPAddressObserver: virtual void OnIPAddressChanged() OVERRIDE; diff --git a/chrome/browser/policy/cloud_policy_subsystem.cc b/chrome/browser/policy/cloud_policy_subsystem.cc index bc51d67..a937508 100644 --- a/chrome/browser/policy/cloud_policy_subsystem.cc +++ b/chrome/browser/policy/cloud_policy_subsystem.cc @@ -158,19 +158,12 @@ void CloudPolicySubsystem::UpdatePolicyRefreshRate(int64 refresh_rate) { } } -void CloudPolicySubsystem::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - DCHECK_EQ(*(content::Details<std::string>(details).ptr()), - std::string(refresh_pref_name_)); - PrefService* local_state = g_browser_process->local_state(); - DCHECK_EQ(content::Source<PrefService>(source).ptr(), local_state); - UpdatePolicyRefreshRate(local_state->GetInteger(refresh_pref_name_)); - } else { - NOTREACHED(); - } +void CloudPolicySubsystem::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK_EQ(pref_name, refresh_pref_name_); + PrefService* local_state = g_browser_process->local_state(); + DCHECK_EQ(service, local_state); + UpdatePolicyRefreshRate(local_state->GetInteger(refresh_pref_name_)); } void CloudPolicySubsystem::ScheduleServiceInitialization( diff --git a/chrome/browser/policy/cloud_policy_subsystem.h b/chrome/browser/policy/cloud_policy_subsystem.h index fd81072..2ff3eab 100644 --- a/chrome/browser/policy/cloud_policy_subsystem.h +++ b/chrome/browser/policy/cloud_policy_subsystem.h @@ -7,7 +7,7 @@ #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" -#include "content/public/browser/notification_observer.h" +#include "base/prefs/public/pref_observer.h" #include "net/base/network_change_notifier.h" class PrefService; @@ -25,7 +25,7 @@ class PolicyNotifier; // policy. It glues together the backend, the policy controller and manages the // life cycle of the policy providers. class CloudPolicySubsystem - : public content::NotificationObserver, + : public PrefObserver, public net::NetworkChangeNotifier::IPAddressObserver { public: enum PolicySubsystemState { @@ -131,10 +131,9 @@ class CloudPolicySubsystem virtual void CreateDeviceTokenFetcher(); virtual void CreateCloudPolicyController(); - // content::NotificationObserver overrides. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver overrides. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // net::NetworkChangeNotifier::IPAddressObserver: virtual void OnIPAddressChanged() OVERRIDE; diff --git a/chrome/browser/policy/url_blacklist_manager.cc b/chrome/browser/policy/url_blacklist_manager.cc index 2235792..d175ebf 100644 --- a/chrome/browser/policy/url_blacklist_manager.cc +++ b/chrome/browser/policy/url_blacklist_manager.cc @@ -297,16 +297,12 @@ void URLBlacklistManager::ShutdownOnUIThread() { URLBlacklistManager::~URLBlacklistManager() { } -void URLBlacklistManager::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void URLBlacklistManager::OnPreferenceChanged(PrefServiceBase* prefs, + const std::string& pref_name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); - PrefService* prefs = content::Source<PrefService>(source).ptr(); DCHECK(prefs == pref_service_); - std::string* pref_name = content::Details<std::string>(details).ptr(); - DCHECK(*pref_name == prefs::kUrlBlacklist || - *pref_name == prefs::kUrlWhitelist); + DCHECK(pref_name == prefs::kUrlBlacklist || + pref_name == prefs::kUrlWhitelist); ScheduleUpdate(); } diff --git a/chrome/browser/policy/url_blacklist_manager.h b/chrome/browser/policy/url_blacklist_manager.h index 8582b9f..9bbf47c 100644 --- a/chrome/browser/policy/url_blacklist_manager.h +++ b/chrome/browser/policy/url_blacklist_manager.h @@ -15,8 +15,8 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/common/extensions/matcher/url_matcher.h" -#include "content/public/browser/notification_observer.h" class GURL; class PrefService; @@ -113,7 +113,7 @@ class URLBlacklist { // exists in UI, then a potential destruction on IO will come after any task // posted to IO from that method on UI. This is used to go through IO before // the actual update starts, and grab a WeakPtr. -class URLBlacklistManager : public content::NotificationObserver { +class URLBlacklistManager : public PrefObserver { public: // Must be constructed on the UI thread. explicit URLBlacklistManager(PrefService* pref_service); @@ -148,9 +148,8 @@ class URLBlacklistManager : public content::NotificationObserver { scoped_ptr<base::ListValue> allow); private: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // --------- // UI thread diff --git a/chrome/browser/prefs/DEPS b/chrome/browser/prefs/DEPS new file mode 100644 index 0000000..6cd8260 --- /dev/null +++ b/chrome/browser/prefs/DEPS @@ -0,0 +1,11 @@ +include_rules = [ + "-content", +] + +specific_include_rules = { + "pref_service.*|browser_prefs.*": [ + "+content/public/browser/browser_thread.h", + "+content/public/browser/render_process_host.h", + "+content/public/test", + ], +} diff --git a/chrome/browser/prefs/pref_notifier_impl.cc b/chrome/browser/prefs/pref_notifier_impl.cc index a226685..9bdf322 100644 --- a/chrome/browser/prefs/pref_notifier_impl.cc +++ b/chrome/browser/prefs/pref_notifier_impl.cc @@ -7,9 +7,6 @@ #include "base/logging.h" #include "base/stl_util.h" #include "chrome/browser/prefs/pref_service.h" -#include "chrome/common/chrome_notification_types.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_service.h" PrefNotifierImpl::PrefNotifierImpl() : pref_service_(NULL) { @@ -25,45 +22,42 @@ PrefNotifierImpl::~PrefNotifierImpl() { // Verify that there are no pref observers when we shut down. for (PrefObserverMap::iterator it = pref_observers_.begin(); it != pref_observers_.end(); ++it) { - NotificationObserverList::Iterator obs_iterator(*(it->second)); + PrefObserverList::Iterator obs_iterator(*(it->second)); if (obs_iterator.GetNext()) { LOG(WARNING) << "pref observer found at shutdown " << it->first; } } + // Same for initialization observers. + if (!init_observers_.empty()) + LOG(WARNING) << "Init observer found at shutdown."; + STLDeleteContainerPairSecondPointers(pref_observers_.begin(), pref_observers_.end()); pref_observers_.clear(); + init_observers_.clear(); } void PrefNotifierImpl::AddPrefObserver(const char* path, - content::NotificationObserver* obs) { + PrefObserver* obs) { // Get the pref observer list associated with the path. - NotificationObserverList* observer_list = NULL; + PrefObserverList* observer_list = NULL; const PrefObserverMap::iterator observer_iterator = pref_observers_.find(path); if (observer_iterator == pref_observers_.end()) { - observer_list = new NotificationObserverList; + observer_list = new PrefObserverList; pref_observers_[path] = observer_list; } else { observer_list = observer_iterator->second; } - // Verify that this observer doesn't already exist. - NotificationObserverList::Iterator it(*observer_list); - content::NotificationObserver* existing_obs; - while ((existing_obs = it.GetNext()) != NULL) { - DCHECK(existing_obs != obs) << path << " observer already registered"; - if (existing_obs == obs) - return; - } - - // Ok, safe to add the pref observer. + // Add the pref observer. ObserverList will DCHECK if it already is + // in the list. observer_list->AddObserver(obs); } void PrefNotifierImpl::RemovePrefObserver(const char* path, - content::NotificationObserver* obs) { + PrefObserver* obs) { DCHECK(CalledOnValidThread()); const PrefObserverMap::iterator observer_iterator = @@ -72,10 +66,14 @@ void PrefNotifierImpl::RemovePrefObserver(const char* path, return; } - NotificationObserverList* observer_list = observer_iterator->second; + PrefObserverList* observer_list = observer_iterator->second; observer_list->RemoveObserver(obs); } +void PrefNotifierImpl::AddInitObserver(base::Callback<void(bool)> obs) { + init_observers_.push_back(obs); +} + void PrefNotifierImpl::OnPreferenceChanged(const std::string& path) { FireObservers(path); } @@ -83,10 +81,17 @@ void PrefNotifierImpl::OnPreferenceChanged(const std::string& path) { void PrefNotifierImpl::OnInitializationCompleted(bool succeeded) { DCHECK(CalledOnValidThread()); - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, - content::Source<PrefService>(pref_service_), - content::Details<bool>(&succeeded)); + // We must make a copy of init_observers_ and clear it before we run + // observers, or we can end up in this method re-entrantly before + // clearing the observers list. + PrefInitObserverList observers(init_observers_); + init_observers_.clear(); + + for (PrefInitObserverList::iterator it = observers.begin(); + it != observers.end(); + ++it) { + it->Run(succeeded); + } } void PrefNotifierImpl::FireObservers(const std::string& path) { @@ -101,13 +106,9 @@ void PrefNotifierImpl::FireObservers(const std::string& path) { if (observer_iterator == pref_observers_.end()) return; - NotificationObserverList::Iterator it(*(observer_iterator->second)); - content::NotificationObserver* observer; - while ((observer = it.GetNext()) != NULL) { - observer->Observe(chrome::NOTIFICATION_PREF_CHANGED, - content::Source<PrefService>(pref_service_), - content::Details<const std::string>(&path)); - } + FOR_EACH_OBSERVER(PrefObserver, + *(observer_iterator->second), + OnPreferenceChanged(pref_service_, path)); } void PrefNotifierImpl::SetPrefService(PrefService* pref_service) { diff --git a/chrome/browser/prefs/pref_notifier_impl.h b/chrome/browser/prefs/pref_notifier_impl.h index 38255ba..34c225f 100644 --- a/chrome/browser/prefs/pref_notifier_impl.h +++ b/chrome/browser/prefs/pref_notifier_impl.h @@ -5,19 +5,18 @@ #ifndef CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ #define CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ +#include <list> #include <string> +#include "base/callback.h" #include "base/hash_tables.h" #include "base/observer_list.h" #include "base/prefs/pref_notifier.h" +#include "base/prefs/public/pref_observer.h" #include "base/threading/non_thread_safe.h" class PrefService; -namespace content { -class NotificationObserver; -} - // The PrefNotifier implementation used by the PrefService. class PrefNotifierImpl : public PrefNotifier, public base::NonThreadSafe { @@ -26,24 +25,30 @@ class PrefNotifierImpl : public PrefNotifier, explicit PrefNotifierImpl(PrefService* pref_service); virtual ~PrefNotifierImpl(); - // If the pref at the given path changes, we call the observer's Observe - // method with PREF_CHANGED. - void AddPrefObserver(const char* path, content::NotificationObserver* obs); - void RemovePrefObserver(const char* path, content::NotificationObserver* obs); + // If the pref at the given path changes, we call the observer's + // OnPreferenceChanged method. + void AddPrefObserver(const char* path, PrefObserver* observer); + void RemovePrefObserver(const char* path, PrefObserver* observer); - // PrefNotifier overrides. - virtual void OnPreferenceChanged(const std::string& pref_name) OVERRIDE; - virtual void OnInitializationCompleted(bool succeeded) OVERRIDE; + // We run the callback once, when initialization completes. The bool + // parameter will be set to true for successful initialization, + // false for unsuccessful. + void AddInitObserver(base::Callback<void(bool)> observer); void SetPrefService(PrefService* pref_service); protected: + // PrefNotifier overrides. + virtual void OnPreferenceChanged(const std::string& pref_name) OVERRIDE; + virtual void OnInitializationCompleted(bool succeeded) OVERRIDE; + // A map from pref names to a list of observers. Observers get fired in the // order they are added. These should only be accessed externally for unit // testing. - typedef ObserverList<content::NotificationObserver> NotificationObserverList; - typedef base::hash_map<std::string, NotificationObserverList*> - PrefObserverMap; + typedef ObserverList<PrefObserver> PrefObserverList; + typedef base::hash_map<std::string, PrefObserverList*> PrefObserverMap; + + typedef std::list<base::Callback<void(bool)> > PrefInitObserverList; const PrefObserverMap* pref_observers() const { return &pref_observers_; } @@ -56,6 +61,7 @@ class PrefNotifierImpl : public PrefNotifier, PrefService* pref_service_; PrefObserverMap pref_observers_; + PrefInitObserverList init_observers_; DISALLOW_COPY_AND_ASSIGN(PrefNotifierImpl); }; diff --git a/chrome/browser/prefs/pref_notifier_impl_unittest.cc b/chrome/browser/prefs/pref_notifier_impl_unittest.cc index 6a5388e..4c5211e 100644 --- a/chrome/browser/prefs/pref_notifier_impl_unittest.cc +++ b/chrome/browser/prefs/pref_notifier_impl_unittest.cc @@ -2,16 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/bind.h" +#include "base/callback.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/prefs/pref_notifier_impl.h" #include "chrome/browser/prefs/pref_observer_mock.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_value_store.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/test/base/testing_pref_service.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_registrar.h" -#include "content/public/browser/notification_source.h" -#include "content/public/test/mock_notification_observer.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -26,7 +25,22 @@ namespace { const char kChangedPref[] = "changed_pref"; const char kUnchangedPref[] = "unchanged_pref"; -// Test PrefNotifier that allows tracking of observers and notifications. +class MockPrefInitObserver { + public: + MOCK_METHOD1(OnInitializationCompleted, void(bool)); +}; + +// This is an unmodified PrefNotifierImpl, except we make +// OnPreferenceChanged public for tests. +class TestingPrefNotifierImpl : public PrefNotifierImpl { + public: + TestingPrefNotifierImpl(PrefService* service) : PrefNotifierImpl(service) {} + + // Make public for tests. + using PrefNotifierImpl::OnPreferenceChanged; +}; + +// Mock PrefNotifier that allows tracking of observers and notifications. class MockPrefNotifier : public PrefNotifierImpl { public: explicit MockPrefNotifier(PrefService* pref_service) @@ -35,15 +49,15 @@ class MockPrefNotifier : public PrefNotifierImpl { MOCK_METHOD1(FireObservers, void(const std::string& path)); - size_t CountObserver(const char* path, content::NotificationObserver* obs) { + size_t CountObserver(const char* path, PrefObserver* obs) { PrefObserverMap::const_iterator observer_iterator = pref_observers()->find(path); if (observer_iterator == pref_observers()->end()) return false; - NotificationObserverList* observer_list = observer_iterator->second; - NotificationObserverList::Iterator it(*observer_list); - content::NotificationObserver* existing_obs; + PrefObserverList* observer_list = observer_iterator->second; + PrefObserverList::Iterator it(*observer_list); + PrefObserver* existing_obs; size_t count = 0; while ((existing_obs = it.GetNext()) != NULL) { if (existing_obs == obs) @@ -52,6 +66,10 @@ class MockPrefNotifier : public PrefNotifierImpl { return count; } + + // Make public for tests below. + using PrefNotifierImpl::OnPreferenceChanged; + using PrefNotifierImpl::OnInitializationCompleted; }; // Test fixture class. @@ -80,14 +98,11 @@ TEST_F(PrefNotifierTest, OnPreferenceChanged) { TEST_F(PrefNotifierTest, OnInitializationCompleted) { MockPrefNotifier notifier(&pref_service_); - content::MockNotificationObserver observer; - content::NotificationRegistrar registrar; - registrar.Add(&observer, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, - content::Source<PrefService>(&pref_service_)); - EXPECT_CALL(observer, Observe( - int(chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED), - content::Source<PrefService>(&pref_service_), - Property(&content::Details<bool>::ptr, testing::Pointee(true)))); + MockPrefInitObserver observer; + notifier.AddInitObserver( + base::Bind(&MockPrefInitObserver::OnInitializationCompleted, + base::Unretained(&observer))); + EXPECT_CALL(observer, OnInitializationCompleted(true)); notifier.OnInitializationCompleted(true); } @@ -155,13 +170,12 @@ TEST_F(PrefNotifierTest, AddAndRemovePrefObservers) { } TEST_F(PrefNotifierTest, FireObservers) { - base::FundamentalValue value_true(true); - PrefNotifierImpl notifier(&pref_service_); + TestingPrefNotifierImpl notifier(&pref_service_); notifier.AddPrefObserver(kChangedPref, &obs1_); notifier.AddPrefObserver(kUnchangedPref, &obs1_); - obs1_.Expect(&pref_service_, kChangedPref, &value_true); - EXPECT_CALL(obs2_, Observe(_, _, _)).Times(0); + EXPECT_CALL(obs1_, OnPreferenceChanged(&pref_service_, kChangedPref)); + EXPECT_CALL(obs2_, OnPreferenceChanged(_, _)).Times(0); notifier.OnPreferenceChanged(kChangedPref); Mock::VerifyAndClearExpectations(&obs1_); Mock::VerifyAndClearExpectations(&obs2_); @@ -169,8 +183,8 @@ TEST_F(PrefNotifierTest, FireObservers) { notifier.AddPrefObserver(kChangedPref, &obs2_); notifier.AddPrefObserver(kUnchangedPref, &obs2_); - obs1_.Expect(&pref_service_, kChangedPref, &value_true); - obs2_.Expect(&pref_service_, kChangedPref, &value_true); + EXPECT_CALL(obs1_, OnPreferenceChanged(&pref_service_, kChangedPref)); + EXPECT_CALL(obs2_, OnPreferenceChanged(&pref_service_, kChangedPref)); notifier.OnPreferenceChanged(kChangedPref); Mock::VerifyAndClearExpectations(&obs1_); Mock::VerifyAndClearExpectations(&obs2_); @@ -178,8 +192,8 @@ TEST_F(PrefNotifierTest, FireObservers) { // Make sure removing an observer from one pref doesn't affect anything else. notifier.RemovePrefObserver(kChangedPref, &obs1_); - EXPECT_CALL(obs1_, Observe(_, _, _)).Times(0); - obs2_.Expect(&pref_service_, kChangedPref, &value_true); + EXPECT_CALL(obs1_, OnPreferenceChanged(_, _)).Times(0); + EXPECT_CALL(obs2_, OnPreferenceChanged(&pref_service_, kChangedPref)); notifier.OnPreferenceChanged(kChangedPref); Mock::VerifyAndClearExpectations(&obs1_); Mock::VerifyAndClearExpectations(&obs2_); @@ -187,8 +201,8 @@ TEST_F(PrefNotifierTest, FireObservers) { // Make sure removing an observer entirely doesn't affect anything else. notifier.RemovePrefObserver(kUnchangedPref, &obs1_); - EXPECT_CALL(obs1_, Observe(_, _, _)).Times(0); - obs2_.Expect(&pref_service_, kChangedPref, &value_true); + EXPECT_CALL(obs1_, OnPreferenceChanged(_, _)).Times(0); + EXPECT_CALL(obs2_, OnPreferenceChanged(&pref_service_, kChangedPref)); notifier.OnPreferenceChanged(kChangedPref); Mock::VerifyAndClearExpectations(&obs1_); Mock::VerifyAndClearExpectations(&obs2_); diff --git a/chrome/browser/prefs/pref_observer_mock.cc b/chrome/browser/prefs/pref_observer_mock.cc index d42c69c..0b3f82ad 100644 --- a/chrome/browser/prefs/pref_observer_mock.cc +++ b/chrome/browser/prefs/pref_observer_mock.cc @@ -9,12 +9,9 @@ PrefObserverMock::PrefObserverMock() {} PrefObserverMock::~PrefObserverMock() {} -void PrefObserverMock::Expect(const PrefService* prefs, +void PrefObserverMock::Expect(PrefServiceBase* prefs, const std::string& pref_name, const Value* value) { - EXPECT_CALL(*this, Observe(int(chrome::NOTIFICATION_PREF_CHANGED), - content::Source<PrefService>(prefs), - Property(&content::Details<std::string>::ptr, - Pointee(pref_name)))) + EXPECT_CALL(*this, OnPreferenceChanged(prefs, pref_name)) .With(PrefValueMatches(prefs, pref_name, value)); } diff --git a/chrome/browser/prefs/pref_observer_mock.h b/chrome/browser/prefs/pref_observer_mock.h index 9697d24..be7f4ff 100644 --- a/chrome/browser/prefs/pref_observer_mock.h +++ b/chrome/browser/prefs/pref_observer_mock.h @@ -7,11 +7,8 @@ #include <string> +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/prefs/pref_service.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_source.h" -#include "content/public/browser/notification_types.h" #include "testing/gmock/include/gmock/gmock.h" using testing::Pointee; @@ -22,7 +19,7 @@ using testing::Truly; // |pref_name| in |prefs| matches |value|. If |value| is NULL, the matcher // checks that the value is not set. MATCHER_P3(PrefValueMatches, prefs, pref_name, value, "") { - const PrefService::Preference* pref = + const PrefServiceBase::Preference* pref = prefs->FindPreference(pref_name.c_str()); if (!pref) return false; @@ -36,16 +33,14 @@ MATCHER_P3(PrefValueMatches, prefs, pref_name, value, "") { } // A mock for testing preference notifications and easy setup of expectations. -class PrefObserverMock : public content::NotificationObserver { +class PrefObserverMock : public PrefObserver { public: PrefObserverMock(); virtual ~PrefObserverMock(); - MOCK_METHOD3(Observe, void(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details)); + MOCK_METHOD2(OnPreferenceChanged, void(PrefServiceBase*, const std::string&)); - void Expect(const PrefService* prefs, + void Expect(PrefServiceBase* prefs, const std::string& pref_name, const Value* value); }; diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc index 36fd093..1eb80b4 100644 --- a/chrome/browser/prefs/pref_service.cc +++ b/chrome/browser/prefs/pref_service.cc @@ -769,16 +769,18 @@ const ListValue* PrefService::GetList(const char* path) const { return static_cast<const ListValue*>(value); } -void PrefService::AddPrefObserver(const char* path, - content::NotificationObserver* obs) { +void PrefService::AddPrefObserver(const char* path, PrefObserver* obs) { pref_notifier_->AddPrefObserver(path, obs); } -void PrefService::RemovePrefObserver(const char* path, - content::NotificationObserver* obs) { +void PrefService::RemovePrefObserver(const char* path, PrefObserver* obs) { pref_notifier_->RemovePrefObserver(path, obs); } +void PrefService::AddPrefInitObserver(base::Callback<void(bool)> obs) { + pref_notifier_->AddInitObserver(obs); +} + void PrefService::RegisterPreference(const char* path, Value* default_value, PrefSyncStatus sync_status) { diff --git a/chrome/browser/prefs/pref_service.h b/chrome/browser/prefs/pref_service.h index c855ef1..1536b95 100644 --- a/chrome/browser/prefs/pref_service.h +++ b/chrome/browser/prefs/pref_service.h @@ -14,6 +14,7 @@ #include <set> #include <string> +#include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/hash_tables.h" @@ -27,6 +28,7 @@ class PersistentPrefStore; class PrefModelAssociator; class PrefNotifier; class PrefNotifierImpl; +class PrefObserver; class PrefServiceObserver; class PrefStore; class PrefValueStore; @@ -277,6 +279,11 @@ class PrefService : public PrefServiceBase, public base::NonThreadSafe { // Do not call this after having derived an incognito or per tab pref service. void UpdateCommandLinePrefStore(CommandLine* command_line); + // We run the callback once, when initialization completes. The bool + // parameter will be set to true for successful initialization, + // false for unsuccessful. + void AddPrefInitObserver(base::Callback<void(bool)> callback); + protected: // Construct a new pref service. This constructor is what // factory methods end up calling and what is used for unit tests. @@ -306,9 +313,9 @@ class PrefService : public PrefServiceBase, public base::NonThreadSafe { // PrefServiceBase implementation (protected in base, private here). virtual void AddPrefObserver(const char* path, - content::NotificationObserver* obs) OVERRIDE; + PrefObserver* obs) OVERRIDE; virtual void RemovePrefObserver(const char* path, - content::NotificationObserver* obs) OVERRIDE; + PrefObserver* obs) OVERRIDE; // Sends notification of a changed preference. This needs to be called by // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. diff --git a/chrome/browser/prefs/pref_service_unittest.cc b/chrome/browser/prefs/pref_service_unittest.cc index cd046e8..280a346 100644 --- a/chrome/browser/prefs/pref_service_unittest.cc +++ b/chrome/browser/prefs/pref_service_unittest.cc @@ -60,7 +60,7 @@ TEST(PrefServiceTest, NoObserverFire) { // Setting the pref to the same value should not set the pref value a second // time. - EXPECT_CALL(obs, Observe(_, _, _)).Times(0); + EXPECT_CALL(obs, OnPreferenceChanged(_, _)).Times(0); prefs.SetString(pref_name, new_pref_value); Mock::VerifyAndClearExpectations(&obs); @@ -71,7 +71,7 @@ TEST(PrefServiceTest, NoObserverFire) { Mock::VerifyAndClearExpectations(&obs); // Clearing the pref again should not cause the pref to fire. - EXPECT_CALL(obs, Observe(_, _, _)).Times(0); + EXPECT_CALL(obs, OnPreferenceChanged(_, _)).Times(0); prefs.ClearPref(pref_name); Mock::VerifyAndClearExpectations(&obs); } @@ -137,7 +137,7 @@ TEST(PrefServiceTest, Observers) { // Make sure obs2 still works after removing obs. registrar.Remove(pref_name, &obs); - EXPECT_CALL(obs, Observe(_, _, _)).Times(0); + EXPECT_CALL(obs, OnPreferenceChanged(_, _)).Times(0); obs2.Expect(&prefs, pref_name, &expected_new_pref_value); // This should only fire the observer in obs2. prefs.SetString(pref_name, new_pref_value); @@ -379,7 +379,7 @@ TEST_F(PrefServiceSetValueTest, SetStringValue) { prefs_.Set(kName, default_value); Mock::VerifyAndClearExpectations(&observer_); - EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); + EXPECT_CALL(observer_, OnPreferenceChanged(_, _)).Times(0); prefs_.Set(kName, default_value); Mock::VerifyAndClearExpectations(&observer_); @@ -395,7 +395,7 @@ TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { registrar.Init(&prefs_); registrar.Add(kName, &observer_); - EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); + EXPECT_CALL(observer_, OnPreferenceChanged(_, _)).Times(0); prefs_.RemoveUserPref(kName); Mock::VerifyAndClearExpectations(&observer_); @@ -405,7 +405,7 @@ TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { prefs_.Set(kName, new_value); Mock::VerifyAndClearExpectations(&observer_); - EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); + EXPECT_CALL(observer_, OnPreferenceChanged(_, _)).Times(0); prefs_.Set(kName, new_value); Mock::VerifyAndClearExpectations(&observer_); @@ -421,7 +421,7 @@ TEST_F(PrefServiceSetValueTest, SetListValue) { registrar.Init(&prefs_); registrar.Add(kName, &observer_); - EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); + EXPECT_CALL(observer_, OnPreferenceChanged(_, _)).Times(0); prefs_.RemoveUserPref(kName); Mock::VerifyAndClearExpectations(&observer_); @@ -431,7 +431,7 @@ TEST_F(PrefServiceSetValueTest, SetListValue) { prefs_.Set(kName, new_value); Mock::VerifyAndClearExpectations(&observer_); - EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); + EXPECT_CALL(observer_, OnPreferenceChanged(_, _)).Times(0); prefs_.Set(kName, new_value); Mock::VerifyAndClearExpectations(&observer_); diff --git a/chrome/browser/prefs/pref_value_store.h b/chrome/browser/prefs/pref_value_store.h index 7c34fe1..4c027a5 100644 --- a/chrome/browser/prefs/pref_value_store.h +++ b/chrome/browser/prefs/pref_value_store.h @@ -14,7 +14,6 @@ #include "base/memory/ref_counted.h" #include "base/prefs/pref_store.h" #include "base/values.h" -#include "content/public/browser/browser_thread.h" class PrefModelAssociator; class PrefNotifier; diff --git a/chrome/browser/prefs/scoped_user_pref_update_unittest.cc b/chrome/browser/prefs/scoped_user_pref_update_unittest.cc index 98ffc89..f5e6927 100644 --- a/chrome/browser/prefs/scoped_user_pref_update_unittest.cc +++ b/chrome/browser/prefs/scoped_user_pref_update_unittest.cc @@ -42,7 +42,7 @@ TEST_F(ScopedUserPrefUpdateTest, RegularUse) { expected_dictionary.SetString(kKey, kValue); { - EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); + EXPECT_CALL(observer_, OnPreferenceChanged(_, _)).Times(0); DictionaryPrefUpdate update(&prefs_, kPref); DictionaryValue* value = update.Get(); ASSERT_TRUE(value); @@ -69,7 +69,7 @@ TEST_F(ScopedUserPrefUpdateTest, RegularUse) { TEST_F(ScopedUserPrefUpdateTest, NeverTouchAnything) { const DictionaryValue* old_value = prefs_.GetDictionary(kPref); - EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); + EXPECT_CALL(observer_, OnPreferenceChanged(_, _)).Times(0); { DictionaryPrefUpdate update(&prefs_, kPref); } diff --git a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc index 49dadfb..18ed40d 100644 --- a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc +++ b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc @@ -207,11 +207,8 @@ void CloudPrintProxyService::OnCloudPrintSetupClosed() { FROM_HERE, base::Bind(&browser::EndKeepAlive)); } -void CloudPrintProxyService::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); +void CloudPrintProxyService::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { ApplyCloudPrintConnectorPolicy(); } diff --git a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h index 99bee15..e12a942 100644 --- a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h +++ b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h @@ -13,9 +13,9 @@ #include "base/memory/weak_ptr.h" #include "base/observer_list.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/printing/cloud_print/cloud_print_setup_handler.h" #include "chrome/browser/profiles/profile_keyed_service.h" -#include "content/public/browser/notification_observer.h" class Profile; class ServiceProcessControl; @@ -29,7 +29,7 @@ struct CloudPrintProxyInfo; class CloudPrintProxyService : public CloudPrintSetupHandlerDelegate, public ProfileKeyedService, - public content::NotificationObserver { + public PrefObserver { public: explicit CloudPrintProxyService(Profile* profile); virtual ~CloudPrintProxyService(); @@ -63,10 +63,9 @@ class CloudPrintProxyService // CloudPrintSetupHandler::Delegate implementation. virtual void OnCloudPrintSetupClosed() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; private: // NotificationDelegate implementation for the token expired notification. diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc index 56c58ca..cad5695 100644 --- a/chrome/browser/printing/print_view_manager.cc +++ b/chrome/browser/printing/print_view_manager.cc @@ -389,10 +389,6 @@ void PrintViewManager::Observe(int type, OnNotifyPrintJobEvent(*content::Details<JobEventDetails>(details).ptr()); break; } - case chrome::NOTIFICATION_PREF_CHANGED: { - UpdateScriptedPrintingBlocked(); - break; - } case chrome::NOTIFICATION_CONTENT_BLOCKED_STATE_CHANGED: { tab_content_blocked_ = *content::Details<const bool>(details).ptr(); UpdateScriptedPrintingBlocked(); @@ -405,6 +401,11 @@ void PrintViewManager::Observe(int type, } } +void PrintViewManager::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + UpdateScriptedPrintingBlocked(); +} + void PrintViewManager::OnNotifyPrintJobEvent( const JobEventDetails& event_details) { switch (event_details.type()) { diff --git a/chrome/browser/printing/print_view_manager.h b/chrome/browser/printing/print_view_manager.h index e23eaab..d83c1a3 100644 --- a/chrome/browser/printing/print_view_manager.h +++ b/chrome/browser/printing/print_view_manager.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ #include "base/memory/ref_counted.h" +#include "base/prefs/public/pref_observer.h" #include "base/string16.h" #include "chrome/browser/api/prefs/pref_member.h" #include "content/public/browser/notification_observer.h" @@ -30,6 +31,7 @@ class PrintViewManagerObserver; // Manages the print commands for a WebContents. class PrintViewManager : public content::NotificationObserver, + public PrefObserver, public PrintedPagesSource, public content::WebContentsObserver, public content::WebContentsUserData<PrintViewManager> { @@ -77,6 +79,10 @@ class PrintViewManager : public content::NotificationObserver, // must be NULL if |observer| is non-NULL. void set_observer(PrintViewManagerObserver* observer); + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // PrintedPagesSource implementation. virtual string16 RenderSourceName() OVERRIDE; diff --git a/chrome/browser/profiles/gaia_info_update_service.cc b/chrome/browser/profiles/gaia_info_update_service.cc index efd5188..4d8b4a8 100644 --- a/chrome/browser/profiles/gaia_info_update_service.cc +++ b/chrome/browser/profiles/gaia_info_update_service.cc @@ -164,17 +164,10 @@ void GAIAInfoUpdateService::OnProfileDownloadFailure( ScheduleNextUpdate(); } -void GAIAInfoUpdateService::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - std::string* name = content::Details<std::string>(details).ptr(); - if (prefs::kGoogleServicesUsername == *name) - OnUsernameChanged(); - } else { - NOTREACHED(); - } +void GAIAInfoUpdateService::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (prefs::kGoogleServicesUsername == pref_name) + OnUsernameChanged(); } void GAIAInfoUpdateService::OnUsernameChanged() { diff --git a/chrome/browser/profiles/gaia_info_update_service.h b/chrome/browser/profiles/gaia_info_update_service.h index 7129328..bd4ca60 100644 --- a/chrome/browser/profiles/gaia_info_update_service.h +++ b/chrome/browser/profiles/gaia_info_update_service.h @@ -8,11 +8,11 @@ #include "base/compiler_specific.h" #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "base/timer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/profiles/profile_downloader.h" #include "chrome/browser/profiles/profile_downloader_delegate.h" -#include "content/public/browser/notification_observer.h" class Profile; class ProfileDownloader; @@ -20,7 +20,7 @@ class ProfileDownloader; // This service kicks off a download of the user's name and profile picture. // The results are saved in the profile info cache. class GAIAInfoUpdateService : public ProfileDownloaderDelegate, - public content::NotificationObserver { + public PrefObserver { public: explicit GAIAInfoUpdateService(Profile* profile); virtual ~GAIAInfoUpdateService(); @@ -45,10 +45,9 @@ class GAIAInfoUpdateService : public ProfileDownloaderDelegate, private: FRIEND_TEST_ALL_PREFIXES(GAIAInfoUpdateServiceTest, ScheduleUpdate); - // content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; void OnUsernameChanged(); diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h index 799e984..611d9dc 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.h +++ b/chrome/browser/profiles/off_the_record_profile_impl.h @@ -12,6 +12,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser_list.h" #include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" using base::Time; using base::TimeDelta; diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 1d917aa..7902049 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -5,6 +5,7 @@ #include "chrome/browser/profiles/profile_impl.h" #include "base/bind.h" +#include "base/callback.h" #include "base/command_line.h" #include "base/compiler_specific.h" #include "base/environment.h" @@ -361,10 +362,12 @@ ProfileImpl::ProfileImpl( new ExtensionPrefStore( ExtensionPrefValueMapFactory::GetForProfile(this), false), true)); - // Wait for the notification that prefs has been loaded (successfully or - // not). - registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, - content::Source<PrefService>(prefs_.get())); + // Wait for the notification that prefs has been loaded + // (successfully or not). Note that we can use base::Unretained + // because the PrefService is owned by this class and lives on + // the same thread. + prefs_->AddPrefInitObserver(base::Bind(&ProfileImpl::OnPrefsLoaded, + base::Unretained(this))); } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { // Load prefs synchronously. prefs_.reset(PrefService::CreatePrefService( @@ -915,32 +918,6 @@ void ProfileImpl::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { switch (type) { - case chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED: { - bool* succeeded = content::Details<bool>(details).ptr(); - PrefService *prefs = content::Source<PrefService>(source).ptr(); - DCHECK(prefs == prefs_.get()); - registrar_.Remove(this, - chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, - content::Source<PrefService>(prefs)); - OnPrefsLoaded(*succeeded); - break; - } - case chrome::NOTIFICATION_PREF_CHANGED: { - std::string* pref_name_in = content::Details<std::string>(details).ptr(); - PrefService* prefs = content::Source<PrefService>(source).ptr(); - DCHECK(pref_name_in && prefs); - if (*pref_name_in == prefs::kGoogleServicesUsername) { - UpdateProfileUserNameCache(); - } else if (*pref_name_in == prefs::kProfileAvatarIndex) { - UpdateProfileAvatarCache(); - } else if (*pref_name_in == prefs::kProfileName) { - UpdateProfileNameCache(); - } else if (*pref_name_in == prefs::kDefaultZoomLevel) { - HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( - prefs->GetDouble(prefs::kDefaultZoomLevel)); - } - break; - } case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: // Causes lazy-load if sync is enabled. ProfileSyncServiceFactory::GetInstance()->GetForProfile(this); @@ -969,6 +946,21 @@ void ProfileImpl::Observe(int type, } } +void ProfileImpl::OnPreferenceChanged(PrefServiceBase* prefs, + const std::string& pref_name_in) { + DCHECK(prefs); + if (pref_name_in == prefs::kGoogleServicesUsername) { + UpdateProfileUserNameCache(); + } else if (pref_name_in == prefs::kProfileAvatarIndex) { + UpdateProfileAvatarCache(); + } else if (pref_name_in == prefs::kProfileName) { + UpdateProfileNameCache(); + } else if (pref_name_in == prefs::kDefaultZoomLevel) { + HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( + prefs->GetDouble(prefs::kDefaultZoomLevel)); + } +} + #if defined(ENABLE_SESSION_SERVICE) void ProfileImpl::StopCreateSessionServiceTimer() { create_session_service_timer_.Stop(); diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index ad7c17f..36ed8bc 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -22,6 +22,7 @@ class NetPrefObserver; class PrefService; +class PrefServiceBase; class PromoResourceService; class SSLConfigServiceManager; @@ -47,7 +48,8 @@ class ExtensionSystem; // The default profile implementation. class ProfileImpl : public Profile, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: // Value written to prefs when the exit type is EXIT_NORMAL. Public for tests. static const char* const kPrefExitTypeNormal; @@ -131,6 +133,10 @@ class ProfileImpl : public Profile, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + private: friend class Profile; FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, @@ -153,6 +159,9 @@ class ProfileImpl : public Profile, void InitHostZoomMap(); + void OnInitializationCompleted(PrefServiceBase* pref_service, + bool succeeded); + // Does final prefs initialization and calls Init(). void OnPrefsLoaded(bool success); diff --git a/chrome/browser/protector/base_prefs_change.cc b/chrome/browser/protector/base_prefs_change.cc index 2a4a871..9ca25c8 100644 --- a/chrome/browser/protector/base_prefs_change.cc +++ b/chrome/browser/protector/base_prefs_change.cc @@ -43,12 +43,9 @@ void BasePrefsChange::IgnorePrefChanges() { pref_observer_.RemoveAll(); } -void BasePrefsChange::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); - const std::string* pref_name = content::Details<std::string>(details).ptr(); - DCHECK(pref_name && pref_observer_.IsObserved(*pref_name)); +void BasePrefsChange::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK(pref_observer_.IsObserved(pref_name)); // Will delete this instance. ProtectorServiceFactory::GetForProfile(profile())->DismissChange(this); } diff --git a/chrome/browser/protector/base_prefs_change.h b/chrome/browser/protector/base_prefs_change.h index 79f5b88..ba29d3a 100644 --- a/chrome/browser/protector/base_prefs_change.h +++ b/chrome/browser/protector/base_prefs_change.h @@ -9,14 +9,14 @@ #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/protector/base_setting_change.h" -#include "content/public/browser/notification_observer.h" namespace protector { // BaseSettingChange subclass for PrefService-managed settings changes. class BasePrefsChange : public BaseSettingChange, - public content::NotificationObserver { + public PrefObserver { public: BasePrefsChange(); virtual ~BasePrefsChange(); @@ -35,10 +35,9 @@ class BasePrefsChange : public BaseSettingChange, void IgnorePrefChanges(); private: - // content::NotificationObserver overrides: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver overrides: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; PrefChangeRegistrar pref_observer_; diff --git a/chrome/browser/protector/protected_prefs_watcher.cc b/chrome/browser/protector/protected_prefs_watcher.cc index b98438d..ed13224 100644 --- a/chrome/browser/protector/protected_prefs_watcher.cc +++ b/chrome/browser/protector/protected_prefs_watcher.cc @@ -195,14 +195,10 @@ void ProtectedPrefsWatcher::ForceUpdateBackup() { InitBackup(); } -void ProtectedPrefsWatcher::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); - const std::string* pref_name = content::Details<std::string>(details).ptr(); - DCHECK(pref_name && pref_observer_.IsObserved(*pref_name)); - if (UpdateBackupEntry(*pref_name)) +void ProtectedPrefsWatcher::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK(pref_observer_.IsObserved(pref_name)); + if (UpdateBackupEntry(pref_name)) UpdateBackupSignature(); } diff --git a/chrome/browser/protector/protected_prefs_watcher.h b/chrome/browser/protector/protected_prefs_watcher.h index 1aaf030..269edc3 100644 --- a/chrome/browser/protector/protected_prefs_watcher.h +++ b/chrome/browser/protector/protected_prefs_watcher.h @@ -10,8 +10,8 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/extensions/extension_prefs.h" -#include "content/public/browser/notification_observer.h" class PrefService; class Profile; @@ -22,7 +22,7 @@ class Value; namespace protector { -class ProtectedPrefsWatcher : public content::NotificationObserver { +class ProtectedPrefsWatcher : public PrefObserver { public: // Current backup version. static const int kCurrentVersionNumber; @@ -51,10 +51,9 @@ class ProtectedPrefsWatcher : public content::NotificationObserver { private: friend class ProtectedPrefsWatcherTest; - // content::NotificationObserver overrides: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver overrides: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // Makes sure that all protected prefs have been migrated before starting to // observe them. diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc index ab82ddf..6d5456f 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.cc +++ b/chrome/browser/safe_browsing/safe_browsing_service.cc @@ -1369,18 +1369,18 @@ void SafeBrowsingService::Observe(int type, RemovePrefService(profile->GetPrefs()); break; } - case chrome::NOTIFICATION_PREF_CHANGED: { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - std::string* pref = content::Details<std::string>(details).ptr(); - DCHECK(*pref == prefs::kSafeBrowsingEnabled); - RefreshState(); - break; - } default: NOTREACHED(); } } +void SafeBrowsingService::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(pref_name == prefs::kSafeBrowsingEnabled); + RefreshState(); +} + bool SafeBrowsingService::IsWhitelisted(const UnsafeResource& resource) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // Check if the user has already ignored our warning for this render_view diff --git a/chrome/browser/safe_browsing/safe_browsing_service.h b/chrome/browser/safe_browsing/safe_browsing_service.h index d650ae1..bf29fb4 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.h +++ b/chrome/browser/safe_browsing/safe_browsing_service.h @@ -20,6 +20,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" +#include "base/prefs/public/pref_observer.h" #include "base/sequenced_task_runner_helpers.h" #include "base/synchronization/lock.h" #include "base/time.h" @@ -55,7 +56,8 @@ class DownloadProtectionService; class SafeBrowsingService : public base::RefCountedThreadSafe< SafeBrowsingService, content::BrowserThread::DeleteOnUIThread>, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: class Client; // Passed a boolean indicating whether or not it is OK to proceed with @@ -470,6 +472,10 @@ class SafeBrowsingService const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver override + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Starts following the safe browsing preference on |pref_service|. void AddPrefService(PrefService* pref_service); diff --git a/chrome/browser/safe_browsing/safe_browsing_tab_observer.cc b/chrome/browser/safe_browsing/safe_browsing_tab_observer.cc index 60444ae..06d4ca1 100644 --- a/chrome/browser/safe_browsing/safe_browsing_tab_observer.cc +++ b/chrome/browser/safe_browsing/safe_browsing_tab_observer.cc @@ -55,26 +55,16 @@ SafeBrowsingTabObserver::~SafeBrowsingTabObserver() { //////////////////////////////////////////////////////////////////////////////// // content::NotificationObserver overrides -void SafeBrowsingTabObserver::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: { - Profile* profile = - Profile::FromBrowserContext(web_contents_->GetBrowserContext()); - std::string* pref_name = content::Details<std::string>(details).ptr(); - DCHECK(content::Source<PrefService>(source).ptr() == - profile->GetPrefs()); - if (*pref_name == prefs::kSafeBrowsingEnabled) { - UpdateSafebrowsingDetectionHost(); - } else { - NOTREACHED() << "unexpected pref change notification" << *pref_name; - } - break; - } - default: - NOTREACHED(); +void SafeBrowsingTabObserver::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { + Profile* profile = + Profile::FromBrowserContext(web_contents_->GetBrowserContext()); + DCHECK(service == profile->GetPrefs()); + if (pref_name == prefs::kSafeBrowsingEnabled) { + UpdateSafebrowsingDetectionHost(); + } else { + NOTREACHED() << "unexpected pref change notification" << pref_name; } } diff --git a/chrome/browser/safe_browsing/safe_browsing_tab_observer.h b/chrome/browser/safe_browsing/safe_browsing_tab_observer.h index ec97fee..b41ecb9 100644 --- a/chrome/browser/safe_browsing/safe_browsing_tab_observer.h +++ b/chrome/browser/safe_browsing/safe_browsing_tab_observer.h @@ -7,7 +7,7 @@ #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" -#include "content/public/browser/notification_observer.h" +#include "base/prefs/public/pref_observer.h" #include "content/public/browser/web_contents_user_data.h" namespace content { @@ -20,7 +20,7 @@ class ClientSideDetectionHost; // Per-tab class to handle safe-browsing functionality. class SafeBrowsingTabObserver - : public content::NotificationObserver, + : public PrefObserver, public content::WebContentsUserData<SafeBrowsingTabObserver> { public: virtual ~SafeBrowsingTabObserver(); @@ -29,10 +29,9 @@ class SafeBrowsingTabObserver explicit SafeBrowsingTabObserver(content::WebContents* web_contents); friend class content::WebContentsUserData<SafeBrowsingTabObserver>; - // content::NotificationObserver overrides: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver overrides: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // Internal helpers ---------------------------------------------------------- diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc index c8d3e01..e4c250e 100644 --- a/chrome/browser/search_engines/template_url_service.cc +++ b/chrome/browser/search_engines/template_url_service.cc @@ -921,32 +921,34 @@ void TemplateURLService::Observe(int type, GoogleBaseURLChanged( content::Details<GoogleURLTracker::UpdatedDetails>(details)->first); } - } else if (type == chrome::NOTIFICATION_PREF_CHANGED) { - // Listen for changes to the default search from Sync. - DCHECK_EQ(std::string(prefs::kSyncedDefaultSearchProviderGUID), - *content::Details<std::string>(details).ptr()); - PrefService* prefs = GetPrefs(); - TemplateURL* new_default_search = GetTemplateURLForGUID( - prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID)); - if (new_default_search && !is_default_search_managed_) { - if (new_default_search != GetDefaultSearchProvider()) { - AutoReset<DefaultSearchChangeOrigin> change_origin( - &dsp_change_origin_, DSP_CHANGE_SYNC_PREF); - SetDefaultSearchProvider(new_default_search); - pending_synced_default_search_ = false; - } - } else { - // If it's not there, or if default search is currently managed, set a - // flag to indicate that we waiting on the search engine entry to come - // in through Sync. - pending_synced_default_search_ = true; - } - UpdateDefaultSearch(); } else { NOTREACHED(); } } +void TemplateURLService::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + // Listen for changes to the default search from Sync. + DCHECK_EQ(std::string(prefs::kSyncedDefaultSearchProviderGUID), pref_name); + PrefService* prefs = GetPrefs(); + TemplateURL* new_default_search = GetTemplateURLForGUID( + prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID)); + if (new_default_search && !is_default_search_managed_) { + if (new_default_search != GetDefaultSearchProvider()) { + AutoReset<DefaultSearchChangeOrigin> change_origin( + &dsp_change_origin_, DSP_CHANGE_SYNC_PREF); + SetDefaultSearchProvider(new_default_search); + pending_synced_default_search_ = false; + } + } else { + // If it's not there, or if default search is currently managed, set a + // flag to indicate that we waiting on the search engine entry to come + // in through Sync. + pending_synced_default_search_ = true; + } + UpdateDefaultSearch(); +} + syncer::SyncDataList TemplateURLService::GetAllSyncData( syncer::ModelType type) const { DCHECK_EQ(syncer::SEARCH_ENGINES, type); diff --git a/chrome/browser/search_engines/template_url_service.h b/chrome/browser/search_engines/template_url_service.h index bc62ff5..510f11c 100644 --- a/chrome/browser/search_engines/template_url_service.h +++ b/chrome/browser/search_engines/template_url_service.h @@ -15,6 +15,7 @@ #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/profiles/profile_keyed_service.h" #include "chrome/browser/search_engines/template_url_id.h" #include "chrome/browser/webdata/web_data_service.h" @@ -67,6 +68,7 @@ struct URLVisitedDetails; class TemplateURLService : public WebDataServiceConsumer, public ProfileKeyedService, public content::NotificationObserver, + public PrefObserver, public syncer::SyncableService { public: typedef std::map<std::string, std::string> QueryTerms; @@ -260,10 +262,15 @@ class TemplateURLService : public WebDataServiceConsumer, string16 GetKeywordShortName(const string16& keyword, bool* is_extension_keyword); + // content::NotificationObserver implementation. virtual void Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // syncer::SyncableService implementation. // Returns all syncable TemplateURLs from this model as SyncData. This should diff --git a/chrome/browser/signin/signin_manager.cc b/chrome/browser/signin/signin_manager.cc index cbf1cd9..56addb0 100644 --- a/chrome/browser/signin/signin_manager.cc +++ b/chrome/browser/signin/signin_manager.cc @@ -506,17 +506,6 @@ void SigninManager::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: - DCHECK(*content::Details<std::string>(details).ptr() == - prefs::kGoogleServicesUsernamePattern); - if (!authenticated_username_.empty() && - !IsAllowedUsername(authenticated_username_)) { - // Signed in user is invalid according to the current policy so sign - // the user out. - SignOut(); - } - break; - #if !defined(OS_CHROMEOS) case chrome::NOTIFICATION_TOKEN_AVAILABLE: { TokenService::TokenAvailableDetails* tok_details = @@ -546,3 +535,13 @@ void SigninManager::Observe(int type, } } +void SigninManager::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK_EQ(std::string(prefs::kGoogleServicesUsernamePattern), pref_name); + if (!authenticated_username_.empty() && + !IsAllowedUsername(authenticated_username_)) { + // Signed in user is invalid according to the current policy so sign + // the user out. + SignOut(); + } +} diff --git a/chrome/browser/signin/signin_manager.h b/chrome/browser/signin/signin_manager.h index ce616eb..d63df0c 100644 --- a/chrome/browser/signin/signin_manager.h +++ b/chrome/browser/signin/signin_manager.h @@ -24,6 +24,7 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/profiles/profile_keyed_service.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -49,6 +50,7 @@ struct GoogleServiceSigninSuccessDetails { class SigninManager : public GaiaAuthConsumer, public content::NotificationObserver, + public PrefObserver, public ProfileKeyedService { public: // Returns true if the cookie policy for the given profile allows cookies @@ -146,6 +148,10 @@ class SigninManager : public GaiaAuthConsumer, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + protected: // Weak pointer to parent profile (protected so FakeSigninManager can access // it). diff --git a/chrome/browser/speech/chrome_speech_recognition_preferences.cc b/chrome/browser/speech/chrome_speech_recognition_preferences.cc index f5ef511..fc057fe 100644 --- a/chrome/browser/speech/chrome_speech_recognition_preferences.cc +++ b/chrome/browser/speech/chrome_speech_recognition_preferences.cc @@ -141,14 +141,11 @@ void ChromeSpeechRecognitionPreferences::DetachFromProfile() { profile_ = NULL; } -void ChromeSpeechRecognitionPreferences::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void ChromeSpeechRecognitionPreferences::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK_EQ(type, chrome::NOTIFICATION_PREF_CHANGED); - std::string* pref_name = content::Details<std::string>(details).ptr(); - ReloadPreference(*pref_name); + ReloadPreference(pref_name); } bool ChromeSpeechRecognitionPreferences::FilterProfanities() const { diff --git a/chrome/browser/speech/chrome_speech_recognition_preferences.h b/chrome/browser/speech/chrome_speech_recognition_preferences.h index 5090ea3..6bab299 100644 --- a/chrome/browser/speech/chrome_speech_recognition_preferences.h +++ b/chrome/browser/speech/chrome_speech_recognition_preferences.h @@ -10,11 +10,11 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/synchronization/lock.h" #include "base/threading/non_thread_safe.h" #include "chrome/browser/profiles/profile_keyed_service.h" #include "chrome/browser/profiles/profile_keyed_service_factory.h" -#include "content/public/browser/notification_observer.h" #include "content/public/browser/speech_recognition_preferences.h" class PrefService; @@ -34,16 +34,15 @@ class ListValue; class ChromeSpeechRecognitionPreferences : public content::SpeechRecognitionPreferences, - public content::NotificationObserver { + public PrefObserver { public: static void InitializeFactory(); static scoped_refptr<ChromeSpeechRecognitionPreferences> GetForProfile( Profile* profile); - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // content::SpeechRecognitionPreferences implementation. diff --git a/chrome/browser/spellchecker/spellcheck_profile.cc b/chrome/browser/spellchecker/spellcheck_profile.cc index 09375c5..256251a 100644 --- a/chrome/browser/spellchecker/spellcheck_profile.cc +++ b/chrome/browser/spellchecker/spellcheck_profile.cc @@ -112,26 +112,19 @@ void SpellCheckProfile::Shutdown() { profile_ = NULL; } -void SpellCheckProfile::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: { - std::string* pref_name_in = content::Details<std::string>(details).ptr(); - PrefService* prefs = content::Source<PrefService>(source).ptr(); - DCHECK(pref_name_in && prefs); - if (*pref_name_in == prefs::kSpellCheckDictionary || - *pref_name_in == prefs::kEnableSpellCheck) { - ReinitializeSpellCheckHost(true); - } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) { - bool enabled = prefs->GetBoolean(prefs::kEnableAutoSpellCorrect); - for (content::RenderProcessHost::iterator i( - content::RenderProcessHost::AllHostsIterator()); - !i.IsAtEnd(); i.Advance()) { - content::RenderProcessHost* process = i.GetCurrentValue(); - process->Send(new SpellCheckMsg_EnableAutoSpellCorrect(enabled)); - } - } +void SpellCheckProfile::OnPreferenceChanged(PrefServiceBase* prefs, + const std::string& pref_name_in) { + DCHECK(prefs); + if (pref_name_in == prefs::kSpellCheckDictionary || + pref_name_in == prefs::kEnableSpellCheck) { + ReinitializeSpellCheckHost(true); + } else if (pref_name_in == prefs::kEnableAutoSpellCorrect) { + bool enabled = prefs->GetBoolean(prefs::kEnableAutoSpellCorrect); + for (content::RenderProcessHost::iterator i( + content::RenderProcessHost::AllHostsIterator()); + !i.IsAtEnd(); i.Advance()) { + content::RenderProcessHost* process = i.GetCurrentValue(); + process->Send(new SpellCheckMsg_EnableAutoSpellCorrect(enabled)); } } } diff --git a/chrome/browser/spellchecker/spellcheck_profile.h b/chrome/browser/spellchecker/spellcheck_profile.h index a269c6f..7955057 100644 --- a/chrome/browser/spellchecker/spellcheck_profile.h +++ b/chrome/browser/spellchecker/spellcheck_profile.h @@ -14,11 +14,11 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/profiles/profile_keyed_service.h" #include "chrome/browser/spellchecker/spellcheck_profile_provider.h" #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" #include "chrome/common/spellcheck_common.h" -#include "content/public/browser/notification_observer.h" class Profile; class SpellCheckHost; @@ -38,7 +38,7 @@ class URLRequestContextGetter; // can be retrieved from SpellCheckFactory::GetHostForProfile(); class SpellCheckProfile : public SpellCheckProfileProvider, public ProfileKeyedService, - public content::NotificationObserver { + public PrefObserver { public: explicit SpellCheckProfile(Profile* profile); virtual ~SpellCheckProfile(); @@ -71,10 +71,9 @@ class SpellCheckProfile : public SpellCheckProfileProvider, // ProfileKeyedService implementation. virtual void Shutdown() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; protected: // Only tests should override this. diff --git a/chrome/browser/sync/credential_cache_service_win.cc b/chrome/browser/sync/credential_cache_service_win.cc index 9c938d0..8d05e0d 100644 --- a/chrome/browser/sync/credential_cache_service_win.cc +++ b/chrome/browser/sync/credential_cache_service_win.cc @@ -94,24 +94,6 @@ void CredentialCacheService::Observe( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(local_store_.get()); switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: { - // One of the two sync encryption tokens has changed. Update its value in - // the local cache. - const std::string pref_name = - *(content::Details<const std::string>(details).ptr()); - if (pref_name == prefs::kSyncEncryptionBootstrapToken) { - PackAndUpdateStringPref(pref_name, - sync_prefs_.GetEncryptionBootstrapToken()); - } else if (pref_name == prefs::kSyncKeystoreEncryptionBootstrapToken) { - PackAndUpdateStringPref( - pref_name, - sync_prefs_.GetKeystoreEncryptionBootstrapToken()); - } else { - NOTREACHED() "Invalid pref name " << pref_name << "."; - } - break; - } - case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: { // The user has signed out. Write blank values to the google username, // encryption tokens and token service credentials in the local cache. @@ -193,6 +175,22 @@ void CredentialCacheService::Observe( } } +void CredentialCacheService::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + // One of the two sync encryption tokens has changed. Update its value in + // the local cache. + if (pref_name == prefs::kSyncEncryptionBootstrapToken) { + PackAndUpdateStringPref(pref_name, + sync_prefs_.GetEncryptionBootstrapToken()); + } else if (pref_name == prefs::kSyncKeystoreEncryptionBootstrapToken) { + PackAndUpdateStringPref( + pref_name, + sync_prefs_.GetKeystoreEncryptionBootstrapToken()); + } else { + NOTREACHED() "Invalid pref name " << pref_name << "."; + } +} + void CredentialCacheService::ReadCachedCredentialsFromAlternateProfile() { // If the local user has signed in and signed out, we do not consume cached // credentials from the alternate profile. There is nothing more to do, now or diff --git a/chrome/browser/sync/credential_cache_service_win.h b/chrome/browser/sync/credential_cache_service_win.h index 625f608..1aea150 100644 --- a/chrome/browser/sync/credential_cache_service_win.h +++ b/chrome/browser/sync/credential_cache_service_win.h @@ -14,6 +14,7 @@ #include "base/memory/weak_ptr.h" #include "base/prefs/json_pref_store.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/profiles/profile_keyed_service.h" #include "chrome/browser/sync/sync_prefs.h" #include "content/public/browser/notification_observer.h" @@ -39,7 +40,8 @@ namespace syncer { // sync using credentials that were cached due to signing in on the other // (alternate) mode. class CredentialCacheService : public ProfileKeyedService, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: explicit CredentialCacheService(Profile* profile); virtual ~CredentialCacheService(); @@ -52,6 +54,10 @@ class CredentialCacheService : public ProfileKeyedService, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Loads cached sync credentials from the alternate profile and applies them // to the local profile if the load was successful. void ReadCachedCredentialsFromAlternateProfile(); diff --git a/chrome/browser/sync/glue/typed_url_data_type_controller.cc b/chrome/browser/sync/glue/typed_url_data_type_controller.cc index 88a9d23..0e9713f 100644 --- a/chrome/browser/sync/glue/typed_url_data_type_controller.cc +++ b/chrome/browser/sync/glue/typed_url_data_type_controller.cc @@ -87,29 +87,22 @@ void TypedUrlDataTypeController::SetBackend(history::HistoryBackend* backend) { backend_ = backend; } -void TypedUrlDataTypeController::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void TypedUrlDataTypeController::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: - DCHECK(*content::Details<std::string>(details).ptr() == - prefs::kSavingBrowserHistoryDisabled); - if (profile()->GetPrefs()->GetBoolean( - prefs::kSavingBrowserHistoryDisabled)) { - // We've turned off history persistence, so if we are running, - // generate an unrecoverable error. This can be fixed by restarting - // Chrome (on restart, typed urls will not be a registered type). - if (state() != NOT_RUNNING && state() != STOPPING) { - profile_sync_service()->DisableBrokenDatatype(syncer::TYPED_URLS, - FROM_HERE, "History saving is now disabled by policy."); - } - } - break; - default: - NOTREACHED(); - break; + DCHECK_EQ(std::string(prefs::kSavingBrowserHistoryDisabled), pref_name); + if (profile()->GetPrefs()->GetBoolean( + prefs::kSavingBrowserHistoryDisabled)) { + // We've turned off history persistence, so if we are running, + // generate an unrecoverable error. This can be fixed by restarting + // Chrome (on restart, typed urls will not be a registered type). + if (state() != NOT_RUNNING && state() != STOPPING) { + profile_sync_service()->DisableBrokenDatatype( + syncer::TYPED_URLS, + FROM_HERE, + "History saving is now disabled by policy."); + } } } @@ -147,7 +140,6 @@ void TypedUrlDataTypeController::StopModels() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(state() == STOPPING || state() == NOT_RUNNING || state() == DISABLED); DVLOG(1) << "TypedUrlDataTypeController::StopModels(): State = " << state(); - notification_registrar_.RemoveAll(); } TypedUrlDataTypeController::~TypedUrlDataTypeController() {} diff --git a/chrome/browser/sync/glue/typed_url_data_type_controller.h b/chrome/browser/sync/glue/typed_url_data_type_controller.h index 650152a..e107627 100644 --- a/chrome/browser/sync/glue/typed_url_data_type_controller.h +++ b/chrome/browser/sync/glue/typed_url_data_type_controller.h @@ -10,11 +10,9 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/common/cancelable_request.h" #include "chrome/browser/sync/glue/non_frontend_data_type_controller.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" -#include "content/public/browser/notification_types.h" class HistoryService; @@ -28,7 +26,7 @@ class ControlTask; // A class that manages the startup and shutdown of typed_url sync. class TypedUrlDataTypeController : public NonFrontendDataTypeController, - public content::NotificationObserver { + public PrefObserver { public: TypedUrlDataTypeController( ProfileSyncComponentsFactory* profile_sync_factory, @@ -39,10 +37,9 @@ class TypedUrlDataTypeController : public NonFrontendDataTypeController, virtual syncer::ModelType type() const OVERRIDE; virtual syncer::ModelSafeGroup model_safe_group() const OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // Invoked on the history thread to set our history backend - must be called // before CreateSyncComponents() is invoked. @@ -60,7 +57,6 @@ class TypedUrlDataTypeController : public NonFrontendDataTypeController, virtual ~TypedUrlDataTypeController(); history::HistoryBackend* backend_; - content::NotificationRegistrar notification_registrar_; PrefChangeRegistrar pref_registrar_; // Helper object to make sure we don't leave tasks running on the history diff --git a/chrome/browser/sync/sync_prefs.cc b/chrome/browser/sync/sync_prefs.cc index ee9380c..c483966 100644 --- a/chrome/browser/sync/sync_prefs.cc +++ b/chrome/browser/sync/sync_prefs.cc @@ -263,24 +263,13 @@ void SyncPrefs::AcknowledgeSyncedTypes(syncer::ModelTypeSet types) { pref_service_->Set(prefs::kSyncAcknowledgedSyncTypes, *value); } -void SyncPrefs::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void SyncPrefs::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { DCHECK(CalledOnValidThread()); - DCHECK(content::Source<PrefService>(pref_service_) == source); - switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: { - const std::string* pref_name = - content::Details<const std::string>(details).ptr(); - if (*pref_name == prefs::kSyncManaged) { - FOR_EACH_OBSERVER(SyncPrefObserver, sync_pref_observers_, - OnSyncManagedPrefChange(*pref_sync_managed_)); - } - break; - } - default: - NOTREACHED(); - break; + DCHECK_EQ(pref_service_, service); + if (pref_name == prefs::kSyncManaged) { + FOR_EACH_OBSERVER(SyncPrefObserver, sync_pref_observers_, + OnSyncManagedPrefChange(*pref_sync_managed_)); } } diff --git a/chrome/browser/sync/sync_prefs.h b/chrome/browser/sync/sync_prefs.h index 0786b90..dcb3dbb 100644 --- a/chrome/browser/sync/sync_prefs.h +++ b/chrome/browser/sync/sync_prefs.h @@ -9,10 +9,10 @@ #include "base/compiler_specific.h" #include "base/memory/weak_ptr.h" #include "base/observer_list.h" +#include "base/prefs/public/pref_observer.h" #include "base/threading/non_thread_safe.h" #include "base/time.h" #include "chrome/browser/api/prefs/pref_member.h" -#include "content/public/browser/notification_observer.h" #include "sync/internal_api/public/base/model_type.h" #include "sync/notifier/invalidation_state_tracker.h" @@ -45,7 +45,7 @@ class SyncPrefObserver { // two_client_preferences_sync_test.cc class SyncPrefs : NON_EXPORTED_BASE(public base::NonThreadSafe), public base::SupportsWeakPtr<SyncPrefs>, - public content::NotificationObserver { + public PrefObserver { public: // |pref_service| may be NULL (for unit tests), but in that case no // setter methods should be called. Does not take ownership of @@ -116,10 +116,9 @@ class SyncPrefs : NON_EXPORTED_BASE(public base::NonThreadSafe), // Merges the given set of types with the set of acknowledged types. void AcknowledgeSyncedTypes(syncer::ModelTypeSet types); - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // For testing. diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc index b3bdca7..641b64c 100644 --- a/chrome/browser/translate/translate_manager.cc +++ b/chrome/browser/translate/translate_manager.cc @@ -409,18 +409,17 @@ void TranslateManager::Observe(int type, delete pref_change_registrar; break; } - case chrome::NOTIFICATION_PREF_CHANGED: { - DCHECK(*content::Details<std::string>(details).ptr() == - prefs::kAcceptLanguages); - PrefService* prefs = content::Source<PrefService>(source).ptr(); - InitAcceptLanguages(prefs); - break; - } default: NOTREACHED(); } } +void TranslateManager::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK_EQ(std::string(prefs::kAcceptLanguages), pref_name); + InitAcceptLanguages(service); +} + void TranslateManager::OnURLFetchComplete(const net::URLFetcher* source) { if (translate_script_request_pending_.get() != source && language_list_request_pending_.get() != source) { @@ -789,7 +788,7 @@ bool TranslateManager::IsAcceptLanguage(WebContents* web_contents, return iter->second.count(language) != 0; } -void TranslateManager::InitAcceptLanguages(PrefService* prefs) { +void TranslateManager::InitAcceptLanguages(PrefServiceBase* prefs) { // We have been asked for this profile, build the languages. std::string accept_langs_str = prefs->GetString(prefs::kAcceptLanguages); std::vector<std::string> accept_langs_list; diff --git a/chrome/browser/translate/translate_manager.h b/chrome/browser/translate/translate_manager.h index 93eca3a..a94a7be 100644 --- a/chrome/browser/translate/translate_manager.h +++ b/chrome/browser/translate/translate_manager.h @@ -15,6 +15,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/time.h" #include "chrome/common/translate_errors.h" #include "content/public/browser/notification_observer.h" @@ -25,6 +26,7 @@ template <typename T> struct DefaultSingletonTraits; class GURL; struct PageTranslatedDetails; class PrefService; +class PrefServiceBase; class TranslateInfoBarDelegate; namespace content { @@ -41,6 +43,7 @@ class URLFetcher; // It is a singleton. class TranslateManager : public content::NotificationObserver, + public PrefObserver, public net::URLFetcherDelegate { public: // Returns the singleton instance. @@ -82,6 +85,10 @@ class TranslateManager : public content::NotificationObserver, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // net::URLFetcherDelegate implementation: virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; @@ -167,7 +174,7 @@ class TranslateManager : public content::NotificationObserver, // Initializes the |accept_languages_| language table based on the associated // preference in |prefs|. - void InitAcceptLanguages(PrefService* prefs); + void InitAcceptLanguages(PrefServiceBase* prefs); // Fetches the JS translate script (the script that is injected in the page // to translate it). @@ -199,7 +206,7 @@ class TranslateManager : public content::NotificationObserver, // A map that associates a profile with its parsed "accept languages". typedef std::set<std::string> LanguageSet; - typedef std::map<PrefService*, LanguageSet> PrefServiceLanguagesMap; + typedef std::map<PrefServiceBase*, LanguageSet> PrefServiceLanguagesMap; PrefServiceLanguagesMap accept_languages_; base::WeakPtrFactory<TranslateManager> weak_method_factory_; diff --git a/chrome/browser/translate/translate_manager_browsertest.cc b/chrome/browser/translate/translate_manager_browsertest.cc index 30cd55b..e5d26d9 100644 --- a/chrome/browser/translate/translate_manager_browsertest.cc +++ b/chrome/browser/translate/translate_manager_browsertest.cc @@ -10,6 +10,7 @@ #include "base/json/json_writer.h" #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "base/values.h" @@ -92,7 +93,8 @@ class NavEntryCommittedObserver : public content::NotificationObserver { }; class TranslateManagerTest : public ChromeRenderViewHostTestHarness, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: TranslateManagerTest() : ui_thread_(BrowserThread::UI, &message_loop_) { @@ -214,6 +216,8 @@ class TranslateManagerTest : public ChromeRenderViewHostTestHarness, content::Details<InfoBarRemovedDetails>(details)->first); } + MOCK_METHOD2(OnPreferenceChanged, void(PrefServiceBase*, const std::string&)); + protected: virtual void SetUp() { WebKit::initialize(webkit_platform_support_.Get()); @@ -291,15 +295,9 @@ class TranslateManagerTest : public ChromeRenderViewHostTestHarness, } void SetPrefObserverExpectation(const char* path) { - EXPECT_CALL( - pref_observer_, - Observe(int(chrome::NOTIFICATION_PREF_CHANGED), - _, - Property(&content::Details<std::string>::ptr, Pointee(path)))); + EXPECT_CALL(*this, OnPreferenceChanged(_, std::string(path))); } - content::MockNotificationObserver pref_observer_; - private: content::NotificationRegistrar notification_registrar_; net::TestURLFetcherFactory url_fetcher_factory_; @@ -1094,8 +1092,7 @@ TEST_F(TranslateManagerTest, NeverTranslateLanguagePref) { PrefService* prefs = profile->GetPrefs(); PrefChangeRegistrar registrar; registrar.Init(prefs); - registrar.Add(TranslatePrefs::kPrefTranslateLanguageBlacklist, - &pref_observer_); + registrar.Add(TranslatePrefs::kPrefTranslateLanguageBlacklist, this); TranslatePrefs translate_prefs(prefs); EXPECT_FALSE(translate_prefs.IsLanguageBlacklisted("fr")); EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url)); @@ -1142,8 +1139,7 @@ TEST_F(TranslateManagerTest, NeverTranslateSitePref) { PrefService* prefs = profile->GetPrefs(); PrefChangeRegistrar registrar; registrar.Init(prefs); - registrar.Add(TranslatePrefs::kPrefTranslateSiteBlacklist, - &pref_observer_); + registrar.Add(TranslatePrefs::kPrefTranslateSiteBlacklist, this); TranslatePrefs translate_prefs(prefs); EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(host)); EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url)); @@ -1182,8 +1178,7 @@ TEST_F(TranslateManagerTest, AlwaysTranslateLanguagePref) { PrefService* prefs = profile->GetPrefs(); PrefChangeRegistrar registrar; registrar.Init(prefs); - registrar.Add(TranslatePrefs::kPrefTranslateWhitelists, - &pref_observer_); + registrar.Add(TranslatePrefs::kPrefTranslateWhitelists, this); TranslatePrefs translate_prefs(prefs); SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); translate_prefs.WhitelistLanguagePair("fr", "en"); diff --git a/chrome/browser/ui/alternate_error_tab_observer.cc b/chrome/browser/ui/alternate_error_tab_observer.cc index 73347f4..569a739 100644 --- a/chrome/browser/ui/alternate_error_tab_observer.cc +++ b/chrome/browser/ui/alternate_error_tab_observer.cc @@ -56,13 +56,18 @@ void AlternateErrorPageTabObserver::Observe( int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - DCHECK_EQ(profile_->GetPrefs(), content::Source<PrefService>(source).ptr()); - DCHECK_EQ(std::string(prefs::kAlternateErrorPagesEnabled), - *content::Details<std::string>(details).ptr()); - } else { - DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type); - } + DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type); + UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); +} + +//////////////////////////////////////////////////////////////////////////////// +// PrefObserver overrides + +void AlternateErrorPageTabObserver::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { + DCHECK_EQ(profile_->GetPrefs(), service); + DCHECK(prefs::kAlternateErrorPagesEnabled == pref_name); UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); } diff --git a/chrome/browser/ui/alternate_error_tab_observer.h b/chrome/browser/ui/alternate_error_tab_observer.h index d5da940..071dea8 100644 --- a/chrome/browser/ui/alternate_error_tab_observer.h +++ b/chrome/browser/ui/alternate_error_tab_observer.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_UI_ALTERNATE_ERROR_TAB_OBSERVER_H_ #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/prefs/pref_service.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -18,7 +19,8 @@ class Profile; class AlternateErrorPageTabObserver : public content::WebContentsObserver, public content::NotificationObserver, - public content::WebContentsUserData<AlternateErrorPageTabObserver> { + public content::WebContentsUserData<AlternateErrorPageTabObserver>, + public PrefObserver { public: virtual ~AlternateErrorPageTabObserver(); @@ -37,6 +39,10 @@ class AlternateErrorPageTabObserver const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver overrides: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Internal helpers ---------------------------------------------------------- // Returns the server that can provide alternate error pages. If the returned diff --git a/chrome/browser/ui/app_list/apps_model_builder.cc b/chrome/browser/ui/app_list/apps_model_builder.cc index 9eb65a2..8dba307 100644 --- a/chrome/browser/ui/app_list/apps_model_builder.cc +++ b/chrome/browser/ui/app_list/apps_model_builder.cc @@ -208,15 +208,16 @@ void AppsModelBuilder::Observe(int type, HighlightApp(); break; } - case chrome::NOTIFICATION_PREF_CHANGED: { - ResortApps(); - break; - } default: NOTREACHED(); } } +void AppsModelBuilder::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + ResortApps(); +} + void AppsModelBuilder::ListItemsAdded(size_t start, size_t count) { } diff --git a/chrome/browser/ui/app_list/apps_model_builder.h b/chrome/browser/ui/app_list/apps_model_builder.h index 5c91583..b943a9a 100644 --- a/chrome/browser/ui/app_list/apps_model_builder.h +++ b/chrome/browser/ui/app_list/apps_model_builder.h @@ -9,6 +9,7 @@ #include "base/gtest_prod_util.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "ui/app_list/app_list_model.h" @@ -19,6 +20,7 @@ class ExtensionAppItem; class Profile; class AppsModelBuilder : public content::NotificationObserver, + public PrefObserver, public ui::ListModelObserver { public: AppsModelBuilder(Profile* profile, @@ -56,6 +58,10 @@ class AppsModelBuilder : public content::NotificationObserver, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // ui::ListModelObserver overrides: virtual void ListItemsAdded(size_t start, size_t count) OVERRIDE; virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE; diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc index 4d0fe51..cd8aef2 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc @@ -784,25 +784,25 @@ void ChromeLauncherController::Observe( app_icon_loader_->ClearImage(extension->id()); break; } - case chrome::NOTIFICATION_PREF_CHANGED: { - const std::string& pref_name( - *content::Details<std::string>(details).ptr()); - if (pref_name == prefs::kPinnedLauncherApps) { - UpdateAppLaunchersFromPref(); - } else if (pref_name == prefs::kShelfAlignmentLocal) { - SetShelfAlignmentFromPrefs(); - } else if (pref_name == prefs::kShelfAutoHideBehaviorLocal) { - SetShelfAutoHideBehaviorFromPrefs(); - } else { - NOTREACHED() << "Unexpected pref change for " << pref_name; - } - break; - } default: NOTREACHED() << "Unexpected notification type=" << type; } } +void ChromeLauncherController::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kPinnedLauncherApps) { + UpdateAppLaunchersFromPref(); + } else if (pref_name == prefs::kShelfAlignmentLocal) { + SetShelfAlignmentFromPrefs(); + } else if (pref_name == prefs::kShelfAutoHideBehaviorLocal) { + SetShelfAutoHideBehaviorFromPrefs(); + } else { + NOTREACHED() << "Unexpected pref change for " << pref_name; + } +} + void ChromeLauncherController::OnShelfAlignmentChanged() { const char* pref_value = NULL; // TODO(oshima): Support multiple displays. diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h index e27982c..0c5a04b 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h @@ -18,6 +18,7 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/timer.h" #include "chrome/browser/api/sync/profile_sync_service_observer.h" #include "chrome/browser/prefs/pref_service_observer.h" @@ -55,6 +56,7 @@ class ChromeLauncherController public ash::LauncherModelObserver, public ash::ShellObserver, public content::NotificationObserver, + public PrefObserver, public ProfileSyncServiceObserver, public PrefServiceObserver { public: @@ -263,6 +265,10 @@ class ChromeLauncherController const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // Overridden from PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Overridden from ash::ShellObserver: virtual void OnShelfAlignmentChanged() OVERRIDE; diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index d8051d3..005d66c 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -1916,23 +1916,6 @@ void Browser::Observe(int type, break; #endif - case chrome::NOTIFICATION_PREF_CHANGED: { - const std::string& pref_name = - *content::Details<std::string>(details).ptr(); - if (pref_name == prefs::kDevToolsDisabled) { - if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) - content::DevToolsManager::GetInstance()->CloseAllClientHosts(); - } else if (pref_name == prefs::kShowBookmarkBar) { - UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE); - } else if (pref_name == prefs::kHomePage) { - PrefService* pref_service = content::Source<PrefService>(source).ptr(); - MarkHomePageAsChanged(pref_service); - } else { - NOTREACHED(); - } - break; - } - case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { WebContents* web_contents = content::Source<WebContents>(source).ptr(); if (web_contents == chrome::GetActiveWebContents(this)) { @@ -1956,6 +1939,20 @@ void Browser::Observe(int type, } } +void Browser::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kDevToolsDisabled) { + if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) + content::DevToolsManager::GetInstance()->CloseAllClientHosts(); + } else if (pref_name == prefs::kShowBookmarkBar) { + UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE); + } else if (pref_name == prefs::kHomePage) { + MarkHomePageAsChanged(static_cast<PrefService*>(service)); + } else { + NOTREACHED(); + } +} + void Browser::ModeChanged(const chrome::search::Mode& old_mode, const chrome::search::Mode& new_mode) { UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index 76f82ee..a4148f2 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -16,6 +16,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/string16.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/debugger/devtools_toggle_action.h" @@ -36,6 +37,7 @@ #include "chrome/common/content_settings.h" #include "chrome/common/content_settings_types.h" #include "chrome/common/extensions/extension_constants.h" +#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/page_navigator.h" #include "content/public/browser/web_contents_delegate.h" @@ -106,6 +108,7 @@ class Browser : public TabStripModelObserver, public ZoomObserver, public content::PageNavigator, public content::NotificationObserver, + public PrefObserver, public ui::SelectFileDialog::Listener, public chrome::search::SearchModelObserver { public: @@ -691,6 +694,10 @@ class Browser : public TabStripModelObserver, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // Overridden from PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Overridden from chrome::search::SearchModelObserver: virtual void ModeChanged(const chrome::search::Mode& old_mode, const chrome::search::Mode& new_mode) OVERRIDE; diff --git a/chrome/browser/ui/browser_command_controller.cc b/chrome/browser/ui/browser_command_controller.cc index ae7c6db..b871deb 100644 --- a/chrome/browser/ui/browser_command_controller.cc +++ b/chrome/browser/ui/browser_command_controller.cc @@ -664,29 +664,6 @@ void BrowserCommandController::Observe( const content::NotificationSource& source, const content::NotificationDetails& details) { switch (type) { - case NOTIFICATION_PREF_CHANGED: { - const std::string& pref_name = - *content::Details<std::string>(details).ptr(); - if (pref_name == prefs::kPrintingEnabled) { - UpdatePrintingState(); - } else if (pref_name == prefs::kIncognitoModeAvailability) { - UpdateCommandsForIncognitoAvailability(); - } else if (pref_name == prefs::kDevToolsDisabled) { - UpdateCommandsForDevTools(); - } else if (pref_name == prefs::kEditBookmarksEnabled) { - UpdateCommandsForBookmarkEditing(); - } else if (pref_name == prefs::kShowBookmarkBar) { - UpdateCommandsForBookmarkBar(); - } else if (pref_name == prefs::kAllowFileSelectionDialogs) { - UpdateSaveAsState(); - UpdateOpenFileState(); - } else if (pref_name == prefs::kInManagedMode) { - UpdateCommandsForMultipleProfiles(); - } else { - NOTREACHED(); - } - break; - } case content::NOTIFICATION_INTERSTITIAL_ATTACHED: UpdateCommandsForTabState(); break; @@ -701,6 +678,32 @@ void BrowserCommandController::Observe( } //////////////////////////////////////////////////////////////////////////////// +// PrefObserver implementation: + +void BrowserCommandController::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kPrintingEnabled) { + UpdatePrintingState(); + } else if (pref_name == prefs::kIncognitoModeAvailability) { + UpdateCommandsForIncognitoAvailability(); + } else if (pref_name == prefs::kDevToolsDisabled) { + UpdateCommandsForDevTools(); + } else if (pref_name == prefs::kEditBookmarksEnabled) { + UpdateCommandsForBookmarkEditing(); + } else if (pref_name == prefs::kShowBookmarkBar) { + UpdateCommandsForBookmarkBar(); + } else if (pref_name == prefs::kAllowFileSelectionDialogs) { + UpdateSaveAsState(); + UpdateOpenFileState(); + } else if (pref_name == prefs::kInManagedMode) { + UpdateCommandsForMultipleProfiles(); + } else { + NOTREACHED(); + } +} + +//////////////////////////////////////////////////////////////////////////////// // BrowserCommandController, TabStripModelObserver implementation: void BrowserCommandController::TabInsertedAt(TabContents* contents, diff --git a/chrome/browser/ui/browser_command_controller.h b/chrome/browser/ui/browser_command_controller.h index ccce17c..5ef5b5c 100644 --- a/chrome/browser/ui/browser_command_controller.h +++ b/chrome/browser/ui/browser_command_controller.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_ #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/sync/profile_sync_service_observer.h" #include "chrome/browser/command_updater.h" #include "chrome/browser/sessions/tab_restore_service_observer.h" @@ -27,6 +28,7 @@ namespace chrome { class BrowserCommandController : public CommandUpdater::CommandUpdaterDelegate, public content::NotificationObserver, + public PrefObserver, public TabStripModelObserver, public TabRestoreServiceObserver, public ProfileSyncServiceObserver { @@ -86,6 +88,10 @@ class BrowserCommandController : public CommandUpdater::CommandUpdaterDelegate, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // Overridden from PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Overridden from TabStripModelObserver: virtual void TabInsertedAt(TabContents* contents, int index, diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc index 66defb1..5f6319a 100644 --- a/chrome/browser/ui/browser_instant_controller.cc +++ b/chrome/browser/ui/browser_instant_controller.cc @@ -104,15 +104,12 @@ TabContents* BrowserInstantController::GetActiveTabContents() const { } //////////////////////////////////////////////////////////////////////////////// -// BrowserInstantController, content::NotificationObserver implementation: - -void BrowserInstantController::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - DCHECK_EQ(std::string(prefs::kInstantEnabled), - *content::Details<std::string>(details).ptr()); +// BrowserInstantController, PrefObserver implementation: + +void BrowserInstantController::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { + DCHECK_EQ(std::string(prefs::kInstantEnabled), pref_name); ResetInstant(); } diff --git a/chrome/browser/ui/browser_instant_controller.h b/chrome/browser/ui/browser_instant_controller.h index 24e6868..13a1e2f 100644 --- a/chrome/browser/ui/browser_instant_controller.h +++ b/chrome/browser/ui/browser_instant_controller.h @@ -9,12 +9,12 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/string16.h" #include "chrome/browser/instant/instant_unload_handler.h" #include "chrome/browser/ui/search/search_model_observer.h" #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" #include "chrome/common/instant_types.h" -#include "content/public/browser/notification_observer.h" #include "webkit/glue/window_open_disposition.h" class Browser; @@ -22,11 +22,6 @@ class InstantController; class InstantTest; class TabContents; -namespace content { -class NotificationDetails; -class NotificationSource; -} - namespace gfx { class Rect; } @@ -35,7 +30,7 @@ namespace chrome { class BrowserInstantController : public TabStripModelObserver, public search::SearchModelObserver, - public content::NotificationObserver { + public PrefObserver { public: explicit BrowserInstantController(Browser* browser); virtual ~BrowserInstantController(); @@ -67,10 +62,9 @@ class BrowserInstantController : public TabStripModelObserver, // preview would be shown. TabContents* GetActiveTabContents() const; - // Overridden from content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // Overridden from PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // Overridden from TabStripModelObserver: virtual void TabDeactivated(TabContents* contents) OVERRIDE; diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.h b/chrome/browser/ui/cocoa/browser_window_cocoa.h index d815aba..fd9c923e 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.h +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.h @@ -8,10 +8,10 @@ #include "base/memory/scoped_nsobject.h" #include "base/memory/weak_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/extensions/extension_keybinding_registry.h" #include "chrome/browser/ui/browser_window.h" -#include "content/public/browser/notification_registrar.h" #include "ui/base/ui_base_types.h" class Browser; @@ -32,7 +32,7 @@ class Extension; class BrowserWindowCocoa : public BrowserWindow, - public content::NotificationObserver, + public PrefObserver, public extensions::ExtensionKeybindingRegistry::Delegate { public: BrowserWindowCocoa(Browser* browser, @@ -147,9 +147,8 @@ class BrowserWindowCocoa : virtual void ShowAvatarBubbleFromAvatarButton() OVERRIDE; // Overridden from NotificationObserver - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // Overridden from ExtensionKeybindingRegistry::Delegate: virtual extensions::ActiveTabPermissionGranter* @@ -167,7 +166,6 @@ class BrowserWindowCocoa : private: NSWindow* window() const; // Accessor for the (current) |NSWindow|. - content::NotificationRegistrar registrar_; PrefChangeRegistrar pref_change_registrar_; Browser* browser_; // weak, owned by controller BrowserWindowController* controller_; // weak, owns us diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm index b15fb7c..1c875c6 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm @@ -614,21 +614,10 @@ bool BrowserWindowCocoa::GetConstrainedWindowTopY(int* top_y) { return false; } -void BrowserWindowCocoa::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: { - const std::string& pref_name = - *content::Details<std::string>(details).ptr(); - DCHECK(pref_name == prefs::kShowBookmarkBar); - [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; - break; - } - default: - NOTREACHED(); // we don't ask for anything else! - break; - } +void BrowserWindowCocoa::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK(pref_name == prefs::kShowBookmarkBar); + [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; } extensions::ActiveTabPermissionGranter* diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa_unittest.mm b/chrome/browser/ui/cocoa/browser_window_cocoa_unittest.mm index e5814f8..1e2f4ce 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa_unittest.mm +++ b/chrome/browser/ui/cocoa/browser_window_cocoa_unittest.mm @@ -4,6 +4,7 @@ #include "base/memory/scoped_nsobject.h" #include "base/memory/scoped_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "base/string_util.h" #include "chrome/browser/bookmarks/bookmark_utils.h" #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" @@ -19,7 +20,7 @@ // A BrowserWindowCocoa that goes PONG when // BOOKMARK_BAR_VISIBILITY_PREF_CHANGED is sent. This is so we can be // sure we are observing it. -class BrowserWindowCocoaPong : public BrowserWindowCocoa { +class BrowserWindowCocoaPong : public BrowserWindowCocoa, public PrefObserver { public: BrowserWindowCocoaPong(Browser* browser, BrowserWindowController* controller) @@ -28,16 +29,10 @@ class BrowserWindowCocoaPong : public BrowserWindowCocoa { } virtual ~BrowserWindowCocoaPong() { } - void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - const std::string& pref_name = - *content::Details<std::string>(details).ptr(); - if (pref_name == prefs::kShowBookmarkBar) - pong_ = true; - } - BrowserWindowCocoa::Observe(type, source, details); + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE { + if (pref_name == prefs::kShowBookmarkBar) + pong_ = true; } bool pong_; diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h index 3290143..bba88ff 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h @@ -13,6 +13,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "base/memory/weak_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/extensions/image_loading_tracker.h" #include "chrome/browser/ui/browser.h" @@ -45,7 +46,8 @@ class ZoomDecoration; class LocationBarViewMac : public LocationBar, public LocationBarTesting, public OmniboxEditController, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: LocationBarViewMac(AutocompleteTextField* field, CommandUpdater* command_updater, @@ -181,6 +183,10 @@ class LocationBarViewMac : public LocationBar, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + Browser* browser() const { return browser_; } private: diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm index b560bcd..1148992 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm @@ -593,17 +593,18 @@ void LocationBarViewMac::Observe(int type, break; } - case chrome::NOTIFICATION_PREF_CHANGED: - UpdateStarDecorationVisibility(); - OnChanged(); - break; - default: NOTREACHED() << "Unexpected notification"; break; } } +void LocationBarViewMac::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + UpdateStarDecorationVisibility(); + OnChanged(); +} + void LocationBarViewMac::PostNotification(NSString* notification) { [[NSNotificationCenter defaultCenter] postNotificationName:notification object:[NSValue valueWithPointer:this]]; diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm index 91f2fee..39f326e 100644 --- a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm @@ -9,6 +9,7 @@ #include "base/mac/bundle_locations.h" #include "base/mac/mac_util.h" #include "base/memory/singleton.h" +#include "base/prefs/public/pref_observer.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "base/utf_string_conversions.h" @@ -87,7 +88,7 @@ const CGFloat kWrenchMenuLeftPadding = 3.0; @property(assign, nonatomic) Browser* browser; - (void)addAccessibilityDescriptions; - (void)initCommandStatus:(CommandUpdater*)commands; -- (void)prefChanged:(std::string*)prefName; +- (void)prefChanged:(const std::string&)prefName; - (BackgroundGradientView*)backgroundGradientView; - (void)toolbarFrameChanged; - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; @@ -105,7 +106,9 @@ namespace ToolbarControllerInternal { // A class registered for C++ notifications. This is used to detect changes in // preferences and upgrade available notifications. Bridges the notification // back to the ToolbarController. -class NotificationBridge : public content::NotificationObserver { +class NotificationBridge + : public content::NotificationObserver, + public PrefObserver { public: explicit NotificationBridge(ToolbarController* controller) : controller_(controller) { @@ -118,11 +121,8 @@ class NotificationBridge : public content::NotificationObserver { // Overridden from content::NotificationObserver: virtual void Observe(int type, const content::NotificationSource& source, - const content::NotificationDetails& details) { + const content::NotificationDetails& details) OVERRIDE { switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: - [controller_ prefChanged:content::Details<std::string>(details).ptr()]; - break; case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: [controller_ badgeWrenchMenuIfNeeded]; @@ -132,6 +132,12 @@ class NotificationBridge : public content::NotificationObserver { } } + // Overridden from PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE { + [controller_ prefChanged:pref_name]; + } + private: ToolbarController* controller_; // weak, owns us @@ -563,9 +569,8 @@ class NotificationBridge : public content::NotificationObserver { [[wrenchButton_ cell] setOverlayImageID:error_badge_id]; } -- (void)prefChanged:(std::string*)prefName { - if (!prefName) return; - if (*prefName == prefs::kShowHomeButton) { +- (void)prefChanged:(const std::string&)prefName { + if (prefName == prefs::kShowHomeButton) { [self showOptionalHomeButton]; } } diff --git a/chrome/browser/ui/gesture_prefs_observer_factory_aura.cc b/chrome/browser/ui/gesture_prefs_observer_factory_aura.cc index 16fa3ef..5cd51d3 100644 --- a/chrome/browser/ui/gesture_prefs_observer_factory_aura.cc +++ b/chrome/browser/ui/gesture_prefs_observer_factory_aura.cc @@ -6,6 +6,7 @@ #include "base/compiler_specific.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_dependency_manager.h" @@ -19,7 +20,7 @@ using ui::GestureConfiguration; namespace { // This class manages gesture configuration preferences. -class GesturePrefsObserver : public content::NotificationObserver, +class GesturePrefsObserver : public PrefObserver, public ProfileKeyedService { public: explicit GesturePrefsObserver(PrefService* prefs); @@ -28,10 +29,9 @@ class GesturePrefsObserver : public content::NotificationObserver, // ProfileKeyedService implementation. virtual void Shutdown() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; private: void Update(); @@ -81,10 +81,8 @@ void GesturePrefsObserver::Shutdown() { registrar_.RemoveAll(); } -void GesturePrefsObserver::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { +void GesturePrefsObserver::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { Update(); } diff --git a/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc b/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc index 3b1b912..7f1b30b 100644 --- a/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc +++ b/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc @@ -980,14 +980,15 @@ void BookmarkBarGtk::Observe(int type, } SetOverflowButtonAppearance(); - } else if (type == chrome::NOTIFICATION_PREF_CHANGED) { - const std::string& pref_name = - *content::Details<std::string>(details).ptr(); - if (pref_name == prefs::kEditBookmarksEnabled) - OnEditBookmarksEnabledChanged(); } } +void BookmarkBarGtk::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kEditBookmarksEnabled) + OnEditBookmarksEnabledChanged(); +} + GtkWidget* BookmarkBarGtk::CreateBookmarkButton(const BookmarkNode* node) { GtkWidget* button = theme_service_->BuildChromeButton(); bookmark_utils::ConfigureButtonForNode(node, model_, button, theme_service_); diff --git a/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h b/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h index 774c076..61f78a6 100644 --- a/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h +++ b/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h @@ -13,6 +13,7 @@ #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" #include "chrome/browser/ui/bookmarks/bookmark_bar.h" @@ -46,6 +47,7 @@ class BookmarkBarGtk : public ui::AnimationDelegate, public BookmarkModelObserver, public MenuBarHelper::Delegate, public content::NotificationObserver, + public PrefObserver, public chrome::BookmarkBarInstructionsDelegate, public BookmarkContextMenuControllerDelegate { public: @@ -236,6 +238,11 @@ class BookmarkBarGtk : public ui::AnimationDelegate, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // Overridden from PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + + GtkWidget* CreateBookmarkButton(const BookmarkNode* node); GtkToolItem* CreateBookmarkToolItem(const BookmarkNode* node); diff --git a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc index d272e1e..6919a515 100644 --- a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc @@ -250,6 +250,7 @@ void BrowserToolbarGtk::Init(GtkWindow* top_level_window) { if (actions_toolbar_->button_count() == 0) gtk_widget_hide(actions_toolbar_->widget()); } + // Initialize pref-dependent UI state. NotifyPrefChanged(NULL); @@ -368,9 +369,7 @@ bool BrowserToolbarGtk::GetAcceleratorForCommandId( void BrowserToolbarGtk::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - NotifyPrefChanged(content::Details<std::string>(details).ptr()); - } else if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { + if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { // Update the spacing around the menu buttons bool use_gtk = theme_service_->UsingNativeTheme(); int border = use_gtk ? 0 : 2; @@ -426,6 +425,11 @@ void BrowserToolbarGtk::Observe(int type, } } +void BrowserToolbarGtk::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + NotifyPrefChanged(&pref_name); +} + // BrowserToolbarGtk, public --------------------------------------------------- void BrowserToolbarGtk::UpdateWebContents(WebContents* contents, diff --git a/chrome/browser/ui/gtk/browser_toolbar_gtk.h b/chrome/browser/ui/gtk/browser_toolbar_gtk.h index e8e6617..1d141e4 100644 --- a/chrome/browser/ui/gtk/browser_toolbar_gtk.h +++ b/chrome/browser/ui/gtk/browser_toolbar_gtk.h @@ -10,6 +10,7 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/command_observer.h" #include "chrome/browser/ui/gtk/custom_button.h" @@ -43,7 +44,8 @@ class WebContents; class BrowserToolbarGtk : public CommandObserver, public ui::AcceleratorProvider, public MenuGtk::Delegate, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window); virtual ~BrowserToolbarGtk(); @@ -104,6 +106,10 @@ class BrowserToolbarGtk : public CommandObserver, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Whether the wrench/hotdogs menu is currently visible to the user. bool IsWrenchMenuShowing() const; @@ -143,7 +149,7 @@ class BrowserToolbarGtk : public CommandObserver, CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnWrenchMenuButtonExpose, GdkEventExpose*); - // Updates preference-dependent state. + // Updates preference-dependent state. |pref| may be NULL. void NotifyPrefChanged(const std::string* pref); static void SetSyncMenuLabel(GtkWidget* widget, gpointer userdata); diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc index 92a4ba3..755521d 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.cc +++ b/chrome/browser/ui/gtk/browser_window_gtk.cc @@ -1185,26 +1185,22 @@ void BrowserWindowGtk::ConfirmBrowserCloseWithPendingDownloads() { void BrowserWindowGtk::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: { - std::string* pref_name = content::Details<std::string>(details).ptr(); - if (*pref_name == prefs::kUseCustomChromeFrame) { - UpdateCustomFrame(); - ui::SetHideTitlebarWhenMaximizedProperty( - ui::GetX11WindowFromGtkWidget(GTK_WIDGET(window_)), - UseCustomFrame() ? ui::HIDE_TITLEBAR_WHEN_MAXIMIZED - : ui::SHOW_TITLEBAR_WHEN_MAXIMIZED); - } else { - NOTREACHED() << "Got pref change notification we didn't register for!"; - } - break; - } - case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: - // The profile avatar icon may have changed. - gtk_util::SetWindowIcon(window_, browser_->profile()); - break; - default: - break; + DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); + // The profile avatar icon may have changed. + gtk_util::SetWindowIcon(window_, browser_->profile()); +} + +void BrowserWindowGtk::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kUseCustomChromeFrame) { + UpdateCustomFrame(); + ui::SetHideTitlebarWhenMaximizedProperty( + ui::GetX11WindowFromGtkWidget(GTK_WIDGET(window_)), + UseCustomFrame() ? + ui::HIDE_TITLEBAR_WHEN_MAXIMIZED : + ui::SHOW_TITLEBAR_WHEN_MAXIMIZED); + } else { + NOTREACHED() << "Got pref change notification we didn't register for!"; } } diff --git a/chrome/browser/ui/gtk/browser_window_gtk.h b/chrome/browser/ui/gtk/browser_window_gtk.h index c0015c2..7c2e5d0 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.h +++ b/chrome/browser/ui/gtk/browser_window_gtk.h @@ -12,6 +12,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "base/timer.h" #include "build/build_config.h" #include "chrome/browser/api/prefs/pref_member.h" @@ -60,6 +61,7 @@ class Extension; class BrowserWindowGtk : public BrowserWindow, public content::NotificationObserver, + public PrefObserver, public TabStripModelObserver, public ui::ActiveWindowWatcherXObserver, public InfoBarContainer::Delegate, @@ -181,6 +183,10 @@ class BrowserWindowGtk const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // Overridden from PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Overridden from TabStripModelObserver: virtual void TabDetachedAt(TabContents* contents, int index) OVERRIDE; virtual void ActiveTabChanged(TabContents* old_contents, diff --git a/chrome/browser/ui/gtk/global_menu_bar.cc b/chrome/browser/ui/gtk/global_menu_bar.cc index 7ea211d..31cf7fc 100644 --- a/chrome/browser/ui/gtk/global_menu_bar.cc +++ b/chrome/browser/ui/gtk/global_menu_bar.cc @@ -281,11 +281,8 @@ void GlobalMenuBar::EnabledStateChangedForCommand(int id, bool enabled) { gtk_widget_set_sensitive(it->second, enabled); } -void GlobalMenuBar::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - const std::string& pref_name = *content::Details<std::string>(details).ptr(); +void GlobalMenuBar::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { DCHECK_EQ(prefs::kShowBookmarkBar, pref_name); OnBookmarkBarVisibilityChanged(); } diff --git a/chrome/browser/ui/gtk/global_menu_bar.h b/chrome/browser/ui/gtk/global_menu_bar.h index ba72f89..a1682d6 100644 --- a/chrome/browser/ui/gtk/global_menu_bar.h +++ b/chrome/browser/ui/gtk/global_menu_bar.h @@ -9,9 +9,9 @@ #include "base/compiler_specific.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/command_observer.h" #include "chrome/browser/ui/gtk/global_history_menu.h" -#include "content/public/browser/notification_observer.h" #include "ui/base/gtk/gtk_signal.h" #include "ui/base/gtk/owned_widget_gtk.h" @@ -31,7 +31,7 @@ typedef struct _GtkWidget GtkWidget; // bar itself is visible, so we insert a GtkMenuBar into the window hierarchy // and set it to be invisible. class GlobalMenuBar : public CommandObserver, - public content::NotificationObserver { + public PrefObserver { public: static const int TAG_NORMAL = 0; static const int TAG_MOST_VISITED = 1; @@ -68,10 +68,9 @@ class GlobalMenuBar : public CommandObserver, // CommandObserver: virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE; - // content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // Updates the visibility of the bookmark bar on pref changes. void OnBookmarkBarVisibilityChanged(); diff --git a/chrome/browser/ui/gtk/gtk_theme_service.cc b/chrome/browser/ui/gtk/gtk_theme_service.cc index 814c535..cfb3368 100644 --- a/chrome/browser/ui/gtk/gtk_theme_service.cc +++ b/chrome/browser/ui/gtk/gtk_theme_service.cc @@ -367,15 +367,10 @@ bool GtkThemeService::UsingNativeTheme() const { return use_gtk_; } -void GtkThemeService::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if ((type == chrome::NOTIFICATION_PREF_CHANGED) && - (*content::Details<std::string>(details).ptr() == - prefs::kUsesSystemTheme)) { +void GtkThemeService::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kUsesSystemTheme) { use_gtk_ = profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); - } else { - ThemeService::Observe(type, source, details); } } diff --git a/chrome/browser/ui/gtk/gtk_theme_service.h b/chrome/browser/ui/gtk/gtk_theme_service.h index 12dba20..1d4f147 100644 --- a/chrome/browser/ui/gtk/gtk_theme_service.h +++ b/chrome/browser/ui/gtk/gtk_theme_service.h @@ -12,8 +12,8 @@ #include "base/lazy_instance.h" #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/themes/theme_service.h" -#include "content/public/browser/notification_observer.h" #include "ui/base/glib/glib_integers.h" #include "ui/base/gtk/gtk_signal.h" #include "ui/base/gtk/owned_widget_gtk.h" @@ -41,7 +41,7 @@ typedef struct _GtkStyle GtkStyle; typedef struct _GtkWidget GtkWidget; // Specialization of ThemeService which supplies system colors. -class GtkThemeService : public ThemeService { +class GtkThemeService : public ThemeService, public PrefObserver { public: // A list of integer keys for a separate PerDisplaySurfaceMap that keeps // what would otherwise be static icons on the X11 server. @@ -77,10 +77,9 @@ class GtkThemeService : public ThemeService { virtual bool UsingDefaultTheme() const OVERRIDE; virtual bool UsingNativeTheme() const OVERRIDE; - // Overridden from ThemeService, content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // Overridden from PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // Creates a GtkChromeButton instance, registered with this theme provider, // with a "destroy" signal to remove it from our internal list when it goes diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc index a90d22f..083b28d 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc @@ -1103,17 +1103,6 @@ void LocationBarViewGtk::Observe(int type, break; } - case chrome::NOTIFICATION_PREF_CHANGED: { - std::string* pref_name_in = content::Details<std::string>(details).ptr(); - DCHECK(pref_name_in); - - if (*pref_name_in == prefs::kEditBookmarksEnabled) - UpdateStarIcon(); - else - NOTREACHED(); - break; - } - case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { if (theme_service_->UsingNativeTheme()) { gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, NULL); @@ -1176,6 +1165,14 @@ void LocationBarViewGtk::Observe(int type, } } +void LocationBarViewGtk::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kEditBookmarksEnabled) + UpdateStarIcon(); + else + NOTREACHED(); +} + gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget, GdkEventExpose* event) { // If we're not using GTK theming, draw our own border over the edge pixels diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.h b/chrome/browser/ui/gtk/location_bar_view_gtk.h index f243c40..fee357d 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.h +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.h @@ -16,6 +16,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "base/memory/weak_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_icon_factory.h" @@ -61,7 +62,8 @@ class AcceleratorGtk; class LocationBarViewGtk : public OmniboxEditController, public LocationBar, public LocationBarTesting, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: explicit LocationBarViewGtk(Browser* browser); virtual ~LocationBarViewGtk(); @@ -165,6 +167,10 @@ class LocationBarViewGtk : public OmniboxEditController, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Edit background color. static const GdkColor kBackgroundColor; diff --git a/chrome/browser/ui/prefs/prefs_tab_helper.cc b/chrome/browser/ui/prefs/prefs_tab_helper.cc index 8074e6d..1d3e3d4 100644 --- a/chrome/browser/ui/prefs/prefs_tab_helper.cc +++ b/chrome/browser/ui/prefs/prefs_tab_helper.cc @@ -137,7 +137,7 @@ void RegisterFontFamilyMap(PrefService* prefs, const char* map_name) { // Registers |obs| to observe per-script font prefs under the path |map_name|. void RegisterFontFamilyMapObserver(PrefChangeRegistrar* registrar, const char* map_name, - content::NotificationObserver* obs) { + PrefObserver* obs) { for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; std::string pref_name = base::StringPrintf("%s.%s", map_name, script); @@ -566,27 +566,26 @@ void PrefsTabHelper::Observe(int type, break; } #endif - case chrome::NOTIFICATION_PREF_CHANGED: { - std::string* pref_name_in = content::Details<std::string>(details).ptr(); - DCHECK(content::Source<PrefService>(source).ptr() == - GetProfile()->GetPrefs()); - if (*pref_name_in == prefs::kDefaultCharset || - StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) { - OnWebPrefChanged(*pref_name_in); - } else if (*pref_name_in == prefs::kDefaultZoomLevel || - *pref_name_in == prefs::kEnableReferrers || - *pref_name_in == prefs::kEnableDoNotTrack) { - UpdateRendererPreferences(); - } else { - NOTREACHED() << "unexpected pref change notification" << *pref_name_in; - } - break; - } default: NOTREACHED(); } } +void PrefsTabHelper::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name_in) { + DCHECK_EQ(GetProfile()->GetPrefs(), service); + if (pref_name_in == prefs::kDefaultCharset || + StartsWithASCII(pref_name_in, "webkit.webprefs.", true)) { + OnWebPrefChanged(pref_name_in); + } else if (pref_name_in == prefs::kDefaultZoomLevel || + pref_name_in == prefs::kEnableReferrers || + pref_name_in == prefs::kEnableDoNotTrack) { + UpdateRendererPreferences(); + } else { + NOTREACHED() << "unexpected pref change notification" << pref_name_in; + } +} + void PrefsTabHelper::UpdateWebPreferences() { web_contents_->GetRenderViewHost()->UpdateWebkitPreferences( web_contents_->GetRenderViewHost()->GetWebkitPreferences()); diff --git a/chrome/browser/ui/prefs/prefs_tab_helper.h b/chrome/browser/ui/prefs/prefs_tab_helper.h index cfb808b..5dc8c98 100644 --- a/chrome/browser/ui/prefs/prefs_tab_helper.h +++ b/chrome/browser/ui/prefs/prefs_tab_helper.h @@ -7,6 +7,7 @@ #include "base/compiler_specific.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/web_contents_user_data.h" @@ -21,6 +22,7 @@ class WebContents; // Per-tab class to handle user preferences. class PrefsTabHelper : public content::NotificationObserver, + public PrefObserver, public content::WebContentsUserData<PrefsTabHelper> { public: virtual ~PrefsTabHelper(); @@ -41,6 +43,10 @@ class PrefsTabHelper : public content::NotificationObserver, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver overrides: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Update the WebContents's RendererPreferences. void UpdateRendererPreferences(); diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index 9812e5d..0ffc957 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -1574,13 +1574,6 @@ void LocationBarView::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: { - std::string* name = content::Details<std::string>(details).ptr(); - if (*name == prefs::kEditBookmarksEnabled) - Update(NULL); - break; - } - case chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED: { // Only update if the updated action box was for the active tab contents. WebContents* target_tab = content::Details<WebContents>(details).ptr(); @@ -1594,6 +1587,12 @@ void LocationBarView::Observe(int type, } } +void LocationBarView::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kEditBookmarksEnabled) + Update(NULL); +} + int LocationBarView::GetInternalHeight(bool use_preferred_size) { int total_height = use_preferred_size ? GetPreferredSize().height() : height(); diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h index e96819d..73b8437 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.h +++ b/chrome/browser/ui/views/location_bar/location_bar_view.h @@ -9,6 +9,7 @@ #include <vector> #include "base/compiler_specific.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/extensions/extension_context_menu_model.h" #include "chrome/browser/search_engines/template_url_service_observer.h" @@ -79,7 +80,8 @@ class LocationBarView : public LocationBar, public DropdownBarHostDelegate, public chrome::search::SearchModelObserver, public TemplateURLServiceObserver, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: // The location bar view's class name. static const char kViewClassName[]; @@ -338,6 +340,10 @@ class LocationBarView : public LocationBar, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // Overridden from PrefObserver + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Returns the height of the control without the top and bottom // edges(i.e. the height of the edit control inside). If // |use_preferred_size| is true this will be the preferred height, diff --git a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc index 3f62535..21c31e9 100644 --- a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc +++ b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc @@ -442,20 +442,11 @@ void BrowserTabStripController::TabBlockedStateChanged(TabContents* contents, //////////////////////////////////////////////////////////////////////////////// // BrowserTabStripController, content::NotificationObserver implementation: -void BrowserTabStripController::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: - if (*content::Details<std::string>(details).ptr() == - prefs::kTabStripLayoutType) { - UpdateLayoutType(); - } - break; - - default: - NOTREACHED(); - break; +void BrowserTabStripController::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kTabStripLayoutType) { + UpdateLayoutType(); } } diff --git a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h index 1a5e852..64dbd2d 100644 --- a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h +++ b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h @@ -8,10 +8,10 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/ui/tabs/hover_tab_selector.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" -#include "content/public/browser/notification_observer.h" class BaseTab; class Browser; @@ -28,7 +28,7 @@ class WebContents; // TabContentses in a TabStripModel. class BrowserTabStripController : public TabStripController, public TabStripModelObserver, - public content::NotificationObserver { + public PrefObserver { public: BrowserTabStripController(Browser* browser, TabStripModel* model); virtual ~BrowserTabStripController(); @@ -97,10 +97,9 @@ class BrowserTabStripController : public TabStripController, virtual void TabBlockedStateChanged(TabContents* contents, int model_index) OVERRIDE; - // content::NotificationObserver implementation: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; protected: // The context in which SetTabRendererDataFromModel is being called. diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc index 31076d1..7f91d3f 100644 --- a/chrome/browser/ui/views/toolbar_view.cc +++ b/chrome/browser/ui/views/toolbar_view.cc @@ -528,14 +528,6 @@ void ToolbarView::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: { - std::string* pref_name = content::Details<std::string>(details).ptr(); - if (*pref_name == prefs::kShowHomeButton) { - Layout(); - SchedulePaint(); - } - break; - } case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: case chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE: case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: @@ -551,6 +543,14 @@ void ToolbarView::Observe(int type, } } +void ToolbarView::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kShowHomeButton) { + Layout(); + SchedulePaint(); + } +} + //////////////////////////////////////////////////////////////////////////////// // ToolbarView, ui::AcceleratorProvider implementation: diff --git a/chrome/browser/ui/views/toolbar_view.h b/chrome/browser/ui/views/toolbar_view.h index b126f89..4e6e244 100644 --- a/chrome/browser/ui/views/toolbar_view.h +++ b/chrome/browser/ui/views/toolbar_view.h @@ -10,6 +10,7 @@ #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/command_observer.h" #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" @@ -39,7 +40,8 @@ class ToolbarView : public views::AccessiblePaneView, public content::NotificationObserver, public CommandObserver, public views::ButtonListener, - public views::WidgetObserver { + public views::WidgetObserver, + public PrefObserver { public: // The view class name. static const char kViewClassName[]; @@ -125,6 +127,10 @@ class ToolbarView : public views::AccessiblePaneView, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // Overridden from PrefObserver: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Overridden from ui::AcceleratorProvider: virtual bool GetAcceleratorForCommandId( int command_id, ui::Accelerator* accelerator) OVERRIDE; diff --git a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc index 902410d..262134c 100644 --- a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc +++ b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc @@ -444,7 +444,6 @@ void ExtensionSettingsHandler::Observe( case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: - case chrome::NOTIFICATION_PREF_CHANGED: MaybeUpdateAfterNotification(); break; default: @@ -452,6 +451,12 @@ void ExtensionSettingsHandler::Observe( } } +void ExtensionSettingsHandler::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { + MaybeUpdateAfterNotification(); +} + void ExtensionSettingsHandler::ExtensionUninstallAccepted() { DCHECK(!extension_id_prompting_.empty()); diff --git a/chrome/browser/ui/webui/extensions/extension_settings_handler.h b/chrome/browser/ui/webui/extensions/extension_settings_handler.h index 50e0160..fee671e 100644 --- a/chrome/browser/ui/webui/extensions/extension_settings_handler.h +++ b/chrome/browser/ui/webui/extensions/extension_settings_handler.h @@ -11,6 +11,7 @@ #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/extensions/extension_install_ui.h" #include "chrome/browser/extensions/extension_uninstall_dialog.h" #include "chrome/browser/extensions/extension_warning_set.h" @@ -59,6 +60,7 @@ struct ExtensionPage { class ExtensionSettingsHandler : public content::WebUIMessageHandler, public content::NotificationObserver, + public PrefObserver, public content::WebContentsObserver, public ui::SelectFileDialog::Listener, public ExtensionUninstallDialog::Delegate, @@ -107,6 +109,10 @@ class ExtensionSettingsHandler const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // ExtensionUninstallDialog::Delegate implementation, used for receiving // notification about uninstall confirmation dialog selections. virtual void ExtensionUninstallAccepted() OVERRIDE; diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc index 701a5e2..d701b20 100644 --- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc +++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc @@ -312,13 +312,6 @@ void AppLauncherHandler::Observe(int type, // TODO(estade): Try to get rid of this inefficient operation. HandleGetApps(NULL); break; - case chrome::NOTIFICATION_PREF_CHANGED: { - DictionaryValue dictionary; - FillAppDictionary(&dictionary); - web_ui()->CallJavascriptFunction("ntp.appsPrefChangeCallback", - dictionary); - break; - } case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: { CrxInstaller* crx_installer = content::Source<CrxInstaller>(source).ptr(); if (!Profile::FromWebUI(web_ui())->IsSameProfile( @@ -336,6 +329,14 @@ void AppLauncherHandler::Observe(int type, } } +void AppLauncherHandler::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DictionaryValue dictionary; + FillAppDictionary(&dictionary); + web_ui()->CallJavascriptFunction("ntp.appsPrefChangeCallback", + dictionary); +} + void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { // CreateAppInfo and ClearOrdinals can change the extension prefs. AutoReset<bool> auto_reset(&ignore_changes_, true); diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.h b/chrome/browser/ui/webui/ntp/app_launcher_handler.h index d91f6ec..9280930 100644 --- a/chrome/browser/ui/webui/ntp/app_launcher_handler.h +++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.h @@ -9,6 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/common/cancelable_request.h" #include "chrome/browser/extensions/extension_install_prompt.h" #include "chrome/browser/extensions/extension_uninstall_dialog.h" @@ -32,7 +33,8 @@ class AppNotification; class AppLauncherHandler : public content::WebUIMessageHandler, public ExtensionUninstallDialog::Delegate, public ExtensionInstallPrompt::Delegate, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: explicit AppLauncherHandler(ExtensionService* extension_service); virtual ~AppLauncherHandler(); @@ -52,6 +54,10 @@ class AppLauncherHandler : public content::WebUIMessageHandler, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Populate the given dictionary with all installed app info. void FillAppDictionary(base::DictionaryValue* value); diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.cc b/chrome/browser/ui/webui/ntp/new_tab_ui.cc index bf78cd0..159a06d 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_ui.cc +++ b/chrome/browser/ui/webui/ntp/new_tab_ui.cc @@ -249,13 +249,6 @@ void NewTabUI::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: { // kShowBookmarkBar - StringValue attached( - GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? - "true" : "false"); - web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached); - break; - } #if defined(ENABLE_THEMES) case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { InitializeCSSCaches(); @@ -288,6 +281,14 @@ void NewTabUI::Observe(int type, } } +void NewTabUI::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + StringValue attached( + GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? + "true" : "false"); + web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached); +} + void NewTabUI::InitializeCSSCaches() { #if defined(ENABLE_THEMES) Profile* profile = GetProfile(); diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.h b/chrome/browser/ui/webui/ntp/new_tab_ui.h index 0fd64c5..59fd481 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_ui.h +++ b/chrome/browser/ui/webui/ntp/new_tab_ui.h @@ -10,6 +10,7 @@ #include "base/gtest_prod_util.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/time.h" #include "base/timer.h" #include "chrome/browser/sessions/tab_restore_service.h" @@ -24,7 +25,8 @@ class Profile; // The WebContents used for the New Tab page. class NewTabUI : public content::WebUIController, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: explicit NewTabUI(content::WebUI* web_ui); virtual ~NewTabUI(); @@ -99,10 +101,15 @@ class NewTabUI : public content::WebUIController, private: FRIEND_TEST_ALL_PREFIXES(NewTabUITest, UpdateUserPrefsVersion); + // content::NotificationObserver implementation. virtual void Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Reset the CSS caches. void InitializeCSSCaches(); diff --git a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc b/chrome/browser/ui/webui/ntp/ntp_login_handler.cc index 4702fb1..476150a 100644 --- a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc +++ b/chrome/browser/ui/webui/ntp/ntp_login_handler.cc @@ -112,15 +112,17 @@ void NTPLoginHandler::Observe(int type, const content::NotificationDetails& details) { if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { UpdateLogin(); - } else if (type == chrome::NOTIFICATION_PREF_CHANGED) { - std::string* name = content::Details<std::string>(details).ptr(); - if (prefs::kGoogleServicesUsername == *name) - UpdateLogin(); } else { NOTREACHED(); } } +void NTPLoginHandler::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (prefs::kGoogleServicesUsername == pref_name) + UpdateLogin(); +} + void NTPLoginHandler::HandleInitializeSyncLogin(const ListValue* args) { UpdateLogin(); } diff --git a/chrome/browser/ui/webui/ntp/ntp_login_handler.h b/chrome/browser/ui/webui/ntp/ntp_login_handler.h index 331caf9e..a00b313 100644 --- a/chrome/browser/ui/webui/ntp/ntp_login_handler.h +++ b/chrome/browser/ui/webui/ntp/ntp_login_handler.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NTP_LOGIN_HANDLER_H_ #define CHROME_BROWSER_UI_WEBUI_NTP_NTP_LOGIN_HANDLER_H_ +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -16,7 +17,8 @@ class Profile; // username at the top of the NTP (and update itself when that changes). // In the future it may expand to allow users to login from the NTP. class NTPLoginHandler : public content::WebUIMessageHandler, - public content::NotificationObserver { + public content::NotificationObserver, + public PrefObserver { public: NTPLoginHandler(); virtual ~NTPLoginHandler(); @@ -29,6 +31,10 @@ class NTPLoginHandler : public content::WebUIMessageHandler, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver interface + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Returns true if the login handler should be shown in a new tab page // for the given |profile|. |profile| must not be NULL. static bool ShouldShow(Profile* profile); diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc index 153dcfa..cdd8730 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc @@ -218,12 +218,6 @@ void NTPResourceCache::Observe(int type, new_tab_html_ = NULL; new_tab_incognito_css_ = NULL; new_tab_css_ = NULL; - } else if (chrome::NOTIFICATION_PREF_CHANGED == type) { - // A change occurred to one of the preferences we care about, so flush the - // cache. - new_tab_incognito_html_ = NULL; - new_tab_html_ = NULL; - new_tab_css_ = NULL; } else if (chrome::NOTIFICATION_NTP_BACKGROUND_THEME_Y_POS_CHANGED == type) { css_background_y_pos_ = *(content::Details<int>(details).ptr()); if (new_tab_css_.get()) @@ -233,6 +227,15 @@ void NTPResourceCache::Observe(int type, } } +void NTPResourceCache::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + // A change occurred to one of the preferences we care about, so flush the + // cache. + new_tab_incognito_html_ = NULL; + new_tab_html_ = NULL; + new_tab_css_ = NULL; +} + void NTPResourceCache::CreateNewTabIncognitoHTML() { DictionaryValue localized_strings; localized_strings.SetString("title", diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.h b/chrome/browser/ui/webui/ntp/ntp_resource_cache.h index c4a57b1..8569649 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.h +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.h @@ -9,6 +9,7 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/string16.h" #include "chrome/browser/profiles/profile_keyed_service.h" #include "content/public/browser/notification_observer.h" @@ -27,6 +28,7 @@ class ThemeProvider; // This class keeps a cache of NTP resources (HTML and CSS) so we don't have to // regenerate them all the time. class NTPResourceCache : public content::NotificationObserver, + public PrefObserver, public ProfileKeyedService { public: explicit NTPResourceCache(Profile* profile); @@ -40,6 +42,10 @@ class NTPResourceCache : public content::NotificationObserver, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver interface. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Returns the CSS background-position-y style for new_tab_theme.css: // - |y_pos| is the vertical offset of theme image in content view. // - |alignment| is alignment of theme image. diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache_android.cc b/chrome/browser/ui/webui/ntp/ntp_resource_cache_android.cc index 28b3dae..34214f8 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache_android.cc +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache_android.cc @@ -56,6 +56,11 @@ void NTPResourceCache::Observe(int type, // No notifications necessary in Android. } +void NTPResourceCache::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + // No notifications necessary in Android. +} + void NTPResourceCache::CreateNewTabHTML() { // TODO(estade): these strings should be defined in their relevant handlers // (in GetLocalizedValues) and should have more legible names. diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc index 8275604..47d6e35 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.cc +++ b/chrome/browser/ui/webui/options/browser_options_handler.cc @@ -866,32 +866,34 @@ void BrowserOptionsHandler::Observe( } else if (type == chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED) { UpdateAccountPicture(); #endif - } else if (type == chrome::NOTIFICATION_PREF_CHANGED) { - std::string* pref_name = content::Details<std::string>(details).ptr(); - if (*pref_name == prefs::kDefaultBrowserSettingEnabled) { - UpdateDefaultBrowserState(); - } else if (*pref_name == prefs::kDownloadExtensionsToOpen) { - SetupAutoOpenFileTypes(); + } else if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { + if (multiprofile_) + SendProfilesInfo(); + } else { + NOTREACHED(); + } +} + +void BrowserOptionsHandler::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kDefaultBrowserSettingEnabled) { + UpdateDefaultBrowserState(); + } else if (pref_name == prefs::kDownloadExtensionsToOpen) { + SetupAutoOpenFileTypes(); #if !defined(OS_CHROMEOS) - } else if (proxy_prefs_.IsObserved(*pref_name)) { - SetupProxySettingsSection(); + } else if (proxy_prefs_.IsObserved(pref_name)) { + SetupProxySettingsSection(); #endif // !defined(OS_CHROMEOS) - } else if ((*pref_name == prefs::kCloudPrintEmail) || - (*pref_name == prefs::kCloudPrintProxyEnabled)) { + } else if ((pref_name == prefs::kCloudPrintEmail) || + (pref_name == prefs::kCloudPrintProxyEnabled)) { #if !defined(OS_CHROMEOS) - if (cloud_print_connector_ui_enabled_) - SetupCloudPrintConnectorSection(); + if (cloud_print_connector_ui_enabled_) + SetupCloudPrintConnectorSection(); #endif - } else if (*pref_name == prefs::kWebKitDefaultFontSize) { - SetupFontSizeSelector(); - } else if (*pref_name == prefs::kDefaultZoomLevel) { - SetupPageZoomSelector(); - } else { - NOTREACHED(); - } - } else if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { - if (multiprofile_) - SendProfilesInfo(); + } else if (pref_name == prefs::kWebKitDefaultFontSize) { + SetupFontSizeSelector(); + } else if (pref_name == prefs::kDefaultZoomLevel) { + SetupPageZoomSelector(); } else { NOTREACHED(); } diff --git a/chrome/browser/ui/webui/options/browser_options_handler.h b/chrome/browser/ui/webui/options/browser_options_handler.h index b67757a..0488e10 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.h +++ b/chrome/browser/ui/webui/options/browser_options_handler.h @@ -8,6 +8,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/api/sync/profile_sync_service_observer.h" #include "chrome/browser/printing/cloud_print/cloud_print_setup_handler.h" @@ -35,6 +36,7 @@ namespace options { class BrowserOptionsHandler : public OptionsPageUIHandler, public CloudPrintSetupHandlerDelegate, + public PrefObserver, public ProfileSyncServiceObserver, public ui::SelectFileDialog::Listener, public ShellIntegration::DefaultWebClientObserver, @@ -74,6 +76,10 @@ class BrowserOptionsHandler const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // SelectFileDialog::Listener implementation virtual void FileSelected(const FilePath& path, int index, diff --git a/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc index 76f5f716..4c337674 100644 --- a/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc @@ -200,19 +200,22 @@ void CoreChromeOSOptionsHandler::Observe( NotifySettingsChanged(content::Details<std::string>(details).ptr()); return; } + ::options::CoreOptionsHandler::Observe(type, source, details); +} + +void CoreChromeOSOptionsHandler::OnPreferenceChanged( + PrefServiceBase* service, + const std::string& pref_name) { // Special handling for preferences kUseSharedProxies and kProxy, the latter // controls the former and decides if it's managed by policy/extension. - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - const PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); - std::string* pref_name = content::Details<std::string>(details).ptr(); - if (content::Source<PrefService>(source).ptr() == pref_service && - (proxy_prefs_.IsObserved(*pref_name) || - *pref_name == prefs::kUseSharedProxies)) { - NotifyPrefChanged(prefs::kUseSharedProxies, prefs::kProxy); - return; - } + const PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); + if (service == pref_service && + (proxy_prefs_.IsObserved(pref_name) || + pref_name == prefs::kUseSharedProxies)) { + NotifyPrefChanged(prefs::kUseSharedProxies, prefs::kProxy); + return; } - ::options::CoreOptionsHandler::Observe(type, source, details); + ::options::CoreOptionsHandler::OnPreferenceChanged(service, pref_name); } void CoreChromeOSOptionsHandler::NotifySettingsChanged( diff --git a/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.h b/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.h index 82b9298f..e14625a 100644 --- a/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.h +++ b/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.h @@ -8,6 +8,7 @@ #include "base/compiler_specific.h" #include "base/memory/weak_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/ui/webui/options/core_options_handler.h" namespace chromeos { @@ -37,6 +38,10 @@ class CoreChromeOSOptionsHandler : public ::options::CoreOptionsHandler { const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + private: // Notifies registered JS callbacks on ChromeOS setting change. void NotifySettingsChanged(const std::string* setting_name); diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc index c8ad7a6..f2565aa1 100644 --- a/chrome/browser/ui/webui/options/content_settings_handler.cc +++ b/chrome/browser/ui/webui/options/content_settings_handler.cc @@ -540,17 +540,6 @@ void ContentSettingsHandler::Observe( break; } - case chrome::NOTIFICATION_PREF_CHANGED: { - const std::string& pref_name = - *content::Details<std::string>(details).ptr(); - if (pref_name == prefs::kGeolocationContentSettings) - UpdateGeolocationExceptionsView(); - else if (pref_name == prefs::kPepperFlashSettingsEnabled) - RefreshFlashSettingsCache(false); - - break; - } - case chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { UpdateNotificationExceptionsView(); break; @@ -566,6 +555,14 @@ void ContentSettingsHandler::Observe( } } +void ContentSettingsHandler::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kGeolocationContentSettings) + UpdateGeolocationExceptionsView(); + else if (pref_name == prefs::kPepperFlashSettingsEnabled) + RefreshFlashSettingsCache(false); +} + void ContentSettingsHandler::OnGetPermissionSettingsCompleted( uint32 request_id, bool success, diff --git a/chrome/browser/ui/webui/options/content_settings_handler.h b/chrome/browser/ui/webui/options/content_settings_handler.h index 63a83ae..5aa54be 100644 --- a/chrome/browser/ui/webui/options/content_settings_handler.h +++ b/chrome/browser/ui/webui/options/content_settings_handler.h @@ -10,6 +10,7 @@ #include "base/memory/scoped_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/pepper_flash_settings_manager.h" #include "chrome/browser/ui/webui/options/options_ui.h" #include "chrome/common/content_settings.h" @@ -23,7 +24,8 @@ class ProtocolHandlerRegistry; namespace options { class ContentSettingsHandler : public OptionsPageUIHandler, - public PepperFlashSettingsManager::Client { + public PepperFlashSettingsManager::Client, + public PrefObserver { public: ContentSettingsHandler(); virtual ~ContentSettingsHandler(); @@ -40,6 +42,10 @@ class ContentSettingsHandler : public OptionsPageUIHandler, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // PepperFlashSettingsManager::Client implementation. virtual void OnGetPermissionSettingsCompleted( uint32 request_id, diff --git a/chrome/browser/ui/webui/options/core_options_handler.cc b/chrome/browser/ui/webui/options/core_options_handler.cc index ea50be9..8e14ea1 100644 --- a/chrome/browser/ui/webui/options/core_options_handler.cc +++ b/chrome/browser/ui/webui/options/core_options_handler.cc @@ -135,22 +135,18 @@ void CoreOptionsHandler::Uninitialize() { } } -void CoreOptionsHandler::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - std::string* pref_name = content::Details<std::string>(details).ptr(); - if (*pref_name == prefs::kClearPluginLSODataEnabled) { - // This preference is stored in Local State, not in the user preferences. - UpdateClearPluginLSOData(); - return; - } - if (*pref_name == prefs::kPepperFlashSettingsEnabled) { - UpdatePepperFlashSettingsEnabled(); - return; - } - NotifyPrefChanged(*pref_name, std::string()); +void CoreOptionsHandler::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kClearPluginLSODataEnabled) { + // This preference is stored in Local State, not in the user preferences. + UpdateClearPluginLSOData(); + return; + } + if (pref_name == prefs::kPepperFlashSettingsEnabled) { + UpdatePepperFlashSettingsEnabled(); + return; } + NotifyPrefChanged(pref_name, std::string()); } void CoreOptionsHandler::RegisterMessages() { diff --git a/chrome/browser/ui/webui/options/core_options_handler.h b/chrome/browser/ui/webui/options/core_options_handler.h index aff1ee7..8cf06f5 100644 --- a/chrome/browser/ui/webui/options/core_options_handler.h +++ b/chrome/browser/ui/webui/options/core_options_handler.h @@ -10,6 +10,7 @@ #include "base/callback.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "base/values.h" #include "chrome/browser/plugins/plugin_status_pref_setter.h" #include "chrome/browser/prefs/pref_service.h" @@ -19,7 +20,8 @@ namespace options { // Core options UI handler. // Handles resource and JS calls common to all options sub-pages. -class CoreOptionsHandler : public OptionsPageUIHandler { +class CoreOptionsHandler : public OptionsPageUIHandler, + public PrefObserver { public: CoreOptionsHandler(); virtual ~CoreOptionsHandler(); @@ -30,10 +32,9 @@ class CoreOptionsHandler : public OptionsPageUIHandler { virtual void InitializePage() OVERRIDE; virtual void Uninitialize() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // WebUIMessageHandler implementation. virtual void RegisterMessages() OVERRIDE; diff --git a/chrome/browser/ui/webui/options/font_settings_handler.cc b/chrome/browser/ui/webui/options/font_settings_handler.cc index ce58d39..22f200e 100644 --- a/chrome/browser/ui/webui/options/font_settings_handler.cc +++ b/chrome/browser/ui/webui/options/font_settings_handler.cc @@ -187,27 +187,23 @@ void FontSettingsHandler::FontsListHasLoaded( selected_values); } -void FontSettingsHandler::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - std::string* pref_name = content::Details<std::string>(details).ptr(); - if (*pref_name == prefs::kWebKitStandardFontFamily) { - SetUpStandardFontSample(); - } else if (*pref_name == prefs::kWebKitSerifFontFamily) { - SetUpSerifFontSample(); - } else if (*pref_name == prefs::kWebKitSansSerifFontFamily) { - SetUpSansSerifFontSample(); - } else if (*pref_name == prefs::kWebKitFixedFontFamily || - *pref_name == prefs::kWebKitDefaultFixedFontSize) { - SetUpFixedFontSample(); - } else if (*pref_name == prefs::kWebKitDefaultFontSize) { - SetUpStandardFontSample(); - SetUpSerifFontSample(); - SetUpSansSerifFontSample(); - } else if (*pref_name == prefs::kWebKitMinimumFontSize) { - SetUpMinimumFontSample(); - } +void FontSettingsHandler::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kWebKitStandardFontFamily) { + SetUpStandardFontSample(); + } else if (pref_name == prefs::kWebKitSerifFontFamily) { + SetUpSerifFontSample(); + } else if (pref_name == prefs::kWebKitSansSerifFontFamily) { + SetUpSansSerifFontSample(); + } else if (pref_name == prefs::kWebKitFixedFontFamily || + pref_name == prefs::kWebKitDefaultFixedFontSize) { + SetUpFixedFontSample(); + } else if (pref_name == prefs::kWebKitDefaultFontSize) { + SetUpStandardFontSample(); + SetUpSerifFontSample(); + SetUpSansSerifFontSample(); + } else if (pref_name == prefs::kWebKitMinimumFontSize) { + SetUpMinimumFontSample(); } } diff --git a/chrome/browser/ui/webui/options/font_settings_handler.h b/chrome/browser/ui/webui/options/font_settings_handler.h index 9b263c7..1c6af16 100644 --- a/chrome/browser/ui/webui/options/font_settings_handler.h +++ b/chrome/browser/ui/webui/options/font_settings_handler.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_UI_WEBUI_OPTIONS_FONT_SETTINGS_HANDLER_H_ #include "base/memory/scoped_ptr.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/ui/webui/options/options_ui.h" @@ -16,7 +17,8 @@ class ListValue; namespace options { // Font settings overlay page UI handler. -class FontSettingsHandler : public OptionsPageUIHandler { +class FontSettingsHandler : public OptionsPageUIHandler, + public PrefObserver { public: FontSettingsHandler(); virtual ~FontSettingsHandler(); @@ -28,10 +30,9 @@ class FontSettingsHandler : public OptionsPageUIHandler { // WebUIMessageHandler implementation. virtual void RegisterMessages() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; private: void HandleFetchFontsData(const ListValue* args); diff --git a/chrome/browser/ui/webui/options/media_galleries_handler.cc b/chrome/browser/ui/webui/options/media_galleries_handler.cc index 903712f..072dd7b 100644 --- a/chrome/browser/ui/webui/options/media_galleries_handler.cc +++ b/chrome/browser/ui/webui/options/media_galleries_handler.cc @@ -130,17 +130,10 @@ void MediaGalleriesHandler::FileSelected( prefs->AddGalleryByPath(path); } -void MediaGalleriesHandler::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED && - *content::Details<std::string>(details).ptr() == - prefs::kMediaGalleriesRememberedGalleries) { - OnGalleriesChanged(); - } else { - NOTREACHED(); - } +void MediaGalleriesHandler::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK_EQ(std::string(prefs::kMediaGalleriesRememberedGalleries), pref_name); + OnGalleriesChanged(); } } // namespace options diff --git a/chrome/browser/ui/webui/options/media_galleries_handler.h b/chrome/browser/ui/webui/options/media_galleries_handler.h index 451a37d..7ce549b 100644 --- a/chrome/browser/ui/webui/options/media_galleries_handler.h +++ b/chrome/browser/ui/webui/options/media_galleries_handler.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_UI_WEBUI_OPTIONS_MEDIA_GALLERIES_HANDLER_H_ #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/ui/webui/options/options_ui.h" #include "content/public/browser/notification_observer.h" #include "ui/base/dialogs/select_file_dialog.h" @@ -14,6 +15,7 @@ namespace options { // Handles messages related to adding or removing media galleries. class MediaGalleriesHandler : public OptionsPageUIHandler, + public PrefObserver, public ui::SelectFileDialog::Listener { public: MediaGalleriesHandler(); @@ -28,10 +30,9 @@ class MediaGalleriesHandler : public OptionsPageUIHandler, virtual void FileSelected(const FilePath& path, int index, void* params) OVERRIDE; - // NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; private: // Handles the "addNewGallery" message (no arguments). diff --git a/chrome/browser/ui/webui/options/password_manager_handler.cc b/chrome/browser/ui/webui/options/password_manager_handler.cc index 73d6cb3..1aefb9b 100644 --- a/chrome/browser/ui/webui/options/password_manager_handler.cc +++ b/chrome/browser/ui/webui/options/password_manager_handler.cc @@ -109,18 +109,10 @@ PasswordStore* PasswordManagerHandler::GetPasswordStore() { Profile::EXPLICIT_ACCESS); } -void PasswordManagerHandler::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - std::string* pref_name = content::Details<std::string>(details).ptr(); - if (*pref_name == prefs::kPasswordManagerAllowShowPasswords) { - UpdatePasswordLists(NULL); - } - } - - OptionsPageUIHandler::Observe(type, source, details); +void PasswordManagerHandler::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK_EQ(std::string(prefs::kPasswordManagerAllowShowPasswords), pref_name); + UpdatePasswordLists(NULL); } void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) { diff --git a/chrome/browser/ui/webui/options/password_manager_handler.h b/chrome/browser/ui/webui/options/password_manager_handler.h index f7b7fc9..4a1436e 100644 --- a/chrome/browser/ui/webui/options/password_manager_handler.h +++ b/chrome/browser/ui/webui/options/password_manager_handler.h @@ -9,6 +9,7 @@ #include <vector> #include "base/memory/scoped_vector.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/password_manager/password_store.h" #include "chrome/browser/password_manager/password_store_consumer.h" @@ -21,7 +22,8 @@ struct PasswordForm; namespace options { class PasswordManagerHandler : public OptionsPageUIHandler, - public PasswordStore::Observer { + public PasswordStore::Observer, + public PrefObserver { public: PasswordManagerHandler(); virtual ~PasswordManagerHandler(); @@ -34,10 +36,9 @@ class PasswordManagerHandler : public OptionsPageUIHandler, // PasswordStore::Observer implementation. virtual void OnLoginsChanged() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; private: // The password store associated with the currently active profile. diff --git a/chrome/browser/ui/webui/options/preferences_browsertest.cc b/chrome/browser/ui/webui/options/preferences_browsertest.cc index 676227d..5f31347 100644 --- a/chrome/browser/ui/webui/options/preferences_browsertest.cc +++ b/chrome/browser/ui/webui/options/preferences_browsertest.cc @@ -162,14 +162,10 @@ void PreferencesBrowserTest::SetUpOnMainThread() { } // Forwards notifications received when pref values change in the backend. -void PreferencesBrowserTest::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - ASSERT_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); - ASSERT_EQ(pref_service_, content::Source<PrefService>(source).ptr()); - const std::string& name = *content::Details<std::string>(details).ptr(); - OnCommit(pref_service_->FindPreference(name.c_str())); +void PreferencesBrowserTest::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + ASSERT_EQ(pref_service_, service); + OnCommit(pref_service_->FindPreference(pref_name.c_str())); } // Sets up a mock user policy provider. diff --git a/chrome/browser/ui/webui/options/preferences_browsertest.h b/chrome/browser/ui/webui/options/preferences_browsertest.h index 1caa410..25d14b0 100644 --- a/chrome/browser/ui/webui/options/preferences_browsertest.h +++ b/chrome/browser/ui/webui/options/preferences_browsertest.h @@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/policy/mock_configuration_policy_provider.h" #include "chrome/browser/policy/policy_types.h" #include "chrome/browser/prefs/pref_service.h" @@ -33,7 +34,7 @@ class RenderViewHost; // CoreOptionsHandler and the specialized classes handling Chrome OS device and // proxy prefs behave correctly. class PreferencesBrowserTest : public InProcessBrowserTest, - public content::NotificationObserver { + public PrefObserver { public: PreferencesBrowserTest(); ~PreferencesBrowserTest(); @@ -41,10 +42,9 @@ class PreferencesBrowserTest : public InProcessBrowserTest, // InProcessBrowserTest implementation: virtual void SetUpOnMainThread() OVERRIDE; - // content::NotificationObserver implementation: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; protected: MOCK_METHOD1(OnCommit, void(const PrefService::Preference*)); diff --git a/chrome/browser/ui/webui/options/startup_pages_handler.cc b/chrome/browser/ui/webui/options/startup_pages_handler.cc index 2d2b476..9ffb34f 100644 --- a/chrome/browser/ui/webui/options/startup_pages_handler.cc +++ b/chrome/browser/ui/webui/options/startup_pages_handler.cc @@ -130,17 +130,10 @@ void StartupPagesHandler::OnItemsRemoved(int start, int length) { OnModelChanged(); } -void StartupPagesHandler::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - std::string* pref = content::Details<std::string>(details).ptr(); - if (*pref == prefs::kURLsToRestoreOnStartup) { - UpdateStartupPages(); - } else { - NOTREACHED(); - } +void StartupPagesHandler::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + if (pref_name == prefs::kURLsToRestoreOnStartup) { + UpdateStartupPages(); } else { NOTREACHED(); } diff --git a/chrome/browser/ui/webui/options/startup_pages_handler.h b/chrome/browser/ui/webui/options/startup_pages_handler.h index 98f7f23..4e9e639 100644 --- a/chrome/browser/ui/webui/options/startup_pages_handler.h +++ b/chrome/browser/ui/webui/options/startup_pages_handler.h @@ -9,6 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/prefs/public/pref_change_registrar.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" #include "chrome/browser/ui/webui/options/options_ui.h" @@ -23,6 +24,7 @@ namespace options { // Chrome browser options page UI handler. class StartupPagesHandler : public OptionsPageUIHandler, public AutocompleteControllerDelegate, + public PrefObserver, public ui::TableModelObserver { public: StartupPagesHandler(); @@ -44,10 +46,9 @@ class StartupPagesHandler : public OptionsPageUIHandler, virtual void OnItemsRemoved(int start, int length) OVERRIDE; private: - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; + // PrefObserver implementation. + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; // Saves the changes that have been made. Called from WebUI. void CommitChanges(const ListValue* args); diff --git a/chrome/browser/ui/zoom/zoom_controller.cc b/chrome/browser/ui/zoom/zoom_controller.cc index a706ae9..6b0de35 100644 --- a/chrome/browser/ui/zoom/zoom_controller.cc +++ b/chrome/browser/ui/zoom/zoom_controller.cc @@ -65,19 +65,14 @@ void ZoomController::DidNavigateMainFrame( void ZoomController::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - switch (type) { - case chrome::NOTIFICATION_PREF_CHANGED: { - std::string* pref_name = content::Details<std::string>(details).ptr(); - DCHECK(pref_name && *pref_name == prefs::kDefaultZoomLevel); - UpdateState(std::string()); - break; - } - case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: - UpdateState(*content::Details<std::string>(details).ptr()); - break; - default: - NOTREACHED(); - } + DCHECK_EQ(content::NOTIFICATION_ZOOM_LEVEL_CHANGED, type); + UpdateState(*content::Details<std::string>(details).ptr()); +} + +void ZoomController::OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) { + DCHECK(pref_name == prefs::kDefaultZoomLevel); + UpdateState(std::string()); } void ZoomController::UpdateState(const std::string& host) { diff --git a/chrome/browser/ui/zoom/zoom_controller.h b/chrome/browser/ui/zoom/zoom_controller.h index ffc2a78f..f7aed95 100644 --- a/chrome/browser/ui/zoom/zoom_controller.h +++ b/chrome/browser/ui/zoom/zoom_controller.h @@ -7,6 +7,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/prefs/public/pref_observer.h" #include "chrome/browser/api/prefs/pref_member.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -21,6 +22,7 @@ class WebContents; // Per-tab class to manage the Omnibox zoom icon. class ZoomController : public content::NotificationObserver, + public PrefObserver, public content::WebContentsObserver, public content::WebContentsUserData<ZoomController> { public: @@ -50,6 +52,10 @@ class ZoomController : public content::NotificationObserver, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PrefObserver overrides: + virtual void OnPreferenceChanged(PrefServiceBase* service, + const std::string& pref_name) OVERRIDE; + // Updates the zoom icon and zoom percentage based on current values and // notifies the observer if changes have occurred. |host| may be empty, // meaning the change should apply to ~all sites. If it is not empty, the diff --git a/chrome/common/DEPS b/chrome/common/DEPS index 03adafd..cefae53 100644 --- a/chrome/common/DEPS +++ b/chrome/common/DEPS @@ -13,7 +13,6 @@ include_rules = [ "+webkit/user_agent", # TODO(jam): remove me once chrome_notifcation_types.h moves to browser - "+content/public/browser/notification_source.h", "+content/public/browser/notification_types.h", # Other libraries. diff --git a/chrome/common/chrome_notification_types.h b/chrome/common/chrome_notification_types.h index 01fed07..1245ae7 100644 --- a/chrome/common/chrome_notification_types.h +++ b/chrome/common/chrome_notification_types.h @@ -406,14 +406,6 @@ enum NotificationType { // to policy. Source and details are unused. NOTIFICATION_DEFAULT_SEARCH_POLICY_CHANGED, - // This is sent to a pref observer when a pref is changed. The source is the - // PrefService and the details a std::string of the changed path. - NOTIFICATION_PREF_CHANGED, - - // This is broadcast after the preference subsystem has completed - // asynchronous initalization of a PrefService. - NOTIFICATION_PREF_INITIALIZATION_COMPLETED, - // The state of a web resource has been changed. A resource may have been // added, removed, or altered. Source is WebResourceService, and the // details are NoDetails. |