diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-11 18:34:53 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-11 18:34:53 +0000 |
commit | dd86101d322f138a056d1d92f859b6b356c34a01 (patch) | |
tree | 7fa678de3203c5c987a7b7a01e8acfa5e87a28cd | |
parent | eb4c6af05ac88f704db922be6e458e5d09a9d621 (diff) | |
download | chromium_src-dd86101d322f138a056d1d92f859b6b356c34a01.zip chromium_src-dd86101d322f138a056d1d92f859b6b356c34a01.tar.gz chromium_src-dd86101d322f138a056d1d92f859b6b356c34a01.tar.bz2 |
Revert r96364, it's breaking a NaCl test.
TEST=
BUG=
TBR=bauerb@chromium.org
Review URL: http://codereview.chromium.org/7627001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96430 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/about_flags.cc | 16 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 4 | ||||
-rw-r--r-- | chrome/browser/browser_about_handler.cc | 4 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 5 | ||||
-rw-r--r-- | chrome/browser/browser_shutdown.cc | 3 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/login_utils.cc | 4 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_log.cc | 1 | ||||
-rw-r--r-- | chrome/browser/pdf_unsupported_feature.cc | 10 | ||||
-rw-r--r-- | chrome/browser/plugin_updater.cc (renamed from chrome/browser/plugin_prefs.cc) | 234 | ||||
-rw-r--r-- | chrome/browser/plugin_updater.h (renamed from chrome/browser/plugin_prefs.h) | 75 | ||||
-rw-r--r-- | chrome/browser/prefs/browser_prefs.cc | 4 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_dependency_manager.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/webui/plugins_ui.cc | 67 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 4 |
14 files changed, 176 insertions, 257 deletions
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 49d4ed2..c914725 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -14,6 +14,7 @@ #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "chrome/browser/plugin_updater.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/common/chrome_content_client.h" @@ -724,10 +725,21 @@ void FlagsState::SetExperimentEnabled( DCHECK(e); if (e->type == Experiment::SINGLE_VALUE) { - if (enable) + if (enable) { enabled_experiments.insert(internal_name); - else + // If enabling NaCl, make sure the plugin is also enabled. See bug + // http://code.google.com/p/chromium/issues/detail?id=81010 for more + // information. + // TODO(dspringer): When NaCl is on by default, remove this code. + if (internal_name == switches::kEnableNaCl) { + PluginUpdater* plugin_updater = PluginUpdater::GetInstance(); + string16 nacl_plugin_name = + ASCIIToUTF16(chrome::ChromeContentClient::kNaClPluginName); + plugin_updater->EnablePluginGroup(true, nacl_plugin_name); + } + } else { enabled_experiments.erase(internal_name); + } } else { if (enable) { // Enable the first choice. diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index ab9ff4c..354a560 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -59,7 +59,6 @@ #include "chrome/browser/password_manager/password_store.h" #include "chrome/browser/password_manager/password_store_change.h" #include "chrome/browser/platform_util.h" -#include "chrome/browser/plugin_prefs.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" @@ -3404,7 +3403,6 @@ void TestingAutomationProvider::GetPluginsInfo( } std::vector<webkit::npapi::WebPluginInfo> plugins; webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); - PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); ListValue* items = new ListValue; for (std::vector<webkit::npapi::WebPluginInfo>::const_iterator it = plugins.begin(); @@ -3415,7 +3413,7 @@ void TestingAutomationProvider::GetPluginsInfo( item->SetString("path", it->path.value()); item->SetString("version", it->version); item->SetString("desc", it->desc); - item->SetBoolean("enabled", plugin_prefs->IsPluginEnabled(*it)); + item->SetBoolean("enabled", webkit::npapi::IsPluginEnabled(*it)); // Add info about mime types. ListValue* mime_types = new ListValue(); for (std::vector<webkit::npapi::WebPluginMimeType>::const_iterator type_it = diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index c750446..9745341 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -32,7 +32,6 @@ #include "chrome/browser/metrics/histogram_synchronizer.h" #include "chrome/browser/net/predictor_api.h" #include "chrome/browser/net/url_fixer_upper.h" -#include "chrome/browser/plugin_prefs.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/browser_dialogs.h" @@ -1114,9 +1113,8 @@ std::string AboutVersionStrings(DictionaryValue* localized_strings, GURL(), "application/x-shockwave-flash", false, NULL, &info_array, NULL); string16 flash_version = l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); - PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); for (size_t i = 0; i < info_array.size(); ++i) { - if (plugin_prefs->IsPluginEnabled(info_array[i])) { + if (webkit::npapi::IsPluginEnabled(info_array[i])) { flash_version = info_array[i].version; break; } diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index d27d333..3dec4f4 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -57,7 +57,7 @@ #include "chrome/browser/net/chrome_net_log.h" #include "chrome/browser/net/predictor_api.h" #include "chrome/browser/net/sdch_dictionary_fetcher.h" -#include "chrome/browser/plugin_prefs.h" +#include "chrome/browser/plugin_updater.h" #include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_value_store.h" @@ -1906,6 +1906,9 @@ int BrowserMain(const MainFunctionParams& parameters) { browser_process->google_url_tracker(); browser_process->intranet_redirect_detector(); + // Do initialize the plug-in service (and related preferences). + PluginUpdater::GetInstance()->SetProfile(profile); + // Prepare for memory caching of SDCH dictionaries. // Perform A/B test to measure global impact of SDCH support. // Set up a field trial to see what disabling SDCH does to latency of page diff --git a/chrome/browser/browser_shutdown.cc b/chrome/browser/browser_shutdown.cc index 92683fe..8bee29e 100644 --- a/chrome/browser/browser_shutdown.cc +++ b/chrome/browser/browser_shutdown.cc @@ -24,6 +24,7 @@ #include "chrome/browser/first_run/upgrade_util.h" #include "chrome/browser/jankometer.h" #include "chrome/browser/metrics/metrics_service.h" +#include "chrome/browser/plugin_updater.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/service/service_process_control.h" @@ -145,6 +146,8 @@ void Shutdown() { chrome_browser_net::SavePredictorStateForNextStartupAndTrim(user_prefs); + PluginUpdater::GetInstance()->Shutdown(); + MetricsService* metrics = g_browser_process->metrics_service(); if (metrics) metrics->RecordCompletedSessionEnd(); diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index 2e1b6a0..192136c 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -41,6 +41,7 @@ #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" #include "chrome/browser/net/gaia/token_service.h" #include "chrome/browser/net/preconnect.h" +#include "chrome/browser/plugin_updater.h" #include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/profiles/profile.h" @@ -547,6 +548,9 @@ void LoginUtilsImpl::OnProfileCreated(Profile* user_profile, Status status) { btl->AddLoginTimeMarker("TPMOwn-End", false); } + // Enable/disable plugins based on user preferences. + PluginUpdater::GetInstance()->SetProfile(user_profile); + // We suck. This is a hack since we do not have the enterprise feature // done yet to pull down policies from the domain admin. We'll take this // out when we get that done properly. diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc index 7e8c6a6..c826923 100644 --- a/chrome/browser/metrics/metrics_log.cc +++ b/chrome/browser/metrics/metrics_log.cc @@ -291,7 +291,6 @@ void MetricsLog::WritePluginList( #endif WriteAttribute("filename", CreateBase64Hash(filename_bytes)); WriteAttribute("version", UTF16ToUTF8(iter->version)); - // TODO(bauerb): Plug-in state is per-profile. WriteIntAttribute("disabled", !webkit::npapi::IsPluginEnabled(*iter)); } } diff --git a/chrome/browser/pdf_unsupported_feature.cc b/chrome/browser/pdf_unsupported_feature.cc index 78e8540..172f4fb 100644 --- a/chrome/browser/pdf_unsupported_feature.cc +++ b/chrome/browser/pdf_unsupported_feature.cc @@ -7,7 +7,7 @@ #include "base/utf_string_conversions.h" #include "base/values.h" #include "base/version.h" -#include "chrome/browser/plugin_prefs.h" +#include "chrome/browser/plugin_updater.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/chrome_interstitial_page.h" @@ -114,12 +114,12 @@ void PDFEnableAdobeReaderInfoBarDelegate::OnYes() { UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK")); webkit::npapi::PluginList::Singleton()->EnableGroup(false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); + PluginUpdater* plugin_updater = PluginUpdater::GetInstance(); + plugin_updater->EnablePluginGroup(true, + ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); Profile* profile = Profile::FromBrowserContext(tab_contents_->browser_context()); - PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); - plugin_prefs->EnablePluginGroup( - true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName)); - plugin_prefs->UpdatePreferences(0); + plugin_updater->UpdatePreferences(profile, 0); } void PDFEnableAdobeReaderInfoBarDelegate::OnNo() { diff --git a/chrome/browser/plugin_prefs.cc b/chrome/browser/plugin_updater.cc index ac35985..887fba8 100644 --- a/chrome/browser/plugin_prefs.cc +++ b/chrome/browser/plugin_updater.cc @@ -2,13 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/plugin_prefs.h" +#include "chrome/browser/plugin_updater.h" #include <string> -#include "base/command_line.h" #include "base/memory/scoped_ptr.h" -#include "base/memory/singleton.h" #include "base/message_loop.h" #include "base/path_service.h" #include "base/utf_string_conversions.h" @@ -17,114 +15,63 @@ #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_dependency_manager.h" -#include "chrome/browser/profiles/profile_keyed_service.h" -#include "chrome/browser/profiles/profile_keyed_service_factory.h" #include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "content/browser/browser_thread.h" #include "content/common/notification_service.h" #include "webkit/plugins/npapi/plugin_list.h" #include "webkit/plugins/npapi/webplugininfo.h" -namespace { - -class PluginPrefsWrapper : public ProfileKeyedService { - public: - explicit PluginPrefsWrapper(scoped_refptr<PluginPrefs> plugin_prefs) - : plugin_prefs_(plugin_prefs) {} - virtual ~PluginPrefsWrapper() {} - - PluginPrefs* plugin_prefs() { return plugin_prefs_.get(); } - - private: - // ProfileKeyedService methods: - virtual void Shutdown() OVERRIDE { - plugin_prefs_->ShutdownOnUIThread(); - } - - scoped_refptr<PluginPrefs> plugin_prefs_; -}; - -} - // How long to wait to save the plugin enabled information, which might need to // go to disk. #define kPluginUpdateDelayMs (60 * 1000) -class PluginPrefs::Factory : public ProfileKeyedServiceFactory { - public: - static Factory* GetInstance(); - - PluginPrefsWrapper* GetWrapperForProfile(Profile* profile); - - private: - friend struct DefaultSingletonTraits<Factory>; - - Factory(); - virtual ~Factory() {} - - // ProfileKeyedServiceFactory methods: - virtual ProfileKeyedService* BuildServiceInstanceFor( - Profile* profile) const OVERRIDE; - virtual bool ServiceRedirectedInIncognito() OVERRIDE { return true; } - virtual bool ServiceIsNULLWhileTesting() OVERRIDE { return true; } -}; - -// static -void PluginPrefs::Initialize() { - Factory::GetInstance(); -} - -// static -PluginPrefs* PluginPrefs::GetForProfile(Profile* profile) { - PluginPrefs* plugin_prefs = - Factory::GetInstance()->GetWrapperForProfile(profile)->plugin_prefs(); - DCHECK(plugin_prefs); - return plugin_prefs; +PluginUpdater::PluginUpdater() + : notify_pending_(false) { } -DictionaryValue* PluginPrefs::CreatePluginFileSummary( +DictionaryValue* PluginUpdater::CreatePluginFileSummary( const webkit::npapi::WebPluginInfo& plugin) { DictionaryValue* data = new DictionaryValue(); data->SetString("path", plugin.path.value()); data->SetString("name", plugin.name); data->SetString("version", plugin.version); - data->SetBoolean("enabled", IsPluginEnabled(plugin)); + data->SetBoolean("enabled", webkit::npapi::IsPluginEnabled(plugin)); return data; } -void PluginPrefs::EnablePluginGroup(bool enable, const string16& group_name) { +// static +ListValue* PluginUpdater::GetPluginGroupsData() { + std::vector<webkit::npapi::PluginGroup> plugin_groups; + webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, &plugin_groups); + + // Construct DictionaryValues to return to the UI + ListValue* plugin_groups_data = new ListValue(); + for (size_t i = 0; i < plugin_groups.size(); ++i) { + plugin_groups_data->Append(plugin_groups[i].GetDataForUI()); + } + return plugin_groups_data; +} + +void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) { webkit::npapi::PluginList::Singleton()->EnableGroup(enable, group_name); NotifyPluginStatusChanged(); } -void PluginPrefs::EnablePlugin(bool enable, const FilePath& path) { +void PluginUpdater::EnablePlugin(bool enable, + const FilePath::StringType& path) { + FilePath file_path(path); if (enable) - webkit::npapi::PluginList::Singleton()->EnablePlugin(path); + webkit::npapi::PluginList::Singleton()->EnablePlugin(file_path); else - webkit::npapi::PluginList::Singleton()->DisablePlugin(path); + webkit::npapi::PluginList::Singleton()->DisablePlugin(file_path); NotifyPluginStatusChanged(); } -bool PluginPrefs::IsPluginEnabled(const webkit::npapi::WebPluginInfo& plugin) { - // If enabling NaCl, make sure the plugin is also enabled. See bug - // http://code.google.com/p/chromium/issues/detail?id=81010 for more - // information. - // TODO(dspringer): When NaCl is on by default, remove this code. - if ((plugin.name == - ASCIIToUTF16(chrome::ChromeContentClient::kNaClPluginName)) && - CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaCl)) { - return true; - } - return webkit::npapi::IsPluginEnabled(plugin); -} - -void PluginPrefs::Observe(int type, +void PluginUpdater::Observe(int type, const NotificationSource& source, const NotificationDetails& details) { DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); @@ -133,21 +80,21 @@ void PluginPrefs::Observe(int type, NOTREACHED(); return; } - DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); if (*pref_name == prefs::kPluginsDisabledPlugins || *pref_name == prefs::kPluginsDisabledPluginsExceptions || *pref_name == prefs::kPluginsEnabledPlugins) { + PrefService* pref_service = Source<PrefService>(source).ptr(); const ListValue* disabled_list = - prefs_->GetList(prefs::kPluginsDisabledPlugins); + pref_service->GetList(prefs::kPluginsDisabledPlugins); const ListValue* exceptions_list = - prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions); + pref_service->GetList(prefs::kPluginsDisabledPluginsExceptions); const ListValue* enabled_list = - prefs_->GetList(prefs::kPluginsEnabledPlugins); + pref_service->GetList(prefs::kPluginsEnabledPlugins); UpdatePluginsStateFromPolicy(disabled_list, exceptions_list, enabled_list); } } -void PluginPrefs::UpdatePluginsStateFromPolicy( +void PluginUpdater::UpdatePluginsStateFromPolicy( const ListValue* disabled_list, const ListValue* exceptions_list, const ListValue* enabled_list) { @@ -167,8 +114,8 @@ void PluginPrefs::UpdatePluginsStateFromPolicy( NotifyPluginStatusChanged(); } -void PluginPrefs::ListValueToStringSet(const ListValue* src, - std::set<string16>* dest) { +void PluginUpdater::ListValueToStringSet(const ListValue* src, + std::set<string16>* dest) { DCHECK(src); DCHECK(dest); ListValue::const_iterator end(src->end()); @@ -181,16 +128,15 @@ void PluginPrefs::ListValueToStringSet(const ListValue* src, } } -void PluginPrefs::SetProfile(Profile* profile) { - prefs_ = profile->GetPrefs(); +void PluginUpdater::SetProfile(Profile* profile) { bool update_internal_dir = false; FilePath last_internal_dir = - prefs_->GetFilePath(prefs::kPluginsLastInternalDirectory); + profile->GetPrefs()->GetFilePath(prefs::kPluginsLastInternalDirectory); FilePath cur_internal_dir; if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && cur_internal_dir != last_internal_dir) { update_internal_dir = true; - prefs_->SetFilePath( + profile->GetPrefs()->SetFilePath( prefs::kPluginsLastInternalDirectory, cur_internal_dir); } @@ -201,16 +147,16 @@ void PluginPrefs::SetProfile(Profile* profile) { FilePath pdf_path; PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); FilePath::StringType pdf_path_str = pdf_path.value(); - if (!prefs_->GetBoolean(prefs::kPluginsEnabledInternalPDF)) { + if (!profile->GetPrefs()->GetBoolean(prefs::kPluginsEnabledInternalPDF)) { // We switched to the internal pdf plugin being on by default, and so we // need to force it to be enabled. We only want to do it this once though, // i.e. we don't want to enable it again if the user disables it afterwards. - prefs_->SetBoolean(prefs::kPluginsEnabledInternalPDF, true); + profile->GetPrefs()->SetBoolean(prefs::kPluginsEnabledInternalPDF, true); force_enable_internal_pdf = true; } { // Scoped update of prefs::kPluginsPluginsList. - ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); + ListPrefUpdate update(profile->GetPrefs(), prefs::kPluginsPluginsList); ListValue* saved_plugins_list = update.Get(); if (saved_plugins_list && !saved_plugins_list->empty()) { for (ListValue::const_iterator it = saved_plugins_list->begin(); @@ -275,17 +221,17 @@ void PluginPrefs::SetProfile(Profile* profile) { // Build the set of policy enabled/disabled plugin patterns once and cache it. // Don't do this in the constructor, there's no profile available there. const ListValue* disabled_plugins = - prefs_->GetList(prefs::kPluginsDisabledPlugins); + profile->GetPrefs()->GetList(prefs::kPluginsDisabledPlugins); const ListValue* disabled_exception_plugins = - prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions); + profile->GetPrefs()->GetList(prefs::kPluginsDisabledPluginsExceptions); const ListValue* enabled_plugins = - prefs_->GetList(prefs::kPluginsEnabledPlugins); + profile->GetPrefs()->GetList(prefs::kPluginsEnabledPlugins); UpdatePluginsStateFromPolicy(disabled_plugins, disabled_exception_plugins, enabled_plugins); registrar_.RemoveAll(); - registrar_.Init(prefs_); + registrar_.Init(profile->GetPrefs()); registrar_.Add(prefs::kPluginsDisabledPlugins, this); registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, this); registrar_.Add(prefs::kPluginsEnabledPlugins, this); @@ -300,88 +246,59 @@ void PluginPrefs::SetProfile(Profile* profile) { // We want to save this, but doing so requires loading the list of plugins, // so do it after a minute as to not impact startup performance. Note that // plugins are loaded after 30s by the metrics service. - UpdatePreferences(kPluginUpdateDelayMs); + UpdatePreferences(profile, kPluginUpdateDelayMs); } } -void PluginPrefs::ShutdownOnUIThread() { - prefs_ = NULL; +void PluginUpdater::Shutdown() { registrar_.RemoveAll(); } -// static -PluginPrefs::Factory* PluginPrefs::Factory::GetInstance() { - return Singleton<PluginPrefs::Factory>::get(); -} - -PluginPrefsWrapper* PluginPrefs::Factory::GetWrapperForProfile( - Profile* profile) { - return static_cast<PluginPrefsWrapper*>(GetServiceForProfile(profile, true)); -} - -PluginPrefs::Factory::Factory() - : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) { -} - -ProfileKeyedService* PluginPrefs::Factory::BuildServiceInstanceFor( - Profile* profile) const { - scoped_refptr<PluginPrefs> plugin_prefs(new PluginPrefs()); - plugin_prefs->SetProfile(profile); - return new PluginPrefsWrapper(plugin_prefs); -} - -PluginPrefs::PluginPrefs() : notify_pending_(false) { -} - -PluginPrefs::~PluginPrefs() { -} - -void PluginPrefs::UpdatePreferences(int delay_ms) { +void PluginUpdater::UpdatePreferences(Profile* profile, int delay_ms) { BrowserThread::PostDelayedTask( - BrowserThread::FILE, - FROM_HERE, - NewRunnableMethod(this, &PluginPrefs::GetPreferencesDataOnFileThread), - delay_ms); + BrowserThread::FILE, + FROM_HERE, + NewRunnableFunction( + &PluginUpdater::GetPreferencesDataOnFileThread, profile), delay_ms); } -void PluginPrefs::GetPreferencesDataOnFileThread() { +void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { std::vector<webkit::npapi::WebPluginInfo> plugins; - std::vector<webkit::npapi::PluginGroup> groups; + webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); - webkit::npapi::PluginList* plugin_list = - webkit::npapi::PluginList::Singleton(); - plugin_list->GetPlugins(&plugins); - plugin_list->GetPluginGroups(false, &groups); + std::vector<webkit::npapi::PluginGroup> groups; + webkit::npapi::PluginList::Singleton()->GetPluginGroups(false, &groups); - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, &PluginPrefs::OnUpdatePreferences, + BrowserThread::PostTask( + BrowserThread::UI, + FROM_HERE, + NewRunnableFunction(&PluginUpdater::OnUpdatePreferences, + static_cast<Profile*>(profile), plugins, groups)); } -void PluginPrefs::OnUpdatePreferences( - std::vector<webkit::npapi::WebPluginInfo> plugins, - std::vector<webkit::npapi::PluginGroup> groups) { - if (!prefs_) - return; - - ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); +void PluginUpdater::OnUpdatePreferences( + Profile* profile, + const std::vector<webkit::npapi::WebPluginInfo>& plugins, + const std::vector<webkit::npapi::PluginGroup>& groups) { + ListPrefUpdate update(profile->GetPrefs(), prefs::kPluginsPluginsList); ListValue* plugins_list = update.Get(); plugins_list->Clear(); FilePath internal_dir; if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) - prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir); + profile->GetPrefs()->SetFilePath(prefs::kPluginsLastInternalDirectory, + internal_dir); // Add the plugin files. for (size_t i = 0; i < plugins.size(); ++i) { DictionaryValue* summary = CreatePluginFileSummary(plugins[i]); // If the plugin is managed by policy, store the user preferred state // instead. - if (plugins[i].enabled & - webkit::npapi::WebPluginInfo::MANAGED_MASK) { + if (plugins[i].enabled & webkit::npapi::WebPluginInfo::MANAGED_MASK) { bool user_enabled = (plugins[i].enabled & webkit::npapi::WebPluginInfo::USER_MASK) == - webkit::npapi::WebPluginInfo::USER_ENABLED; + webkit::npapi::WebPluginInfo::USER_ENABLED; summary->SetBoolean("enabled", user_enabled); } plugins_list->Append(summary); @@ -400,25 +317,30 @@ void PluginPrefs::OnUpdatePreferences( } } -void PluginPrefs::NotifyPluginStatusChanged() { +void PluginUpdater::NotifyPluginStatusChanged() { if (notify_pending_) return; notify_pending_ = true; MessageLoop::current()->PostTask( FROM_HERE, - NewRunnableMethod(this, &PluginPrefs::OnNotifyPluginStatusChanged)); + NewRunnableFunction(&PluginUpdater::OnNotifyPluginStatusChanged)); } -void PluginPrefs::OnNotifyPluginStatusChanged() { - notify_pending_ = false; +void PluginUpdater::OnNotifyPluginStatusChanged() { + GetInstance()->notify_pending_ = false; NotificationService::current()->Notify( content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, - Source<PluginPrefs>(this), + Source<PluginUpdater>(GetInstance()), NotificationService::NoDetails()); } /*static*/ -void PluginPrefs::RegisterPrefs(PrefService* prefs) { +PluginUpdater* PluginUpdater::GetInstance() { + return Singleton<PluginUpdater>::get(); +} + +/*static*/ +void PluginUpdater::RegisterPrefs(PrefService* prefs) { FilePath internal_dir; PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir); prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory, diff --git a/chrome/browser/plugin_prefs.h b/chrome/browser/plugin_updater.h index 0aca32f..dc9cfaf 100644 --- a/chrome/browser/plugin_prefs.h +++ b/chrome/browser/plugin_updater.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_PLUGIN_PREFS_H_ -#define CHROME_BROWSER_PLUGIN_PREFS_H_ +#ifndef CHROME_BROWSER_PLUGIN_UPDATER_H_ +#define CHROME_BROWSER_PLUGIN_UPDATER_H_ #pragma once #include <set> @@ -11,7 +11,7 @@ #include "base/basictypes.h" #include "base/file_path.h" -#include "base/memory/ref_counted.h" +#include "base/memory/singleton.h" #include "chrome/browser/prefs/pref_change_registrar.h" #include "content/common/notification_observer.h" @@ -19,10 +19,6 @@ class NotificationDetails; class NotificationSource; class Profile; -namespace content { -class ResourceContext; -} - namespace base { class DictionaryValue; class ListValue; @@ -35,68 +31,59 @@ struct WebPluginInfo; } } -// This class stores information about whether a plug-in or a plug-in group is -// enabled or disabled. -// Except for the |IsPluginEnabled| method, it should only be used on the UI -// thread. -class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, - public NotificationObserver { +class PluginUpdater : public NotificationObserver { public: - // Initializes the factory for this class for dependency tracking. - // This should be called before the first profile is created. - static void Initialize(); - - static PluginPrefs* GetForProfile(Profile* profile); + // Get a list of all the plugin groups. The caller should take ownership + // of the returned ListValue. + static base::ListValue* GetPluginGroupsData(); // Enable or disable a plugin group. void EnablePluginGroup(bool enable, const string16& group_name); // Enable or disable a specific plugin file. - void EnablePlugin(bool enable, const FilePath& file_path); + void EnablePlugin(bool enable, const FilePath::StringType& file_path); - // Returns whether the plugin is enabled or not. - bool IsPluginEnabled(const webkit::npapi::WebPluginInfo& plugin); + // Associates the PluginUpdater with |profile|. This enables or disables + // plugin groups as defined by the user's preferences. + void SetProfile(Profile* profile); + + // Called at shutdown before the profile is destroyed. + void Shutdown(); // Write the enable/disable status to the user's preference file. - void UpdatePreferences(int delay_ms); + void UpdatePreferences(Profile* profile, int delay_ms); // NotificationObserver method overrides virtual void Observe(int type, const NotificationSource& source, const NotificationDetails& details); - static void RegisterPrefs(PrefService* prefs); + static PluginUpdater* GetInstance(); - void ShutdownOnUIThread(); + static void RegisterPrefs(PrefService* prefs); private: - friend class base::RefCountedThreadSafe<PluginPrefs>; - - class Factory; - - PluginPrefs(); - virtual ~PluginPrefs(); - - // Associates the PluginPrefs with |profile|. This enables or disables - // plugin groups as defined by the user's preferences. - void SetProfile(Profile* profile); + PluginUpdater(); + virtual ~PluginUpdater() {} // Called on the file thread to get the data necessary to update the saved - // preferences. - void GetPreferencesDataOnFileThread(); + // preferences. The profile pointer is only to be passed to the UI thread. + static void GetPreferencesDataOnFileThread(void* profile); // Called on the UI thread with the plugin data to save the preferences. - void OnUpdatePreferences(std::vector<webkit::npapi::WebPluginInfo> plugins, - std::vector<webkit::npapi::PluginGroup> groups); + static void OnUpdatePreferences( + Profile* profile, + const std::vector<webkit::npapi::WebPluginInfo>& plugins, + const std::vector<webkit::npapi::PluginGroup>& groups); // Queues sending the notification that plugin data has changed. This is done // so that if a bunch of changes happen, we only send one notification. void NotifyPluginStatusChanged(); // Used for the post task to notify that plugin enabled status changed. - void OnNotifyPluginStatusChanged(); + static void OnNotifyPluginStatusChanged(); - base::DictionaryValue* CreatePluginFileSummary( + static base::DictionaryValue* CreatePluginFileSummary( const webkit::npapi::WebPluginInfo& plugin); // Force plugins to be enabled or disabled due to policy. @@ -110,14 +97,14 @@ class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, void ListValueToStringSet(const base::ListValue* src, std::set<string16>* dest); - // Weak pointer, owned by the profile. - PrefService* prefs_; + // Needed to allow singleton instantiation using private constructor. + friend struct DefaultSingletonTraits<PluginUpdater>; PrefChangeRegistrar registrar_; bool notify_pending_; - DISALLOW_COPY_AND_ASSIGN(PluginPrefs); + DISALLOW_COPY_AND_ASSIGN(PluginUpdater); }; -#endif // CHROME_BROWSER_PLUGIN_PREFS_H_ +#endif // CHROME_BROWSER_PLUGIN_UPDATER_H_ diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 60fae12..4bc07cd 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -36,7 +36,7 @@ #include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/page_info_model.h" #include "chrome/browser/password_manager/password_manager.h" -#include "chrome/browser/plugin_prefs.h" +#include "chrome/browser/plugin_updater.h" #include "chrome/browser/policy/cloud_policy_subsystem.h" #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/session_startup_pref.h" @@ -156,8 +156,8 @@ void RegisterUserPrefs(PrefService* user_prefs) { ExtensionsUI::RegisterUserPrefs(user_prefs); IncognitoModePrefs::RegisterUserPrefs(user_prefs); NewTabUI::RegisterUserPrefs(user_prefs); - PluginPrefs::RegisterPrefs(user_prefs); PluginsUI::RegisterUserPrefs(user_prefs); + PluginUpdater::RegisterPrefs(user_prefs); ProfileImpl::RegisterUserPrefs(user_prefs); PromoResourceService::RegisterUserPrefs(user_prefs); HostContentSettingsMap::RegisterUserPrefs(user_prefs); diff --git a/chrome/browser/profiles/profile_dependency_manager.cc b/chrome/browser/profiles/profile_dependency_manager.cc index db551a2..cdfbe2f 100644 --- a/chrome/browser/profiles/profile_dependency_manager.cc +++ b/chrome/browser/profiles/profile_dependency_manager.cc @@ -9,7 +9,6 @@ #include <iterator> #include "chrome/browser/background/background_contents_service_factory.h" -#include "chrome/browser/plugin_prefs.h" #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h" #include "chrome/browser/profiles/profile_keyed_service.h" #include "chrome/browser/profiles/profile_keyed_service_factory.h" @@ -37,7 +36,6 @@ void AssertFactoriesBuilt() { if (!g_initialized) { BackgroundContentsServiceFactory::GetInstance(); CloudPrintProxyServiceFactory::GetInstance(); - PluginPrefs::Initialize(); SessionServiceFactory::GetInstance(); TabRestoreServiceFactory::GetInstance(); TemplateURLServiceFactory::GetInstance(); diff --git a/chrome/browser/ui/webui/plugins_ui.cc b/chrome/browser/ui/webui/plugins_ui.cc index 55304c3..b830969 100644 --- a/chrome/browser/ui/webui/plugins_ui.cc +++ b/chrome/browser/ui/webui/plugins_ui.cc @@ -13,7 +13,7 @@ #include "base/path_service.h" #include "base/utf_string_conversions.h" #include "base/values.h" -#include "chrome/browser/plugin_prefs.h" +#include "chrome/browser/plugin_updater.h" #include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" @@ -122,19 +122,23 @@ class PluginsDOMHandler : public WebUIMessageHandler, const NotificationDetails& details) OVERRIDE; private: + // This extra wrapper is used to ensure we don't leak the ListValue* pointer + // if the PluginsDOMHandler object goes away before the task on the UI thread + // to give it the plugin list runs. + struct ListWrapper { + ListValue* list; + }; // Loads the plugins on the FILE thread. - static void LoadPluginsOnFileThread( - std::vector<webkit::npapi::PluginGroup>* groups, Task* task); + static void LoadPluginsOnFileThread(ListWrapper* wrapper, Task* task); // Used in conjunction with ListWrapper to avoid any memory leaks. - static void EnsurePluginGroupsDeleted( - std::vector<webkit::npapi::PluginGroup>* groups); + static void EnsureListDeleted(ListWrapper* wrapper); // Call this to start getting the plugins on the UI thread. void LoadPlugins(); // Called on the UI thread when the plugin information is ready. - void PluginsLoaded(const std::vector<webkit::npapi::PluginGroup>* groups); + void PluginsLoaded(ListWrapper* wrapper); NotificationRegistrar registrar_; @@ -157,7 +161,7 @@ PluginsDOMHandler::PluginsDOMHandler() WebUIMessageHandler* PluginsDOMHandler::Attach(WebUI* web_ui) { PrefService* prefs = Profile::FromWebUI(web_ui)->GetPrefs(); - show_details_.Init(prefs::kPluginsShowDetails, prefs, NULL); + show_details_.Init(prefs::kPluginsShowDetails, prefs, this); return WebUIMessageHandler::Attach(web_ui); } @@ -198,13 +202,13 @@ void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { return; bool enable = enable_str == "true"; - PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); + PluginUpdater* plugin_updater = PluginUpdater::GetInstance(); if (is_group_str == "true") { string16 group_name; if (!args->GetString(0, &group_name)) return; - plugin_prefs->EnablePluginGroup(enable, group_name); + plugin_updater->EnablePluginGroup(enable, group_name); if (enable) { // See http://crbug.com/50105 for background. string16 adobereader = ASCIIToUTF16( @@ -212,9 +216,9 @@ void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { string16 internalpdf = ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); if (group_name == adobereader) { - plugin_prefs->EnablePluginGroup(false, internalpdf); + plugin_updater->EnablePluginGroup(false, internalpdf); } else if (group_name == internalpdf) { - plugin_prefs->EnablePluginGroup(false, adobereader); + plugin_updater->EnablePluginGroup(false, adobereader); } } } else { @@ -222,13 +226,13 @@ void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { if (!args->GetString(0, &file_path)) return; - plugin_prefs->EnablePlugin(enable, FilePath(file_path)); + plugin_updater->EnablePlugin(enable, file_path); } // TODO(viettrungluu): We might also want to ensure that the plugins // list is always written to prefs even when the user hasn't disabled a // plugin. <http://crbug.com/39101> - plugin_prefs->UpdatePreferences(0); + plugin_updater->UpdatePreferences(profile, 0); } void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { @@ -252,50 +256,41 @@ void PluginsDOMHandler::Observe(int type, LoadPlugins(); } -void PluginsDOMHandler::LoadPluginsOnFileThread( - std::vector<webkit::npapi::PluginGroup>* groups, - Task* task) { - webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, groups); - +void PluginsDOMHandler::LoadPluginsOnFileThread(ListWrapper* wrapper, + Task* task) { + wrapper->list = PluginUpdater::GetInstance()->GetPluginGroupsData(); BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task); BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - NewRunnableFunction(&PluginsDOMHandler::EnsurePluginGroupsDeleted, - groups)); + NewRunnableFunction(&PluginsDOMHandler::EnsureListDeleted, wrapper)); } -void PluginsDOMHandler::EnsurePluginGroupsDeleted( - std::vector<webkit::npapi::PluginGroup>* groups) { - delete groups; +void PluginsDOMHandler::EnsureListDeleted(ListWrapper* wrapper) { + delete wrapper->list; + delete wrapper; } void PluginsDOMHandler::LoadPlugins() { if (!get_plugins_factory_.empty()) return; - std::vector<webkit::npapi::PluginGroup>* groups = - new std::vector<webkit::npapi::PluginGroup>; + ListWrapper* wrapper = new ListWrapper; + wrapper->list = NULL; Task* task = get_plugins_factory_.NewRunnableMethod( - &PluginsDOMHandler::PluginsLoaded, groups); + &PluginsDOMHandler::PluginsLoaded, wrapper); BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, NewRunnableFunction( - &PluginsDOMHandler::LoadPluginsOnFileThread, groups, task)); + &PluginsDOMHandler::LoadPluginsOnFileThread, wrapper, task)); } -void PluginsDOMHandler::PluginsLoaded( - const std::vector<webkit::npapi::PluginGroup>* groups) { - // Construct DictionaryValues to return to the UI - ListValue* plugin_groups_data = new ListValue(); - for (size_t i = 0; i < groups->size(); ++i) { - plugin_groups_data->Append((*groups)[i].GetDataForUI()); - // TODO(bauerb): Fetch plugin enabled state from PluginPrefs. - } +void PluginsDOMHandler::PluginsLoaded(ListWrapper* wrapper) { DictionaryValue results; - results.Set("plugins", plugin_groups_data); + results.Set("plugins", wrapper->list); + wrapper->list = NULL; // So it doesn't get deleted. web_ui_->CallJavascriptFunction("returnPluginsData", results); } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 8ea63b5..79d5a3b 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1642,8 +1642,8 @@ 'browser/plugin_installer_infobar_delegate.h', 'browser/plugin_observer.cc', 'browser/plugin_observer.h', - 'browser/plugin_prefs.cc', - 'browser/plugin_prefs.h', + 'browser/plugin_updater.cc', + 'browser/plugin_updater.h', 'browser/policy/asynchronous_policy_loader.cc', 'browser/policy/asynchronous_policy_loader.h', 'browser/policy/asynchronous_policy_provider.cc', |