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 /chrome/browser/content_settings | |
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
Diffstat (limited to 'chrome/browser/content_settings')
9 files changed, 45 insertions, 72 deletions
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 |