blob: 3fe2b03c57d22dc112b21a99ce39a280ee2622e8 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
[email protected]55eb70e762012-02-20 17:38:392// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/public/browser/browser_context.h"
6
avib7348942015-12-25 20:57:107#include <stddef.h>
8#include <stdint.h>
avi1ed4a4372017-04-25 05:39:419
erge69130f52016-03-02 00:13:2810#include <algorithm>
11#include <limits>
rockot963ad3e82016-04-13 16:33:2312#include <memory>
Wayne Jackson Jr.1b7322472024-10-29 13:08:5113#include <optional>
Takuto Ikuta8332bf9d2019-01-05 03:58:0014#include <unordered_set>
dcheng36b6aec92015-12-26 06:16:3615#include <utility>
rockot963ad3e82016-04-13 16:33:2316#include <vector>
avib7348942015-12-25 20:57:1017
mmenkec0b2b8b12017-04-21 16:27:5218#include "base/base64.h"
Hans Wennborg0917de892020-04-28 20:21:1519#include "base/check_op.h"
rockot963ad3e82016-04-13 16:33:2320#include "base/command_line.h"
Chris Cunninghama5b38012017-10-28 07:27:1821#include "base/files/file_path.h"
Avi Drissmanadac21992023-01-11 23:46:3922#include "base/functional/bind.h"
erge69130f52016-03-02 00:13:2823#include "base/lazy_instance.h"
avi1ed4a4372017-04-25 05:39:4124#include "base/memory/ptr_util.h"
Ken Rockot435132692018-11-20 21:46:1025#include "base/memory/weak_ptr.h"
Chris Cunningham4507edfa2019-05-30 20:15:5426#include "base/metrics/field_trial_params.h"
Hans Wennborg0917de892020-04-28 20:21:1527#include "base/notreached.h"
Lei Zhang19c1df02025-04-17 01:53:5628#include "base/trace_event/trace_event.h"
Andrey Lushnikovd39d9062018-04-24 17:33:3529#include "base/unguessable_token.h"
avib7348942015-12-25 20:57:1030#include "build/build_config.h"
Stephan Hartmann63027c62022-12-19 13:56:1731#include "components/download/public/common/in_progress_download_manager.h"
Ari Chivukulad1cf518c2022-05-06 23:14:2232#include "components/services/storage/privileged/mojom/indexed_db_control.mojom.h"
dmurph7ac019a2016-05-13 00:13:1733#include "content/browser/blob_storage/chrome_blob_storage_context.h"
Lukasz Anforowicz729a9e12021-03-31 17:44:0134#include "content/browser/browser_context_impl.h"
Etienne Noel2ac27c22022-12-06 04:28:4635#include "content/browser/browsing_data/browsing_data_remover_impl.h"
Will Harriscd57b832023-01-05 20:03:1036#include "content/browser/child_process_host_impl.h"
Alex Moshchuk99b795422019-03-07 00:27:3237#include "content/browser/child_process_security_policy_impl.h"
Christian Biesingerc59336f2024-07-26 17:08:2238#include "content/browser/in_memory_federated_permission_context.h"
Wayne Jackson Jr.1b7322472024-10-29 13:08:5139#include "content/browser/preloading/prefetch/prefetch_container.h"
40#include "content/browser/preloading/prefetch/prefetch_service.h"
41#include "content/browser/preloading/prefetch/prefetch_type.h"
mvanouwerkerk17205ea2014-11-07 17:30:1542#include "content/browser/push_messaging/push_messaging_router.h"
Sharon Yangd70a5392021-10-26 23:06:3243#include "content/browser/site_info.h"
[email protected]4c3a23582012-08-18 08:54:3444#include "content/browser/storage_partition_impl_map.h"
[email protected]393b6cb2014-05-15 00:55:1245#include "content/public/browser/blob_handle.h"
Eric Seckler8652dcd52018-09-20 10:42:2846#include "content/public/browser/browser_task_traits.h"
[email protected]55eb70e762012-02-20 17:38:3947#include "content/public/browser/browser_thread.h"
[email protected]b441a8492012-06-06 14:55:5748#include "content/public/browser/content_browser_client.h"
Lukasz Anforowicz729a9e12021-03-31 17:44:0149#include "content/public/browser/download_manager.h"
50#include "content/public/browser/permission_controller.h"
Wayne Jackson Jr.3dfcf9472025-01-31 14:07:1651#include "content/public/browser/prefetch_service_delegate.h"
Wayne Jackson Jr.1b7322472024-10-29 13:08:5152#include "content/public/browser/preloading_trigger_type.h"
falken04a6912a2016-09-23 21:06:2953#include "content/public/browser/render_process_host.h"
[email protected]536fd0b2013-03-14 17:41:5754#include "content/public/browser/site_instance.h"
Bret Sepulveda56652152020-06-24 14:47:1355#include "content/public/browser/storage_partition_config.h"
Hans Wennborg5ffd1392019-10-16 11:00:0256#include "content/public/common/content_client.h"
rockot963ad3e82016-04-13 16:33:2357#include "content/public/common/content_switches.h"
Lukasz Anforowicz287ec63c2021-04-07 22:07:3958#include "media/base/media_switches.h"
59#include "media/capabilities/in_memory_video_decode_stats_db_impl.h"
60#include "media/capabilities/video_decode_stats_db_impl.h"
61#include "media/mojo/services/video_decode_perf_history.h"
Johannes Kron33182672022-05-20 09:52:0362#include "media/mojo/services/webrtc_video_perf_history.h"
Wayne Jackson Jr.1b7322472024-10-29 13:08:5163#include "net/http/http_request_headers.h"
Xing Liu89860472018-02-09 20:07:0264#include "storage/browser/blob/blob_storage_context.h"
DongJun Kimfebb3c22019-10-21 02:08:0665#include "storage/browser/file_system/external_mount_points.h"
David Sandersb4b48702025-01-08 02:29:1866#include "third_party/blink/public/mojom/loader/referrer.mojom.h"
Hans Wennborg78b52182021-06-15 13:42:1567#include "third_party/blink/public/mojom/push_messaging/push_messaging.mojom.h"
Hans Wennborg0e472112021-06-16 21:36:3268#include "third_party/perfetto/include/perfetto/tracing/traced_proto.h"
Alexander Timinf785f342021-03-18 00:00:5669#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"
Wayne Jackson Jr.1b7322472024-10-29 13:08:5170#include "url/gurl.h"
[email protected]55eb70e762012-02-20 17:38:3971
[email protected]55eb70e762012-02-20 17:38:3972namespace content {
73
Wayne Jackson Jr.1b7322472024-10-29 13:08:5174class PrefetchService;
Wayne Jackson Jr.3dfcf9472025-01-31 14:07:1675class PrefetchServiceDelegate;
Wayne Jackson Jr.1b7322472024-10-29 13:08:5176
[email protected]735e20c2012-03-20 01:16:5977namespace {
78
ssid6bedaa92021-06-16 10:25:2479using perfetto::protos::pbzero::ChromeBrowserContext;
80using perfetto::protos::pbzero::ChromeTrackEvent;
81
Jens Widell7ca8fb42018-02-21 14:11:5482base::WeakPtr<storage::BlobStorageContext> BlobStorageContextGetterForBrowser(
Xing Liu89860472018-02-09 20:07:0283 scoped_refptr<ChromeBlobStorageContext> blob_context) {
84 DCHECK_CURRENTLY_ON(BrowserThread::IO);
85 return blob_context->context()->AsWeakPtr();
86}
87
[email protected]735e20c2012-03-20 01:16:5988} // namespace
89
Lukasz Anforowiczb6802442021-04-02 20:47:5190BrowserContext::BrowserContext() {
Arthur Sonzogni61cb46d12022-02-15 17:25:2891 impl_ = base::WrapUnique(new BrowserContextImpl(this));
ssid6bedaa92021-06-16 10:25:2492 TRACE_EVENT("shutdown", "BrowserContext::BrowserContext",
93 ChromeTrackEvent::kChromeBrowserContext, *this);
94 TRACE_EVENT_BEGIN("shutdown", "Browser.BrowserContext",
95 perfetto::Track::FromPointer(this),
96 ChromeTrackEvent::kChromeBrowserContext, *this);
[email protected]399583b2012-12-11 09:33:4297}
98
Lukasz Anforowiczb6802442021-04-02 20:47:5199BrowserContext::~BrowserContext() {
100 TRACE_EVENT("shutdown", "BrowserContext::~BrowserContext",
ssid6bedaa92021-06-16 10:25:24101 ChromeTrackEvent::kChromeBrowserContext, *this);
102
103 // End for ASYNC event "Browser.BrowserContext".
104 TRACE_EVENT_END("shutdown", perfetto::Track::FromPointer(this),
105 ChromeTrackEvent::kChromeBrowserContext, *this);
Lukasz Anforowiczb6802442021-04-02 20:47:51106
107 impl_.reset();
[email protected]14acc642012-11-17 12:20:10108}
109
Lukasz Anforowicz48d83452021-05-12 02:58:20110DownloadManager* BrowserContext::GetDownloadManager() {
mostynbfbcdc27a2015-03-13 17:58:52111 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Lukasz Anforowicz48d83452021-05-12 02:58:20112 return impl()->GetDownloadManager();
[email protected]b441a8492012-06-06 14:55:57113}
114
Lukasz Anforowiczeda637d22021-05-20 00:32:23115storage::ExternalMountPoints* BrowserContext::GetMountPoints() {
116 return impl()->GetMountPoints();
[email protected]6ef0c3912013-01-25 22:46:34117}
118
Lukasz Anforowicz8b6a9322021-05-13 02:16:32119BrowsingDataRemover* BrowserContext::GetBrowsingDataRemover() {
120 return impl()->GetBrowsingDataRemover();
msrameke169ccb2017-04-26 05:21:41121}
122
Lukasz Anforowicz82061152021-05-14 02:14:26123PermissionController* BrowserContext::GetPermissionController() {
Andrey Lushnikovebff0442018-07-12 20:02:58124 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Lukasz Anforowicz82061152021-05-14 02:14:26125 return impl()->GetPermissionController();
Andrey Lushnikovebff0442018-07-12 20:02:58126}
127
[email protected]4c3a23582012-08-18 08:54:34128StoragePartition* BrowserContext::GetStoragePartition(
Dan Elphick6c0d8492017-09-12 09:35:38129 SiteInstance* site_instance,
130 bool can_create) {
Aaron Colwell364199b2021-03-24 05:25:39131 if (site_instance)
Lukasz Anforowiczb9a969a2021-04-29 15:26:25132 DCHECK_EQ(this, site_instance->GetBrowserContext());
Aaron Colwell364199b2021-03-24 05:25:39133
Alex Moshchuka03a6e82021-11-15 19:09:42134 auto partition_config = site_instance
135 ? site_instance->GetStoragePartitionConfig()
136 : StoragePartitionConfig::CreateDefault(this);
Lukasz Anforowiczb9a969a2021-04-29 15:26:25137 return GetStoragePartition(partition_config, can_create);
Bret Sepulveda56652152020-06-24 14:47:13138}
139
140StoragePartition* BrowserContext::GetStoragePartition(
Bret Sepulveda56652152020-06-24 14:47:13141 const StoragePartitionConfig& storage_partition_config,
142 bool can_create) {
Lukasz Anforowiczb9a969a2021-04-29 15:26:25143 if (IsOffTheRecord()) {
Aaron Colwell15013112021-03-10 17:06:26144 // An off the record profile MUST only use in memory storage partitions.
145 CHECK(storage_partition_config.in_memory());
146 }
Bret Sepulveda56652152020-06-24 14:47:13147
Lukasz Anforowiczb9a969a2021-04-29 15:26:25148 return impl()->GetOrCreateStoragePartitionMap()->Get(storage_partition_config,
149 can_create);
[email protected]4c3a23582012-08-18 08:54:34150}
151
Aaron Colwellb54ca392021-03-18 23:20:56152StoragePartition* BrowserContext::GetStoragePartitionForUrl(
Aaron Colwellb54ca392021-03-18 23:20:56153 const GURL& url,
Dan Elphick6c0d8492017-09-12 09:35:38154 bool can_create) {
Alex Moshchuke1f71d3a2023-03-28 19:36:39155 auto storage_partition_config =
156 SiteInfo::GetStoragePartitionConfigForUrl(this, url);
[email protected]e94bbcb2012-09-07 05:33:57157
Lukasz Anforowiczb9a969a2021-04-29 15:26:25158 return GetStoragePartition(storage_partition_config, can_create);
[email protected]e94bbcb2012-09-07 05:33:57159}
160
Robbie McElrath785b5e02023-01-18 00:32:46161void BrowserContext::ForEachLoadedStoragePartition(
Daniel Chengcb3ab642023-11-22 06:41:59162 base::FunctionRef<void(StoragePartition*)> fn) {
Lukasz Anforowiczb9a969a2021-04-29 15:26:25163 StoragePartitionImplMap* partition_map = impl()->storage_partition_map();
[email protected]4c3a23582012-08-18 08:54:34164 if (!partition_map)
165 return;
166
Daniel Chengcb3ab642023-11-22 06:41:59167 partition_map->ForEach(fn);
[email protected]4c3a23582012-08-18 08:54:34168}
169
Robbie McElrath785b5e02023-01-18 00:32:46170size_t BrowserContext::GetLoadedStoragePartitionCount() {
Lukasz Anforowiczb9a969a2021-04-29 15:26:25171 StoragePartitionImplMap* partition_map = impl()->storage_partition_map();
Brandon Maslendd4ba9e02020-02-19 21:52:37172 return partition_map ? partition_map->size() : 0;
173}
174
Lukasz Anforowiczb6802442021-04-02 20:47:51175void BrowserContext::AsyncObliterateStoragePartition(
Lukasz Anforowiczb6802442021-04-02 20:47:51176 const std::string& partition_domain,
Maria Petrisor2d611d62021-09-02 22:44:15177 base::OnceClosure on_gc_required,
178 base::OnceClosure done_callback) {
Lukasz Anforowiczb9a969a2021-04-29 15:26:25179 impl()->GetOrCreateStoragePartitionMap()->AsyncObliterate(
Maria Petrisor2d611d62021-09-02 22:44:15180 partition_domain, std::move(on_gc_required), std::move(done_callback));
[email protected]55eb70e762012-02-20 17:38:39181}
182
Lukasz Anforowiczb6802442021-04-02 20:47:51183void BrowserContext::GarbageCollectStoragePartitions(
Lei Zhang3ea75942022-01-20 16:57:03184 std::unordered_set<base::FilePath> active_paths,
Lukasz Anforowiczb6802442021-04-02 20:47:51185 base::OnceClosure done) {
Lukasz Anforowiczb9a969a2021-04-29 15:26:25186 impl()->GetOrCreateStoragePartitionMap()->GarbageCollect(
Lukasz Anforowiczb6802442021-04-02 20:47:51187 std::move(active_paths), std::move(done));
188}
189
Lukasz Anforowiczb9a969a2021-04-29 15:26:25190StoragePartition* BrowserContext::GetDefaultStoragePartition() {
191 return GetStoragePartition(StoragePartitionConfig::CreateDefault(this));
Lukasz Anforowiczb6802442021-04-02 20:47:51192}
193
elabadysayedab1b97c02025-02-13 11:06:26194std::unique_ptr<content::PrefetchHandle>
195BrowserContext::StartBrowserPrefetchRequest(
Wayne Jackson Jr.1b7322472024-10-29 13:08:51196 const GURL& url,
Taiyo Mizuhashi49959d02025-04-22 16:07:54197 const std::string& embedder_histogram_suffix,
Wayne Jackson Jr.1b7322472024-10-29 13:08:51198 bool javascript_enabled,
Rulong Chen(陈汝龙)bf12169c2024-12-16 05:38:16199 std::optional<net::HttpNoVarySearchData> no_vary_search_hint,
Taiyo Mizuhashid7c856992025-06-23 08:56:02200 std::optional<PrefetchPriority> priority,
Wayne Jackson Jr.1b7322472024-10-29 13:08:51201 const net::HttpRequestHeaders& additional_headers,
elabadysayedf7d6b00f2025-02-05 11:27:00202 std::unique_ptr<PrefetchRequestStatusListener> request_status_listener,
kenoss70bfbfe2025-06-10 08:04:42203 base::TimeDelta ttl,
Taiyo Mizuhashicd08a8f2025-06-10 17:27:32204 bool should_append_variations_header,
205 bool should_disable_block_until_head_timeout) {
Wayne Jackson Jr.1b7322472024-10-29 13:08:51206 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Wayne Jackson Jr.679a6e72024-12-10 17:02:40207 TRACE_EVENT0("loading", "BrowserContext::StartBrowserPrefetchRequest");
Wayne Jackson Jr.1b7322472024-10-29 13:08:51208
209 PrefetchService* prefetch_service =
210 BrowserContextImpl::From(this)->GetPrefetchService();
211 if (!prefetch_service) {
Wayne Jackson Jr.b22d53b22024-11-15 11:40:06212 if (request_status_listener) {
Wayne Jackson Jr.0118d2a2025-02-21 10:53:46213 request_status_listener->OnPrefetchStartFailedGeneric();
Wayne Jackson Jr.1b7322472024-10-29 13:08:51214 }
elabadysayedab1b97c02025-02-13 11:06:26215 return nullptr;
Wayne Jackson Jr.1b7322472024-10-29 13:08:51216 }
217
218 PrefetchType prefetch_type(PreloadingTriggerType::kEmbedder,
219 /*use_prefetch_proxy=*/false);
220 auto container = std::make_unique<PrefetchContainer>(
Taiyo Mizuhashi49959d02025-04-22 16:07:54221 this, url, prefetch_type, embedder_histogram_suffix,
222 blink::mojom::Referrer(), javascript_enabled,
Rulong Chen(陈汝龙)bf12169c2024-12-16 05:38:16223 /*referring_origin=*/std::nullopt, std::move(no_vary_search_hint),
Taiyo Mizuhashid7c856992025-06-23 08:56:02224 std::move(priority),
Wayne Jackson Jr.1b7322472024-10-29 13:08:51225 /*attempt=*/nullptr, additional_headers,
Taiyo Mizuhashicd08a8f2025-06-10 17:27:32226 std::move(request_status_listener), ttl, should_append_variations_header,
227 should_disable_block_until_head_timeout);
elabadysayedab1b97c02025-02-13 11:06:26228 return prefetch_service->AddPrefetchContainerWithHandle(std::move(container));
Wayne Jackson Jr.1b7322472024-10-29 13:08:51229}
230
Wayne Jackson Jr.3dfcf9472025-01-31 14:07:16231void BrowserContext::UpdatePrefetchServiceDelegateAcceptLanguageHeader(
232 std::string accept_language_header) {
233 PrefetchService* prefetch_service =
234 BrowserContextImpl::From(this)->GetPrefetchService();
235 if (!prefetch_service) {
236 return;
237 }
238 prefetch_service->GetPrefetchServiceDelegate()->SetAcceptLanguageHeader(
239 accept_language_header);
240}
241
Wayne Jackson Jr.0118d2a2025-02-21 10:53:46242bool BrowserContext::IsPrefetchDuplicate(
243 GURL& url,
244 std::optional<net::HttpNoVarySearchData> no_vary_search_hint) {
245 PrefetchService* prefetch_service =
246 BrowserContextImpl::From(this)->GetPrefetchService();
247 // `CHECK` is used here because this method should not be called unless there
248 // is a `prefetch_service` created for `this` browser context.
249 CHECK(prefetch_service);
250 return prefetch_service->IsPrefetchDuplicate(url, no_vary_search_hint);
251}
252
Lukasz Anforowicz7ef1cfd2021-05-04 02:18:37253void BrowserContext::CreateMemoryBackedBlob(base::span<const uint8_t> data,
Marijn Kruisselbrink604fd7e72017-10-26 16:31:05254 const std::string& content_type,
255 BlobCallback callback) {
mostynbfbcdc27a2015-03-13 17:58:52256 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]393b6cb2014-05-15 00:55:12257
258 ChromeBlobStorageContext* blob_context =
Lukasz Anforowicz7ef1cfd2021-05-04 02:18:37259 ChromeBlobStorageContext::GetFor(this);
Gabriel Charettee7cdc5cd2020-05-27 23:35:05260 GetIOThreadTaskRunner({})->PostTaskAndReplyWithResult(
261 FROM_HERE,
Marijn Kruisselbrink604fd7e72017-10-26 16:31:05262 base::BindOnce(&ChromeBlobStorageContext::CreateMemoryBackedBlob,
Adrienne Walkerac6a9e52019-10-28 20:59:33263 base::WrapRefCounted(blob_context), data, content_type),
Marijn Kruisselbrink604fd7e72017-10-26 16:31:05264 std::move(callback));
[email protected]393b6cb2014-05-15 00:55:12265}
266
Lukasz Anforowicz7ef1cfd2021-05-04 02:18:37267BrowserContext::BlobContextGetter BrowserContext::GetBlobStorageContext() {
Xing Liu89860472018-02-09 20:07:02268 DCHECK_CURRENTLY_ON(BrowserThread::UI);
269 scoped_refptr<ChromeBlobStorageContext> chrome_blob_context =
Lukasz Anforowicz7ef1cfd2021-05-04 02:18:37270 ChromeBlobStorageContext::GetFor(this);
Jens Widell7ca8fb42018-02-21 14:11:54271 return base::BindRepeating(&BlobStorageContextGetterForBrowser,
272 chrome_blob_context);
Xing Liu89860472018-02-09 20:07:02273}
274
Julie Jeongeun Kimbc4a76d2019-09-11 02:28:23275mojo::PendingRemote<blink::mojom::Blob> BrowserContext::GetBlobRemote(
Marijn Kruisselbrink9e073a82018-06-18 17:48:58276 const std::string& uuid) {
277 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Lukasz Anforowicz7ef1cfd2021-05-04 02:18:37278 return ChromeBlobStorageContext::GetBlobRemote(this, uuid);
Marijn Kruisselbrink9e073a82018-06-18 17:48:58279}
280
[email protected]66e53d0282014-08-07 10:04:35281void BrowserContext::DeliverPushMessage(
[email protected]66e53d0282014-08-07 10:04:35282 const GURL& origin,
avib7348942015-12-25 20:57:10283 int64_t service_worker_registration_id,
Rayan Kanso3b686202019-05-10 17:41:55284 const std::string& message_id,
Arthur Sonzognic686e8f2024-01-11 08:36:37285 std::optional<std::string> payload,
Nwokedi Idika5aaefbb2025-08-06 21:18:33286 bool record_network_requests,
Viviane Yangd125aad2020-08-07 07:38:25287 base::OnceCallback<void(blink::mojom::PushEventStatus)> callback) {
mostynbfbcdc27a2015-03-13 17:58:52288 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Matt Falkenhagenb5f46c452019-12-02 05:25:58289 PushMessagingRouter::DeliverMessage(
Lukasz Anforowicz5389590e2021-05-11 02:20:06290 this, origin, service_worker_registration_id, message_id,
Nwokedi Idika5aaefbb2025-08-06 21:18:33291 std::move(payload), record_network_requests, std::move(callback));
[email protected]66e53d0282014-08-07 10:04:35292}
293
Viviane Yang7e3680c2020-08-05 12:20:57294void BrowserContext::FirePushSubscriptionChangeEvent(
Viviane Yang7e3680c2020-08-05 12:20:57295 const GURL& origin,
296 int64_t service_worker_registration_id,
297 blink::mojom::PushSubscriptionPtr new_subscription,
298 blink::mojom::PushSubscriptionPtr old_subscription,
Viviane Yangd125aad2020-08-07 07:38:25299 base::OnceCallback<void(blink::mojom::PushEventStatus)> callback) {
Viviane Yang7e3680c2020-08-05 12:20:57300 DCHECK_CURRENTLY_ON(BrowserThread::UI);
301 PushMessagingRouter::FireSubscriptionChangeEvent(
Lukasz Anforowicz5389590e2021-05-11 02:20:06302 this, origin, service_worker_registration_id, std::move(new_subscription),
Lukasz Anforowiczb6802442021-04-02 20:47:51303 std::move(old_subscription), std::move(callback));
Viviane Yang7e3680c2020-08-05 12:20:57304}
305
Lukasz Anforowiczeda637d22021-05-20 00:32:23306void BrowserContext::NotifyWillBeDestroyed() {
307 impl()->NotifyWillBeDestroyed();
Lukasz Anforowicz729a9e12021-03-31 17:44:01308}
Lukasz Anforowicz58d0dac2018-03-23 15:48:10309
Lukasz Anforowiczeda637d22021-05-20 00:32:23310void BrowserContext::EnsureResourceContextInitialized() {
[email protected]7e26ac92012-02-27 20:15:05311 // This will be enough to tickle initialization of BrowserContext if
312 // necessary, which initializes ResourceContext. The reason we don't call
[email protected]4c3a23582012-08-18 08:54:34313 // ResourceContext::InitializeResourceContext() directly here is that
314 // ResourceContext initialization may call back into BrowserContext
Lukasz Anforowicz729a9e12021-03-31 17:44:01315 // and when that call returns it'll end rewriting its Impl. It will
[email protected]4c3a23582012-08-18 08:54:34316 // end up rewriting the same value but this still causes a race condition.
317 //
318 // See http://crbug.com/115678.
Lukasz Anforowiczeda637d22021-05-20 00:32:23319 GetDefaultStoragePartition();
[email protected]55eb70e762012-02-20 17:38:39320}
321
Lukasz Anforowiczeda637d22021-05-20 00:32:23322void BrowserContext::SaveSessionState() {
323 StoragePartition* storage_partition = GetDefaultStoragePartition();
[email protected]6e2d3d22012-02-24 18:10:36324
Clark DuVall385b5a52018-06-14 21:33:32325 storage_partition->GetCookieManagerForBrowserProcess()
326 ->SetForceKeepSessionState();
327
[email protected]5f2aa722013-08-07 16:59:41328 DOMStorageContextWrapper* dom_storage_context_proxy =
329 static_cast<DOMStorageContextWrapper*>(
[email protected]b1b502e2012-09-16 07:31:43330 storage_partition->GetDOMStorageContext());
[email protected]5f2aa722013-08-07 16:59:41331 dom_storage_context_proxy->SetForceKeepSessionState();
[email protected]735e20c2012-03-20 01:16:59332
Evan Stade1fd200c2024-03-26 21:06:00333 storage_partition->GetIndexedDBControl().SetForceKeepSessionState();
[email protected]6e2d3d22012-02-24 18:10:36334}
335
ttr31481dc54b2015-08-06 20:11:26336void BrowserContext::SetDownloadManagerForTesting(
Lukasz Anforowicz223d2532021-03-09 17:04:07337 std::unique_ptr<DownloadManager> download_manager) {
Lukasz Anforowicz48d83452021-05-12 02:58:20338 impl()->SetDownloadManagerForTesting(std::move(download_manager)); // IN-TEST
ttr31481dc54b2015-08-06 20:11:26339}
340
Mario Sanchez Pradafa6dda8c2019-11-25 18:20:19341void BrowserContext::SetPermissionControllerForTesting(
Mario Sanchez Pradafa6dda8c2019-11-25 18:20:19342 std::unique_ptr<PermissionController> permission_controller) {
343 DCHECK_CURRENTLY_ON(BrowserThread::UI);
344 DCHECK(permission_controller);
Lukasz Anforowicz82061152021-05-14 02:14:26345 impl()->SetPermissionControllerForTesting( // IN-TEST
Lukasz Anforowicz729a9e12021-03-31 17:44:01346 std::move(permission_controller));
Mario Sanchez Pradafa6dda8c2019-11-25 18:20:19347}
348
Lukasz Anforowiczeda637d22021-05-20 00:32:23349SharedCorsOriginAccessList* BrowserContext::GetSharedCorsOriginAccessList() {
350 return impl()->shared_cors_origin_access_list();
Lukasz Anforowicz223d2532021-03-09 17:04:07351}
352
kinukof6ed359c2016-07-26 13:27:21353void BrowserContext::ShutdownStoragePartitions() {
Lukasz Anforowicz729a9e12021-03-31 17:44:01354 impl()->ShutdownStoragePartitions();
kinukof6ed359c2016-07-26 13:27:21355}
356
Lukasz Anforowiczb6802442021-04-02 20:47:51357bool BrowserContext::ShutdownStarted() {
358 return impl()->ShutdownStarted();
Andrey Lushnikovd39d9062018-04-24 17:33:35359}
360
Lucas Furukawa Gadanif45223862019-06-21 23:11:14361const std::string& BrowserContext::UniqueId() {
Lukasz Anforowicz729a9e12021-03-31 17:44:01362 return impl()->UniqueId();
mmenkec0b2b8b12017-04-21 16:27:52363}
364
Chris Cunninghama5b38012017-10-28 07:27:18365media::VideoDecodePerfHistory* BrowserContext::GetVideoDecodePerfHistory() {
Lukasz Anforowicz729a9e12021-03-31 17:44:01366 return impl()->GetVideoDecodePerfHistory();
Chris Cunninghama5b38012017-10-28 07:27:18367}
368
Johannes Kron33182672022-05-20 09:52:03369media::WebrtcVideoPerfHistory* BrowserContext::GetWebrtcVideoPerfHistory() {
370 return impl()->GetWebrtcVideoPerfHistory();
371}
372
Tom Sepez70ae8892022-12-07 21:19:49373std::unique_ptr<download::InProgressDownloadManager>
374BrowserContext::RetrieveInProgressDownloadManager() {
Min Qind3ff2ed62018-07-21 06:46:59375 return nullptr;
376}
377
ssid6bedaa92021-06-16 10:25:24378void BrowserContext::WriteIntoTrace(
Alexander Timin074cd182022-03-23 18:11:22379 perfetto::TracedProto<ChromeBrowserContext> proto) const {
380 perfetto::WriteIntoTracedProto(std::move(proto), impl());
ssid6bedaa92021-06-16 10:25:24381}
382
Arthur Sonzogniff837582023-12-22 10:05:45383ResourceContext* BrowserContext::GetResourceContext() const {
384 return impl()->GetResourceContext();
385}
386
Ryan Tarpine35c4db22024-12-26 21:56:02387void BrowserContext::BackfillPopupHeuristicGrants(
388 base::OnceCallback<void(bool)> callback) {
389 return impl_->BackfillPopupHeuristicGrants(std::move(callback));
390}
391
Fred Shihf00e12a2023-12-12 01:49:31392base::WeakPtr<BrowserContext> BrowserContext::GetWeakPtr() {
393 return weak_factory_.GetWeakPtr();
394}
395
Lukasz Anforowiczb6802442021-04-02 20:47:51396//////////////////////////////////////////////////////////////////////////////
397// The //content embedder can override the methods below to change or extend
398// how the //content layer interacts with a BrowserContext. The code below
399// provides default implementations where appropriate.
400//
Alison Gale770f3fc2024-04-27 00:39:58401// TODO(crbug.com/40169693): Migrate method definitions from this
Lukasz Anforowiczb6802442021-04-02 20:47:51402// section into a separate BrowserContextDelegate class and a separate
403// browser_context_delegate.cc source file.
404
Austin Sullivanafefb722021-01-14 01:26:39405FileSystemAccessPermissionContext*
406BrowserContext::GetFileSystemAccessPermissionContext() {
Marijn Kruisselbrink83e5cdb2019-06-20 00:06:28407 return nullptr;
408}
409
Rayan Kanso03a847b2019-06-27 21:00:09410ContentIndexProvider* BrowserContext::GetContentIndexProvider() {
411 return nullptr;
412}
413
Marijn Kruisselbrink2ba0ef322019-11-27 19:12:41414bool BrowserContext::CanUseDiskWhenOffTheRecord() {
415 return false;
416}
417
Alex Clarke3ebd9772020-02-28 10:50:27418variations::VariationsClient* BrowserContext::GetVariationsClient() {
419 return nullptr;
420}
421
Lukasz Anforowicz287ec63c2021-04-07 22:07:39422std::unique_ptr<media::VideoDecodePerfHistory>
423BrowserContext::CreateVideoDecodePerfHistory() {
424 DCHECK_CURRENTLY_ON(BrowserThread::UI);
425
426 const char kUseInMemoryDBParamName[] = "db_in_memory";
427 const bool kUseInMemoryDBDefault = false;
428 bool use_in_memory_db = base::GetFieldTrialParamByFeatureAsBool(
429 media::kMediaCapabilitiesWithParameters, kUseInMemoryDBParamName,
430 kUseInMemoryDBDefault);
431
432 std::unique_ptr<media::VideoDecodeStatsDB> stats_db;
433 if (use_in_memory_db) {
434 stats_db = std::make_unique<media::InMemoryVideoDecodeStatsDBImpl>(nullptr);
435 } else {
Lukasz Anforowiczb9a969a2021-04-29 15:26:25436 auto* db_provider =
437 GetDefaultStoragePartition()->GetProtoDatabaseProvider();
Lukasz Anforowicz287ec63c2021-04-07 22:07:39438
439 stats_db = media::VideoDecodeStatsDBImpl::Create(
440 GetPath().Append(FILE_PATH_LITERAL("VideoDecodeStats")), db_provider);
441 }
442
Henrique Ferreirob39856e82025-08-04 12:13:56443 return std::make_unique<media::VideoDecodePerfHistory>(std::move(stats_db));
Lukasz Anforowicz287ec63c2021-04-07 22:07:39444}
445
Peter Kotwicz90c0dc222022-03-09 18:24:45446FederatedIdentityApiPermissionContextDelegate*
447BrowserContext::GetFederatedIdentityApiPermissionContext() {
Christian Biesingerc59336f2024-07-26 17:08:22448 return impl()->GetFederatedPermissionContext();
Peter Kotwicz90c0dc222022-03-09 18:24:45449}
450
Zachary Tancef872422023-02-17 14:45:49451FederatedIdentityAutoReauthnPermissionContextDelegate*
452BrowserContext::GetFederatedIdentityAutoReauthnPermissionContext() {
Christian Biesingerc59336f2024-07-26 17:08:22453 return impl()->GetFederatedPermissionContext();
Zachary Tan3d1c32c2023-01-31 16:50:54454}
455
Peter Kotwiczc18ea672022-11-30 23:58:27456FederatedIdentityPermissionContextDelegate*
457BrowserContext::GetFederatedIdentityPermissionContext() {
Christian Biesingerc59336f2024-07-26 17:08:22458 return impl()->GetFederatedPermissionContext();
Ken Buchanane6778362021-04-27 16:00:54459}
460
Russ Hamiltonf61b3b5c2022-09-16 15:35:43461KAnonymityServiceDelegate* BrowserContext::GetKAnonymityServiceDelegate() {
Russ Hamiltonabc8ce032022-08-27 14:48:05462 return nullptr;
463}
464
Peter Birk Pakkenberg73e07b62022-09-21 11:20:30465OriginTrialsControllerDelegate*
466BrowserContext::GetOriginTrialsControllerDelegate() {
467 return nullptr;
468}
469
Hiroki Nakagawa8348bc42024-12-13 16:24:42470#if BUILDFLAG(IS_ANDROID)
Doug Turner7ce58cf2025-08-04 22:03:25471net::HttpRequestHeaders BrowserContext::GetExtraHeadersForUrl(const GURL& url) {
472 return net::HttpRequestHeaders();
Hiroki Nakagawa8348bc42024-12-13 16:24:42473}
474#endif // BUILDFLAG(IS_ANDROID)
475
[email protected]55eb70e762012-02-20 17:38:39476} // namespace content