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