[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" |
Ken Rockot | fd03e68 | 2019-06-20 21:13:54 | [diff] [blame] | 57 | #include "content/public/browser/system_connector.h" |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 58 | #include "content/public/common/content_switches.h" |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 59 | #include "content/public/common/service_manager_connection.h" |
ben | 51bb6c6 | 2016-11-17 20:15:57 | [diff] [blame] | 60 | #include "content/public/common/service_names.mojom.h" |
Chris Cunningham | 4507edfa | 2019-05-30 20:15:54 | [diff] [blame] | 61 | #include "media/base/media_switches.h" |
| 62 | #include "media/capabilities/in_memory_video_decode_stats_db_impl.h" |
Chris Cunningham | 9e66947 | 2017-11-15 21:03:11 | [diff] [blame] | 63 | #include "media/capabilities/video_decode_stats_db_impl.h" |
Chris Cunningham | a5b3801 | 2017-10-28 07:27:18 | [diff] [blame] | 64 | #include "media/mojo/services/video_decode_perf_history.h" |
Ken Rockot | 40a1df79 | 2019-05-08 22:15:52 | [diff] [blame] | 65 | #include "mojo/public/cpp/bindings/remote.h" |
[email protected] | 4d7c4ef | 2012-03-16 01:47:12 | [diff] [blame] | 66 | #include "net/cookies/cookie_store.h" |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 67 | #include "net/url_request/url_request_context.h" |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 68 | #include "net/url_request/url_request_context_getter.h" |
Ken Rockot | 84f58fd | 2018-06-22 21:54:14 | [diff] [blame] | 69 | #include "services/content/public/mojom/constants.mojom.h" |
| 70 | #include "services/content/service.h" |
ben | 768c8dc | 2016-08-12 00:26:50 | [diff] [blame] | 71 | #include "services/file/file_service.h" |
Ken Rockot | 21142de | 2018-02-10 01:45:30 | [diff] [blame] | 72 | #include "services/file/public/mojom/constants.mojom.h" |
ben | 768c8dc | 2016-08-12 00:26:50 | [diff] [blame] | 73 | #include "services/file/user_id_map.h" |
Takashi Toyoshima | a12ecf4 | 2018-09-25 07:46:01 | [diff] [blame] | 74 | #include "services/network/public/cpp/features.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 75 | #include "services/service_manager/public/cpp/connector.h" |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 76 | #include "services/service_manager/public/cpp/service.h" |
Ken Rockot | 543f5e3 | 2018-02-04 02:13:50 | [diff] [blame] | 77 | #include "services/service_manager/public/mojom/service.mojom.h" |
Xing Liu | 8986047 | 2018-02-09 20:07:02 | [diff] [blame] | 78 | #include "storage/browser/blob/blob_storage_context.h" |
pilgrim | e92c5fcd | 2014-09-10 23:31:23 | [diff] [blame] | 79 | #include "storage/browser/database/database_tracker.h" |
| 80 | #include "storage/browser/fileapi/external_mount_points.h" |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 81 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 82 | using base::UserDataAdapter; |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 83 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 84 | namespace content { |
| 85 | |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 86 | namespace { |
| 87 | |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 88 | using TokenToContextMap = std::map<base::Token, BrowserContext*>; |
| 89 | TokenToContextMap& GetTokenToContextMap() { |
| 90 | static base::NoDestructor<TokenToContextMap> map; |
| 91 | return *map; |
| 92 | } |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 93 | |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 94 | class ServiceInstanceGroupHolder : public base::SupportsUserData::Data { |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 95 | public: |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 96 | explicit ServiceInstanceGroupHolder(const base::Token& instance_group) |
| 97 | : instance_group_(instance_group) {} |
| 98 | ~ServiceInstanceGroupHolder() override {} |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 99 | |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 100 | const base::Token& instance_group() const { return instance_group_; } |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 101 | |
| 102 | private: |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 103 | base::Token instance_group_; |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 104 | |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 105 | DISALLOW_COPY_AND_ASSIGN(ServiceInstanceGroupHolder); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 106 | }; |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 107 | |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 108 | // The file service runs on the IO thread but we want to limit its lifetime to |
| 109 | // that of the BrowserContext which creates it. This provides thread-safe access |
| 110 | // to the relevant state on the IO thread. |
| 111 | class FileServiceIOThreadState |
| 112 | : public base::RefCountedThreadSafe<FileServiceIOThreadState> { |
| 113 | public: |
| 114 | explicit FileServiceIOThreadState( |
| 115 | scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| 116 | : io_task_runner_(std::move(io_task_runner)) {} |
| 117 | |
| 118 | void StartOnIOThread(service_manager::mojom::ServiceRequest request) { |
| 119 | DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 120 | file_service_ = std::make_unique<file::FileService>(std::move(request)); |
| 121 | } |
| 122 | |
| 123 | void ShutDown() { |
| 124 | io_task_runner_->PostTask( |
| 125 | FROM_HERE, |
| 126 | base::BindOnce(&FileServiceIOThreadState::ShutDownOnIOThread, this)); |
| 127 | } |
| 128 | |
| 129 | private: |
| 130 | friend class base::RefCountedThreadSafe<FileServiceIOThreadState>; |
| 131 | |
| 132 | ~FileServiceIOThreadState() { DCHECK(!file_service_); } |
| 133 | |
| 134 | void ShutDownOnIOThread() { file_service_.reset(); } |
| 135 | |
| 136 | const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 137 | std::unique_ptr<file::FileService> file_service_; |
| 138 | |
| 139 | DISALLOW_COPY_AND_ASSIGN(FileServiceIOThreadState); |
| 140 | }; |
| 141 | |
| 142 | class FileServiceHolder : public base::SupportsUserData::Data { |
| 143 | public: |
| 144 | explicit FileServiceHolder(scoped_refptr<FileServiceIOThreadState> state) |
| 145 | : state_(std::move(state)) {} |
| 146 | ~FileServiceHolder() override { state_->ShutDown(); } |
| 147 | |
| 148 | private: |
| 149 | const scoped_refptr<FileServiceIOThreadState> state_; |
| 150 | |
| 151 | DISALLOW_COPY_AND_ASSIGN(FileServiceHolder); |
| 152 | }; |
| 153 | |
Ken Rockot | 84f58fd | 2018-06-22 21:54:14 | [diff] [blame] | 154 | class ContentServiceDelegateHolder : public base::SupportsUserData::Data { |
| 155 | public: |
| 156 | explicit ContentServiceDelegateHolder(BrowserContext* browser_context) |
| 157 | : delegate_(browser_context) {} |
| 158 | ~ContentServiceDelegateHolder() override = default; |
| 159 | |
| 160 | ContentServiceDelegateImpl* delegate() { return &delegate_; } |
| 161 | |
| 162 | private: |
| 163 | ContentServiceDelegateImpl delegate_; |
| 164 | |
| 165 | DISALLOW_COPY_AND_ASSIGN(ContentServiceDelegateHolder); |
| 166 | }; |
| 167 | |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 168 | // Key names on BrowserContext. |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 169 | const char kBrowsingDataRemoverKey[] = "browsing-data-remover"; |
Ken Rockot | 84f58fd | 2018-06-22 21:54:14 | [diff] [blame] | 170 | const char kContentServiceDelegateKey[] = "content-service-delegate"; |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 171 | const char kFileServiceKey[] = "file-service"; |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 172 | const char kDownloadManagerKeyName[] = "download_manager"; |
Takashi Toyoshima | 621e2bf | 2018-09-18 08:05:16 | [diff] [blame] | 173 | const char kPermissionControllerKey[] = "permission-controller"; |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 174 | const char kServiceManagerConnection[] = "service-manager-connection"; |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 175 | const char kServiceInstanceGroup[] = "service-instance-group"; |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 176 | const char kStoragePartitionMapKeyName[] = "content_storage_partition_map"; |
Chris Cunningham | a5b3801 | 2017-10-28 07:27:18 | [diff] [blame] | 177 | const char kVideoDecodePerfHistoryId[] = "video-decode-perf-history"; |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 178 | |
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 179 | #if defined(OS_CHROMEOS) |
| 180 | const char kMountPointsKey[] = "mount_points"; |
| 181 | #endif // defined(OS_CHROMEOS) |
| 182 | |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 183 | void RemoveBrowserContextFromInstanceGroupMap(BrowserContext* browser_context) { |
| 184 | ServiceInstanceGroupHolder* holder = static_cast<ServiceInstanceGroupHolder*>( |
| 185 | browser_context->GetUserData(kServiceInstanceGroup)); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 186 | if (holder) { |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 187 | auto it = GetTokenToContextMap().find(holder->instance_group()); |
| 188 | if (it != GetTokenToContextMap().end()) |
| 189 | GetTokenToContextMap().erase(it); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 193 | StoragePartitionImplMap* GetStoragePartitionMap( |
| 194 | BrowserContext* browser_context) { |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 195 | StoragePartitionImplMap* partition_map = |
| 196 | static_cast<StoragePartitionImplMap*>( |
a.cavalcanti | ffab7376 | 2015-08-15 02:55:48 | [diff] [blame] | 197 | browser_context->GetUserData(kStoragePartitionMapKeyName)); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 198 | if (!partition_map) { |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 199 | auto partition_map_owned = |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 200 | std::make_unique<StoragePartitionImplMap>(browser_context); |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 201 | partition_map = partition_map_owned.get(); |
| 202 | browser_context->SetUserData(kStoragePartitionMapKeyName, |
| 203 | std::move(partition_map_owned)); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 204 | } |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 205 | return partition_map; |
| 206 | } |
| 207 | |
| 208 | StoragePartition* GetStoragePartitionFromConfig( |
| 209 | BrowserContext* browser_context, |
| 210 | const std::string& partition_domain, |
| 211 | const std::string& partition_name, |
Dan Elphick | 6c0d849 | 2017-09-12 09:35:38 | [diff] [blame] | 212 | bool in_memory, |
| 213 | bool can_create) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 214 | StoragePartitionImplMap* partition_map = |
| 215 | GetStoragePartitionMap(browser_context); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 216 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 217 | if (browser_context->IsOffTheRecord()) |
| 218 | in_memory = true; |
| 219 | |
Dan Elphick | 6c0d849 | 2017-09-12 09:35:38 | [diff] [blame] | 220 | return partition_map->Get(partition_domain, partition_name, in_memory, |
| 221 | can_create); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 222 | } |
| 223 | |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 224 | void SaveSessionStateOnIOThread( |
| 225 | const scoped_refptr<net::URLRequestContextGetter>& context_getter, |
[email protected] | 98d6d456 | 2014-06-25 20:57:55 | [diff] [blame] | 226 | AppCacheServiceImpl* appcache_service) { |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 227 | appcache_service->set_force_keep_session_state(); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 228 | } |
| 229 | |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 230 | void SaveSessionStateOnIndexedDBThread( |
Daniel Murphy | d9a41e7b | 2019-05-09 17:56:54 | [diff] [blame] | 231 | scoped_refptr<IndexedDBContext> indexed_db_context) { |
[email protected] | bf510ed | 2012-06-05 08:31:43 | [diff] [blame] | 232 | indexed_db_context->SetForceKeepSessionState(); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 233 | } |
| 234 | |
falken | 41f417516 | 2014-10-29 07:03:41 | [diff] [blame] | 235 | void ShutdownServiceWorkerContext(StoragePartition* partition) { |
| 236 | ServiceWorkerContextWrapper* wrapper = |
| 237 | static_cast<ServiceWorkerContextWrapper*>( |
| 238 | partition->GetServiceWorkerContext()); |
| 239 | wrapper->process_manager()->Shutdown(); |
| 240 | } |
| 241 | |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 242 | void SetDownloadManager( |
| 243 | BrowserContext* context, |
| 244 | std::unique_ptr<content::DownloadManager> download_manager) { |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 245 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 246 | DCHECK(download_manager); |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 247 | context->SetUserData(kDownloadManagerKeyName, std::move(download_manager)); |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 248 | } |
| 249 | |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 250 | std::unique_ptr<service_manager::Service> |
| 251 | CreateMainThreadServiceForBrowserContext( |
| 252 | BrowserContext* browser_context, |
| 253 | const std::string& service_name, |
| 254 | service_manager::mojom::ServiceRequest request) { |
| 255 | if (service_name == content::mojom::kServiceName) { |
| 256 | auto* delegate_holder = static_cast<ContentServiceDelegateHolder*>( |
| 257 | browser_context->GetUserData(kContentServiceDelegateKey)); |
| 258 | auto* delegate = delegate_holder->delegate(); |
| 259 | auto service = |
| 260 | std::make_unique<content::Service>(delegate, std::move(request)); |
| 261 | delegate->AddService(service.get()); |
| 262 | return service; |
| 263 | } |
| 264 | |
| 265 | return browser_context->HandleServiceRequest(service_name, |
| 266 | std::move(request)); |
| 267 | } |
| 268 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 269 | class BrowserContextServiceManagerConnectionHolder |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 270 | : public base::SupportsUserData::Data { |
| 271 | public: |
ben | aad37ecd | 2017-04-12 22:08:20 | [diff] [blame] | 272 | explicit BrowserContextServiceManagerConnectionHolder( |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 273 | BrowserContext* browser_context, |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 274 | service_manager::mojom::ServiceRequest request, |
| 275 | scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner) |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 276 | : browser_context_(browser_context), |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 277 | main_thread_task_runner_(std::move(main_thread_task_runner)), |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 278 | service_manager_connection_(ServiceManagerConnection::Create( |
rockot | cef3827 | 2016-07-15 22:47:47 | [diff] [blame] | 279 | std::move(request), |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 280 | base::CreateSingleThreadTaskRunnerWithTraits( |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 281 | {BrowserThread::IO}))) { |
| 282 | service_manager_connection_->SetDefaultServiceRequestHandler( |
| 283 | base::BindRepeating( |
| 284 | &BrowserContextServiceManagerConnectionHolder::OnServiceRequest, |
| 285 | weak_ptr_factory_.GetWeakPtr())); |
| 286 | } |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 287 | ~BrowserContextServiceManagerConnectionHolder() override {} |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 288 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 289 | ServiceManagerConnection* service_manager_connection() { |
| 290 | return service_manager_connection_.get(); |
| 291 | } |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 292 | |
Ken Rockot | ad3c758 | 2018-12-12 17:04:14 | [diff] [blame] | 293 | void DestroyRunningServices() { running_services_.clear(); } |
| 294 | |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 295 | private: |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 296 | void OnServiceRequest(const std::string& service_name, |
| 297 | service_manager::mojom::ServiceRequest request) { |
| 298 | std::unique_ptr<service_manager::Service> service = |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 299 | CreateMainThreadServiceForBrowserContext(browser_context_, service_name, |
| 300 | std::move(request)); |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 301 | if (!service) { |
| 302 | LOG(ERROR) << "Ignoring request for unknown per-browser-context service:" |
| 303 | << service_name; |
| 304 | return; |
| 305 | } |
| 306 | |
| 307 | auto* raw_service = service.get(); |
| 308 | service->set_termination_closure(base::BindOnce( |
| 309 | &BrowserContextServiceManagerConnectionHolder::OnServiceQuit, |
| 310 | base::Unretained(this), raw_service)); |
| 311 | running_services_.emplace(raw_service, std::move(service)); |
| 312 | } |
| 313 | |
| 314 | void OnServiceQuit(service_manager::Service* service) { |
| 315 | running_services_.erase(service); |
| 316 | } |
| 317 | |
| 318 | BrowserContext* const browser_context_; |
Ken Rockot | 499519e | 2018-12-04 06:57:44 | [diff] [blame] | 319 | const scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner_; |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 320 | std::unique_ptr<ServiceManagerConnection> service_manager_connection_; |
Ken Rockot | 43513269 | 2018-11-20 21:46:10 | [diff] [blame] | 321 | std::map<service_manager::Service*, std::unique_ptr<service_manager::Service>> |
| 322 | running_services_; |
| 323 | |
| 324 | base::WeakPtrFactory<BrowserContextServiceManagerConnectionHolder> |
| 325 | weak_ptr_factory_{this}; |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 326 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 327 | DISALLOW_COPY_AND_ASSIGN(BrowserContextServiceManagerConnectionHolder); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 328 | }; |
| 329 | |
Jens Widell | 7ca8fb4 | 2018-02-21 14:11:54 | [diff] [blame] | 330 | base::WeakPtr<storage::BlobStorageContext> BlobStorageContextGetterForBrowser( |
Xing Liu | 8986047 | 2018-02-09 20:07:02 | [diff] [blame] | 331 | scoped_refptr<ChromeBlobStorageContext> blob_context) { |
| 332 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 333 | return blob_context->context()->AsWeakPtr(); |
| 334 | } |
| 335 | |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 336 | } // namespace |
| 337 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 338 | // static |
| 339 | void BrowserContext::AsyncObliterateStoragePartition( |
| 340 | BrowserContext* browser_context, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 341 | const GURL& site, |
| 342 | const base::Closure& on_gc_required) { |
Marijn Kruisselbrink | 83e5cdb | 2019-06-20 00:06:28 | [diff] [blame] | 343 | GetStoragePartitionMap(browser_context) |
| 344 | ->AsyncObliterate(site, on_gc_required); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | // static |
| 348 | void BrowserContext::GarbageCollectStoragePartitions( |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 349 | BrowserContext* browser_context, |
Takuto Ikuta | 8332bf9d | 2019-01-05 03:58:00 | [diff] [blame] | 350 | std::unique_ptr<std::unordered_set<base::FilePath>> active_paths, |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 351 | const base::Closure& done) { |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 352 | GetStoragePartitionMap(browser_context) |
| 353 | ->GarbageCollect(std::move(active_paths), done); |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 354 | } |
| 355 | |
Marijn Kruisselbrink | 83e5cdb | 2019-06-20 00:06:28 | [diff] [blame] | 356 | DownloadManager* BrowserContext::GetDownloadManager(BrowserContext* context) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 357 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 358 | if (!context->GetUserData(kDownloadManagerKeyName)) { |
Min Qin | ddb40ce | 2017-10-28 03:38:26 | [diff] [blame] | 359 | DownloadManager* download_manager = new DownloadManagerImpl(context); |
[email protected] | d25fda1 | 2012-06-12 17:05:03 | [diff] [blame] | 360 | |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 361 | SetDownloadManager(context, base::WrapUnique(download_manager)); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 362 | download_manager->SetDelegate(context->GetDownloadManagerDelegate()); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 363 | } |
| 364 | |
[email protected] | eba4a4d | 2013-05-29 02:18:06 | [diff] [blame] | 365 | return static_cast<DownloadManager*>( |
| 366 | context->GetUserData(kDownloadManagerKeyName)); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 367 | } |
| 368 | |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 369 | // static |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 370 | storage::ExternalMountPoints* BrowserContext::GetMountPoints( |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 371 | BrowserContext* context) { |
| 372 | // Ensure that these methods are called on the UI thread, except for |
| 373 | // unittests where a UI thread might not have been created. |
| 374 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
Gabriel Charette | 2983181c | 2018-03-28 17:01:09 | [diff] [blame] | 375 | !BrowserThread::IsThreadInitialized(BrowserThread::UI)); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 376 | |
| 377 | #if defined(OS_CHROMEOS) |
| 378 | if (!context->GetUserData(kMountPointsKey)) { |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 379 | scoped_refptr<storage::ExternalMountPoints> mount_points = |
| 380 | storage::ExternalMountPoints::CreateRefCounted(); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 381 | context->SetUserData( |
| 382 | kMountPointsKey, |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 383 | std::make_unique<UserDataAdapter<storage::ExternalMountPoints>>( |
avi | cb129c0 | 2017-05-03 06:49:29 | [diff] [blame] | 384 | mount_points.get())); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 385 | } |
| 386 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 387 | return UserDataAdapter<storage::ExternalMountPoints>::Get(context, |
| 388 | kMountPointsKey); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 389 | #else |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 390 | return nullptr; |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 391 | #endif |
| 392 | } |
| 393 | |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 394 | // static |
| 395 | content::BrowsingDataRemover* content::BrowserContext::GetBrowsingDataRemover( |
| 396 | BrowserContext* context) { |
| 397 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 398 | |
| 399 | if (!context->GetUserData(kBrowsingDataRemoverKey)) { |
| 400 | std::unique_ptr<BrowsingDataRemoverImpl> remover = |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 401 | std::make_unique<BrowsingDataRemoverImpl>(context); |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 402 | remover->SetEmbedderDelegate(context->GetBrowsingDataRemoverDelegate()); |
| 403 | context->SetUserData(kBrowsingDataRemoverKey, std::move(remover)); |
| 404 | } |
| 405 | |
| 406 | return static_cast<BrowsingDataRemoverImpl*>( |
| 407 | context->GetUserData(kBrowsingDataRemoverKey)); |
| 408 | } |
| 409 | |
Andrey Lushnikov | ebff044 | 2018-07-12 20:02:58 | [diff] [blame] | 410 | // static |
| 411 | content::PermissionController* content::BrowserContext::GetPermissionController( |
| 412 | BrowserContext* context) { |
| 413 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 414 | |
| 415 | if (!context->GetUserData(kPermissionControllerKey)) { |
| 416 | context->SetUserData(kPermissionControllerKey, |
| 417 | std::make_unique<PermissionControllerImpl>(context)); |
| 418 | } |
| 419 | |
| 420 | return static_cast<PermissionControllerImpl*>( |
| 421 | context->GetUserData(kPermissionControllerKey)); |
| 422 | } |
| 423 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 424 | StoragePartition* BrowserContext::GetStoragePartition( |
| 425 | BrowserContext* browser_context, |
Dan Elphick | 6c0d849 | 2017-09-12 09:35:38 | [diff] [blame] | 426 | SiteInstance* site_instance, |
| 427 | bool can_create) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 428 | std::string partition_domain; |
| 429 | std::string partition_name; |
| 430 | bool in_memory = false; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 431 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 432 | if (site_instance) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 433 | GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
Marijn Kruisselbrink | 83e5cdb | 2019-06-20 00:06:28 | [diff] [blame] | 434 | browser_context, site_instance->GetSiteURL(), true, &partition_domain, |
| 435 | &partition_name, &in_memory); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 436 | } |
| 437 | |
Dan Elphick | 6c0d849 | 2017-09-12 09:35:38 | [diff] [blame] | 438 | return GetStoragePartitionFromConfig(browser_context, partition_domain, |
| 439 | partition_name, in_memory, can_create); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 440 | } |
| 441 | |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 442 | StoragePartition* BrowserContext::GetStoragePartitionForSite( |
| 443 | BrowserContext* browser_context, |
Dan Elphick | 6c0d849 | 2017-09-12 09:35:38 | [diff] [blame] | 444 | const GURL& site, |
| 445 | bool can_create) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 446 | std::string partition_domain; |
| 447 | std::string partition_name; |
| 448 | bool in_memory; |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 449 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 450 | GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 451 | browser_context, site, true, &partition_domain, &partition_name, |
| 452 | &in_memory); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 453 | |
Dan Elphick | 6c0d849 | 2017-09-12 09:35:38 | [diff] [blame] | 454 | return GetStoragePartitionFromConfig(browser_context, partition_domain, |
| 455 | partition_name, in_memory, can_create); |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 456 | } |
| 457 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 458 | void BrowserContext::ForEachStoragePartition( |
| 459 | BrowserContext* browser_context, |
| 460 | const StoragePartitionCallback& callback) { |
| 461 | StoragePartitionImplMap* partition_map = |
| 462 | static_cast<StoragePartitionImplMap*>( |
a.cavalcanti | ffab7376 | 2015-08-15 02:55:48 | [diff] [blame] | 463 | browser_context->GetUserData(kStoragePartitionMapKeyName)); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 464 | if (!partition_map) |
| 465 | return; |
| 466 | |
| 467 | partition_map->ForEach(callback); |
| 468 | } |
| 469 | |
| 470 | StoragePartition* BrowserContext::GetDefaultStoragePartition( |
| 471 | BrowserContext* browser_context) { |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 472 | return GetStoragePartition(browser_context, nullptr); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 473 | } |
| 474 | |
tbarzic | db71268 | 2015-03-06 06:05:41 | [diff] [blame] | 475 | // static |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 476 | void BrowserContext::CreateMemoryBackedBlob(BrowserContext* browser_context, |
Marijn Kruisselbrink | 604fd7e7 | 2017-10-26 16:31:05 | [diff] [blame] | 477 | const char* data, |
| 478 | size_t length, |
| 479 | const std::string& content_type, |
| 480 | BlobCallback callback) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 481 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 482 | |
| 483 | ChromeBlobStorageContext* blob_context = |
| 484 | ChromeBlobStorageContext::GetFor(browser_context); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 485 | base::PostTaskWithTraitsAndReplyWithResult( |
| 486 | FROM_HERE, {BrowserThread::IO}, |
Marijn Kruisselbrink | 604fd7e7 | 2017-10-26 16:31:05 | [diff] [blame] | 487 | base::BindOnce(&ChromeBlobStorageContext::CreateMemoryBackedBlob, |
| 488 | base::WrapRefCounted(blob_context), data, length, |
| 489 | content_type), |
| 490 | std::move(callback)); |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 491 | } |
| 492 | |
[email protected] | 66e53d028 | 2014-08-07 10:04:35 | [diff] [blame] | 493 | // static |
Xing Liu | 8986047 | 2018-02-09 20:07:02 | [diff] [blame] | 494 | BrowserContext::BlobContextGetter BrowserContext::GetBlobStorageContext( |
| 495 | BrowserContext* browser_context) { |
| 496 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 497 | scoped_refptr<ChromeBlobStorageContext> chrome_blob_context = |
| 498 | ChromeBlobStorageContext::GetFor(browser_context); |
Jens Widell | 7ca8fb4 | 2018-02-21 14:11:54 | [diff] [blame] | 499 | return base::BindRepeating(&BlobStorageContextGetterForBrowser, |
| 500 | chrome_blob_context); |
Xing Liu | 8986047 | 2018-02-09 20:07:02 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | // static |
Marijn Kruisselbrink | 9e073a8 | 2018-06-18 17:48:58 | [diff] [blame] | 504 | blink::mojom::BlobPtr BrowserContext::GetBlobPtr( |
| 505 | BrowserContext* browser_context, |
| 506 | const std::string& uuid) { |
| 507 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 508 | return ChromeBlobStorageContext::GetBlobPtr(browser_context, uuid); |
| 509 | } |
| 510 | |
| 511 | // static |
[email protected] | 66e53d028 | 2014-08-07 10:04:35 | [diff] [blame] | 512 | void BrowserContext::DeliverPushMessage( |
| 513 | BrowserContext* browser_context, |
| 514 | const GURL& origin, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 515 | int64_t service_worker_registration_id, |
Rayan Kanso | 3b68620 | 2019-05-10 17:41:55 | [diff] [blame] | 516 | const std::string& message_id, |
Han Leon | c1deace | 2018-08-03 03:52:53 | [diff] [blame] | 517 | base::Optional<std::string> payload, |
Mario Sanchez Prada | d299011 | 2019-05-07 08:13:49 | [diff] [blame] | 518 | const base::Callback<void(blink::mojom::PushDeliveryStatus)>& callback) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 519 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
harkness | dd4d2b2 | 2016-01-27 19:26:43 | [diff] [blame] | 520 | PushMessagingRouter::DeliverMessage(browser_context, origin, |
Han Leon | c1deace | 2018-08-03 03:52:53 | [diff] [blame] | 521 | service_worker_registration_id, |
Rayan Kanso | 3b68620 | 2019-05-10 17:41:55 | [diff] [blame] | 522 | message_id, std::move(payload), callback); |
[email protected] | 66e53d028 | 2014-08-07 10:04:35 | [diff] [blame] | 523 | } |
| 524 | |
falken | 41f417516 | 2014-10-29 07:03:41 | [diff] [blame] | 525 | // static |
| 526 | void BrowserContext::NotifyWillBeDestroyed(BrowserContext* browser_context) { |
Lukasz Anforowicz | 58d0dac | 2018-03-23 15:48:10 | [diff] [blame] | 527 | // Make sure NotifyWillBeDestroyed is idempotent. This helps facilitate the |
| 528 | // pattern where NotifyWillBeDestroyed is called from *both* |
Kent Tamura | 21d1de6 | 2018-12-10 04:45:20 | [diff] [blame] | 529 | // ShellBrowserContext and its derived classes (e.g. WebTestBrowserContext). |
Lukasz Anforowicz | 58d0dac | 2018-03-23 15:48:10 | [diff] [blame] | 530 | if (browser_context->was_notify_will_be_destroyed_called_) |
| 531 | return; |
| 532 | browser_context->was_notify_will_be_destroyed_called_ = true; |
| 533 | |
Ken Rockot | 99c5bc74 | 2018-07-12 15:36:56 | [diff] [blame] | 534 | // Subclasses of BrowserContext may expect there to be no more |
| 535 | // RenderProcessHosts using them by the time this function returns. We |
| 536 | // therefore explicitly tear down embedded Content Service instances now to |
| 537 | // ensure that all their WebContents (and therefore RPHs) are torn down too. |
| 538 | browser_context->RemoveUserData(kContentServiceDelegateKey); |
| 539 | |
Ken Rockot | ad3c758 | 2018-12-12 17:04:14 | [diff] [blame] | 540 | // Tear down all running service instances which were started on behalf of |
| 541 | // this BrowserContext. Note that we leave the UserData itself in place |
| 542 | // because it's possible for someone to call |
| 543 | // |GetServiceManagerConnectionFor()| between now and actual BrowserContext |
| 544 | // destruction. |
| 545 | BrowserContextServiceManagerConnectionHolder* connection_holder = |
| 546 | static_cast<BrowserContextServiceManagerConnectionHolder*>( |
| 547 | browser_context->GetUserData(kServiceManagerConnection)); |
| 548 | if (connection_holder) |
| 549 | connection_holder->DestroyRunningServices(); |
| 550 | |
falken | 41f417516 | 2014-10-29 07:03:41 | [diff] [blame] | 551 | // Service Workers must shutdown before the browser context is destroyed, |
| 552 | // since they keep render process hosts alive and the codebase assumes that |
| 553 | // render process hosts die before their profile (browser context) dies. |
| 554 | ForEachStoragePartition(browser_context, |
| 555 | base::Bind(ShutdownServiceWorkerContext)); |
falken | 04a6912a | 2016-09-23 21:06:29 | [diff] [blame] | 556 | |
| 557 | // Shared workers also keep render process hosts alive, and are expected to |
Darin Fisher | d3768b2f6 | 2017-10-07 01:00:16 | [diff] [blame] | 558 | // return ref counts to 0 after documents close. However, to ensure that |
| 559 | // hosts are destructed now, forcibly release their ref counts here. |
falken | 04a6912a | 2016-09-23 21:06:29 | [diff] [blame] | 560 | for (RenderProcessHost::iterator host_iterator = |
| 561 | RenderProcessHost::AllHostsIterator(); |
| 562 | !host_iterator.IsAtEnd(); host_iterator.Advance()) { |
| 563 | RenderProcessHost* host = host_iterator.GetCurrentValue(); |
Benoit Lize | ab08362c | 2017-07-19 14:50:54 | [diff] [blame] | 564 | if (host->GetBrowserContext() == browser_context) { |
| 565 | // This will also clean up spare RPH references. |
Yutaka Hirano | 09a9afb9 | 2017-08-16 09:11:45 | [diff] [blame] | 566 | host->DisableKeepAliveRefCount(); |
Benoit Lize | ab08362c | 2017-07-19 14:50:54 | [diff] [blame] | 567 | } |
falken | 04a6912a | 2016-09-23 21:06:29 | [diff] [blame] | 568 | } |
Alex Moshchuk | 99b79542 | 2019-03-07 00:27:32 | [diff] [blame] | 569 | |
Aaron Colwell | 67f93006c | 2019-04-01 22:45:28 | [diff] [blame] | 570 | // Clean up any isolated origins associated with this BrowserContext. This |
Alex Moshchuk | 99b79542 | 2019-03-07 00:27:32 | [diff] [blame] | 571 | // should be safe now that all RenderProcessHosts are destroyed, since future |
| 572 | // navigations or security decisions shouldn't ever need to consult these |
Aaron Colwell | 67f93006c | 2019-04-01 22:45:28 | [diff] [blame] | 573 | // isolated origins. |
Alex Moshchuk | 99b79542 | 2019-03-07 00:27:32 | [diff] [blame] | 574 | ChildProcessSecurityPolicyImpl* policy = |
| 575 | ChildProcessSecurityPolicyImpl::GetInstance(); |
Aaron Colwell | 67f93006c | 2019-04-01 22:45:28 | [diff] [blame] | 576 | policy->RemoveIsolatedOriginsForBrowserContext(*browser_context); |
falken | 41f417516 | 2014-10-29 07:03:41 | [diff] [blame] | 577 | } |
| 578 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 579 | void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) { |
[email protected] | 7e26ac9 | 2012-02-27 20:15:05 | [diff] [blame] | 580 | // This will be enough to tickle initialization of BrowserContext if |
| 581 | // necessary, which initializes ResourceContext. The reason we don't call |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 582 | // ResourceContext::InitializeResourceContext() directly here is that |
| 583 | // ResourceContext initialization may call back into BrowserContext |
| 584 | // and when that call returns it'll end rewriting its UserData map. It will |
| 585 | // end up rewriting the same value but this still causes a race condition. |
| 586 | // |
| 587 | // See http://crbug.com/115678. |
| 588 | GetDefaultStoragePartition(context); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 589 | } |
| 590 | |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 591 | void BrowserContext::SaveSessionState(BrowserContext* browser_context) { |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 592 | StoragePartition* storage_partition = |
| 593 | BrowserContext::GetDefaultStoragePartition(browser_context); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 594 | |
Joshua Bell | 607cb14 | 2017-07-24 19:17:16 | [diff] [blame] | 595 | storage::DatabaseTracker* database_tracker = |
| 596 | storage_partition->GetDatabaseTracker(); |
| 597 | database_tracker->task_runner()->PostTask( |
| 598 | FROM_HERE, |
| 599 | base::BindOnce(&storage::DatabaseTracker::SetForceKeepSessionState, |
kylechar | da69d88 | 2017-10-04 05:49:52 | [diff] [blame] | 600 | base::WrapRefCounted(database_tracker))); |
Joshua Bell | 607cb14 | 2017-07-24 19:17:16 | [diff] [blame] | 601 | |
Gabriel Charette | 2983181c | 2018-03-28 17:01:09 | [diff] [blame] | 602 | if (BrowserThread::IsThreadInitialized(BrowserThread::IO)) { |
John Abd-El-Malek | b175a61 | 2018-12-03 20:11:58 | [diff] [blame] | 603 | scoped_refptr<net::URLRequestContextGetter> context_getter; |
John Abd-El-Malek | b175a61 | 2018-12-03 20:11:58 | [diff] [blame] | 604 | if (!base::FeatureList::IsEnabled(network::features::kNetworkService)) |
| 605 | context_getter = storage_partition->GetURLRequestContext(); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 606 | base::PostTaskWithTraits( |
| 607 | FROM_HERE, {BrowserThread::IO}, |
John Abd-El-Malek | b175a61 | 2018-12-03 20:11:58 | [diff] [blame] | 608 | base::BindOnce(&SaveSessionStateOnIOThread, context_getter, |
| 609 | static_cast<AppCacheServiceImpl*>( |
| 610 | storage_partition->GetAppCacheService()))); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 611 | } |
| 612 | |
Clark DuVall | 385b5a5 | 2018-06-14 21:33:32 | [diff] [blame] | 613 | storage_partition->GetCookieManagerForBrowserProcess() |
| 614 | ->SetForceKeepSessionState(); |
| 615 | |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 616 | DOMStorageContextWrapper* dom_storage_context_proxy = |
| 617 | static_cast<DOMStorageContextWrapper*>( |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 618 | storage_partition->GetDOMStorageContext()); |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 619 | dom_storage_context_proxy->SetForceKeepSessionState(); |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 620 | |
Daniel Murphy | d9a41e7b | 2019-05-09 17:56:54 | [diff] [blame] | 621 | scoped_refptr<IndexedDBContext> indexed_db_context = |
| 622 | storage_partition->GetIndexedDBContext(); |
Victor Costan | 4b8909d5 | 2019-05-28 19:25:51 | [diff] [blame] | 623 | IndexedDBContext* const indexed_db_context_ptr = indexed_db_context.get(); |
| 624 | indexed_db_context_ptr->TaskRunner()->PostTask( |
| 625 | FROM_HERE, base::BindOnce(&SaveSessionStateOnIndexedDBThread, |
| 626 | std::move(indexed_db_context))); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 627 | } |
| 628 | |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 629 | void BrowserContext::SetDownloadManagerForTesting( |
| 630 | BrowserContext* browser_context, |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 631 | std::unique_ptr<content::DownloadManager> download_manager) { |
| 632 | SetDownloadManager(browser_context, std::move(download_manager)); |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 633 | } |
| 634 | |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 635 | // static |
Marijn Kruisselbrink | 83e5cdb | 2019-06-20 00:06:28 | [diff] [blame] | 636 | void BrowserContext::Initialize(BrowserContext* browser_context, |
| 637 | const base::FilePath& path) { |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 638 | const base::Token new_group = base::Token::CreateRandom(); |
| 639 | ServiceInstanceGroupHolder* holder = static_cast<ServiceInstanceGroupHolder*>( |
| 640 | browser_context->GetUserData(kServiceInstanceGroup)); |
| 641 | if (holder) { |
| 642 | file::ForgetServiceInstanceGroupUserDirAssociation( |
| 643 | holder->instance_group()); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 644 | } |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 645 | file::AssociateServiceInstanceGroupWithUserDir(new_group, path); |
| 646 | RemoveBrowserContextFromInstanceGroupMap(browser_context); |
| 647 | GetTokenToContextMap()[new_group] = browser_context; |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 648 | browser_context->SetUserData( |
Ken Rockot | da7edc6 | 2018-11-10 01:01:45 | [diff] [blame] | 649 | kServiceInstanceGroup, |
| 650 | std::make_unique<ServiceInstanceGroupHolder>(new_group)); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 651 | |
Ken Rockot | fd03e68 | 2019-06-20 21:13:54 | [diff] [blame] | 652 | auto* system_connector = GetSystemConnector(); |
| 653 | if (system_connector && 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()); |
Ken Rockot | fd03e68 | 2019-06-20 21:13:54 | [diff] [blame] | 664 | system_connector->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 | |
Lucas Furukawa Gadani | f4522386 | 2019-06-21 23:11:14 | [diff] [blame] | 776 | const std::string& BrowserContext::UniqueId() { |
Andrey Lushnikov | d39d906 | 2018-04-24 17:33:35 | [diff] [blame] | 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 | |
Lucas Furukawa Gadani | 0a70be9 | 2019-06-28 17:31:26 | [diff] [blame^] | 828 | SharedCorsOriginAccessList* BrowserContext::GetSharedCorsOriginAccessList() { |
Takashi Toyoshima | 0190a3b | 2019-01-21 07:39:06 | [diff] [blame] | 829 | // Need to return a valid instance regardless of CORS bypass supports. |
| 830 | static const base::NoDestructor<scoped_refptr<SharedCorsOriginAccessList>> |
| 831 | empty_list(SharedCorsOriginAccessList::Create()); |
| 832 | return empty_list->get(); |
| 833 | } |
| 834 | |
Sam Goto | 0230b71 | 2019-05-14 00:30:51 | [diff] [blame] | 835 | SmsService* BrowserContext::GetSmsService() { |
| 836 | return nullptr; |
| 837 | } |
| 838 | |
Marijn Kruisselbrink | 83e5cdb | 2019-06-20 00:06:28 | [diff] [blame] | 839 | NativeFileSystemPermissionContext* |
| 840 | BrowserContext::GetNativeFileSystemPermissionContext() { |
| 841 | return nullptr; |
| 842 | } |
| 843 | |
Rayan Kanso | 03a847b | 2019-06-27 21:00:09 | [diff] [blame] | 844 | ContentIndexProvider* BrowserContext::GetContentIndexProvider() { |
| 845 | return nullptr; |
| 846 | } |
| 847 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 848 | } // namespace content |