diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-15 23:54:59 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-15 23:54:59 +0000 |
commit | cb7cec1be6e2897708da3174b5cadd22a5c437b6 (patch) | |
tree | 68d87ad88f62ad644cbe11cd7971cb4c9f7faa88 | |
parent | c7486cc49e9bebda3598cb14bab05bd16969d9cb (diff) | |
download | chromium_src-cb7cec1be6e2897708da3174b5cadd22a5c437b6.zip chromium_src-cb7cec1be6e2897708da3174b5cadd22a5c437b6.tar.gz chromium_src-cb7cec1be6e2897708da3174b5cadd22a5c437b6.tar.bz2 |
Merging PrefSetObserver into PrefChangeRegistrar.
Removing Chrome-specific factories and inlining what they used to do. One was (after the bulk of this change) just adding a single pref to the PrefChangeRegistrar, the other was used in only one place.
TBR=usageupdate@chromium.org,ben@chromium.org
BUG=155525,122215
Review URL: https://chromiumcodereview.appspot.com/11110014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162007 0039d316-1c4b-4281-b951-d872f2087c98
18 files changed, 156 insertions, 277 deletions
diff --git a/chrome/browser/api/prefs/pref_change_registrar.cc b/chrome/browser/api/prefs/pref_change_registrar.cc index 2b05f5b..43d2b4a 100644 --- a/chrome/browser/api/prefs/pref_change_registrar.cc +++ b/chrome/browser/api/prefs/pref_change_registrar.cc @@ -67,3 +67,23 @@ void PrefChangeRegistrar::RemoveAll() { bool PrefChangeRegistrar::IsEmpty() const { return observers_.empty(); } + +bool PrefChangeRegistrar::IsObserved(const std::string& pref) { + for (std::set<ObserverRegistration>::const_iterator it = observers_.begin(); + it != observers_.end(); ++it) { + if (it->first == pref) + return true; + } + return false; +} + +bool PrefChangeRegistrar::IsManaged() { + for (std::set<ObserverRegistration>::const_iterator it = observers_.begin(); + it != observers_.end(); ++it) { + const PrefServiceBase::Preference* pref = + service_->FindPreference(it->first.c_str()); + if (pref && pref->IsManaged()) + return true; + } + return false; +} diff --git a/chrome/browser/api/prefs/pref_change_registrar.h b/chrome/browser/api/prefs/pref_change_registrar.h index 6f2d296..e6e2114d 100644 --- a/chrome/browser/api/prefs/pref_change_registrar.h +++ b/chrome/browser/api/prefs/pref_change_registrar.h @@ -47,6 +47,12 @@ class PrefChangeRegistrar { // Returns true if no pref observers are registered. bool IsEmpty() const; + // Check whether |pref| is in the set of preferences being observed. + bool IsObserved(const std::string& pref); + + // Check whether any of the observed preferences has the managed bit set. + bool IsManaged(); + private: typedef std::pair<std::string, content::NotificationObserver*> ObserverRegistration; diff --git a/chrome/browser/api/prefs/pref_change_registrar_unittest.cc b/chrome/browser/api/prefs/pref_change_registrar_unittest.cc index f9235dc..2152cce2 100644 --- a/chrome/browser/api/prefs/pref_change_registrar_unittest.cc +++ b/chrome/browser/api/prefs/pref_change_registrar_unittest.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/common/chrome_notification_types.h" +#include "chrome/common/pref_names.h" #include "chrome/browser/api/prefs/pref_change_registrar.h" #include "chrome/test/base/testing_pref_service.h" #include "content/public/browser/notification_details.h" @@ -118,3 +120,88 @@ TEST_F(PrefChangeRegistrarTest, RemoveAll) { // worked (rather than the registrar destructor doing the work). Mock::VerifyAndClearExpectations(service()); } + +class ObserveSetOfPreferencesTest : public testing::Test { + public: + virtual void SetUp() { + pref_service_.reset(new TestingPrefService); + pref_service_->RegisterStringPref(prefs::kHomePage, + "http://google.com", + PrefService::UNSYNCABLE_PREF); + pref_service_->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, + false, + PrefService::UNSYNCABLE_PREF); + pref_service_->RegisterStringPref(prefs::kApplicationLocale, + "", + PrefService::UNSYNCABLE_PREF); + } + + PrefChangeRegistrar* CreatePrefChangeRegistrar( + content::NotificationObserver* observer) { + PrefChangeRegistrar* pref_set = new PrefChangeRegistrar(); + pref_set->Init(pref_service_.get()); + pref_set->Add(prefs::kHomePage, observer); + pref_set->Add(prefs::kHomePageIsNewTabPage, observer); + return pref_set; + } + + scoped_ptr<TestingPrefService> pref_service_; +}; + +TEST_F(ObserveSetOfPreferencesTest, IsObserved) { + scoped_ptr<PrefChangeRegistrar> pref_set(CreatePrefChangeRegistrar(NULL)); + EXPECT_TRUE(pref_set->IsObserved(prefs::kHomePage)); + EXPECT_TRUE(pref_set->IsObserved(prefs::kHomePageIsNewTabPage)); + EXPECT_FALSE(pref_set->IsObserved(prefs::kApplicationLocale)); +} + +TEST_F(ObserveSetOfPreferencesTest, IsManaged) { + scoped_ptr<PrefChangeRegistrar> pref_set(CreatePrefChangeRegistrar(NULL)); + EXPECT_FALSE(pref_set->IsManaged()); + pref_service_->SetManagedPref(prefs::kHomePage, + Value::CreateStringValue("http://crbug.com")); + EXPECT_TRUE(pref_set->IsManaged()); + pref_service_->SetManagedPref(prefs::kHomePageIsNewTabPage, + Value::CreateBooleanValue(true)); + EXPECT_TRUE(pref_set->IsManaged()); + pref_service_->RemoveManagedPref(prefs::kHomePage); + EXPECT_TRUE(pref_set->IsManaged()); + pref_service_->RemoveManagedPref(prefs::kHomePageIsNewTabPage); + EXPECT_FALSE(pref_set->IsManaged()); +} + +MATCHER_P(PrefNameDetails, name, "details references named preference") { + std::string* pstr = + reinterpret_cast<const content::Details<std::string>&>(arg).ptr(); + return pstr && *pstr == name; +} + +TEST_F(ObserveSetOfPreferencesTest, Observe) { + using testing::_; + using testing::Mock; + + content::MockNotificationObserver 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))); + 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))); + pref_service_->SetUserPref(prefs::kHomePageIsNewTabPage, + Value::CreateBooleanValue(true)); + Mock::VerifyAndClearExpectations(&observer); + + EXPECT_CALL(observer, Observe(_, _, _)).Times(0); + pref_service_->SetUserPref(prefs::kApplicationLocale, + Value::CreateStringValue("en_US.utf8")); + Mock::VerifyAndClearExpectations(&observer); +} diff --git a/chrome/browser/net/pref_proxy_config_tracker_impl.cc b/chrome/browser/net/pref_proxy_config_tracker_impl.cc index 6b4c30f..9760f02 100644 --- a/chrome/browser/net/pref_proxy_config_tracker_impl.cc +++ b/chrome/browser/net/pref_proxy_config_tracker_impl.cc @@ -7,7 +7,6 @@ #include "base/bind.h" #include "base/values.h" #include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/prefs/pref_set_observer.h" #include "chrome/browser/prefs/proxy_config_dictionary.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" @@ -130,8 +129,8 @@ PrefProxyConfigTrackerImpl::PrefProxyConfigTrackerImpl( chrome_proxy_config_service_(NULL), update_pending_(true) { config_state_ = ReadPrefConfig(&pref_config_); - proxy_prefs_observer_.reset( - PrefSetObserver::CreateProxyPrefSetObserver(pref_service_, this)); + proxy_prefs_.Init(pref_service); + proxy_prefs_.Add(prefs::kProxy, this); } PrefProxyConfigTrackerImpl::~PrefProxyConfigTrackerImpl() { @@ -150,7 +149,7 @@ void PrefProxyConfigTrackerImpl::SetChromeProxyConfigService( void PrefProxyConfigTrackerImpl::DetachFromPrefService() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // Stop notifications. - proxy_prefs_observer_.reset(); + proxy_prefs_.RemoveAll(); pref_service_ = NULL; SetChromeProxyConfigService(NULL); } diff --git a/chrome/browser/net/pref_proxy_config_tracker_impl.h b/chrome/browser/net/pref_proxy_config_tracker_impl.h index c55a651..c393486 100644 --- a/chrome/browser/net/pref_proxy_config_tracker_impl.h +++ b/chrome/browser/net/pref_proxy_config_tracker_impl.h @@ -9,13 +9,13 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" +#include "chrome/browser/api/prefs/pref_change_registrar.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" class PrefService; -class PrefSetObserver; // A net::ProxyConfigService implementation that applies preference proxy // settings (pushed from PrefProxyConfigTrackerImpl) as overrides to the proxy @@ -157,7 +157,7 @@ class PrefProxyConfigTrackerImpl : public content::NotificationObserver { PrefService* pref_service_; ChromeProxyConfigService* chrome_proxy_config_service_; // Weak ptr. bool update_pending_; // True if config has not been pushed to network stack. - scoped_ptr<PrefSetObserver> proxy_prefs_observer_; + PrefChangeRegistrar proxy_prefs_; DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTrackerImpl); }; diff --git a/chrome/browser/prefs/pref_set_observer.cc b/chrome/browser/prefs/pref_set_observer.cc deleted file mode 100644 index 8694b23..0000000 --- a/chrome/browser/prefs/pref_set_observer.cc +++ /dev/null @@ -1,81 +0,0 @@ -// 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. - -#include "chrome/browser/prefs/pref_set_observer.h" - -#include "chrome/common/pref_names.h" -#include "chrome/browser/extensions/extension_prefs.h" -#include "content/public/browser/notification_types.h" - -PrefSetObserver::PrefSetObserver(PrefService* pref_service, - content::NotificationObserver* observer) - : pref_service_(pref_service), - observer_(observer) { - registrar_.Init(pref_service); -} - -PrefSetObserver::~PrefSetObserver() {} - -void PrefSetObserver::AddPref(const std::string& pref) { - if (!prefs_.count(pref) && pref_service_->FindPreference(pref.c_str())) { - prefs_.insert(pref); - registrar_.Add(pref.c_str(), this); - } -} - -void PrefSetObserver::RemovePref(const std::string& pref) { - if (prefs_.erase(pref)) - registrar_.Remove(pref.c_str(), this); -} - -bool PrefSetObserver::IsObserved(const std::string& pref) { - return prefs_.count(pref) > 0; -} - -bool PrefSetObserver::IsManaged() { - for (PrefSet::const_iterator i(prefs_.begin()); i != prefs_.end(); ++i) { - const PrefService::Preference* pref = - pref_service_->FindPreference(i->c_str()); - if (pref && pref->IsManaged()) - return true; - } - return false; -} - -// static -PrefSetObserver* PrefSetObserver::CreateProxyPrefSetObserver( - PrefService* pref_service, - content::NotificationObserver* observer) { - PrefSetObserver* pref_set = new PrefSetObserver(pref_service, observer); - pref_set->AddPref(prefs::kProxy); - - return pref_set; -} - -// static -PrefSetObserver* PrefSetObserver::CreateProtectedPrefSetObserver( - PrefService* pref_service, - content::NotificationObserver* observer) { - PrefSetObserver* pref_set = new PrefSetObserver(pref_service, observer); - // Homepage. - pref_set->AddPref(prefs::kHomePageIsNewTabPage); - pref_set->AddPref(prefs::kHomePage); - pref_set->AddPref(prefs::kShowHomeButton); - // Session startup. - pref_set->AddPref(prefs::kRestoreOnStartup); - pref_set->AddPref(prefs::kURLsToRestoreOnStartup); - // Pinned tabs. - pref_set->AddPref(prefs::kPinnedTabs); - // Extensions. - pref_set->AddPref(extensions::ExtensionPrefs::kExtensionsPref); - - return pref_set; -} - -void PrefSetObserver::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (observer_) - observer_->Observe(type, source, details); -} diff --git a/chrome/browser/prefs/pref_set_observer.h b/chrome/browser/prefs/pref_set_observer.h deleted file mode 100644 index 438aaad..0000000 --- a/chrome/browser/prefs/pref_set_observer.h +++ /dev/null @@ -1,60 +0,0 @@ -// 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 CHROME_BROWSER_PREFS_PREF_SET_OBSERVER_H_ -#define CHROME_BROWSER_PREFS_PREF_SET_OBSERVER_H_ - -#include <set> - -#include "base/basictypes.h" -#include "chrome/browser/api/prefs/pref_change_registrar.h" -#include "chrome/browser/prefs/pref_service.h" -#include "content/public/browser/notification_observer.h" - -// Observes the state of a set of preferences and allows to query their combined -// managed bits. -class PrefSetObserver : public content::NotificationObserver { - public: - // Initialize with an empty set of preferences. - PrefSetObserver(PrefService* pref_service, - content::NotificationObserver* observer); - virtual ~PrefSetObserver(); - - // Add a |pref| to the set of preferences to observe. - void AddPref(const std::string& pref); - // Remove |pref| from the set of observed peferences. - void RemovePref(const std::string& pref); - - // Check whether |pref| is in the set of observed preferences. - bool IsObserved(const std::string& pref); - // Check whether any of the observed preferences has the managed bit set. - bool IsManaged(); - - // Create a pref set observer for all preferences relevant to proxies. - static PrefSetObserver* CreateProxyPrefSetObserver( - PrefService* pref_service, - content::NotificationObserver* observer); - - // Create a pref set observer for preferences accessed by ProtectorService. - static PrefSetObserver* CreateProtectedPrefSetObserver( - PrefService* pref_service, - content::NotificationObserver* observer); - - private: - // Overridden from content::NotificationObserver. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - typedef std::set<std::string> PrefSet; - PrefSet prefs_; - - PrefService* pref_service_; - PrefChangeRegistrar registrar_; - content::NotificationObserver* observer_; - - DISALLOW_COPY_AND_ASSIGN(PrefSetObserver); -}; - -#endif // CHROME_BROWSER_PREFS_PREF_SET_OBSERVER_H_ diff --git a/chrome/browser/prefs/pref_set_observer_unittest.cc b/chrome/browser/prefs/pref_set_observer_unittest.cc deleted file mode 100644 index adb6011..0000000 --- a/chrome/browser/prefs/pref_set_observer_unittest.cc +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) 2011 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. - -#include "chrome/browser/prefs/pref_set_observer.h" -#include "chrome/common/chrome_notification_types.h" -#include "chrome/common/pref_names.h" -#include "chrome/test/base/testing_pref_service.h" -#include "content/public/browser/notification_details.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" - -// Unit tests for PrefSetObserver. -class PrefSetObserverTest : public testing::Test { - public: - virtual void SetUp() { - pref_service_.reset(new TestingPrefService); - pref_service_->RegisterStringPref(prefs::kHomePage, - "http://google.com", - PrefService::UNSYNCABLE_PREF); - pref_service_->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, - false, - PrefService::UNSYNCABLE_PREF); - pref_service_->RegisterStringPref(prefs::kApplicationLocale, - "", - PrefService::UNSYNCABLE_PREF); - } - - PrefSetObserver* CreatePrefSetObserver( - content::NotificationObserver* observer) { - PrefSetObserver* pref_set = - new PrefSetObserver(pref_service_.get(), observer); - pref_set->AddPref(prefs::kHomePage); - pref_set->AddPref(prefs::kHomePageIsNewTabPage); - return pref_set; - } - - scoped_ptr<TestingPrefService> pref_service_; -}; - -TEST_F(PrefSetObserverTest, IsObserved) { - scoped_ptr<PrefSetObserver> pref_set(CreatePrefSetObserver(NULL)); - EXPECT_TRUE(pref_set->IsObserved(prefs::kHomePage)); - EXPECT_TRUE(pref_set->IsObserved(prefs::kHomePageIsNewTabPage)); - EXPECT_FALSE(pref_set->IsObserved(prefs::kApplicationLocale)); -} - -TEST_F(PrefSetObserverTest, IsManaged) { - scoped_ptr<PrefSetObserver> pref_set(CreatePrefSetObserver(NULL)); - EXPECT_FALSE(pref_set->IsManaged()); - pref_service_->SetManagedPref(prefs::kHomePage, - Value::CreateStringValue("http://crbug.com")); - EXPECT_TRUE(pref_set->IsManaged()); - pref_service_->SetManagedPref(prefs::kHomePageIsNewTabPage, - Value::CreateBooleanValue(true)); - EXPECT_TRUE(pref_set->IsManaged()); - pref_service_->RemoveManagedPref(prefs::kHomePage); - EXPECT_TRUE(pref_set->IsManaged()); - pref_service_->RemoveManagedPref(prefs::kHomePageIsNewTabPage); - EXPECT_FALSE(pref_set->IsManaged()); -} - -MATCHER_P(PrefNameDetails, name, "details references named preference") { - std::string* pstr = - reinterpret_cast<const content::Details<std::string>&>(arg).ptr(); - return pstr && *pstr == name; -} - -TEST_F(PrefSetObserverTest, Observe) { - using testing::_; - using testing::Mock; - - content::MockNotificationObserver observer; - scoped_ptr<PrefSetObserver> pref_set(CreatePrefSetObserver(&observer)); - - EXPECT_CALL(observer, - Observe(int(chrome::NOTIFICATION_PREF_CHANGED), - content::Source<PrefService>(pref_service_.get()), - PrefNameDetails(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))); - pref_service_->SetUserPref(prefs::kHomePageIsNewTabPage, - Value::CreateBooleanValue(true)); - Mock::VerifyAndClearExpectations(&observer); - - EXPECT_CALL(observer, Observe(_, _, _)).Times(0); - pref_service_->SetUserPref(prefs::kApplicationLocale, - Value::CreateStringValue("en_US.utf8")); - Mock::VerifyAndClearExpectations(&observer); -} diff --git a/chrome/browser/protector/base_prefs_change.cc b/chrome/browser/protector/base_prefs_change.cc index 7e9dca6..2a4a871 100644 --- a/chrome/browser/protector/base_prefs_change.cc +++ b/chrome/browser/protector/base_prefs_change.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/prefs/pref_set_observer.h" +#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/protector/base_prefs_change.h" #include "chrome/browser/protector/protected_prefs_watcher.h" @@ -23,7 +23,7 @@ BasePrefsChange::~BasePrefsChange() { bool BasePrefsChange::Init(Profile* profile) { if (!BaseSettingChange::Init(profile)) return false; - pref_observer_.reset(new PrefSetObserver(profile->GetPrefs(), this)); + pref_observer_.Init(profile->GetPrefs()); return true; } @@ -35,12 +35,12 @@ void BasePrefsChange::InitWhenDisabled(Profile* profile) { } void BasePrefsChange::DismissOnPrefChange(const std::string& pref_name) { - DCHECK(!pref_observer_->IsObserved(pref_name)); - pref_observer_->AddPref(pref_name); + DCHECK(!pref_observer_.IsObserved(pref_name)); + pref_observer_.Add(pref_name.c_str(), this); } void BasePrefsChange::IgnorePrefChanges() { - pref_observer_.reset(); + pref_observer_.RemoveAll(); } void BasePrefsChange::Observe(int type, @@ -48,7 +48,7 @@ void BasePrefsChange::Observe(int type, 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)); + DCHECK(pref_name && 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 96ed5ce..a3f6b86 100644 --- a/chrome/browser/protector/base_prefs_change.h +++ b/chrome/browser/protector/base_prefs_change.h @@ -8,11 +8,10 @@ #include <string> #include "base/memory/scoped_ptr.h" +#include "chrome/browser/api/prefs/pref_change_registrar.h" #include "chrome/browser/protector/base_setting_change.h" #include "content/public/browser/notification_observer.h" -class PrefSetObserver; - namespace protector { // BaseSettingChange subclass for PrefService-managed settings changes. @@ -41,7 +40,7 @@ class BasePrefsChange : public BaseSettingChange, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; - scoped_ptr<PrefSetObserver> pref_observer_; + PrefChangeRegistrar pref_observer_; DISALLOW_COPY_AND_ASSIGN(BasePrefsChange); }; diff --git a/chrome/browser/protector/protected_prefs_watcher.cc b/chrome/browser/protector/protected_prefs_watcher.cc index 80dd4a0..b98438d 100644 --- a/chrome/browser/protector/protected_prefs_watcher.cc +++ b/chrome/browser/protector/protected_prefs_watcher.cc @@ -9,8 +9,8 @@ #include "base/metrics/histogram.h" #include "base/stringprintf.h" #include "base/values.h" +#include "chrome/browser/extensions/extension_prefs.h" #include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/prefs/pref_set_observer.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/browser/profiles/profile.h" @@ -109,8 +109,19 @@ ProtectedPrefsWatcher::ProtectedPrefsWatcher(Profile* profile) // Perform necessary pref migrations before actually starting to observe // pref changes, otherwise the migration would affect the backup data as well. EnsurePrefsMigration(); - pref_observer_.reset(PrefSetObserver::CreateProtectedPrefSetObserver( - profile->GetPrefs(), this)); + + pref_observer_.Init(profile->GetPrefs()); + pref_observer_.Add(prefs::kHomePageIsNewTabPage, this); + pref_observer_.Add(prefs::kHomePage, this); + pref_observer_.Add(prefs::kShowHomeButton, this); + // Session startup. + pref_observer_.Add(prefs::kRestoreOnStartup, this); + pref_observer_.Add(prefs::kURLsToRestoreOnStartup, this); + // Pinned tabs. + pref_observer_.Add(prefs::kPinnedTabs, this); + // Extensions. + pref_observer_.Add(ExtensionPrefs::kExtensionsPref, this); + UpdateCachedPrefs(); ValidateBackup(); VLOG(1) << "Initialized pref watcher"; @@ -190,7 +201,7 @@ void ProtectedPrefsWatcher::Observe( 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)); + DCHECK(pref_name && 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 6a785b4..8dc264d 100644 --- a/chrome/browser/protector/protected_prefs_watcher.h +++ b/chrome/browser/protector/protected_prefs_watcher.h @@ -9,11 +9,11 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" +#include "chrome/browser/api/prefs/pref_change_registrar.h" #include "chrome/browser/extensions/extension_prefs.h" #include "content/public/browser/notification_observer.h" class PrefService; -class PrefSetObserver; class Profile; namespace base { @@ -93,7 +93,7 @@ class ProtectedPrefsWatcher : public content::NotificationObserver { // Cached set of extension IDs. They are not changed as frequently extensions::ExtensionIdList cached_extension_ids_; - scoped_ptr<PrefSetObserver> pref_observer_; + PrefChangeRegistrar pref_observer_; // True if the backup was valid at the profile load time. bool is_backup_valid_; diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc index e1ceea1..73ff7f3 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.cc +++ b/chrome/browser/ui/webui/options/browser_options_handler.cc @@ -604,8 +604,8 @@ void BrowserOptionsHandler::InitializeHandler() { default_font_size_.Init(prefs::kWebKitDefaultFontSize, prefs, this); default_zoom_level_.Init(prefs::kDefaultZoomLevel, prefs, this); #if !defined(OS_CHROMEOS) - proxy_prefs_.reset( - PrefSetObserver::CreateProxyPrefSetObserver(prefs, this)); + proxy_prefs_.Init(prefs); + proxy_prefs_.Add(prefs::kProxy, this); #endif // !defined(OS_CHROMEOS) } @@ -857,7 +857,7 @@ void BrowserOptionsHandler::Observe( } else if (*pref_name == prefs::kDownloadExtensionsToOpen) { SetupAutoOpenFileTypes(); #if !defined(OS_CHROMEOS) - } else if (proxy_prefs_->IsObserved(*pref_name)) { + } else if (proxy_prefs_.IsObserved(*pref_name)) { SetupProxySettingsSection(); #endif // !defined(OS_CHROMEOS) } else if ((*pref_name == prefs::kCloudPrintEmail) || @@ -1389,8 +1389,8 @@ void BrowserOptionsHandler::SetupProxySettingsSection() { bool is_extension_controlled = (proxy_config && proxy_config->IsExtensionControlled()); - base::FundamentalValue disabled(proxy_prefs_->IsManaged() || - is_extension_controlled); + base::FundamentalValue disabled(proxy_prefs_.IsManaged() || + is_extension_controlled); // Get the appropriate info string to describe the button. string16 label_str; diff --git a/chrome/browser/ui/webui/options/browser_options_handler.h b/chrome/browser/ui/webui/options/browser_options_handler.h index e6d5d1c..b0749a3 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.h +++ b/chrome/browser/ui/webui/options/browser_options_handler.h @@ -21,7 +21,7 @@ #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/system/pointer_device_observer.h" #else -#include "chrome/browser/prefs/pref_set_observer.h" +#include "chrome/browser/api/prefs/pref_change_registrar.h" #endif // defined(OS_CHROMEOS) class AutocompleteController; @@ -292,7 +292,7 @@ class BrowserOptionsHandler DoublePrefMember default_zoom_level_; #if !defined(OS_CHROMEOS) - scoped_ptr<PrefSetObserver> proxy_prefs_; + PrefChangeRegistrar proxy_prefs_; #endif // !defined(OS_CHROMEOS) DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler); 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 6abee13..7894ff1 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 @@ -16,7 +16,7 @@ #include "chrome/browser/chromeos/proxy_cros_settings_parser.h" #include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/policy/browser_policy_connector.h" -#include "chrome/browser/prefs/pref_set_observer.h" +#include "chrome/browser/api/prefs/pref_change_registrar.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h" #include "chrome/browser/ui/webui/options/chromeos/accounts_options_handler.h" @@ -102,8 +102,8 @@ CoreChromeOSOptionsHandler::~CoreChromeOSOptionsHandler() { void CoreChromeOSOptionsHandler::InitializeHandler() { CoreOptionsHandler::InitializeHandler(); - proxy_prefs_.reset(PrefSetObserver::CreateProxyPrefSetObserver( - Profile::FromWebUI(web_ui())->GetPrefs(), this)); + proxy_prefs_.Init(Profile::FromWebUI(web_ui())->GetPrefs()); + proxy_prefs_.Add(prefs::kProxy, this); // Observe the chromeos::ProxyConfigServiceImpl for changes from the UI. PrefProxyConfigTracker* proxy_tracker = Profile::FromWebUI(web_ui())->GetProxyConfigTracker(); @@ -206,7 +206,7 @@ void CoreChromeOSOptionsHandler::Observe( 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) || + (proxy_prefs_.IsObserved(*pref_name) || *pref_name == prefs::kUseSharedProxies)) { NotifyPrefChanged(prefs::kUseSharedProxies, prefs::kProxy); return; 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 ff6c6bc..46fa0ee 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 @@ -7,10 +7,9 @@ #include "base/compiler_specific.h" #include "base/memory/weak_ptr.h" +#include "chrome/browser/api/prefs/pref_change_registrar.h" #include "chrome/browser/ui/webui/options/core_options_handler.h" -class PrefSetObserver; - namespace chromeos { namespace options { @@ -43,7 +42,7 @@ class CoreChromeOSOptionsHandler : public ::options::CoreOptionsHandler { void NotifySettingsChanged(const std::string* setting_name); void NotifyProxyPrefsChanged(); - scoped_ptr<PrefSetObserver> proxy_prefs_; + PrefChangeRegistrar proxy_prefs_; base::WeakPtrFactory<CoreChromeOSOptionsHandler> pointer_factory_; }; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index ffacfb1..7d2aee3 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1405,8 +1405,6 @@ 'browser/prefs/pref_notifier_impl.h', 'browser/prefs/pref_service.cc', 'browser/prefs/pref_service.h', - 'browser/prefs/pref_set_observer.cc', - 'browser/prefs/pref_set_observer.h', 'browser/prefs/pref_value_map.cc', 'browser/prefs/pref_value_map.h', 'browser/prefs/pref_value_store.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 86aa4e6..13b6db9 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1523,7 +1523,6 @@ 'browser/prefs/pref_model_associator_unittest.cc', 'browser/prefs/pref_notifier_impl_unittest.cc', 'browser/prefs/pref_service_unittest.cc', - 'browser/prefs/pref_set_observer_unittest.cc', 'browser/prefs/pref_value_map_unittest.cc', 'browser/prefs/pref_value_store_unittest.cc', 'browser/prefs/proxy_config_dictionary_unittest.cc', |