[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // 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 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 9 | |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 10 | #include <algorithm> |
| 11 | #include <limits> |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 12 | #include <memory> |
Takuto Ikuta | 8332bf9d | 2019-01-05 03:58:00 | [diff] [blame] | 13 | #include <unordered_set> |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 14 | #include <utility> |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 15 | #include <vector> |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 16 | |
mmenke | c0b2b8b1 | 2017-04-21 16:27:52 | [diff] [blame] | 17 | #include "base/base64.h" |
Takashi Toyoshima | a12ecf4 | 2018-09-25 07:46:01 | [diff] [blame] | 18 | #include "base/bind.h" |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 19 | #include "base/command_line.h" |
Takashi Toyoshima | a12ecf4 | 2018-09-25 07:46:01 | [diff] [blame] | 20 | #include "base/feature_list.h" |
Chris Cunningham | a5b3801 | 2017-10-28 07:27:18 | [diff] [blame] | 21 | #include "base/files/file_path.h" |
ben | cccfe2a | 2016-03-05 16:54:14 | [diff] [blame] | 22 | #include "base/guid.h" |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 23 | #include "base/lazy_instance.h" |
mmenke | c0b2b8b1 | 2017-04-21 16:27:52 | [diff] [blame] | 24 | #include "base/logging.h" |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 25 | #include "base/macros.h" |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 26 | #include "base/memory/ptr_util.h" |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 27 | #include "base/memory/weak_ptr.h" |
Chris Cunningham | 4507edfa | 2019-05-30 20:15:54 | [diff] [blame] | 28 | #include "base/metrics/field_trial_params.h" |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 29 | #include "base/no_destructor.h" |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 30 | #include "base/rand_util.h" |
Takashi Toyoshima | 621e2bf | 2018-09-18 08:05:16 | [diff] [blame] | 31 | #include "base/supports_user_data.h" |
Gabriel Charette | 44db142 | 2018-08-06 11:19:33 | [diff] [blame] | 32 | #include "base/task/post_task.h" |
Ken Rockot | 84f58fd | 2018-06-22 21:54:14 | [diff] [blame] | 33 | #include "base/threading/sequenced_task_runner_handle.h" |
ben | 21a34c25 | 2016-06-29 22:24:37 | [diff] [blame] | 34 | #include "base/threading/thread_task_runner_handle.h" |
Andrey Lushnikov | d39d906 | 2018-04-24 17:33:35 | [diff] [blame] | 35 | #include "base/unguessable_token.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 36 | #include "build/build_config.h" |
dmurph | 7ac019a | 2016-05-13 00:13:17 | [diff] [blame] | 37 | #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 38 | #include "content/browser/browsing_data/browsing_data_remover_impl.h" |
Alex Moshchuk | 99b79542 | 2019-03-07 00:27:32 | [diff] [blame] | 39 | #include "content/browser/child_process_security_policy_impl.h" |
Ken Rockot | 84f58fd | 2018-06-22 21:54:14 | [diff] [blame] | 40 | #include "content/browser/content_service_delegate_impl.h" |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 41 | #include "content/browser/download/download_manager_impl.h" |
[email protected] | 678c036 | 2012-12-05 08:02:44 | [diff] [blame] | 42 | #include "content/browser/loader/resource_dispatcher_host_impl.h" |
[email protected] | 3dcea37a | 2019-02-11 19:46:51 | [diff] [blame] | 43 | #include "content/browser/media/browser_feature_provider.h" |
Andrey Lushnikov | ebff044 | 2018-07-12 20:02:58 | [diff] [blame] | 44 | #include "content/browser/permissions/permission_controller_impl.h" |
mvanouwerkerk | 17205ea | 2014-11-07 17:30:15 | [diff] [blame] | 45 | #include "content/browser/push_messaging/push_messaging_router.h" |
Ken Rockot | c7a279c | 2017-05-04 23:51:45 | [diff] [blame] | 46 | #include "content/browser/service_manager/common_browser_interfaces.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 47 | #include "content/browser/storage_partition_impl_map.h" |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 48 | #include "content/common/child_process_host_impl.h" |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 49 | #include "content/public/browser/blob_handle.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 50 | #include "content/public/browser/browser_task_traits.h" |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 51 | #include "content/public/browser/browser_thread.h" |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 52 | #include "content/public/browser/content_browser_client.h" |
Daniel Murphy | d9a41e7b | 2019-05-09 17:56:54 | [diff] [blame] | 53 | #include "content/public/browser/indexed_db_context.h" |
falken | 04a6912a | 2016-09-23 21:06:29 | [diff] [blame] | 54 | #include "content/public/browser/render_process_host.h" |
Takashi Toyoshima | 0190a3b | 2019-01-21 07:39:06 | [diff] [blame] | 55 | #include "content/public/browser/shared_cors_origin_access_list.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 56 | #include "content/public/browser/site_instance.h" |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 57 | #include "content/public/common/content_switches.h" |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 58 | #include "content/public/common/service_manager_connection.h" |
ben | 51bb6c6 | 2016-11-17 20:15:57 | [diff] [blame] | 59 | #include "content/public/common/service_names.mojom.h" |
Chris Cunningham | 4507edfa | 2019-05-30 20:15:54 | [diff] [blame] | 60 | #include "media/base/media_switches.h" |
| 61 | #include "media/capabilities/in_memory_video_decode_stats_db_impl.h" |
Chris Cunningham | 9e66947 | 2017-11-15 21:03:11 | [diff] [blame] | 62 | #include "media/capabilities/video_decode_stats_db_impl.h" |
Chris Cunningham | a5b3801 | 2017-10-28 07:27:18 | [diff] [blame] | 63 | #include "media/mojo/services/video_decode_perf_history.h" |
Ken Rockot | 40a1df79 | 2019-05-08 22:15:52 | [diff] [blame] | 64 | #include "mojo/public/cpp/bindings/remote.h" |
[email protected] | 4d7c4ef | 2012-03-16 01:47:12 | [diff] [blame] | 65 | #include "net/cookies/cookie_store.h" |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 66 | #include "net/url_request/url_request_context.h" |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 67 | #include "net/url_request/url_request_context_getter.h" |
Ken Rockot | 84f58fd | 2018-06-22 21:54:14 | [diff] [blame] | 68 | #include "services/content/public/mojom/constants.mojom.h" |
| 69 | #include "services/content/service.h" |
ben | 768c8dc | 2016-08-12 00:26:50 | [diff] [blame] | 70 | #include "services/file/file_service.h" |
Ken Rockot | 21142de | 2018-02-10 01:45:30 | [diff] [blame] | 71 | #include "services/file/public/mojom/constants.mojom.h" |
ben | 768c8dc | 2016-08-12 00:26:50 | [diff] [blame] | 72 | #include "services/file/user_id_map.h" |
Takashi Toyoshima | a12ecf4 | 2018-09-25 07:46:01 | [diff] [blame] | 73 | #include "services/network/public/cpp/features.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 74 | #include "services/service_manager/public/cpp/connector.h" |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 75 | #include "services/service_manager/public/cpp/service.h" |
Ken Rockot | 543f5e3 | 2018-02-04 02:13:50 | [diff] [blame] | 76 | #include "services/service_manager/public/mojom/service.mojom.h" |
Xing Liu | 8986047 | 2018-02-09 20:07:02 | [diff] [blame] | 77 | #include "storage/browser/blob/blob_storage_context.h" |
pilgrim | e92c5fcd | 2014-09-10 23:31:23 | [diff] [blame] | 78 | #include "storage/browser/database/database_tracker.h" |
| 79 | #include "storage/browser/fileapi/external_mount_points.h" |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 80 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 81 | using base::UserDataAdapter; |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 82 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 83 | namespace content { |
| 84 | |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 85 | namespace { |
| 86 | |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 87 | using TokenToContextMap = std::map<base::Token, BrowserContext*>; |
| 88 | TokenToContextMap& GetTokenToContextMap() { |
| 89 | static base::NoDestructor<TokenToContextMap> map; |
| 90 | return *map; |
| 91 | } |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 92 | |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 93 | class ServiceInstanceGroupHolder : public base::SupportsUserData::Data { |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 94 | public: |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 95 | explicit ServiceInstanceGroupHolder(const base::Token& instance_group) |
| 96 | : instance_group_(instance_group) {} |
| 97 | ~ServiceInstanceGroupHolder() override {} |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 98 | |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 99 | const base::Token& instance_group() const { return instance_group_; } |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 100 | |
| 101 | private: |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 102 | base::Token instance_group_; |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 103 | |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 104 | DISALLOW_COPY_AND_ASSIGN(ServiceInstanceGroupHolder); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 105 | }; |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 106 | |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 107 | // The file service runs on the IO thread but we want to limit its lifetime to |
| 108 | // that of the BrowserContext which creates it. This provides thread-safe access |
| 109 | // to the relevant state on the IO thread. |
| 110 | class FileServiceIOThreadState |
| 111 | : public base::RefCountedThreadSafe<FileServiceIOThreadState> { |
| 112 | public: |
| 113 | explicit FileServiceIOThreadState( |
| 114 | scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| 115 | : io_task_runner_(std::move(io_task_runner)) {} |
| 116 | |
| 117 | void StartOnIOThread(service_manager::mojom::ServiceRequest request) { |
| 118 | DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 119 | file_service_ = std::make_unique<file::FileService>(std::move(request)); |
| 120 | } |
| 121 | |
| 122 | void ShutDown() { |
| 123 | io_task_runner_->PostTask( |
| 124 | FROM_HERE, |
| 125 | base::BindOnce(&FileServiceIOThreadState::ShutDownOnIOThread, this)); |
| 126 | } |
| 127 | |
| 128 | private: |
| 129 | friend class base::RefCountedThreadSafe<FileServiceIOThreadState>; |
| 130 | |
| 131 | ~FileServiceIOThreadState() { DCHECK(!file_service_); } |
| 132 | |
| 133 | void ShutDownOnIOThread() { file_service_.reset(); } |
| 134 | |
| 135 | const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 136 | std::unique_ptr<file::FileService> file_service_; |
| 137 | |
| 138 | DISALLOW_COPY_AND_ASSIGN(FileServiceIOThreadState); |
| 139 | }; |
| 140 | |
| 141 | class FileServiceHolder : public base::SupportsUserData::Data { |
| 142 | public: |
| 143 | explicit FileServiceHolder(scoped_refptr<FileServiceIOThreadState> state) |
| 144 | : state_(std::move(state)) {} |
| 145 | ~FileServiceHolder() override { state_->ShutDown(); } |
| 146 | |
| 147 | private: |
| 148 | const scoped_refptr<FileServiceIOThreadState> state_; |
| 149 | |
| 150 | DISALLOW_COPY_AND_ASSIGN(FileServiceHolder); |
| 151 | }; |
| 152 | |
Ken Rockot | 84f58fd | 2018-06-22 21:54:14 | [diff] [blame] | 153 | class ContentServiceDelegateHolder : public base::SupportsUserData::Data { |
| 154 | public: |
| 155 | explicit ContentServiceDelegateHolder(BrowserContext* browser_context) |
| 156 | : delegate_(browser_context) {} |
| 157 | ~ContentServiceDelegateHolder() override = default; |
| 158 | |
| 159 | ContentServiceDelegateImpl* delegate() { return &delegate_; } |
| 160 | |
| 161 | private: |
| 162 | ContentServiceDelegateImpl delegate_; |
| 163 | |
| 164 | DISALLOW_COPY_AND_ASSIGN(ContentServiceDelegateHolder); |
| 165 | }; |
| 166 | |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 167 | // Key names on BrowserContext. |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 168 | const char kBrowsingDataRemoverKey[] = "browsing-data-remover"; |
Ken Rockot | 84f58fd | 2018-06-22 21:54:14 | [diff] [blame] | 169 | const char kContentServiceDelegateKey[] = "content-service-delegate"; |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 170 | const char kFileServiceKey[] = "file-service"; |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 171 | const char kDownloadManagerKeyName[] = "download_manager"; |
Takashi Toyoshima | 621e2bf | 2018-09-18 08:05:16 | [diff] [blame] | 172 | const char kPermissionControllerKey[] = "permission-controller"; |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 173 | const char kServiceManagerConnection[] = "service-manager-connection"; |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 174 | const char kServiceInstanceGroup[] = "service-instance-group"; |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 175 | const char kStoragePartitionMapKeyName[] = "content_storage_partition_map"; |
Chris Cunningham | a5b3801 | 2017-10-28 07:27:18 | [diff] [blame] | 176 | const char kVideoDecodePerfHistoryId[] = "video-decode-perf-history"; |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 177 | |
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 178 | #if defined(OS_CHROMEOS) |
| 179 | const char kMountPointsKey[] = "mount_points"; |
| 180 | #endif // defined(OS_CHROMEOS) |
| 181 | |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 182 | void RemoveBrowserContextFromInstanceGroupMap(BrowserContext* browser_context) { |
| 183 | ServiceInstanceGroupHolder* holder = static_cast<ServiceInstanceGroupHolder*>( |
| 184 | browser_context->GetUserData(kServiceInstanceGroup)); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 185 | if (holder) { |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 186 | auto it = GetTokenToContextMap().find(holder->instance_group()); |
| 187 | if (it != GetTokenToContextMap().end()) |
| 188 | GetTokenToContextMap().erase(it); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 192 | StoragePartitionImplMap* GetStoragePartitionMap( |
| 193 | BrowserContext* browser_context) { |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 194 | StoragePartitionImplMap* partition_map = |
| 195 | static_cast<StoragePartitionImplMap*>( |
a.cavalcanti | ffab7376 | 2015-08-15 02:55:48 | [diff] [blame] | 196 | browser_context->GetUserData(kStoragePartitionMapKeyName)); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 197 | if (!partition_map) { |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 198 | auto partition_map_owned = |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 199 | std::make_unique<StoragePartitionImplMap>(browser_context); |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 200 | partition_map = partition_map_owned.get(); |
| 201 | browser_context->SetUserData(kStoragePartitionMapKeyName, |
| 202 | std::move(partition_map_owned)); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 203 | } |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 204 | return partition_map; |
| 205 | } |
| 206 | |
| 207 | StoragePartition* GetStoragePartitionFromConfig( |
| 208 | BrowserContext* browser_context, |
| 209 | const std::string& partition_domain, |
| 210 | const std::string& partition_name, |
Dan Elphick | 6c0d849 | 2017-09-12 09:35:38 | [diff] [blame] | 211 | bool in_memory, |
| 212 | bool can_create) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 213 | StoragePartitionImplMap* partition_map = |
| 214 | GetStoragePartitionMap(browser_context); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 215 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 216 | if (browser_context->IsOffTheRecord()) |
| 217 | in_memory = true; |
| 218 | |
Dan Elphick | 6c0d849 | 2017-09-12 09:35:38 | [diff] [blame] | 219 | return partition_map->Get(partition_domain, partition_name, in_memory, |
| 220 | can_create); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 221 | } |
| 222 | |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 223 | void SaveSessionStateOnIOThread( |
| 224 | const scoped_refptr<net::URLRequestContextGetter>& context_getter, |
[email protected] | 98d6d456 | 2014-06-25 20:57:55 | [diff] [blame] | 225 | AppCacheServiceImpl* appcache_service) { |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 226 | appcache_service->set_force_keep_session_state(); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 227 | } |
| 228 | |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 229 | void SaveSessionStateOnIndexedDBThread( |
Daniel Murphy | d9a41e7b | 2019-05-09 17:56:54 | [diff] [blame] | 230 | scoped_refptr<IndexedDBContext> indexed_db_context) { |
[email protected] | bf510ed | 2012-06-05 08:31:43 | [diff] [blame] | 231 | indexed_db_context->SetForceKeepSessionState(); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 232 | } |
| 233 | |
falken | 41f417516 | 2014-10-29 07:03:41 | [diff] [blame] | 234 | void ShutdownServiceWorkerContext(StoragePartition* partition) { |
| 235 | ServiceWorkerContextWrapper* wrapper = |
| 236 | static_cast<ServiceWorkerContextWrapper*>( |
| 237 | partition->GetServiceWorkerContext()); |
| 238 | wrapper->process_manager()->Shutdown(); |
| 239 | } |
| 240 | |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 241 | void SetDownloadManager( |
| 242 | BrowserContext* context, |
| 243 | std::unique_ptr<content::DownloadManager> download_manager) { |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 244 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 245 | DCHECK(download_manager); |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 246 | context->SetUserData(kDownloadManagerKeyName, std::move(download_manager)); |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 247 | } |
| 248 | |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 249 | std::unique_ptr<service_manager::Service> |
| 250 | CreateMainThreadServiceForBrowserContext( |
| 251 | BrowserContext* browser_context, |
| 252 | const std::string& service_name, |
| 253 | service_manager::mojom::ServiceRequest request) { |
| 254 | if (service_name == content::mojom::kServiceName) { |
| 255 | auto* delegate_holder = static_cast<ContentServiceDelegateHolder*>( |
| 256 | browser_context->GetUserData(kContentServiceDelegateKey)); |
| 257 | auto* delegate = delegate_holder->delegate(); |
| 258 | auto service = |
| 259 | std::make_unique<content::Service>(delegate, std::move(request)); |
| 260 | delegate->AddService(service.get()); |
| 261 | return service; |
| 262 | } |
| 263 | |
| 264 | return browser_context->HandleServiceRequest(service_name, |
| 265 | std::move(request)); |
| 266 | } |
| 267 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 268 | class BrowserContextServiceManagerConnectionHolder |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 269 | : public base::SupportsUserData::Data { |
| 270 | public: |
ben | aad37ecd | 2017-04-12 22:08:20 | [diff] [blame] | 271 | explicit BrowserContextServiceManagerConnectionHolder( |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 272 | BrowserContext* browser_context, |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 273 | service_manager::mojom::ServiceRequest request, |
| 274 | scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner) |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 275 | : browser_context_(browser_context), |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 276 | main_thread_task_runner_(std::move(main_thread_task_runner)), |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 277 | service_manager_connection_(ServiceManagerConnection::Create( |
rockot | cef3827 | 2016-07-15 22:47:47 | [diff] [blame] | 278 | std::move(request), |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 279 | base::CreateSingleThreadTaskRunnerWithTraits( |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 280 | {BrowserThread::IO}))) { |
| 281 | service_manager_connection_->SetDefaultServiceRequestHandler( |
| 282 | base::BindRepeating( |
| 283 | &BrowserContextServiceManagerConnectionHolder::OnServiceRequest, |
| 284 | weak_ptr_factory_.GetWeakPtr())); |
| 285 | } |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 286 | ~BrowserContextServiceManagerConnectionHolder() override {} |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 287 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 288 | ServiceManagerConnection* service_manager_connection() { |
| 289 | return service_manager_connection_.get(); |
| 290 | } |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 291 | |
Ken Rockot | ad3c758 | 2018-12-12 17:04:14 | [diff] [blame] | 292 | void DestroyRunningServices() { running_services_.clear(); } |
| 293 | |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 294 | private: |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 295 | void OnServiceRequest(const std::string& service_name, |
| 296 | service_manager::mojom::ServiceRequest request) { |
| 297 | std::unique_ptr<service_manager::Service> service = |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 298 | CreateMainThreadServiceForBrowserContext(browser_context_, service_name, |
| 299 | std::move(request)); |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 300 | if (!service) { |
| 301 | LOG(ERROR) << "Ignoring request for unknown per-browser-context service:" |
| 302 | << service_name; |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | auto* raw_service = service.get(); |
| 307 | service->set_termination_closure(base::BindOnce( |
| 308 | &BrowserContextServiceManagerConnectionHolder::OnServiceQuit, |
| 309 | base::Unretained(this), raw_service)); |
| 310 | running_services_.emplace(raw_service, std::move(service)); |
| 311 | } |
| 312 | |
| 313 | void OnServiceQuit(service_manager::Service* service) { |
| 314 | running_services_.erase(service); |
| 315 | } |
| 316 | |
| 317 | BrowserContext* const browser_context_; |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 318 | const scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner_; |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 319 | std::unique_ptr<ServiceManagerConnection> service_manager_connection_; |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 320 | std::map<service_manager::Service*, std::unique_ptr<service_manager::Service>> |
| 321 | running_services_; |
| 322 | |
| 323 | base::WeakPtrFactory<BrowserContextServiceManagerConnectionHolder> |
| 324 | weak_ptr_factory_{this}; |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 325 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 326 | DISALLOW_COPY_AND_ASSIGN(BrowserContextServiceManagerConnectionHolder); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 327 | }; |
| 328 | |
Jens Widell | 7ca8fb4 | 2018-02-21 14:11:54 | [diff] [blame] | 329 | base::WeakPtr<storage::BlobStorageContext> BlobStorageContextGetterForBrowser( |
Xing Liu | 8986047 | 2018-02-09 20:07:02 | [diff] [blame] | 330 | scoped_refptr<ChromeBlobStorageContext> blob_context) { |
| 331 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 332 | return blob_context->context()->AsWeakPtr(); |
| 333 | } |
| 334 | |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 335 | } // namespace |
| 336 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 337 | // static |
| 338 | void BrowserContext::AsyncObliterateStoragePartition( |
| 339 | BrowserContext* browser_context, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 340 | const GURL& site, |
| 341 | const base::Closure& on_gc_required) { |
Marijn Kruisselbrink | 83e5cdb | 2019-06-20 00:06:28 | [diff] [blame^] | 342 | GetStoragePartitionMap(browser_context) |
| 343 | ->AsyncObliterate(site, on_gc_required); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | // static |
| 347 | void BrowserContext::GarbageCollectStoragePartitions( |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 348 | BrowserContext* browser_context, |
Takuto Ikuta | 8332bf9d | 2019-01-05 03:58:00 | [diff] [blame] | 349 | std::unique_ptr<std::unordered_set<base::FilePath>> active_paths, |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 350 | const base::Closure& done) { |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 351 | GetStoragePartitionMap(browser_context) |
| 352 | ->GarbageCollect(std::move(active_paths), done); |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 353 | } |
| 354 | |
Marijn Kruisselbrink | 83e5cdb | 2019-06-20 00:06:28 | [diff] [blame^] | 355 | DownloadManager* BrowserContext::GetDownloadManager(BrowserContext* context) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 356 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 357 | if (!context->GetUserData(kDownloadManagerKeyName)) { |
Min Qin | ddb40ce | 2017-10-28 03:38:26 | [diff] [blame] | 358 | DownloadManager* download_manager = new DownloadManagerImpl(context); |
[email protected] | d25fda1 | 2012-06-12 17:05:03 | [diff] [blame] | 359 | |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 360 | SetDownloadManager(context, base::WrapUnique(download_manager)); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 361 | download_manager->SetDelegate(context->GetDownloadManagerDelegate()); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 362 | } |
| 363 | |
[email protected] | eba4a4d | 2013-05-29 02:18:06 | [diff] [blame] | 364 | return static_cast<DownloadManager*>( |
| 365 | context->GetUserData(kDownloadManagerKeyName)); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 366 | } |
| 367 | |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 368 | // static |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 369 | storage::ExternalMountPoints* BrowserContext::GetMountPoints( |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 370 | BrowserContext* context) { |
| 371 | // Ensure that these methods are called on the UI thread, except for |
| 372 | // unittests where a UI thread might not have been created. |
| 373 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
Gabriel Charette | 2983181c | 2018-03-28 17:01:09 | [diff] [blame] | 374 | !BrowserThread::IsThreadInitialized(BrowserThread::UI)); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 375 | |
| 376 | #if defined(OS_CHROMEOS) |
| 377 | if (!context->GetUserData(kMountPointsKey)) { |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 378 | scoped_refptr<storage::ExternalMountPoints> mount_points = |
| 379 | storage::ExternalMountPoints::CreateRefCounted(); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 380 | context->SetUserData( |
| 381 | kMountPointsKey, |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 382 | std::make_unique<UserDataAdapter<storage::ExternalMountPoints>>( |
avi | cb129c0 | 2017-05-03 06:49:29 | [diff] [blame] | 383 | mount_points.get())); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 384 | } |
| 385 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 386 | return UserDataAdapter<storage::ExternalMountPoints>::Get(context, |
| 387 | kMountPointsKey); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 388 | #else |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 389 | return nullptr; |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 390 | #endif |
| 391 | } |
| 392 | |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 393 | // static |
| 394 | content::BrowsingDataRemover* content::BrowserContext::GetBrowsingDataRemover( |
| 395 | BrowserContext* context) { |
| 396 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 397 | |
| 398 | if (!context->GetUserData(kBrowsingDataRemoverKey)) { |
| 399 | std::unique_ptr<BrowsingDataRemoverImpl> remover = |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 400 | std::make_unique<BrowsingDataRemoverImpl>(context); |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 401 | remover->SetEmbedderDelegate(context->GetBrowsingDataRemoverDelegate()); |
| 402 | context->SetUserData(kBrowsingDataRemoverKey, std::move(remover)); |
| 403 | } |
| 404 | |
| 405 | return static_cast<BrowsingDataRemoverImpl*>( |
| 406 | context->GetUserData(kBrowsingDataRemoverKey)); |
| 407 | } |
| 408 | |
Andrey Lushnikov | ebff044 | 2018-07-12 20:02:58 | [diff] [blame] | 409 | // static |
| 410 | content::PermissionController* content::BrowserContext::GetPermissionController( |
| 411 | BrowserContext* context) { |
| 412 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 413 | |
| 414 | if (!context->GetUserData(kPermissionControllerKey)) { |
| 415 | context->SetUserData(kPermissionControllerKey, |
| 416 | std::make_unique<PermissionControllerImpl>(context)); |
| 417 | } |
| 418 | |
| 419 | return static_cast<PermissionControllerImpl*>( |
| 420 | context->GetUserData(kPermissionControllerKey)); |
| 421 | } |
| 422 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 423 | StoragePartition* BrowserContext::GetStoragePartition( |
| 424 | BrowserContext* browser_context, |
Dan Elphick | 6c0d849 | 2017-09-12 09:35:38 | [diff] [blame] | 425 | SiteInstance* site_instance, |
| 426 | bool can_create) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 427 | std::string partition_domain; |
| 428 | std::string partition_name; |
| 429 | bool in_memory = false; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 430 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 431 | if (site_instance) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 432 | GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
Marijn Kruisselbrink | 83e5cdb | 2019-06-20 00:06:28 | [diff] [blame^] | 433 | browser_context, site_instance->GetSiteURL(), true, &partition_domain, |
| 434 | &partition_name, &in_memory); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 435 | } |
| 436 | |
Dan Elphick | 6c0d849 | 2017-09-12 09:35:38 | [diff] [blame] | 437 | return GetStoragePartitionFromConfig(browser_context, partition_domain, |
| 438 | partition_name, in_memory, can_create); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 439 | } |
| 440 | |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 441 | StoragePartition* BrowserContext::GetStoragePartitionForSite( |
| 442 | BrowserContext* browser_context, |
Dan Elphick | 6c0d849 | 2017-09-12 09:35:38 | [diff] [blame] | 443 | const GURL& site, |
| 444 | bool can_create) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 445 | std::string partition_domain; |
| 446 | std::string partition_name; |
| 447 | bool in_memory; |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 448 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 449 | GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 450 | browser_context, site, true, &partition_domain, &partition_name, |
| 451 | &in_memory); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 452 | |
Dan Elphick | 6c0d849 | 2017-09-12 09:35:38 | [diff] [blame] | 453 | return GetStoragePartitionFromConfig(browser_context, partition_domain, |
| 454 | partition_name, in_memory, can_create); |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 455 | } |
| 456 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 457 | void BrowserContext::ForEachStoragePartition( |
| 458 | BrowserContext* browser_context, |
| 459 | const StoragePartitionCallback& callback) { |
| 460 | StoragePartitionImplMap* partition_map = |
| 461 | static_cast<StoragePartitionImplMap*>( |
a.cavalcanti | ffab7376 | 2015-08-15 02:55:48 | [diff] [blame] | 462 | browser_context->GetUserData(kStoragePartitionMapKeyName)); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 463 | if (!partition_map) |
| 464 | return; |
| 465 | |
| 466 | partition_map->ForEach(callback); |
| 467 | } |
| 468 | |
| 469 | StoragePartition* BrowserContext::GetDefaultStoragePartition( |
| 470 | BrowserContext* browser_context) { |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 471 | return GetStoragePartition(browser_context, nullptr); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 472 | } |
| 473 | |
tbarzic | db71268 | 2015-03-06 06:05:41 | [diff] [blame] | 474 | // static |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 475 | void BrowserContext::CreateMemoryBackedBlob(BrowserContext* browser_context, |
Marijn Kruisselbrink | 604fd7e7 | 2017-10-26 16:31:05 | [diff] [blame] | 476 | const char* data, |
| 477 | size_t length, |
| 478 | const std::string& content_type, |
| 479 | BlobCallback callback) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 480 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 481 | |
| 482 | ChromeBlobStorageContext* blob_context = |
| 483 | ChromeBlobStorageContext::GetFor(browser_context); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 484 | base::PostTaskWithTraitsAndReplyWithResult( |
| 485 | FROM_HERE, {BrowserThread::IO}, |
Marijn Kruisselbrink | 604fd7e7 | 2017-10-26 16:31:05 | [diff] [blame] | 486 | base::BindOnce(&ChromeBlobStorageContext::CreateMemoryBackedBlob, |
| 487 | base::WrapRefCounted(blob_context), data, length, |
| 488 | content_type), |
| 489 | std::move(callback)); |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 490 | } |
| 491 | |
[email protected] | 66e53d028 | 2014-08-07 10:04:35 | [diff] [blame] | 492 | // static |
Xing Liu | 8986047 | 2018-02-09 20:07:02 | [diff] [blame] | 493 | BrowserContext::BlobContextGetter BrowserContext::GetBlobStorageContext( |
| 494 | BrowserContext* browser_context) { |
| 495 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 496 | scoped_refptr<ChromeBlobStorageContext> chrome_blob_context = |
| 497 | ChromeBlobStorageContext::GetFor(browser_context); |
Jens Widell | 7ca8fb4 | 2018-02-21 14:11:54 | [diff] [blame] | 498 | return base::BindRepeating(&BlobStorageContextGetterForBrowser, |
| 499 | chrome_blob_context); |
Xing Liu | 8986047 | 2018-02-09 20:07:02 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | // static |
Marijn Kruisselbrink | 9e073a8 | 2018-06-18 17:48:58 | [diff] [blame] | 503 | blink::mojom::BlobPtr BrowserContext::GetBlobPtr( |
| 504 | BrowserContext* browser_context, |
| 505 | const std::string& uuid) { |
| 506 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 507 | return ChromeBlobStorageContext::GetBlobPtr(browser_context, uuid); |
| 508 | } |
| 509 | |
| 510 | // static |
[email protected] | 66e53d028 | 2014-08-07 10:04:35 | [diff] [blame] | 511 | void BrowserContext::DeliverPushMessage( |
| 512 | BrowserContext* browser_context, |
| 513 | const GURL& origin, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 514 | int64_t service_worker_registration_id, |
Rayan Kanso | 3b68620 | 2019-05-10 17:41:55 | [diff] [blame] | 515 | const std::string& message_id, |
Han Leon | c1deace | 2018-08-03 03:52:53 | [diff] [blame] | 516 | base::Optional<std::string> payload, |
Mario Sanchez Prada | d299011 | 2019-05-07 08:13:49 | [diff] [blame] | 517 | const base::Callback<void(blink::mojom::PushDeliveryStatus)>& callback) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 518 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
harkness | dd4d2b2 | 2016-01-27 19:26:43 | [diff] [blame] | 519 | PushMessagingRouter::DeliverMessage(browser_context, origin, |
Han Leon | c1deace | 2018-08-03 03:52:53 | [diff] [blame] | 520 | service_worker_registration_id, |
Rayan Kanso | 3b68620 | 2019-05-10 17:41:55 | [diff] [blame] | 521 | message_id, std::move(payload), callback); |
[email protected] | 66e53d028 | 2014-08-07 10:04:35 | [diff] [blame] | 522 | } |
| 523 | |
falken | 41f417516 | 2014-10-29 07:03:41 | [diff] [blame] | 524 | // static |
| 525 | void BrowserContext::NotifyWillBeDestroyed(BrowserContext* browser_context) { |
Lukasz Anforowicz | 58d0dac | 2018-03-23 15:48:10 | [diff] [blame] | 526 | // Make sure NotifyWillBeDestroyed is idempotent. This helps facilitate the |
| 527 | // pattern where NotifyWillBeDestroyed is called from *both* |
Kent Tamura | 21d1de6 | 2018-12-10 04:45:20 | [diff] [blame] | 528 | // ShellBrowserContext and its derived classes (e.g. WebTestBrowserContext). |
Lukasz Anforowicz | 58d0dac | 2018-03-23 15:48:10 | [diff] [blame] | 529 | if (browser_context->was_notify_will_be_destroyed_called_) |
| 530 | return; |
| 531 | browser_context->was_notify_will_be_destroyed_called_ = true; |
| 532 | |
Ken Rockot | 99c5bc74 | 2018-07-12 15:36:56 | [diff] [blame] | 533 | // Subclasses of BrowserContext may expect there to be no more |
| 534 | // RenderProcessHosts using them by the time this function returns. We |
| 535 | // therefore explicitly tear down embedded Content Service instances now to |
| 536 | // ensure that all their WebContents (and therefore RPHs) are torn down too. |
| 537 | browser_context->RemoveUserData(kContentServiceDelegateKey); |
| 538 | |
Ken Rockot | ad3c758 | 2018-12-12 17:04:14 | [diff] [blame] | 539 | // Tear down all running service instances which were started on behalf of |
| 540 | // this BrowserContext. Note that we leave the UserData itself in place |
| 541 | // because it's possible for someone to call |
| 542 | // |GetServiceManagerConnectionFor()| between now and actual BrowserContext |
| 543 | // destruction. |
| 544 | BrowserContextServiceManagerConnectionHolder* connection_holder = |
| 545 | static_cast<BrowserContextServiceManagerConnectionHolder*>( |
| 546 | browser_context->GetUserData(kServiceManagerConnection)); |
| 547 | if (connection_holder) |
| 548 | connection_holder->DestroyRunningServices(); |
| 549 | |
falken | 41f417516 | 2014-10-29 07:03:41 | [diff] [blame] | 550 | // Service Workers must shutdown before the browser context is destroyed, |
| 551 | // since they keep render process hosts alive and the codebase assumes that |
| 552 | // render process hosts die before their profile (browser context) dies. |
| 553 | ForEachStoragePartition(browser_context, |
| 554 | base::Bind(ShutdownServiceWorkerContext)); |
falken | 04a6912a | 2016-09-23 21:06:29 | [diff] [blame] | 555 | |
| 556 | // Shared workers also keep render process hosts alive, and are expected to |
Darin Fisher | d3768b2f6 | 2017-10-07 01:00:16 | [diff] [blame] | 557 | // return ref counts to 0 after documents close. However, to ensure that |
| 558 | // hosts are destructed now, forcibly release their ref counts here. |
falken | 04a6912a | 2016-09-23 21:06:29 | [diff] [blame] | 559 | for (RenderProcessHost::iterator host_iterator = |
| 560 | RenderProcessHost::AllHostsIterator(); |
| 561 | !host_iterator.IsAtEnd(); host_iterator.Advance()) { |
| 562 | RenderProcessHost* host = host_iterator.GetCurrentValue(); |
Benoit Lize | ab08362c | 2017-07-19 14:50:54 | [diff] [blame] | 563 | if (host->GetBrowserContext() == browser_context) { |
| 564 | // This will also clean up spare RPH references. |
Yutaka Hirano | 09a9afb9 | 2017-08-16 09:11:45 | [diff] [blame] | 565 | host->DisableKeepAliveRefCount(); |
Benoit Lize | ab08362c | 2017-07-19 14:50:54 | [diff] [blame] | 566 | } |
falken | 04a6912a | 2016-09-23 21:06:29 | [diff] [blame] | 567 | } |
Alex Moshchuk | 99b79542 | 2019-03-07 00:27:32 | [diff] [blame] | 568 | |
Aaron Colwell | 67f93006c | 2019-04-01 22:45:28 | [diff] [blame] | 569 | // Clean up any isolated origins associated with this BrowserContext. This |
Alex Moshchuk | 99b79542 | 2019-03-07 00:27:32 | [diff] [blame] | 570 | // should be safe now that all RenderProcessHosts are destroyed, since future |
| 571 | // navigations or security decisions shouldn't ever need to consult these |
Aaron Colwell | 67f93006c | 2019-04-01 22:45:28 | [diff] [blame] | 572 | // isolated origins. |
Alex Moshchuk | 99b79542 | 2019-03-07 00:27:32 | [diff] [blame] | 573 | ChildProcessSecurityPolicyImpl* policy = |
| 574 | ChildProcessSecurityPolicyImpl::GetInstance(); |
Aaron Colwell | 67f93006c | 2019-04-01 22:45:28 | [diff] [blame] | 575 | policy->RemoveIsolatedOriginsForBrowserContext(*browser_context); |
falken | 41f417516 | 2014-10-29 07:03:41 | [diff] [blame] | 576 | } |
| 577 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 578 | void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) { |
[email protected] | 7e26ac9 | 2012-02-27 20:15:05 | [diff] [blame] | 579 | // This will be enough to tickle initialization of BrowserContext if |
| 580 | // necessary, which initializes ResourceContext. The reason we don't call |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 581 | // ResourceContext::InitializeResourceContext() directly here is that |
| 582 | // ResourceContext initialization may call back into BrowserContext |
| 583 | // and when that call returns it'll end rewriting its UserData map. It will |
| 584 | // end up rewriting the same value but this still causes a race condition. |
| 585 | // |
| 586 | // See http://crbug.com/115678. |
| 587 | GetDefaultStoragePartition(context); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 588 | } |
| 589 | |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 590 | void BrowserContext::SaveSessionState(BrowserContext* browser_context) { |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 591 | StoragePartition* storage_partition = |
| 592 | BrowserContext::GetDefaultStoragePartition(browser_context); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 593 | |
Joshua Bell | 607cb14 | 2017-07-24 19:17:16 | [diff] [blame] | 594 | storage::DatabaseTracker* database_tracker = |
| 595 | storage_partition->GetDatabaseTracker(); |
| 596 | database_tracker->task_runner()->PostTask( |
| 597 | FROM_HERE, |
| 598 | base::BindOnce(&storage::DatabaseTracker::SetForceKeepSessionState, |
kylechar | da69d88 | 2017-10-04 05:49:52 | [diff] [blame] | 599 | base::WrapRefCounted(database_tracker))); |
Joshua Bell | 607cb14 | 2017-07-24 19:17:16 | [diff] [blame] | 600 | |
Gabriel Charette | 2983181c | 2018-03-28 17:01:09 | [diff] [blame] | 601 | if (BrowserThread::IsThreadInitialized(BrowserThread::IO)) { |
John Abd-El-Malek | b175a61 | 2018-12-03 20:11:58 | [diff] [blame] | 602 | scoped_refptr<net::URLRequestContextGetter> context_getter; |
John Abd-El-Malek | b175a61 | 2018-12-03 20:11:58 | [diff] [blame] | 603 | if (!base::FeatureList::IsEnabled(network::features::kNetworkService)) |
| 604 | context_getter = storage_partition->GetURLRequestContext(); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 605 | base::PostTaskWithTraits( |
| 606 | FROM_HERE, {BrowserThread::IO}, |
John Abd-El-Malek | b175a61 | 2018-12-03 20:11:58 | [diff] [blame] | 607 | base::BindOnce(&SaveSessionStateOnIOThread, context_getter, |
| 608 | static_cast<AppCacheServiceImpl*>( |
| 609 | storage_partition->GetAppCacheService()))); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 610 | } |
| 611 | |
Clark DuVall | 385b5a5 | 2018-06-14 21:33:32 | [diff] [blame] | 612 | storage_partition->GetCookieManagerForBrowserProcess() |
| 613 | ->SetForceKeepSessionState(); |
| 614 | |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 615 | DOMStorageContextWrapper* dom_storage_context_proxy = |
| 616 | static_cast<DOMStorageContextWrapper*>( |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 617 | storage_partition->GetDOMStorageContext()); |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 618 | dom_storage_context_proxy->SetForceKeepSessionState(); |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 619 | |
Daniel Murphy | d9a41e7b | 2019-05-09 17:56:54 | [diff] [blame] | 620 | scoped_refptr<IndexedDBContext> indexed_db_context = |
| 621 | storage_partition->GetIndexedDBContext(); |
Victor Costan | 4b8909d5 | 2019-05-28 19:25:51 | [diff] [blame] | 622 | IndexedDBContext* const indexed_db_context_ptr = indexed_db_context.get(); |
| 623 | indexed_db_context_ptr->TaskRunner()->PostTask( |
| 624 | FROM_HERE, base::BindOnce(&SaveSessionStateOnIndexedDBThread, |
| 625 | std::move(indexed_db_context))); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 626 | } |
| 627 | |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 628 | void BrowserContext::SetDownloadManagerForTesting( |
| 629 | BrowserContext* browser_context, |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 630 | std::unique_ptr<content::DownloadManager> download_manager) { |
| 631 | SetDownloadManager(browser_context, std::move(download_manager)); |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 632 | } |
| 633 | |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 634 | // static |
Marijn Kruisselbrink | 83e5cdb | 2019-06-20 00:06:28 | [diff] [blame^] | 635 | void BrowserContext::Initialize(BrowserContext* browser_context, |
| 636 | const base::FilePath& path) { |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 637 | const base::Token new_group = base::Token::CreateRandom(); |
| 638 | ServiceInstanceGroupHolder* holder = static_cast<ServiceInstanceGroupHolder*>( |
| 639 | browser_context->GetUserData(kServiceInstanceGroup)); |
| 640 | if (holder) { |
| 641 | file::ForgetServiceInstanceGroupUserDirAssociation( |
| 642 | holder->instance_group()); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 643 | } |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 644 | file::AssociateServiceInstanceGroupWithUserDir(new_group, path); |
| 645 | RemoveBrowserContextFromInstanceGroupMap(browser_context); |
| 646 | GetTokenToContextMap()[new_group] = browser_context; |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 647 | browser_context->SetUserData( |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 648 | kServiceInstanceGroup, |
| 649 | std::make_unique<ServiceInstanceGroupHolder>(new_group)); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 650 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 651 | ServiceManagerConnection* service_manager_connection = |
| 652 | ServiceManagerConnection::GetForProcess(); |
fdoray | 4f155f0 | 2016-10-12 11:28:50 | [diff] [blame] | 653 | if (service_manager_connection && base::ThreadTaskRunnerHandle::IsSet()) { |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 654 | // NOTE: Many unit tests create a TestBrowserContext without initializing |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 655 | // Mojo or the global service manager connection. |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 656 | |
Ken Rockot | 40a1df79 | 2019-05-08 22:15:52 | [diff] [blame] | 657 | mojo::PendingRemote<service_manager::mojom::Service> service; |
| 658 | auto service_receiver = service.InitWithNewPipeAndPassReceiver(); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 659 | |
Ken Rockot | 40a1df79 | 2019-05-08 22:15:52 | [diff] [blame] | 660 | mojo::Remote<service_manager::mojom::ProcessMetadata> metadata; |
Ken Rockot | a86fa54 | 2018-11-13 21:47:13 | [diff] [blame] | 661 | service_manager::Identity identity(mojom::kBrowserServiceName, new_group, |
| 662 | base::Token{}, |
| 663 | base::Token::CreateRandom()); |
| 664 | service_manager_connection->GetConnector()->RegisterServiceInstance( |
Ken Rockot | 40a1df79 | 2019-05-08 22:15:52 | [diff] [blame] | 665 | identity, std::move(service), metadata.BindNewPipeAndPassReceiver()); |
| 666 | metadata->SetPID(base::GetCurrentProcId()); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 667 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 668 | BrowserContextServiceManagerConnectionHolder* connection_holder = |
| 669 | new BrowserContextServiceManagerConnectionHolder( |
Ken Rockot | 40a1df79 | 2019-05-08 22:15:52 | [diff] [blame] | 670 | browser_context, std::move(service_receiver), |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 671 | base::SequencedTaskRunnerHandle::Get()); |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 672 | browser_context->SetUserData(kServiceManagerConnection, |
| 673 | base::WrapUnique(connection_holder)); |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 674 | ServiceManagerConnection* connection = |
| 675 | connection_holder->service_manager_connection(); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 676 | |
Ken Rockot | 84f58fd | 2018-06-22 21:54:14 | [diff] [blame] | 677 | browser_context->SetUserData( |
| 678 | kContentServiceDelegateKey, |
| 679 | std::make_unique<ContentServiceDelegateHolder>(browser_context)); |
| 680 | |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 681 | scoped_refptr<FileServiceIOThreadState> file_service_io_thread_state = |
| 682 | base::MakeRefCounted<FileServiceIOThreadState>( |
| 683 | base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO})); |
| 684 | connection->AddServiceRequestHandler( |
| 685 | file::mojom::kServiceName, |
| 686 | base::BindRepeating( |
| 687 | [](scoped_refptr<FileServiceIOThreadState> io_thread_state, |
| 688 | service_manager::mojom::ServiceRequest request) { |
| 689 | io_thread_state->StartOnIOThread(std::move(request)); |
| 690 | }, |
| 691 | file_service_io_thread_state)); |
| 692 | |
| 693 | browser_context->SetUserData(kFileServiceKey, |
| 694 | std::make_unique<FileServiceHolder>( |
| 695 | std::move(file_service_io_thread_state))); |
tibell | ab3d36b | 2017-03-10 02:57:25 | [diff] [blame] | 696 | |
Ken Rockot | c7a279c | 2017-05-04 23:51:45 | [diff] [blame] | 697 | RegisterCommonBrowserInterfaces(connection); |
sammc | 030f501 | 2017-03-13 02:28:45 | [diff] [blame] | 698 | connection->Start(); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 699 | } |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 700 | } |
| 701 | |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 702 | // static |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 703 | const base::Token& BrowserContext::GetServiceInstanceGroupFor( |
ben | cccfe2a | 2016-03-05 16:54:14 | [diff] [blame] | 704 | BrowserContext* browser_context) { |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 705 | ServiceInstanceGroupHolder* holder = static_cast<ServiceInstanceGroupHolder*>( |
| 706 | browser_context->GetUserData(kServiceInstanceGroup)); |
| 707 | CHECK(holder) << "Attempting to get the instance group for a BrowserContext " |
| 708 | << "that was never Initialized()."; |
| 709 | return holder->instance_group(); |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 710 | } |
| 711 | |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 712 | // static |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 713 | BrowserContext* BrowserContext::GetBrowserContextForServiceInstanceGroup( |
| 714 | const base::Token& instance_group) { |
| 715 | auto it = GetTokenToContextMap().find(instance_group); |
| 716 | return it != GetTokenToContextMap().end() ? it->second : nullptr; |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | // static |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 720 | service_manager::Connector* BrowserContext::GetConnectorFor( |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 721 | BrowserContext* browser_context) { |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 722 | ServiceManagerConnection* connection = |
| 723 | GetServiceManagerConnectionFor(browser_context); |
ben | 5be0b913 | 2016-08-03 00:17:18 | [diff] [blame] | 724 | return connection ? connection->GetConnector() : nullptr; |
| 725 | } |
| 726 | |
| 727 | // static |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 728 | ServiceManagerConnection* BrowserContext::GetServiceManagerConnectionFor( |
ben | 5be0b913 | 2016-08-03 00:17:18 | [diff] [blame] | 729 | BrowserContext* browser_context) { |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 730 | BrowserContextServiceManagerConnectionHolder* connection_holder = |
| 731 | static_cast<BrowserContextServiceManagerConnectionHolder*>( |
| 732 | browser_context->GetUserData(kServiceManagerConnection)); |
| 733 | return connection_holder ? connection_holder->service_manager_connection() |
| 734 | : nullptr; |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 735 | } |
| 736 | |
mmenke | c0b2b8b1 | 2017-04-21 16:27:52 | [diff] [blame] | 737 | BrowserContext::BrowserContext() |
Takashi Toyoshima | 0190a3b | 2019-01-21 07:39:06 | [diff] [blame] | 738 | : unique_id_(base::UnguessableToken::Create().ToString()) {} |
mmenke | c0b2b8b1 | 2017-04-21 16:27:52 | [diff] [blame] | 739 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 740 | BrowserContext::~BrowserContext() { |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 741 | CHECK(GetUserData(kServiceInstanceGroup)) |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 742 | << "Attempting to destroy a BrowserContext that never called " |
| 743 | << "Initialize()"; |
| 744 | |
kinuko | f6ed359c | 2016-07-26 13:27:21 | [diff] [blame] | 745 | DCHECK(!GetUserData(kStoragePartitionMapKeyName)) |
| 746 | << "StoragePartitionMap is not shut down properly"; |
| 747 | |
Lukasz Anforowicz | 58d0dac | 2018-03-23 15:48:10 | [diff] [blame] | 748 | DCHECK(was_notify_will_be_destroyed_called_); |
| 749 | |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 750 | RemoveBrowserContextFromInstanceGroupMap(this); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 751 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 752 | if (GetUserData(kDownloadManagerKeyName)) |
| 753 | GetDownloadManager(this)->Shutdown(); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 754 | } |
| 755 | |
kinuko | f6ed359c | 2016-07-26 13:27:21 | [diff] [blame] | 756 | void BrowserContext::ShutdownStoragePartitions() { |
| 757 | if (GetUserData(kStoragePartitionMapKeyName)) |
| 758 | RemoveUserData(kStoragePartitionMapKeyName); |
| 759 | } |
| 760 | |
mmenke | c0b2b8b1 | 2017-04-21 16:27:52 | [diff] [blame] | 761 | std::string BrowserContext::GetMediaDeviceIDSalt() { |
Andrey Lushnikov | d39d906 | 2018-04-24 17:33:35 | [diff] [blame] | 762 | return unique_id_; |
mmenke | c0b2b8b1 | 2017-04-21 16:27:52 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | // static |
| 766 | std::string BrowserContext::CreateRandomMediaDeviceIDSalt() { |
Andrey Lushnikov | d39d906 | 2018-04-24 17:33:35 | [diff] [blame] | 767 | return base::UnguessableToken::Create().ToString(); |
| 768 | } |
| 769 | |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 770 | std::unique_ptr<service_manager::Service> BrowserContext::HandleServiceRequest( |
| 771 | const std::string& service_name, |
| 772 | service_manager::mojom::ServiceRequest request) { |
| 773 | return nullptr; |
| 774 | } |
| 775 | |
Andrey Lushnikov | d39d906 | 2018-04-24 17:33:35 | [diff] [blame] | 776 | const std::string& BrowserContext::UniqueId() const { |
| 777 | return unique_id_; |
mmenke | c0b2b8b1 | 2017-04-21 16:27:52 | [diff] [blame] | 778 | } |
| 779 | |
Chris Cunningham | a5b3801 | 2017-10-28 07:27:18 | [diff] [blame] | 780 | media::VideoDecodePerfHistory* BrowserContext::GetVideoDecodePerfHistory() { |
| 781 | media::VideoDecodePerfHistory* decode_history = |
| 782 | static_cast<media::VideoDecodePerfHistory*>( |
| 783 | GetUserData(kVideoDecodePerfHistoryId)); |
| 784 | |
| 785 | // Lazily created. Note, this does not trigger loading the DB from disk. That |
| 786 | // occurs later upon first VideoDecodePerfHistory API request that requires DB |
| 787 | // access. DB operations will not block the UI thread. |
| 788 | if (!decode_history) { |
Chris Cunningham | 4507edfa | 2019-05-30 20:15:54 | [diff] [blame] | 789 | const char kUseInMemoryDBParamName[] = "db_in_memory"; |
| 790 | const bool kUseInMemoryDBDefault = false; |
| 791 | bool use_in_memory_db = base::GetFieldTrialParamByFeatureAsBool( |
| 792 | media::kMediaCapabilitiesWithParameters, kUseInMemoryDBParamName, |
| 793 | kUseInMemoryDBDefault); |
| 794 | |
| 795 | std::unique_ptr<media::VideoDecodeStatsDB> stats_db; |
| 796 | if (use_in_memory_db) { |
| 797 | stats_db = |
| 798 | std::make_unique<media::InMemoryVideoDecodeStatsDBImpl>(nullptr); |
| 799 | } else { |
| 800 | stats_db = media::VideoDecodeStatsDBImpl::Create( |
| 801 | GetPath().Append(FILE_PATH_LITERAL("VideoDecodeStats"))); |
| 802 | } |
| 803 | |
[email protected] | 3dcea37a | 2019-02-11 19:46:51 | [diff] [blame] | 804 | auto new_decode_history = std::make_unique<media::VideoDecodePerfHistory>( |
| 805 | std::move(stats_db), BrowserFeatureProvider::GetFactoryCB()); |
chcunningham | 06b8109 | 2018-09-24 20:20:51 | [diff] [blame] | 806 | decode_history = new_decode_history.get(); |
| 807 | |
| 808 | SetUserData(kVideoDecodePerfHistoryId, std::move(new_decode_history)); |
Chris Cunningham | a5b3801 | 2017-10-28 07:27:18 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | return decode_history; |
| 812 | } |
| 813 | |
Min Qin | d3ff2ed6 | 2018-07-21 06:46:59 | [diff] [blame] | 814 | download::InProgressDownloadManager* |
| 815 | BrowserContext::RetriveInProgressDownloadManager() { |
| 816 | return nullptr; |
| 817 | } |
| 818 | |
Takashi Toyoshima | 0190a3b | 2019-01-21 07:39:06 | [diff] [blame] | 819 | void BrowserContext::SetCorsOriginAccessListForOrigin( |
| 820 | const url::Origin& source_origin, |
| 821 | std::vector<network::mojom::CorsOriginPatternPtr> allow_patterns, |
| 822 | std::vector<network::mojom::CorsOriginPatternPtr> block_patterns, |
| 823 | base::OnceClosure closure) { |
| 824 | NOTREACHED() << "Sub-classes should implement this method to communicate " |
| 825 | "with NetworkService to bypass CORS checks."; |
| 826 | } |
| 827 | |
| 828 | const SharedCorsOriginAccessList* |
| 829 | BrowserContext::GetSharedCorsOriginAccessList() const { |
| 830 | // Need to return a valid instance regardless of CORS bypass supports. |
| 831 | static const base::NoDestructor<scoped_refptr<SharedCorsOriginAccessList>> |
| 832 | empty_list(SharedCorsOriginAccessList::Create()); |
| 833 | return empty_list->get(); |
| 834 | } |
| 835 | |
Sam Goto | 0230b71 | 2019-05-14 00:30:51 | [diff] [blame] | 836 | SmsService* BrowserContext::GetSmsService() { |
| 837 | return nullptr; |
| 838 | } |
| 839 | |
Marijn Kruisselbrink | 83e5cdb | 2019-06-20 00:06:28 | [diff] [blame^] | 840 | NativeFileSystemPermissionContext* |
| 841 | BrowserContext::GetNativeFileSystemPermissionContext() { |
| 842 | return nullptr; |
| 843 | } |
| 844 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 845 | } // namespace content |