Commit 3457cbd1 authored by Salvador Guerrero's avatar Salvador Guerrero Committed by Commit Bot

Add SimpleFactoryKey in //content embedders with their own BrowserContext.

Some parts of BrowserContext (such as VideoDecodePerfHistory and
DownloadDB) depend on //components. The components they depend will going
forward need to depend on a component service that is build with a
SimpleKeyedServiceFactory, which requires a SimpleFactoryKey. For most
use-cases, this key can be retrieved from Profile in //chrome, and used
in all of //components, since the implementation of the key lives in
//components/keyed_service/core. However, that is not the case for code
in //content or other embedders of //content such as ChromeCast, headless
and Fuchsia.

This CL therefore updates the subclasses of BrowserContext in these
embedders to provide and own a SimpleFactoryKey:

CastBrowserContext
HeadlessBrowserContextImpl
WebEngineBrowserContext

TBR=blundell@chromium.org

Bug: 943170
Change-Id: I021b817c576c789b9ef059e882c6f8bfe1bd1b3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1616422
Commit-Queue: Salvador Guerrero <salg@google.com>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarSean Topping <seantopping@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664889}
parent f9981715
......@@ -16,6 +16,7 @@ include_rules = [
"+components/crash/core",
"+components/download/public/common",
"+components/heap_profiling",
"+components/keyed_service/core",
"+components/minidump_uploader",
"+components/navigation_interception",
"+components/policy/core/browser",
......
......@@ -25,6 +25,7 @@
#include "base/task/post_task.h"
#include "components/autofill/core/browser/autocomplete_history_manager.h"
#include "components/download/public/common/in_progress_download_manager.h"
#include "components/keyed_service/core/simple_key_map.h"
#include "components/policy/core/browser/browser_policy_connector_base.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
......@@ -107,9 +108,12 @@ AwBrowserContext::AwBrowserContext(
std::unique_ptr<policy::BrowserPolicyConnectorBase> policy_connector)
: context_storage_path_(path),
user_pref_service_(std::move(pref_service)),
browser_policy_connector_(std::move(policy_connector)) {
browser_policy_connector_(std::move(policy_connector)),
simple_factory_key_(GetPath(), IsOffTheRecord()) {
DCHECK(!g_browser_context);
g_browser_context = this;
SimpleKeyMap::GetInstance()->Associate(this, &simple_factory_key_);
BrowserContext::Initialize(this, path);
pref_change_registrar_.Init(user_pref_service_.get());
......@@ -122,6 +126,7 @@ AwBrowserContext::AwBrowserContext(
AwBrowserContext::~AwBrowserContext() {
DCHECK_EQ(this, g_browser_context);
SimpleKeyMap::GetInstance()->Dissociate(this);
g_browser_context = NULL;
}
......
......@@ -15,6 +15,7 @@
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "components/keyed_service/core/simple_factory_key.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/safe_browsing/android/remote_database_manager.h"
#include "components/visitedlink/browser/visitedlink_delegate.h"
......@@ -187,6 +188,7 @@ class AwBrowserContext : public content::BrowserContext,
std::unique_ptr<AwSafeBrowsingWhitelistManager>
safe_browsing_whitelist_manager_;
SimpleFactoryKey simple_factory_key_;
DISALLOW_COPY_AND_ASSIGN(AwBrowserContext);
};
......
......@@ -18,6 +18,7 @@
#include "chromecast/browser/cast_download_manager_delegate.h"
#include "chromecast/browser/cast_permission_manager.h"
#include "chromecast/browser/url_request_context_factory.h"
#include "components/keyed_service/core/simple_key_map.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/cors_origin_pattern_setter.h"
#include "content/public/browser/resource_context.h"
......@@ -54,9 +55,13 @@ CastBrowserContext::CastBrowserContext(
shared_cors_origin_access_list_(
content::SharedCorsOriginAccessList::Create()) {
InitWhileIOAllowed();
simple_factory_key_ =
std::make_unique<SimpleFactoryKey>(GetPath(), IsOffTheRecord());
SimpleKeyMap::GetInstance()->Associate(this, simple_factory_key_.get());
}
CastBrowserContext::~CastBrowserContext() {
SimpleKeyMap::GetInstance()->Dissociate(this);
BrowserContext::NotifyWillBeDestroyed(this);
ShutdownStoragePartitions();
content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
......
......@@ -9,6 +9,7 @@
#include "base/files/file_path.h"
#include "base/macros.h"
#include "components/keyed_service/core/simple_factory_key.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h"
......@@ -81,6 +82,7 @@ class CastBrowserContext final : public content::BrowserContext {
base::FilePath path_;
std::unique_ptr<CastResourceContext> resource_context_;
std::unique_ptr<content::PermissionControllerDelegate> permission_manager_;
std::unique_ptr<SimpleFactoryKey> simple_factory_key_;
scoped_refptr<content::SharedCorsOriginAccessList>
shared_cors_origin_access_list_;
......
include_rules = [
"+components/keyed_service/core",
"+components/version_info",
"+content/public/common",
"+content/public/browser",
......
......@@ -13,6 +13,7 @@
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/task/post_task.h"
#include "components/keyed_service/core/simple_key_map.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_context.h"
......@@ -55,11 +56,14 @@ WebEngineBrowserContext::WebEngineBrowserContext(bool force_incognito)
data_dir_path_.clear();
}
}
simple_factory_key_ =
std::make_unique<SimpleFactoryKey>(GetPath(), IsOffTheRecord());
SimpleKeyMap::GetInstance()->Associate(this, simple_factory_key_.get());
BrowserContext::Initialize(this, data_dir_path_);
}
WebEngineBrowserContext::~WebEngineBrowserContext() {
SimpleKeyMap::GetInstance()->Dissociate(this);
NotifyWillBeDestroyed(this);
if (resource_context_) {
......
......@@ -9,6 +9,7 @@
#include "base/files/file_path.h"
#include "base/macros.h"
#include "components/keyed_service/core/simple_factory_key.h"
#include "content/public/browser/browser_context.h"
class WebEngineNetLog;
......@@ -61,6 +62,7 @@ class WebEngineBrowserContext : public content::BrowserContext {
std::unique_ptr<WebEngineNetLog> net_log_;
scoped_refptr<WebEngineURLRequestContextGetter> url_request_getter_;
std::unique_ptr<SimpleFactoryKey> simple_factory_key_;
std::unique_ptr<ResourceContext> resource_context_;
DISALLOW_COPY_AND_ASSIGN(WebEngineBrowserContext);
......
include_rules = [
"+cc/base",
"+components/keyed_service/core",
"+components/printing/browser",
"+components/printing/common",
"+components/security_state",
......
......@@ -12,6 +12,7 @@
#include "base/guid.h"
#include "base/path_service.h"
#include "base/task/post_task.h"
#include "components/keyed_service/core/simple_key_map.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
......@@ -34,6 +35,9 @@ HeadlessBrowserContextImpl::HeadlessBrowserContextImpl(
permission_controller_delegate_(
std::make_unique<HeadlessPermissionManager>(this)) {
InitWhileIOAllowed();
simple_factory_key_ =
std::make_unique<SimpleFactoryKey>(GetPath(), IsOffTheRecord());
SimpleKeyMap::GetInstance()->Associate(this, simple_factory_key_.get());
base::FilePath user_data_path =
IsOffTheRecord() || context_options_->user_data_dir().empty()
? base::FilePath()
......@@ -44,6 +48,7 @@ HeadlessBrowserContextImpl::HeadlessBrowserContextImpl(
HeadlessBrowserContextImpl::~HeadlessBrowserContextImpl() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
SimpleKeyMap::GetInstance()->Dissociate(this);
NotifyWillBeDestroyed(this);
// Destroy all web contents before shutting down storage partitions.
......
......@@ -12,6 +12,7 @@
#include "base/files/file_path.h"
#include "base/unguessable_token.h"
#include "components/keyed_service/core/simple_factory_key.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/resource_context.h"
......@@ -143,6 +144,7 @@ class HEADLESS_EXPORT HeadlessBrowserContextImpl final
permission_controller_delegate_;
std::unique_ptr<HeadlessRequestContextManager> request_context_manager_;
std::unique_ptr<SimpleFactoryKey> simple_factory_key_;
DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserContextImpl);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment