Commit bc16a667 authored by John Abd-El-Malek's avatar John Abd-El-Malek Committed by Commit Bot

Move WebLayer's BrowserContext implementation to a separate file.

This allows production code to get to ProfileImpl from a BrowserContext, and tests to interact with it directly in future cls.

Change-Id: I5f3c9899a661a3b05c67e1287467b3dbabf7f75e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1983255Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Auto-Submit: John Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727647}
parent b0c35bff
......@@ -102,6 +102,8 @@ jumbo_static_library("weblayer_lib") {
"app/content_main_delegate_impl.cc",
"app/content_main_delegate_impl.h",
"app/main.cc",
"browser/browser_context_impl.cc",
"browser/browser_context_impl.h",
"browser/browser_main_parts_impl.cc",
"browser/browser_main_parts_impl.h",
"browser/content_browser_client_impl.cc",
......
// Copyright 2019 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 "weblayer/browser/browser_context_impl.h"
#include "components/prefs/in_memory_pref_store.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/pref_service_factory.h"
#include "components/safe_browsing/common/safe_browsing_prefs.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/resource_context.h"
namespace weblayer {
class ResourceContextImpl : public content::ResourceContext {
public:
ResourceContextImpl() = default;
~ResourceContextImpl() override = default;
private:
DISALLOW_COPY_AND_ASSIGN(ResourceContextImpl);
};
BrowserContextImpl::BrowserContextImpl(ProfileImpl* profile_impl,
const base::FilePath& path)
: profile_impl_(profile_impl),
path_(path),
resource_context_(new ResourceContextImpl()) {
content::BrowserContext::Initialize(this, path_);
CreateUserPrefService();
}
BrowserContextImpl::~BrowserContextImpl() {
NotifyWillBeDestroyed(this);
}
#if !defined(OS_ANDROID)
std::unique_ptr<content::ZoomLevelDelegate>
BrowserContextImpl::CreateZoomLevelDelegate(const base::FilePath&) {
return nullptr;
}
#endif // !defined(OS_ANDROID)
base::FilePath BrowserContextImpl::GetPath() {
return path_;
}
bool BrowserContextImpl::IsOffTheRecord() {
return path_.empty();
}
content::DownloadManagerDelegate*
BrowserContextImpl::GetDownloadManagerDelegate() {
return &download_delegate_;
}
content::ResourceContext* BrowserContextImpl::GetResourceContext() {
return resource_context_.get();
}
content::BrowserPluginGuestManager* BrowserContextImpl::GetGuestManager() {
return nullptr;
}
storage::SpecialStoragePolicy* BrowserContextImpl::GetSpecialStoragePolicy() {
return nullptr;
}
content::PushMessagingService* BrowserContextImpl::GetPushMessagingService() {
return nullptr;
}
content::StorageNotificationService*
BrowserContextImpl::GetStorageNotificationService() {
return nullptr;
}
content::SSLHostStateDelegate* BrowserContextImpl::GetSSLHostStateDelegate() {
return &ssl_host_state_delegate_;
}
content::PermissionControllerDelegate*
BrowserContextImpl::GetPermissionControllerDelegate() {
return nullptr;
}
content::ClientHintsControllerDelegate*
BrowserContextImpl::GetClientHintsControllerDelegate() {
return nullptr;
}
content::BackgroundFetchDelegate*
BrowserContextImpl::GetBackgroundFetchDelegate() {
return nullptr;
}
content::BackgroundSyncController*
BrowserContextImpl::GetBackgroundSyncController() {
return nullptr;
}
content::BrowsingDataRemoverDelegate*
BrowserContextImpl::GetBrowsingDataRemoverDelegate() {
return nullptr;
}
content::ContentIndexProvider* BrowserContextImpl::GetContentIndexProvider() {
return nullptr;
}
void BrowserContextImpl::CreateUserPrefService() {
auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
RegisterPrefs(pref_registry.get());
PrefServiceFactory pref_service_factory;
pref_service_factory.set_user_prefs(
base::MakeRefCounted<InMemoryPrefStore>());
user_pref_service_ = pref_service_factory.Create(pref_registry);
// Note: UserPrefs::Set also ensures that the user_pref_service_ has not
// been set previously.
user_prefs::UserPrefs::Set(this, user_pref_service_.get());
}
void BrowserContextImpl::RegisterPrefs(PrefRegistrySimple* pref_registry) {
safe_browsing::RegisterProfilePrefs(pref_registry);
}
} // namespace weblayer
// Copyright 2019 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 WEBLAYER_BROWSER_BROWSER_CONTEXT_IMPL_H_
#define WEBLAYER_BROWSER_BROWSER_CONTEXT_IMPL_H_
#include "base/files/file_path.h"
#include "base/macros.h"
#include "build/build_config.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "weblayer/browser/download_manager_delegate_impl.h"
#include "weblayer/browser/ssl_host_state_delegate_impl.h"
#include "weblayer/public/profile.h"
class PrefRegistrySimple;
class PrefService;
namespace weblayer {
class ProfileImpl;
class ResourceContextImpl;
class BrowserContextImpl : public content::BrowserContext {
public:
BrowserContextImpl(ProfileImpl* profile_impl, const base::FilePath& path);
~BrowserContextImpl() override;
// BrowserContext implementation:
#if !defined(OS_ANDROID)
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
const base::FilePath&) override;
#endif // !defined(OS_ANDROID)
base::FilePath GetPath() override;
bool IsOffTheRecord() override;
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
content::ResourceContext* GetResourceContext() override;
content::BrowserPluginGuestManager* GetGuestManager() override;
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
content::PushMessagingService* GetPushMessagingService() override;
content::StorageNotificationService* GetStorageNotificationService() override;
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
content::PermissionControllerDelegate* GetPermissionControllerDelegate()
override;
content::ClientHintsControllerDelegate* GetClientHintsControllerDelegate()
override;
content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override;
content::BackgroundSyncController* GetBackgroundSyncController() override;
content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
override;
content::ContentIndexProvider* GetContentIndexProvider() override;
ProfileImpl* profile_impl() const { return profile_impl_; }
private:
// Creates a simple in-memory pref service.
// TODO(timvolodine): Investigate whether WebLayer needs persistent pref
// service.
void CreateUserPrefService();
// Registers the preferences that WebLayer accesses.
void RegisterPrefs(PrefRegistrySimple* pref_registry);
ProfileImpl* const profile_impl_;
base::FilePath path_;
// ResourceContext needs to be deleted on the IO thread in general (and in
// particular due to the destruction of the safebrowsing mojo interface
// that has been added in ContentBrowserClient::ExposeInterfacesToRenderer
// on IO thread, see crbug.com/1029317). Also this is similar to how Chrome
// handles ProfileIOData.
// TODO(timvolodine): consider a more general Profile shutdown/destruction
// sequence for the IO/UI bits (crbug.com/1029879).
std::unique_ptr<ResourceContextImpl, content::BrowserThread::DeleteOnIOThread>
resource_context_;
DownloadManagerDelegateImpl download_delegate_;
SSLHostStateDelegateImpl ssl_host_state_delegate_;
std::unique_ptr<PrefService> user_pref_service_;
DISALLOW_COPY_AND_ASSIGN(BrowserContextImpl);
};
} // namespace weblayer
#endif // WEBLAYER_BROWSER_BROWSER_CONTEXT_IMPL_H_
......@@ -11,21 +11,12 @@
#include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "components/prefs/in_memory_pref_store.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/pref_service_factory.h"
#include "components/safe_browsing/common/safe_browsing_prefs.h"
#include "components/user_prefs/user_prefs.h"
#include "components/web_cache/browser/web_cache_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/storage_partition.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "weblayer/browser/download_manager_delegate_impl.h"
#include "weblayer/browser/ssl_host_state_delegate_impl.h"
#include "weblayer/browser/browser_context_impl.h"
#include "weblayer/browser/tab_impl.h"
#include "weblayer/common/weblayer_paths.h"
......@@ -49,15 +40,6 @@ namespace weblayer {
namespace {
class ResourceContextImpl : public content::ResourceContext {
public:
ResourceContextImpl() = default;
~ResourceContextImpl() override = default;
private:
DISALLOW_COPY_AND_ASSIGN(ResourceContextImpl);
};
bool IsNameValid(const std::string& name) {
for (size_t i = 0; i < name.size(); ++i) {
char c = name[i];
......@@ -70,129 +52,6 @@ bool IsNameValid(const std::string& name) {
} // namespace
class ProfileImpl::BrowserContextImpl : public content::BrowserContext {
public:
BrowserContextImpl(ProfileImpl* profile_impl, const base::FilePath& path)
: profile_impl_(profile_impl),
path_(path),
resource_context_(new ResourceContextImpl()) {
content::BrowserContext::Initialize(this, path_);
CreateUserPrefService();
}
~BrowserContextImpl() override { NotifyWillBeDestroyed(this); }
// BrowserContext implementation:
#if !defined(OS_ANDROID)
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
const base::FilePath&) override {
return nullptr;
}
#endif // !defined(OS_ANDROID)
base::FilePath GetPath() override { return path_; }
bool IsOffTheRecord() override { return path_.empty(); }
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override {
return &download_delegate_;
}
content::ResourceContext* GetResourceContext() override {
return resource_context_.get();
}
content::BrowserPluginGuestManager* GetGuestManager() override {
return nullptr;
}
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override {
return nullptr;
}
content::PushMessagingService* GetPushMessagingService() override {
return nullptr;
}
content::StorageNotificationService* GetStorageNotificationService()
override {
return nullptr;
}
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override {
return &ssl_host_state_delegate_;
}
content::PermissionControllerDelegate* GetPermissionControllerDelegate()
override {
return nullptr;
}
content::ClientHintsControllerDelegate* GetClientHintsControllerDelegate()
override {
return nullptr;
}
content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override {
return nullptr;
}
content::BackgroundSyncController* GetBackgroundSyncController() override {
return nullptr;
}
content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
override {
return nullptr;
}
content::ContentIndexProvider* GetContentIndexProvider() override {
return nullptr;
}
ProfileImpl* profile_impl() const { return profile_impl_; }
private:
// Creates a simple in-memory pref service.
// TODO(timvolodine): Investigate whether WebLayer needs persistent pref
// service.
void CreateUserPrefService() {
auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
RegisterPrefs(pref_registry.get());
PrefServiceFactory pref_service_factory;
pref_service_factory.set_user_prefs(
base::MakeRefCounted<InMemoryPrefStore>());
user_pref_service_ = pref_service_factory.Create(pref_registry);
// Note: UserPrefs::Set also ensures that the user_pref_service_ has not
// been set previously.
user_prefs::UserPrefs::Set(this, user_pref_service_.get());
}
// Registers the preferences that WebLayer accesses.
void RegisterPrefs(PrefRegistrySimple* pref_registry) {
safe_browsing::RegisterProfilePrefs(pref_registry);
}
ProfileImpl* const profile_impl_;
base::FilePath path_;
// ResourceContext needs to be deleted on the IO thread in general (and in
// particular due to the destruction of the safebrowsing mojo interface
// that has been added in ContentBrowserClient::ExposeInterfacesToRenderer
// on IO thread, see crbug.com/1029317). Also this is similar to how Chrome
// handles ProfileIOData.
// TODO(timvolodine): consider a more general Profile shutdown/destruction
// sequence for the IO/UI bits (crbug.com/1029879).
std::unique_ptr<ResourceContextImpl, content::BrowserThread::DeleteOnIOThread>
resource_context_;
DownloadManagerDelegateImpl download_delegate_;
SSLHostStateDelegateImpl ssl_host_state_delegate_;
std::unique_ptr<PrefService> user_pref_service_;
DISALLOW_COPY_AND_ASSIGN(BrowserContextImpl);
};
class ProfileImpl::DataClearer : public content::BrowsingDataRemover::Observer {
public:
DataClearer(content::BrowserContext* browser_context,
......
......@@ -22,6 +22,7 @@ class BrowserContext;
}
namespace weblayer {
class BrowserContextImpl;
class ProfileImpl : public Profile {
public:
......@@ -55,7 +56,6 @@ class ProfileImpl : public Profile {
#endif
private:
class BrowserContextImpl;
class DataClearer;
void ClearRendererCache();
......
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