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