blob: 492880eaca9be30ba8bf2a249ad03d2e28cffd19 [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]037edb52011-11-15 21:14:0610#include "base/bind.h"
[email protected]2f2b9512012-06-08 17:31:0011#include "base/command_line.h"
[email protected]5cba3bf2012-01-14 02:40:3512#include "base/environment.h"
thestigb7aad54f2014-09-05 18:25:3913#include "base/files/file_util.h"
[email protected]b0f146f2011-09-15 22:14:2514#include "base/logging.h"
15#include "base/path_service.h"
[email protected]2e5b60a22011-11-28 15:56:4116#include "base/threading/thread.h"
avi66a07722015-12-25 23:38:1217#include "build/build_config.h"
juliatuttleca57a11b2016-11-15 19:07:5318#include "components/keyed_service/content/browser_context_dependency_manager.h"
Henrique Nakashimadd1cdd12019-04-25 15:47:0419#include "components/keyed_service/core/simple_dependency_manager.h"
Xi Han720a2a22019-05-21 17:39:5920#include "components/keyed_service/core/simple_factory_key.h"
Henrique Nakashima7bb9d522019-04-16 20:57:3621#include "components/keyed_service/core/simple_key_map.h"
mmenke68a50212017-06-12 20:20:3122#include "components/network_session_configurator/common/network_switches.h"
Eric Seckler8652dcd52018-09-20 10:42:2823#include "content/public/browser/browser_task_traits.h"
[email protected]c38831a12011-10-28 12:44:4924#include "content/public/browser/browser_thread.h"
[email protected]6bd30072013-02-08 18:17:1125#include "content/public/browser/storage_partition.h"
26#include "content/public/common/content_switches.h"
Victor Tan10d93aca2022-08-12 16:46:2827#include "content/shell/browser/shell_content_browser_client.h"
danakjdd5bb4ef2020-06-26 23:29:2228#include "content/shell/browser/shell_content_index_provider.h"
[email protected]de7d61ff2013-08-20 11:30:4129#include "content/shell/browser/shell_download_manager_delegate.h"
Christian Biesingerdcca1722022-03-18 15:02:4830#include "content/shell/browser/shell_federated_permission_context.h"
John Abd-El-Malek22763052021-06-15 03:35:5331#include "content/shell/browser/shell_paths.h"
mlamouri4e372022015-03-29 14:51:0632#include "content/shell/browser/shell_permission_manager.h"
[email protected]b7c504c2013-05-07 14:42:1233#include "content/shell/common/shell_switches.h"
nsatragnodb7b65c642016-02-16 20:14:0234#include "content/test/mock_background_sync_controller.h"
Victor Tan10d93aca2022-08-12 16:46:2835#include "content/test/mock_reduce_accept_language_controller_delegate.h"
[email protected]b0f146f2011-09-15 22:14:2536
[email protected]810ddc52012-01-24 01:00:3537namespace content {
38
John Abd-El-Malek8104d672018-11-28 20:27:0339ShellBrowserContext::ShellResourceContext::ShellResourceContext() {}
[email protected]6bd30072013-02-08 18:17:1140
hanxi3328d992014-10-09 13:27:1141ShellBrowserContext::ShellResourceContext::~ShellResourceContext() {
42}
[email protected]6bd30072013-02-08 18:17:1143
[email protected]d5869bf2013-07-03 16:21:4744ShellBrowserContext::ShellBrowserContext(bool off_the_record,
Michael Giuffridac55719602018-02-09 17:10:3545 bool delay_services_creation)
Kevin McNee6f0513b2020-09-29 19:37:0146 : resource_context_(std::make_unique<ShellResourceContext>()),
47 off_the_record_(off_the_record) {
[email protected]11a65b692012-03-30 11:29:1648 InitWhileIOAllowed();
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 // Need to destruct the ResourceContext before posting tasks which may delete
69 // the URLRequestContext because ResourceContext's destructor will remove any
70 // outstanding request while URLRequestContext's destructor ensures that there
71 // are no more outstanding requests.
[email protected]59383c782013-04-17 16:43:2772 if (resource_context_) {
Gabriel Charettee7cdc5cd2020-05-27 23:35:0573 GetIOThreadTaskRunner({})->DeleteSoon(FROM_HERE,
74 resource_context_.release());
[email protected]e99ca5112011-09-26 17:22:5475 }
jam21e62ae2017-03-21 19:57:4876 ShutdownStoragePartitions();
[email protected]b0f146f2011-09-15 22:14:2577}
78
[email protected]11a65b692012-03-30 11:29:1679void ShellBrowserContext::InitWhileIOAllowed() {
avi83883c82014-12-23 00:08:4980 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
mkwstd993d06a2014-10-10 11:44:3881 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors))
[email protected]c2dad292012-09-07 21:27:3582 ignore_certificate_errors_ = true;
[email protected]e1cf85a22012-08-17 22:39:2383 if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
84 path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
michaelpg49a54b592016-10-04 02:07:2185 if (base::DirectoryExists(path_) || base::CreateDirectory(path_)) {
86 // BrowserContext needs an absolute path, which we would normally get via
87 // PathService. In this case, manually ensure the path is absolute.
88 if (!path_.IsAbsolute())
89 path_ = base::MakeAbsoluteFilePath(path_);
90 if (!path_.empty()) {
Henrique Nakashima7bb9d522019-04-16 20:57:3691 FinishInitWhileIOAllowed();
Will Harrisd5478a02022-08-05 22:21:1092 base::PathService::OverrideAndCreateIfNeeded(
93 SHELL_DIR_USER_DATA, path_, /*is_absolute=*/true, /*create=*/false);
michaelpg49a54b592016-10-04 02:07:2194 return;
95 }
96 } else {
97 LOG(WARNING) << "Unable to create data-path directory: " << path_.value();
98 }
[email protected]e1cf85a22012-08-17 22:39:2399 }
michaelpg49a54b592016-10-04 02:07:21100
John Abd-El-Malek22763052021-06-15 03:35:53101 CHECK(base::PathService::Get(SHELL_DIR_USER_DATA, &path_));
Henrique Nakashima7bb9d522019-04-16 20:57:36102
103 FinishInitWhileIOAllowed();
104}
105
106void ShellBrowserContext::FinishInitWhileIOAllowed() {
Xi Han720a2a22019-05-21 17:39:59107 key_ = std::make_unique<SimpleFactoryKey>(path_, off_the_record_);
Henrique Nakashima7bb9d522019-04-16 20:57:36108 SimpleKeyMap::GetInstance()->Associate(this, key_.get());
[email protected]11a65b692012-03-30 11:29:16109}
[email protected]b0f146f2011-09-15 22:14:25110
dcheng6003e0b2016-04-09 18:42:34111std::unique_ptr<ZoomLevelDelegate> ShellBrowserContext::CreateZoomLevelDelegate(
wjmacleancaa7d6d2014-11-12 16:42:11112 const base::FilePath&) {
Lei Zhangdf291f62021-04-14 17:23:44113 return nullptr;
wjmacleancaa7d6d2014-11-12 16:42:11114}
115
Lucas Furukawa Gadanif45223862019-06-21 23:11:14116base::FilePath ShellBrowserContext::GetPath() {
[email protected]e99ca5112011-09-26 17:22:54117 return path_;
[email protected]b0f146f2011-09-15 22:14:25118}
119
Lucas Furukawa Gadanif45223862019-06-21 23:11:14120bool ShellBrowserContext::IsOffTheRecord() {
[email protected]71d504f2012-07-25 17:15:28121 return off_the_record_;
[email protected]b0f146f2011-09-15 22:14:25122}
123
[email protected]b441a8492012-06-06 14:55:57124DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
[email protected]fc72bb12013-06-02 21:13:46125 if (!download_manager_delegate_.get()) {
Peter Boströmdd7e40ec2021-04-05 20:40:10126 download_manager_delegate_ =
127 std::make_unique<ShellDownloadManagerDelegate>();
Lukasz Anforowicz48d83452021-05-12 02:58:20128 download_manager_delegate_->SetDownloadManager(GetDownloadManager());
[email protected]59002092012-08-27 19:42:56129 }
[email protected]08c92ac2012-08-21 23:41:40130
[email protected]b441a8492012-06-06 14:55:57131 return download_manager_delegate_.get();
[email protected]b0f146f2011-09-15 22:14:25132}
133
[email protected]df02aca2012-02-09 21:03:20134ResourceContext* ShellBrowserContext::GetResourceContext() {
[email protected]df02aca2012-02-09 21:03:20135 return resource_context_.get();
[email protected]b0f146f2011-09-15 22:14:25136}
137
[email protected]139355f2014-05-11 14:21:28138BrowserPluginGuestManager* ShellBrowserContext::GetGuestManager() {
Kevin McNee6f0513b2020-09-29 19:37:01139 return nullptr;
[email protected]24569262014-05-06 03:31:30140}
141
[email protected]cd501a72014-08-22 19:58:31142storage::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28143 return nullptr;
[email protected]b0f146f2011-09-15 22:14:25144}
145
Richard Knoll77b8b2b2021-09-08 09:29:01146PlatformNotificationService*
147ShellBrowserContext::GetPlatformNotificationService() {
148 return nullptr;
149}
150
[email protected]c5c89d042014-06-13 14:43:37151PushMessagingService* ShellBrowserContext::GetPushMessagingService() {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28152 return nullptr;
[email protected]c5c89d042014-06-13 14:43:37153}
154
Jarryd20733d32019-10-02 23:27:17155StorageNotificationService*
156ShellBrowserContext::GetStorageNotificationService() {
157 return nullptr;
158}
159
[email protected]c5bbe0e2014-08-01 23:23:30160SSLHostStateDelegate* ShellBrowserContext::GetSSLHostStateDelegate() {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28161 return nullptr;
[email protected]c5bbe0e2014-08-01 23:23:30162}
163
Andrey Lushnikovf3500102018-07-16 19:55:22164PermissionControllerDelegate*
165ShellBrowserContext::GetPermissionControllerDelegate() {
mlamouri4e372022015-03-29 14:51:06166 if (!permission_manager_.get())
Peter Boströmdd7e40ec2021-04-05 20:40:10167 permission_manager_ = std::make_unique<ShellPermissionManager>();
mlamouri4e372022015-03-29 14:51:06168 return permission_manager_.get();
169}
170
Tarun Bansal1ff665c2019-01-09 16:35:52171ClientHintsControllerDelegate*
172ShellBrowserContext::GetClientHintsControllerDelegate() {
Scott Violet3cd8d362020-04-30 22:18:24173 return client_hints_controller_delegate_;
Tarun Bansal1ff665c2019-01-09 16:35:52174}
175
Dan Elphick975213182017-09-22 10:37:47176BackgroundFetchDelegate* ShellBrowserContext::GetBackgroundFetchDelegate() {
177 return nullptr;
178}
179
jkarlin6f5078ed2015-10-06 15:13:35180BackgroundSyncController* ShellBrowserContext::GetBackgroundSyncController() {
Peter Boströmdd7e40ec2021-04-05 20:40:10181 if (!background_sync_controller_) {
182 background_sync_controller_ =
183 std::make_unique<MockBackgroundSyncController>();
184 }
jkarlin428a4a32016-01-08 16:13:24185 return background_sync_controller_.get();
jkarlin6f5078ed2015-10-06 15:13:35186}
187
msramek86b6bc72017-05-31 12:21:10188BrowsingDataRemoverDelegate*
189ShellBrowserContext::GetBrowsingDataRemoverDelegate() {
190 return nullptr;
191}
192
Rayan Kanso4f753a672019-08-12 17:30:07193ContentIndexProvider* ShellBrowserContext::GetContentIndexProvider() {
194 if (!content_index_provider_)
danakjdd5bb4ef2020-06-26 23:29:22195 content_index_provider_ = std::make_unique<ShellContentIndexProvider>();
Rayan Kanso4f753a672019-08-12 17:30:07196 return content_index_provider_.get();
197}
198
Peter Kotwicz153898a2022-05-05 18:48:39199FederatedIdentityApiPermissionContextDelegate*
200ShellBrowserContext::GetFederatedIdentityApiPermissionContext() {
201 if (!federated_permission_context_)
202 federated_permission_context_ =
203 std::make_unique<ShellFederatedPermissionContext>();
204 return federated_permission_context_.get();
205}
206
Christian Biesingerdcca1722022-03-18 15:02:48207FederatedIdentitySharingPermissionContextDelegate*
208ShellBrowserContext::GetFederatedIdentitySharingPermissionContext() {
209 if (!federated_permission_context_)
210 federated_permission_context_ =
211 std::make_unique<ShellFederatedPermissionContext>();
212 return federated_permission_context_.get();
213}
214
215FederatedIdentityActiveSessionPermissionContextDelegate*
216ShellBrowserContext::GetFederatedIdentityActiveSessionPermissionContext() {
217 if (!federated_permission_context_)
218 federated_permission_context_ =
219 std::make_unique<ShellFederatedPermissionContext>();
220 return federated_permission_context_.get();
221}
222
Victor Tan10d93aca2022-08-12 16:46:28223ReduceAcceptLanguageControllerDelegate*
224ShellBrowserContext::GetReduceAcceptLanguageControllerDelegate() {
225 if (!reduce_accept_lang_controller_delegate_) {
226 reduce_accept_lang_controller_delegate_ =
227 std::make_unique<MockReduceAcceptLanguageControllerDelegate>(
228 GetShellLanguage());
229 }
230 return reduce_accept_lang_controller_delegate_.get();
231}
232
[email protected]b0f146f2011-09-15 22:14:25233} // namespace content