Remove HostContentSettingsMap usage due to UI thread blockage when creating multiple request contexts (issue #1734)

This commit is contained in:
Marshall Greenblatt
2015-10-14 11:14:05 -04:00
parent 3e9c8df55f
commit 4737056482
8 changed files with 19 additions and 101 deletions

View File

@@ -104,7 +104,6 @@
// CefURLRequestContextGetter* destruction.
*/
class HostContentSettingsMap;
class PrefService;
namespace extensions {
@@ -145,9 +144,6 @@ class CefBrowserContext
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) = 0;
// Settings for plugins and extensions.
virtual HostContentSettingsMap* GetHostContentSettingsMap() = 0;
// Preferences.
virtual PrefService* GetPrefs() = 0;

View File

@@ -13,17 +13,13 @@
#include "libcef/browser/permission_manager.h"
#include "libcef/browser/ssl_host_state_delegate.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/extensions/extensions_util.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/net/proxy_service_factory.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/guest_view/browser/guest_view_manager.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/browser_thread.h"
@@ -133,9 +129,6 @@ CefBrowserContextImpl::CefBrowserContextImpl(
CefBrowserContextImpl::~CefBrowserContextImpl() {
pref_proxy_config_tracker_->DetachFromPrefService();
if (host_content_settings_map_.get())
host_content_settings_map_->ShutdownOnUIThread();
// Delete the download manager delegate here because otherwise we'll crash
// when it's accessed from the content::BrowserContext destructor.
if (download_manager_delegate_.get())
@@ -348,35 +341,6 @@ net::URLRequestContextGetter*
return NULL;
}
HostContentSettingsMap* CefBrowserContextImpl::GetHostContentSettingsMap() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!host_content_settings_map_.get()) {
// The |incognito| argument is intentionally set to false as it otherwise
// limits the types of values that can be stored in the settings map (for
// example, default values set via DefaultProvider::SetWebsiteSetting).
host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false);
// Change the default plugin policy.
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
const std::string& plugin_policy_str =
command_line->GetSwitchValueASCII(switches::kPluginPolicy);
if (!plugin_policy_str.empty()) {
ContentSetting plugin_policy = CONTENT_SETTING_ALLOW;
if (base::LowerCaseEqualsASCII(plugin_policy_str,
switches::kPluginPolicy_Detect)) {
plugin_policy = CONTENT_SETTING_DETECT_IMPORTANT_CONTENT;
} else if (base::LowerCaseEqualsASCII(plugin_policy_str,
switches::kPluginPolicy_Block)) {
plugin_policy = CONTENT_SETTING_BLOCK;
}
host_content_settings_map_->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, plugin_policy);
}
}
return host_content_settings_map_.get();
}
PrefService* CefBrowserContextImpl::GetPrefs() {
// TODO(cef): Perhaps use per-context settings.
return CefContentBrowserClient::Get()->pref_service();

View File

@@ -87,7 +87,6 @@ class CefBrowserContextImpl : public CefBrowserContext {
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors)
override;
HostContentSettingsMap* GetHostContentSettingsMap() override;
PrefService* GetPrefs() override;
// Guaranteed to exist once this object has been initialized.
@@ -117,7 +116,6 @@ class CefBrowserContextImpl : public CefBrowserContext {
scoped_refptr<CefURLRequestContextGetterImpl> url_request_getter_;
scoped_ptr<content::PermissionManager> permission_manager_;
scoped_ptr<CefSSLHostStateDelegate> ssl_host_state_delegate_;
scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContextImpl);
};

View File

@@ -170,10 +170,6 @@ net::URLRequestContextGetter*
return NULL;
}
HostContentSettingsMap* CefBrowserContextProxy::GetHostContentSettingsMap() {
return parent_->GetHostContentSettingsMap();
}
PrefService* CefBrowserContextProxy::GetPrefs() {
return parent_->GetPrefs();
}

View File

@@ -69,7 +69,6 @@ class CefBrowserContextProxy : public CefBrowserContext {
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors)
override;
HostContentSettingsMap* GetHostContentSettingsMap() override;
PrefService* GetPrefs() override;
scoped_refptr<CefBrowserContextImpl> parent() const {

View File

@@ -17,7 +17,6 @@
#include "chrome/browser/prefs/command_line_pref_store.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/proxy_config/proxy_config_dictionary.h"
#include "extensions/browser/extension_prefs.h"
@@ -92,7 +91,6 @@ scoped_ptr<PrefService> CefBrowserPrefStore::CreateService() {
CefMediaCaptureDevicesDispatcher::RegisterPrefs(registry.get());
PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get());
extensions::ExtensionPrefs::RegisterProfilePrefs(registry.get());
HostContentSettingsMap::RegisterProfilePrefs(registry.get());
// Print settings.
registry->RegisterBooleanPref(prefs::kPrintingEnabled, true);

View File

@@ -9,11 +9,14 @@
#include "libcef/browser/plugins/plugin_service_filter.h"
#include "libcef/browser/web_plugin_impl.h"
#include "libcef/common/cef_messages.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/extensions/extensions_util.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/thread_task_runner_handle.h"
#include "chrome/browser/plugins/plugin_finder.h"
@@ -159,8 +162,7 @@ CefPluginInfoMessageFilter::Context::Context(
int render_process_id,
CefBrowserContext* profile)
: render_process_id_(render_process_id),
resource_context_(profile->GetResourceContext()),
host_content_settings_map_(profile->GetHostContentSettingsMap()) {
resource_context_(profile->GetResourceContext()) {
#if defined(ENABLE_EXTENSIONS)
if (extensions::ExtensionsEnabled())
extension_registry_ = extensions::ExtensionRegistry::Get(profile);
@@ -500,57 +502,24 @@ void CefPluginInfoMessageFilter::Context::GetPluginContentSetting(
ContentSetting* setting,
bool* uses_default_content_setting,
bool* is_managed) const {
scoped_ptr<base::Value> value;
content_settings::SettingInfo info;
bool uses_plugin_specific_setting = false;
if (ShouldUseJavaScriptSettingForPlugin(plugin)) {
value = host_content_settings_map_->GetWebsiteSetting(
policy_url,
policy_url,
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string(),
&info);
} else {
content_settings::SettingInfo specific_info;
scoped_ptr<base::Value> specific_setting =
host_content_settings_map_->GetWebsiteSetting(
policy_url,
plugin_url,
CONTENT_SETTINGS_TYPE_PLUGINS,
resource,
&specific_info);
content_settings::SettingInfo general_info;
scoped_ptr<base::Value> general_setting =
host_content_settings_map_->GetWebsiteSetting(
policy_url,
plugin_url,
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string(),
&general_info);
*setting = CONTENT_SETTING_ALLOW;
*uses_default_content_setting = true;
*is_managed = false;
// If there is a plugin-specific setting, we use it, unless the general
// setting was set by policy, in which case it takes precedence.
// TODO(tommycli): Remove once we deprecate the plugin ASK policy.
bool legacy_ask_user = content_settings::ValueToContentSetting(
general_setting.get()) == CONTENT_SETTING_ASK;
bool use_policy =
general_info.source == content_settings::SETTING_SOURCE_POLICY &&
!legacy_ask_user;
uses_plugin_specific_setting = specific_setting && !use_policy;
if (uses_plugin_specific_setting) {
value = specific_setting.Pass();
info = specific_info;
} else {
value = general_setting.Pass();
info = general_info;
// Change the default plugin policy.
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
const std::string& plugin_policy_str =
command_line->GetSwitchValueASCII(switches::kPluginPolicy);
if (!plugin_policy_str.empty()) {
if (base::LowerCaseEqualsASCII(plugin_policy_str,
switches::kPluginPolicy_Detect)) {
*setting = CONTENT_SETTING_DETECT_IMPORTANT_CONTENT;
} else if (base::LowerCaseEqualsASCII(plugin_policy_str,
switches::kPluginPolicy_Block)) {
*setting = CONTENT_SETTING_BLOCK;
}
}
*setting = content_settings::ValueToContentSetting(value.get());
*uses_default_content_setting =
!uses_plugin_specific_setting &&
info.primary_pattern == ContentSettingsPattern::Wildcard() &&
info.secondary_pattern == ContentSettingsPattern::Wildcard();
*is_managed = info.source == content_settings::SETTING_SOURCE_POLICY;
}
bool CefPluginInfoMessageFilter::Context::IsPluginEnabled(

View File

@@ -15,7 +15,6 @@
#include "base/prefs/pref_member.h"
#include "base/sequenced_task_runner_helpers.h"
#include "chrome/browser/plugins/plugin_metadata.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "content/public/browser/browser_message_filter.h"
@@ -74,7 +73,6 @@ class CefPluginInfoMessageFilter : public content::BrowserMessageFilter {
#if defined(ENABLE_EXTENSIONS)
extensions::ExtensionRegistry* extension_registry_;
#endif
const HostContentSettingsMap* host_content_settings_map_;
BooleanPrefMember allow_outdated_plugins_;
BooleanPrefMember always_authorize_plugins_;