blob: 0323671149fa7f9e8c2c5aa47fe7f98ac2630caa [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2013 The Chromium Authors
[email protected]b0f146f2011-09-15 22:14:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]de7d61ff2013-08-20 11:30:415#include "content/shell/browser/shell_browser_context.h"
[email protected]b0f146f2011-09-15 22:14:256
Peter Boströmdd7e40ec2021-04-05 20:40:107#include <memory>
dchengf63a1252015-12-26 20:43:138#include <utility>
9
[email protected]2f2b9512012-06-08 17:31:0010#include "base/command_line.h"
[email protected]5cba3bf2012-01-14 02:40:3511#include "base/environment.h"
thestigb7aad54f2014-09-05 18:25:3912#include "base/files/file_util.h"
Avi Drissmanadac21992023-01-11 23:46:3913#include "base/functional/bind.h"
[email protected]b0f146f2011-09-15 22:14:2514#include "base/path_service.h"
[email protected]2e5b60a22011-11-28 15:56:4115#include "base/threading/thread.h"
avi66a07722015-12-25 23:38:1216#include "build/build_config.h"
juliatuttleca57a11b2016-11-15 19:07:5317#include "components/keyed_service/content/browser_context_dependency_manager.h"
Henrique Nakashimadd1cdd12019-04-25 15:47:0418#include "components/keyed_service/core/simple_dependency_manager.h"
Xi Han720a2a22019-05-21 17:39:5919#include "components/keyed_service/core/simple_factory_key.h"
Henrique Nakashima7bb9d522019-04-16 20:57:3620#include "components/keyed_service/core/simple_key_map.h"
mmenke68a50212017-06-12 20:20:3121#include "components/network_session_configurator/common/network_switches.h"
Peter Birk Pakkenbergd927c942022-11-17 14:30:4222#include "components/origin_trials/browser/leveldb_persistence_provider.h"
23#include "components/origin_trials/browser/origin_trials.h"
Eric Seckler8652dcd52018-09-20 10:42:2824#include "content/public/browser/browser_task_traits.h"
[email protected]c38831a12011-10-28 12:44:4925#include "content/public/browser/browser_thread.h"
Peter Birk Pakkenbergd927c942022-11-17 14:30:4226#include "content/public/browser/origin_trials_controller_delegate.h"
[email protected]6bd30072013-02-08 18:17:1127#include "content/public/browser/storage_partition.h"
28#include "content/public/common/content_switches.h"
Victor Tan10d93aca2022-08-12 16:46:2829#include "content/shell/browser/shell_content_browser_client.h"
danakjdd5bb4ef2020-06-26 23:29:2230#include "content/shell/browser/shell_content_index_provider.h"
[email protected]de7d61ff2013-08-20 11:30:4131#include "content/shell/browser/shell_download_manager_delegate.h"
mlamouri4e372022015-03-29 14:51:0632#include "content/shell/browser/shell_permission_manager.h"
Julie Jeongeun Kimed909db2025-05-12 08:02:2733#include "content/shell/common/shell_paths.h"
[email protected]b7c504c2013-05-07 14:42:1234#include "content/shell/common/shell_switches.h"
nsatragnodb7b65c642016-02-16 20:14:0235#include "content/test/mock_background_sync_controller.h"
Victor Tan10d93aca2022-08-12 16:46:2836#include "content/test/mock_reduce_accept_language_controller_delegate.h"
Peter Birk Pakkenbergd927c942022-11-17 14:30:4237#include "third_party/blink/public/common/origin_trials/trial_token_validator.h"
[email protected]b0f146f2011-09-15 22:14:2538
[email protected]810ddc52012-01-24 01:00:3539namespace content {
40
[email protected]d5869bf2013-07-03 16:21:4741ShellBrowserContext::ShellBrowserContext(bool off_the_record,
Michael Giuffridac55719602018-02-09 17:10:3542 bool delay_services_creation)
Arthur Sonzogniff837582023-12-22 10:05:4543 : off_the_record_(off_the_record) {
[email protected]11a65b692012-03-30 11:29:1644 InitWhileIOAllowed();
Will Harris7ddd8502023-01-10 23:51:3445#if BUILDFLAG(IS_WIN)
46 base::SetExtraNoExecuteAllowedPath(SHELL_DIR_USER_DATA);
47#endif // BUILDFLAG(IS_WIN)
48
Michael Giuffridac55719602018-02-09 17:10:3549 if (!delay_services_creation) {
50 BrowserContextDependencyManager::GetInstance()
51 ->CreateBrowserContextServices(this);
52 }
[email protected]b0f146f2011-09-15 22:14:2553}
54
55ShellBrowserContext::~ShellBrowserContext() {
Lukasz Anforowiczeda637d22021-05-20 00:32:2356 NotifyWillBeDestroyed();
Lukasz Anforowicz58d0dac2018-03-23 15:48:1057
Henrique Nakashimadd1cdd12019-04-25 15:47:0458 // The SimpleDependencyManager should always be passed after the
59 // BrowserContextDependencyManager. This is because the KeyedService instances
60 // in the BrowserContextDependencyManager's dependency graph can depend on the
61 // ones in the SimpleDependencyManager's graph.
62 DependencyManager::PerformInterlockedTwoPhaseShutdown(
63 BrowserContextDependencyManager::GetInstance(), this,
64 SimpleDependencyManager::GetInstance(), key_.get());
Henrique Nakashima7bb9d522019-04-16 20:57:3665
66 SimpleKeyMap::GetInstance()->Dissociate(this);
67
jam21e62ae2017-03-21 19:57:4868 ShutdownStoragePartitions();
[email protected]b0f146f2011-09-15 22:14:2569}
70
[email protected]11a65b692012-03-30 11:29:1671void ShellBrowserContext::InitWhileIOAllowed() {
avi83883c82014-12-23 00:08:4972 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
mkwstd993d06a2014-10-10 11:44:3873 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors))
[email protected]c2dad292012-09-07 21:27:3574 ignore_certificate_errors_ = true;
Weizhong Xia8f0a38f2024-02-21 00:50:3275
John Abd-El-Malek22763052021-06-15 03:35:5376 CHECK(base::PathService::Get(SHELL_DIR_USER_DATA, &path_));
Henrique Nakashima7bb9d522019-04-16 20:57:3677
78 FinishInitWhileIOAllowed();
79}
80
81void ShellBrowserContext::FinishInitWhileIOAllowed() {
Xi Han720a2a22019-05-21 17:39:5982 key_ = std::make_unique<SimpleFactoryKey>(path_, off_the_record_);
Henrique Nakashima7bb9d522019-04-16 20:57:3683 SimpleKeyMap::GetInstance()->Associate(this, key_.get());
[email protected]11a65b692012-03-30 11:29:1684}
[email protected]b0f146f2011-09-15 22:14:2585
dcheng6003e0b2016-04-09 18:42:3486std::unique_ptr<ZoomLevelDelegate> ShellBrowserContext::CreateZoomLevelDelegate(
wjmacleancaa7d6d2014-11-12 16:42:1187 const base::FilePath&) {
Lei Zhangdf291f62021-04-14 17:23:4488 return nullptr;
wjmacleancaa7d6d2014-11-12 16:42:1189}
90
Lucas Furukawa Gadanif45223862019-06-21 23:11:1491base::FilePath ShellBrowserContext::GetPath() {
[email protected]e99ca5112011-09-26 17:22:5492 return path_;
[email protected]b0f146f2011-09-15 22:14:2593}
94
Lucas Furukawa Gadanif45223862019-06-21 23:11:1495bool ShellBrowserContext::IsOffTheRecord() {
[email protected]71d504f2012-07-25 17:15:2896 return off_the_record_;
[email protected]b0f146f2011-09-15 22:14:2597}
98
[email protected]b441a8492012-06-06 14:55:5799DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
[email protected]fc72bb12013-06-02 21:13:46100 if (!download_manager_delegate_.get()) {
Peter Boströmdd7e40ec2021-04-05 20:40:10101 download_manager_delegate_ =
102 std::make_unique<ShellDownloadManagerDelegate>();
Lukasz Anforowicz48d83452021-05-12 02:58:20103 download_manager_delegate_->SetDownloadManager(GetDownloadManager());
[email protected]59002092012-08-27 19:42:56104 }
[email protected]08c92ac2012-08-21 23:41:40105
[email protected]b441a8492012-06-06 14:55:57106 return download_manager_delegate_.get();
[email protected]b0f146f2011-09-15 22:14:25107}
108
[email protected]139355f2014-05-11 14:21:28109BrowserPluginGuestManager* ShellBrowserContext::GetGuestManager() {
Kevin McNee6f0513b2020-09-29 19:37:01110 return nullptr;
[email protected]24569262014-05-06 03:31:30111}
112
[email protected]cd501a72014-08-22 19:58:31113storage::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28114 return nullptr;
[email protected]b0f146f2011-09-15 22:14:25115}
116
Richard Knoll77b8b2b2021-09-08 09:29:01117PlatformNotificationService*
118ShellBrowserContext::GetPlatformNotificationService() {
119 return nullptr;
120}
121
[email protected]c5c89d042014-06-13 14:43:37122PushMessagingService* ShellBrowserContext::GetPushMessagingService() {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28123 return nullptr;
[email protected]c5c89d042014-06-13 14:43:37124}
125
Jarryd20733d32019-10-02 23:27:17126StorageNotificationService*
127ShellBrowserContext::GetStorageNotificationService() {
128 return nullptr;
129}
130
[email protected]c5bbe0e2014-08-01 23:23:30131SSLHostStateDelegate* ShellBrowserContext::GetSSLHostStateDelegate() {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28132 return nullptr;
[email protected]c5bbe0e2014-08-01 23:23:30133}
134
Andrey Lushnikovf3500102018-07-16 19:55:22135PermissionControllerDelegate*
136ShellBrowserContext::GetPermissionControllerDelegate() {
mlamouri4e372022015-03-29 14:51:06137 if (!permission_manager_.get())
Peter Boströmdd7e40ec2021-04-05 20:40:10138 permission_manager_ = std::make_unique<ShellPermissionManager>();
mlamouri4e372022015-03-29 14:51:06139 return permission_manager_.get();
140}
141
Tarun Bansal1ff665c2019-01-09 16:35:52142ClientHintsControllerDelegate*
143ShellBrowserContext::GetClientHintsControllerDelegate() {
Scott Violet3cd8d362020-04-30 22:18:24144 return client_hints_controller_delegate_;
Tarun Bansal1ff665c2019-01-09 16:35:52145}
146
Dan Elphick975213182017-09-22 10:37:47147BackgroundFetchDelegate* ShellBrowserContext::GetBackgroundFetchDelegate() {
148 return nullptr;
149}
150
jkarlin6f5078ed2015-10-06 15:13:35151BackgroundSyncController* ShellBrowserContext::GetBackgroundSyncController() {
Peter Boströmdd7e40ec2021-04-05 20:40:10152 if (!background_sync_controller_) {
153 background_sync_controller_ =
154 std::make_unique<MockBackgroundSyncController>();
155 }
jkarlin428a4a32016-01-08 16:13:24156 return background_sync_controller_.get();
jkarlin6f5078ed2015-10-06 15:13:35157}
158
msramek86b6bc72017-05-31 12:21:10159BrowsingDataRemoverDelegate*
160ShellBrowserContext::GetBrowsingDataRemoverDelegate() {
161 return nullptr;
162}
163
Rayan Kanso4f753a672019-08-12 17:30:07164ContentIndexProvider* ShellBrowserContext::GetContentIndexProvider() {
165 if (!content_index_provider_)
danakjdd5bb4ef2020-06-26 23:29:22166 content_index_provider_ = std::make_unique<ShellContentIndexProvider>();
Rayan Kanso4f753a672019-08-12 17:30:07167 return content_index_provider_.get();
168}
169
Victor Tan10d93aca2022-08-12 16:46:28170ReduceAcceptLanguageControllerDelegate*
171ShellBrowserContext::GetReduceAcceptLanguageControllerDelegate() {
172 if (!reduce_accept_lang_controller_delegate_) {
173 reduce_accept_lang_controller_delegate_ =
174 std::make_unique<MockReduceAcceptLanguageControllerDelegate>(
175 GetShellLanguage());
176 }
177 return reduce_accept_lang_controller_delegate_.get();
178}
179
Peter Birk Pakkenbergd927c942022-11-17 14:30:42180OriginTrialsControllerDelegate*
181ShellBrowserContext::GetOriginTrialsControllerDelegate() {
Peter Birk Pakkenbergd927c942022-11-17 14:30:42182 if (!origin_trials_controller_delegate_) {
183 origin_trials_controller_delegate_ =
184 std::make_unique<origin_trials::OriginTrials>(
185 std::make_unique<origin_trials::LevelDbPersistenceProvider>(
186 GetPath(),
187 GetDefaultStoragePartition()->GetProtoDatabaseProvider()),
188 std::make_unique<blink::TrialTokenValidator>());
189 }
190 return origin_trials_controller_delegate_.get();
191}
192
[email protected]b0f146f2011-09-15 22:14:25193} // namespace content