diff options
Diffstat (limited to 'chrome/browser/extensions')
6 files changed, 61 insertions, 42 deletions
diff --git a/chrome/browser/extensions/extension_toolbar_model.cc b/chrome/browser/extensions/extension_toolbar_model.cc index 325f0c4..100c7aa 100644 --- a/chrome/browser/extensions/extension_toolbar_model.cc +++ b/chrome/browser/extensions/extension_toolbar_model.cc @@ -33,6 +33,10 @@ ExtensionToolbarModel::ExtensionToolbarModel(ExtensionsService* service) ExtensionToolbarModel::~ExtensionToolbarModel() { } +void ExtensionToolbarModel::DestroyingProfile() { + registrar_.RemoveAll(); +} + void ExtensionToolbarModel::AddObserver(Observer* observer) { observers_.AddObserver(observer); } diff --git a/chrome/browser/extensions/extension_toolbar_model.h b/chrome/browser/extensions/extension_toolbar_model.h index 028c8b5..a38fc8c 100644 --- a/chrome/browser/extensions/extension_toolbar_model.h +++ b/chrome/browser/extensions/extension_toolbar_model.h @@ -20,6 +20,10 @@ class ExtensionToolbarModel : public NotificationObserver { explicit ExtensionToolbarModel(ExtensionsService* service); ~ExtensionToolbarModel(); + // Notifies the toolbar model that the Profile that suplied its + // prefs is being destroyed. + void DestroyingProfile(); + // A class which is informed of changes to the model; represents the view of // MVC. class Observer { diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index e2e6342..017890f 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -528,11 +528,11 @@ bool ExtensionsService::IsDownloadFromMiniGallery(const GURL& download_url) { ExtensionsService::ExtensionsService(Profile* profile, const CommandLine* command_line, - PrefService* prefs, const FilePath& install_directory, bool autoupdate_enabled) : profile_(profile), - extension_prefs_(new ExtensionPrefs(prefs, install_directory)), + extension_prefs_(new ExtensionPrefs(profile->GetPrefs(), + install_directory)), install_directory_(install_directory), extensions_enabled_(true), show_extensions_prompts_(true), @@ -547,8 +547,9 @@ ExtensionsService::ExtensionsService(Profile* profile, registrar_.Add(this, NotificationType::EXTENSION_PROCESS_TERMINATED, NotificationService::AllSources()); - prefs->AddPrefObserver(prefs::kExtensionInstallAllowList, this); - prefs->AddPrefObserver(prefs::kExtensionInstallDenyList, this); + pref_change_registrar_.Init(profile->GetPrefs()); + pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this); + pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this); // Set up the ExtensionUpdater if (autoupdate_enabled) { @@ -558,7 +559,9 @@ ExtensionsService::ExtensionsService(Profile* profile, switches::kExtensionsUpdateFrequency), &update_frequency); } - updater_ = new ExtensionUpdater(this, prefs, update_frequency); + updater_ = new ExtensionUpdater(this, + profile->GetPrefs(), + update_frequency); } backend_ = new ExtensionsServiceBackend(install_directory_, @@ -572,6 +575,7 @@ ExtensionsService::ExtensionsService(Profile* profile, } ExtensionsService::~ExtensionsService() { + DCHECK(!profile_); // Profile should have told us it's going away. UnloadAllExtensions(); if (updater_.get()) { updater_->Stop(); @@ -1186,12 +1190,9 @@ void ExtensionsService::UpdateExtensionBlacklist( } void ExtensionsService::DestroyingProfile() { - profile_->GetPrefs()->RemovePrefObserver( - prefs::kExtensionInstallAllowList, this); - profile_->GetPrefs()->RemovePrefObserver( - prefs::kExtensionInstallDenyList, this); - + pref_change_registrar_.RemoveAll(); profile_ = NULL; + toolbar_model_.DestroyingProfile(); } void ExtensionsService::CheckAdminBlacklist() { diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index cc9bb769..7d5ad97 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -28,6 +28,7 @@ #include "chrome/browser/extensions/extensions_quota_service.h" #include "chrome/browser/extensions/external_extension_provider.h" #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" +#include "chrome/browser/prefs/pref_change_registrar.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/extensions/extension.h" @@ -140,7 +141,6 @@ class ExtensionsService ExtensionsService(Profile* profile, const CommandLine* command_line, - PrefService* prefs, const FilePath& install_directory, bool autoupdate_enabled); @@ -486,6 +486,7 @@ class ExtensionsService OrphanedDevTools orphaned_dev_tools_; NotificationRegistrar registrar_; + PrefChangeRegistrar pref_change_registrar_; // Keeps track of menu items added by extensions. ExtensionMenuManager menu_manager_; diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index a434b8f..7781945 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -287,23 +287,22 @@ void ExtensionsServiceTestBase::InitializeExtensionsService( ExtensionTestingProfile* profile = new ExtensionTestingProfile(); // Create a preference service that only contains user defined // preference values. - prefs_.reset(PrefService::CreateUserPrefService(pref_file)); + PrefService* prefs = PrefService::CreateUserPrefService(pref_file); + Profile::RegisterUserPrefs(prefs); + browser::RegisterUserPrefs(prefs); + profile->SetPrefService(prefs); - Profile::RegisterUserPrefs(prefs_.get()); - browser::RegisterUserPrefs(prefs_.get()); profile_.reset(profile); // TODO(scherkus): Remove this when we no longer need to have Talk // component extension state as a preference http://crbug.com/56429 DictionaryValue* dict = - prefs_->GetMutableDictionary("extensions.settings"); + profile->GetPrefs()->GetMutableDictionary("extensions.settings"); dict->Remove("ggnioahjipcehijkhpdjekioddnjoben", NULL); - service_ = new ExtensionsService(profile_.get(), - CommandLine::ForCurrentProcess(), - prefs_.get(), - extensions_install_dir, - false); + service_ = profile->CreateExtensionsService( + CommandLine::ForCurrentProcess(), + extensions_install_dir); service_->set_extensions_enabled(true); service_->set_show_extensions_prompts(false); profile->set_extensions_service(service_.get()); @@ -524,7 +523,7 @@ class ExtensionsServiceTest void ValidatePrefKeyCount(size_t count) { DictionaryValue* dict = - prefs_->GetMutableDictionary("extensions.settings"); + profile_->GetPrefs()->GetMutableDictionary("extensions.settings"); ASSERT_TRUE(dict != NULL); EXPECT_EQ(count, dict->size()); } @@ -539,7 +538,9 @@ class ExtensionsServiceTest msg += " == "; msg += expected_val ? "true" : "false"; - const DictionaryValue* dict = prefs_->GetDictionary("extensions.settings"); + PrefService* prefs = profile_->GetPrefs(); + const DictionaryValue* dict = + prefs->GetDictionary("extensions.settings"); ASSERT_TRUE(dict != NULL) << msg; DictionaryValue* pref = NULL; ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; @@ -551,7 +552,8 @@ class ExtensionsServiceTest bool IsPrefExist(const std::string& extension_id, const std::string& pref_path) { - const DictionaryValue* dict = prefs_->GetDictionary("extensions.settings"); + const DictionaryValue* dict = + profile_->GetPrefs()->GetDictionary("extensions.settings"); if (dict == NULL) return false; DictionaryValue* pref = NULL; if (!dict->GetDictionary(extension_id, &pref)) { @@ -577,7 +579,9 @@ class ExtensionsServiceTest msg += " == "; msg += base::IntToString(expected_val); - const DictionaryValue* dict = prefs_->GetDictionary("extensions.settings"); + PrefService* prefs = profile_->GetPrefs(); + const DictionaryValue* dict = + prefs->GetDictionary("extensions.settings"); ASSERT_TRUE(dict != NULL) << msg; DictionaryValue* pref = NULL; ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; @@ -597,7 +601,8 @@ class ExtensionsServiceTest msg += " == "; msg += expected_val; - const DictionaryValue* dict = prefs_->GetDictionary("extensions.settings"); + const DictionaryValue* dict = + profile_->GetPrefs()->GetDictionary("extensions.settings"); ASSERT_TRUE(dict != NULL) << msg; DictionaryValue* pref = NULL; std::string manifest_path = extension_id + ".manifest"; @@ -619,7 +624,7 @@ class ExtensionsServiceTest msg += base::IntToString(value); const DictionaryValue* dict = - prefs_->GetMutableDictionary("extensions.settings"); + profile_->GetPrefs()->GetMutableDictionary("extensions.settings"); ASSERT_TRUE(dict != NULL) << msg; DictionaryValue* pref = NULL; ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; @@ -845,7 +850,8 @@ TEST_F(ExtensionsServiceTest, CleanupOnStartup) { InitializeInstalledExtensionsService(pref_path, source_install_dir); // Simulate that one of them got partially deleted by clearing its pref. - DictionaryValue* dict = prefs_->GetMutableDictionary("extensions.settings"); + DictionaryValue* dict = + profile_->GetPrefs()->GetMutableDictionary("extensions.settings"); ASSERT_TRUE(dict != NULL); dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL); @@ -1868,8 +1874,10 @@ TEST_F(ExtensionsServiceTest, WillNotLoadPluginExtensionsFromDirectory) { TEST_F(ExtensionsServiceTest, BlacklistedByPolicyWillNotInstall) { InitializeEmptyExtensionsService(); - ListValue* whitelist = prefs_->GetMutableList("extensions.install.allowlist"); - ListValue* blacklist = prefs_->GetMutableList("extensions.install.denylist"); + ListValue* whitelist = + profile_->GetPrefs()->GetMutableList("extensions.install.allowlist"); + ListValue* blacklist = + profile_->GetPrefs()->GetMutableList("extensions.install.denylist"); ASSERT_TRUE(whitelist != NULL && blacklist != NULL); // Blacklist everything. @@ -1906,16 +1914,18 @@ TEST_F(ExtensionsServiceTest, BlacklistedByPolicyRemovedIfRunning) { loop_.RunAllPending(); EXPECT_EQ(1u, service_->extensions()->size()); - ListValue* blacklist = prefs_->GetMutableList("extensions.install.denylist"); + PrefService* prefs = profile_->GetPrefs(); + ListValue* blacklist = + prefs->GetMutableList("extensions.install.denylist"); ASSERT_TRUE(blacklist != NULL); // Blacklist this extension. blacklist->Append(Value::CreateStringValue(good_crx)); - prefs_->ScheduleSavePersistentPrefs(); + prefs->ScheduleSavePersistentPrefs(); // Programmatically appending to the prefs doesn't seem to notify the // observers... :/ - prefs_->pref_notifier()->FireObservers("extensions.install.denylist"); + prefs->pref_notifier()->FireObservers("extensions.install.denylist"); // Extension should not be running now. loop_.RunAllPending(); @@ -2233,7 +2243,7 @@ void ExtensionsServiceTest::TestExternalProvider( // Now clear the preference and reinstall. SetPrefInteg(good_crx, "state", Extension::ENABLED); - prefs_->ScheduleSavePersistentPrefs(); + profile_->GetPrefs()->ScheduleSavePersistentPrefs(); loaded_.clear(); service_->CheckForExternalUpdates(); @@ -2461,8 +2471,8 @@ TEST(ExtensionsServiceTestSimple, Enabledness) { // By default, we are enabled. command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); - service = new ExtensionsService(profile.get(), command_line.get(), - profile->GetPrefs(), install_dir, false); + service = profile->CreateExtensionsService(command_line.get(), + install_dir); EXPECT_TRUE(service->extensions_enabled()); service->Init(); loop.RunAllPending(); @@ -2472,8 +2482,8 @@ TEST(ExtensionsServiceTestSimple, Enabledness) { recorder.set_ready(false); profile.reset(new TestingProfile()); command_line->AppendSwitch(switches::kDisableExtensions); - service = new ExtensionsService(profile.get(), command_line.get(), - profile->GetPrefs(), install_dir, false); + service = profile->CreateExtensionsService(command_line.get(), + install_dir); EXPECT_FALSE(service->extensions_enabled()); service->Init(); loop.RunAllPending(); @@ -2482,8 +2492,8 @@ TEST(ExtensionsServiceTestSimple, Enabledness) { recorder.set_ready(false); profile.reset(new TestingProfile()); profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); - service = new ExtensionsService(profile.get(), command_line.get(), - profile->GetPrefs(), install_dir, false); + service = profile->CreateExtensionsService(command_line.get(), + install_dir); EXPECT_FALSE(service->extensions_enabled()); service->Init(); loop.RunAllPending(); @@ -2493,8 +2503,8 @@ TEST(ExtensionsServiceTestSimple, Enabledness) { profile.reset(new TestingProfile()); profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); - service = new ExtensionsService(profile.get(), command_line.get(), - profile->GetPrefs(), install_dir, false); + service = profile->CreateExtensionsService(command_line.get(), + install_dir); EXPECT_FALSE(service->extensions_enabled()); service->Init(); loop.RunAllPending(); diff --git a/chrome/browser/extensions/extensions_service_unittest.h b/chrome/browser/extensions/extensions_service_unittest.h index 62f6a95..fe298b4b 100644 --- a/chrome/browser/extensions/extensions_service_unittest.h +++ b/chrome/browser/extensions/extensions_service_unittest.h @@ -38,7 +38,6 @@ class ExtensionsServiceTestBase : public testing::Test { protected: ScopedTempDir temp_dir_; - scoped_ptr<PrefService> prefs_; scoped_ptr<Profile> profile_; FilePath extensions_install_dir_; scoped_refptr<ExtensionsService> service_; |