[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 | |
mmenke | c0b2b8b1 | 2017-04-21 16:27:52 | [diff] [blame] | 16 | #include "base/base64.h" |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 17 | #include "base/command_line.h" |
ben | cccfe2a | 2016-03-05 16:54:14 | [diff] [blame] | 18 | #include "base/guid.h" |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 19 | #include "base/lazy_instance.h" |
mmenke | c0b2b8b1 | 2017-04-21 16:27:52 | [diff] [blame] | 20 | #include "base/logging.h" |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 21 | #include "base/macros.h" |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 22 | #include "base/memory/ptr_util.h" |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 23 | #include "base/rand_util.h" |
ben | 21a34c25 | 2016-06-29 22:24:37 | [diff] [blame] | 24 | #include "base/threading/thread_task_runner_handle.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 25 | #include "build/build_config.h" |
dmurph | 7ac019a | 2016-05-13 00:13:17 | [diff] [blame] | 26 | #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 27 | #include "content/browser/browsing_data/browsing_data_remover_impl.h" |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 28 | #include "content/browser/download/download_manager_impl.h" |
[email protected] | c4d28166 | 2013-03-31 00:35:08 | [diff] [blame] | 29 | #include "content/browser/indexed_db/indexed_db_context_impl.h" |
[email protected] | 678c036 | 2012-12-05 08:02:44 | [diff] [blame] | 30 | #include "content/browser/loader/resource_dispatcher_host_impl.h" |
mvanouwerkerk | 17205ea | 2014-11-07 17:30:15 | [diff] [blame] | 31 | #include "content/browser/push_messaging/push_messaging_router.h" |
Ken Rockot | c7a279c | 2017-05-04 23:51:45 | [diff] [blame^] | 32 | #include "content/browser/service_manager/common_browser_interfaces.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 33 | #include "content/browser/storage_partition_impl_map.h" |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 34 | #include "content/common/child_process_host_impl.h" |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 35 | #include "content/public/browser/blob_handle.h" |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 36 | #include "content/public/browser/browser_thread.h" |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 37 | #include "content/public/browser/content_browser_client.h" |
falken | 04a6912a | 2016-09-23 21:06:29 | [diff] [blame] | 38 | #include "content/public/browser/render_process_host.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 39 | #include "content/public/browser/site_instance.h" |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 40 | #include "content/public/common/content_switches.h" |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 41 | #include "content/public/common/service_manager_connection.h" |
ben | 51bb6c6 | 2016-11-17 20:15:57 | [diff] [blame] | 42 | #include "content/public/common/service_names.mojom.h" |
[email protected] | 4d7c4ef | 2012-03-16 01:47:12 | [diff] [blame] | 43 | #include "net/cookies/cookie_store.h" |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 44 | #include "net/ssl/channel_id_service.h" |
| 45 | #include "net/ssl/channel_id_store.h" |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 46 | #include "net/url_request/url_request_context.h" |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 47 | #include "net/url_request/url_request_context_getter.h" |
ben | 768c8dc | 2016-08-12 00:26:50 | [diff] [blame] | 48 | #include "services/file/file_service.h" |
ben | aabad0b | 2016-11-16 23:54:17 | [diff] [blame] | 49 | #include "services/file/public/interfaces/constants.mojom.h" |
ben | 768c8dc | 2016-08-12 00:26:50 | [diff] [blame] | 50 | #include "services/file/user_id_map.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 51 | #include "services/service_manager/public/cpp/connector.h" |
| 52 | #include "services/service_manager/public/interfaces/service.mojom.h" |
pilgrim | e92c5fcd | 2014-09-10 23:31:23 | [diff] [blame] | 53 | #include "storage/browser/database/database_tracker.h" |
| 54 | #include "storage/browser/fileapi/external_mount_points.h" |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 55 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 56 | using base::UserDataAdapter; |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 57 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 58 | namespace content { |
| 59 | |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 60 | namespace { |
| 61 | |
scottmg | 5e65e3a | 2017-03-08 08:48:46 | [diff] [blame] | 62 | base::LazyInstance<std::map<std::string, BrowserContext*>>::DestructorAtExit |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 63 | g_user_id_to_context = LAZY_INSTANCE_INITIALIZER; |
| 64 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 65 | class ServiceUserIdHolder : public base::SupportsUserData::Data { |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 66 | public: |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 67 | explicit ServiceUserIdHolder(const std::string& user_id) |
| 68 | : user_id_(user_id) {} |
| 69 | ~ServiceUserIdHolder() override {} |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 70 | |
| 71 | const std::string& user_id() const { return user_id_; } |
| 72 | |
| 73 | private: |
| 74 | std::string user_id_; |
| 75 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 76 | DISALLOW_COPY_AND_ASSIGN(ServiceUserIdHolder); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 77 | }; |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 78 | |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 79 | // Key names on BrowserContext. |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 80 | const char kBrowsingDataRemoverKey[] = "browsing-data-remover"; |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 81 | const char kDownloadManagerKeyName[] = "download_manager"; |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 82 | const char kMojoWasInitialized[] = "mojo-was-initialized"; |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 83 | const char kServiceManagerConnection[] = "service-manager-connection"; |
| 84 | const char kServiceUserId[] = "service-user-id"; |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 85 | const char kStoragePartitionMapKeyName[] = "content_storage_partition_map"; |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 86 | |
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 87 | #if defined(OS_CHROMEOS) |
| 88 | const char kMountPointsKey[] = "mount_points"; |
| 89 | #endif // defined(OS_CHROMEOS) |
| 90 | |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 91 | void RemoveBrowserContextFromUserIdMap(BrowserContext* browser_context) { |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 92 | ServiceUserIdHolder* holder = static_cast<ServiceUserIdHolder*>( |
| 93 | browser_context->GetUserData(kServiceUserId)); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 94 | if (holder) { |
| 95 | auto it = g_user_id_to_context.Get().find(holder->user_id()); |
| 96 | if (it != g_user_id_to_context.Get().end()) |
| 97 | g_user_id_to_context.Get().erase(it); |
| 98 | } |
| 99 | } |
| 100 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 101 | StoragePartitionImplMap* GetStoragePartitionMap( |
| 102 | BrowserContext* browser_context) { |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 103 | StoragePartitionImplMap* partition_map = |
| 104 | static_cast<StoragePartitionImplMap*>( |
a.cavalcanti | ffab7376 | 2015-08-15 02:55:48 | [diff] [blame] | 105 | browser_context->GetUserData(kStoragePartitionMapKeyName)); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 106 | if (!partition_map) { |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 107 | auto partition_map_owned = |
| 108 | base::MakeUnique<StoragePartitionImplMap>(browser_context); |
| 109 | partition_map = partition_map_owned.get(); |
| 110 | browser_context->SetUserData(kStoragePartitionMapKeyName, |
| 111 | std::move(partition_map_owned)); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 112 | } |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 113 | return partition_map; |
| 114 | } |
| 115 | |
| 116 | StoragePartition* GetStoragePartitionFromConfig( |
| 117 | BrowserContext* browser_context, |
| 118 | const std::string& partition_domain, |
| 119 | const std::string& partition_name, |
| 120 | bool in_memory) { |
| 121 | StoragePartitionImplMap* partition_map = |
| 122 | GetStoragePartitionMap(browser_context); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 123 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 124 | if (browser_context->IsOffTheRecord()) |
| 125 | in_memory = true; |
| 126 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 127 | return partition_map->Get(partition_domain, partition_name, in_memory); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 128 | } |
| 129 | |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 130 | void SaveSessionStateOnIOThread( |
| 131 | const scoped_refptr<net::URLRequestContextGetter>& context_getter, |
[email protected] | 98d6d456 | 2014-06-25 20:57:55 | [diff] [blame] | 132 | AppCacheServiceImpl* appcache_service) { |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 133 | net::URLRequestContext* context = context_getter->GetURLRequestContext(); |
mmenke | ded79da | 2016-02-06 08:28:51 | [diff] [blame] | 134 | context->cookie_store()->SetForceKeepSessionState(); |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 135 | context->channel_id_service()->GetChannelIDStore()-> |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 136 | SetForceKeepSessionState(); |
| 137 | appcache_service->set_force_keep_session_state(); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 138 | } |
| 139 | |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 140 | void SaveSessionStateOnIndexedDBThread( |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 141 | scoped_refptr<IndexedDBContextImpl> indexed_db_context) { |
[email protected] | bf510ed | 2012-06-05 08:31:43 | [diff] [blame] | 142 | indexed_db_context->SetForceKeepSessionState(); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 143 | } |
| 144 | |
falken | 41f417516 | 2014-10-29 07:03:41 | [diff] [blame] | 145 | void ShutdownServiceWorkerContext(StoragePartition* partition) { |
| 146 | ServiceWorkerContextWrapper* wrapper = |
| 147 | static_cast<ServiceWorkerContextWrapper*>( |
| 148 | partition->GetServiceWorkerContext()); |
| 149 | wrapper->process_manager()->Shutdown(); |
| 150 | } |
| 151 | |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 152 | void SetDownloadManager( |
| 153 | BrowserContext* context, |
| 154 | std::unique_ptr<content::DownloadManager> download_manager) { |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 155 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 156 | DCHECK(download_manager); |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 157 | context->SetUserData(kDownloadManagerKeyName, std::move(download_manager)); |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 158 | } |
| 159 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 160 | class BrowserContextServiceManagerConnectionHolder |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 161 | : public base::SupportsUserData::Data { |
| 162 | public: |
ben | aad37ecd | 2017-04-12 22:08:20 | [diff] [blame] | 163 | explicit BrowserContextServiceManagerConnectionHolder( |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 164 | service_manager::mojom::ServiceRequest request) |
ben | aad37ecd | 2017-04-12 22:08:20 | [diff] [blame] | 165 | : service_manager_connection_(ServiceManagerConnection::Create( |
rockot | cef3827 | 2016-07-15 22:47:47 | [diff] [blame] | 166 | std::move(request), |
| 167 | BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))) {} |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 168 | ~BrowserContextServiceManagerConnectionHolder() override {} |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 169 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 170 | ServiceManagerConnection* service_manager_connection() { |
| 171 | return service_manager_connection_.get(); |
| 172 | } |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 173 | |
| 174 | private: |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 175 | std::unique_ptr<ServiceManagerConnection> service_manager_connection_; |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 176 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 177 | DISALLOW_COPY_AND_ASSIGN(BrowserContextServiceManagerConnectionHolder); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 178 | }; |
| 179 | |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 180 | } // namespace |
| 181 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 182 | // static |
| 183 | void BrowserContext::AsyncObliterateStoragePartition( |
| 184 | BrowserContext* browser_context, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 185 | const GURL& site, |
| 186 | const base::Closure& on_gc_required) { |
| 187 | GetStoragePartitionMap(browser_context)->AsyncObliterate(site, |
| 188 | on_gc_required); |
| 189 | } |
| 190 | |
| 191 | // static |
| 192 | void BrowserContext::GarbageCollectStoragePartitions( |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 193 | BrowserContext* browser_context, |
| 194 | std::unique_ptr<base::hash_set<base::FilePath>> active_paths, |
| 195 | const base::Closure& done) { |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 196 | GetStoragePartitionMap(browser_context) |
| 197 | ->GarbageCollect(std::move(active_paths), done); |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 198 | } |
| 199 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 200 | DownloadManager* BrowserContext::GetDownloadManager( |
| 201 | BrowserContext* context) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 202 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 203 | if (!context->GetUserData(kDownloadManagerKeyName)) { |
[email protected] | eba4a4d | 2013-05-29 02:18:06 | [diff] [blame] | 204 | DownloadManager* download_manager = |
[email protected] | d25fda1 | 2012-06-12 17:05:03 | [diff] [blame] | 205 | new DownloadManagerImpl( |
[email protected] | 1679869 | 2013-04-23 18:08:38 | [diff] [blame] | 206 | GetContentClient()->browser()->GetNetLog(), context); |
[email protected] | d25fda1 | 2012-06-12 17:05:03 | [diff] [blame] | 207 | |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 208 | SetDownloadManager(context, base::WrapUnique(download_manager)); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 209 | download_manager->SetDelegate(context->GetDownloadManagerDelegate()); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 210 | } |
| 211 | |
[email protected] | eba4a4d | 2013-05-29 02:18:06 | [diff] [blame] | 212 | return static_cast<DownloadManager*>( |
| 213 | context->GetUserData(kDownloadManagerKeyName)); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 214 | } |
| 215 | |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 216 | // static |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 217 | storage::ExternalMountPoints* BrowserContext::GetMountPoints( |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 218 | BrowserContext* context) { |
| 219 | // Ensure that these methods are called on the UI thread, except for |
| 220 | // unittests where a UI thread might not have been created. |
| 221 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 222 | !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); |
| 223 | |
| 224 | #if defined(OS_CHROMEOS) |
| 225 | if (!context->GetUserData(kMountPointsKey)) { |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 226 | scoped_refptr<storage::ExternalMountPoints> mount_points = |
| 227 | storage::ExternalMountPoints::CreateRefCounted(); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 228 | context->SetUserData( |
| 229 | kMountPointsKey, |
avi | cb129c0 | 2017-05-03 06:49:29 | [diff] [blame] | 230 | base::MakeUnique<UserDataAdapter<storage::ExternalMountPoints>>( |
| 231 | mount_points.get())); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 232 | } |
| 233 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 234 | return UserDataAdapter<storage::ExternalMountPoints>::Get(context, |
| 235 | kMountPointsKey); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 236 | #else |
| 237 | return NULL; |
| 238 | #endif |
| 239 | } |
| 240 | |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 241 | // static |
| 242 | content::BrowsingDataRemover* content::BrowserContext::GetBrowsingDataRemover( |
| 243 | BrowserContext* context) { |
| 244 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 245 | |
| 246 | if (!context->GetUserData(kBrowsingDataRemoverKey)) { |
| 247 | std::unique_ptr<BrowsingDataRemoverImpl> remover = |
| 248 | base::MakeUnique<BrowsingDataRemoverImpl>(context); |
| 249 | remover->SetEmbedderDelegate(context->GetBrowsingDataRemoverDelegate()); |
| 250 | context->SetUserData(kBrowsingDataRemoverKey, std::move(remover)); |
| 251 | } |
| 252 | |
| 253 | return static_cast<BrowsingDataRemoverImpl*>( |
| 254 | context->GetUserData(kBrowsingDataRemoverKey)); |
| 255 | } |
| 256 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 257 | StoragePartition* BrowserContext::GetStoragePartition( |
| 258 | BrowserContext* browser_context, |
| 259 | SiteInstance* site_instance) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 260 | std::string partition_domain; |
| 261 | std::string partition_name; |
| 262 | bool in_memory = false; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 263 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 264 | if (site_instance) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 265 | GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 266 | browser_context, site_instance->GetSiteURL(), true, |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 267 | &partition_domain, &partition_name, &in_memory); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 268 | } |
| 269 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 270 | return GetStoragePartitionFromConfig( |
| 271 | browser_context, partition_domain, partition_name, in_memory); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 272 | } |
| 273 | |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 274 | StoragePartition* BrowserContext::GetStoragePartitionForSite( |
| 275 | BrowserContext* browser_context, |
| 276 | const GURL& site) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 277 | std::string partition_domain; |
| 278 | std::string partition_name; |
| 279 | bool in_memory; |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 280 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 281 | GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 282 | browser_context, site, true, &partition_domain, &partition_name, |
| 283 | &in_memory); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 284 | |
| 285 | return GetStoragePartitionFromConfig( |
| 286 | browser_context, partition_domain, partition_name, in_memory); |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 287 | } |
| 288 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 289 | void BrowserContext::ForEachStoragePartition( |
| 290 | BrowserContext* browser_context, |
| 291 | const StoragePartitionCallback& callback) { |
| 292 | StoragePartitionImplMap* partition_map = |
| 293 | static_cast<StoragePartitionImplMap*>( |
a.cavalcanti | ffab7376 | 2015-08-15 02:55:48 | [diff] [blame] | 294 | browser_context->GetUserData(kStoragePartitionMapKeyName)); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 295 | if (!partition_map) |
| 296 | return; |
| 297 | |
| 298 | partition_map->ForEach(callback); |
| 299 | } |
| 300 | |
| 301 | StoragePartition* BrowserContext::GetDefaultStoragePartition( |
| 302 | BrowserContext* browser_context) { |
| 303 | return GetStoragePartition(browser_context, NULL); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 304 | } |
| 305 | |
tbarzic | db71268 | 2015-03-06 06:05:41 | [diff] [blame] | 306 | // static |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 307 | void BrowserContext::CreateMemoryBackedBlob(BrowserContext* browser_context, |
| 308 | const char* data, size_t length, |
| 309 | const BlobCallback& callback) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 310 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 311 | |
| 312 | ChromeBlobStorageContext* blob_context = |
| 313 | ChromeBlobStorageContext::GetFor(browser_context); |
| 314 | BrowserThread::PostTaskAndReplyWithResult( |
| 315 | BrowserThread::IO, FROM_HERE, |
| 316 | base::Bind(&ChromeBlobStorageContext::CreateMemoryBackedBlob, |
| 317 | make_scoped_refptr(blob_context), data, length), |
| 318 | callback); |
| 319 | } |
| 320 | |
[email protected] | 66e53d028 | 2014-08-07 10:04:35 | [diff] [blame] | 321 | // static |
tbarzic | db71268 | 2015-03-06 06:05:41 | [diff] [blame] | 322 | void BrowserContext::CreateFileBackedBlob( |
| 323 | BrowserContext* browser_context, |
| 324 | const base::FilePath& path, |
| 325 | int64_t offset, |
| 326 | int64_t size, |
| 327 | const base::Time& expected_modification_time, |
| 328 | const BlobCallback& callback) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 329 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
tbarzic | db71268 | 2015-03-06 06:05:41 | [diff] [blame] | 330 | |
| 331 | ChromeBlobStorageContext* blob_context = |
| 332 | ChromeBlobStorageContext::GetFor(browser_context); |
| 333 | BrowserThread::PostTaskAndReplyWithResult( |
| 334 | BrowserThread::IO, FROM_HERE, |
| 335 | base::Bind(&ChromeBlobStorageContext::CreateFileBackedBlob, |
| 336 | make_scoped_refptr(blob_context), path, offset, size, |
| 337 | expected_modification_time), |
| 338 | callback); |
| 339 | } |
| 340 | |
| 341 | // static |
[email protected] | 66e53d028 | 2014-08-07 10:04:35 | [diff] [blame] | 342 | void BrowserContext::DeliverPushMessage( |
| 343 | BrowserContext* browser_context, |
| 344 | const GURL& origin, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 345 | int64_t service_worker_registration_id, |
harkness | dd4d2b2 | 2016-01-27 19:26:43 | [diff] [blame] | 346 | const PushEventPayload& payload, |
johnme | a80c255 | 2014-10-17 14:51:40 | [diff] [blame] | 347 | const base::Callback<void(PushDeliveryStatus)>& callback) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 348 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
harkness | dd4d2b2 | 2016-01-27 19:26:43 | [diff] [blame] | 349 | PushMessagingRouter::DeliverMessage(browser_context, origin, |
| 350 | service_worker_registration_id, payload, |
| 351 | callback); |
[email protected] | 66e53d028 | 2014-08-07 10:04:35 | [diff] [blame] | 352 | } |
| 353 | |
falken | 41f417516 | 2014-10-29 07:03:41 | [diff] [blame] | 354 | // static |
| 355 | void BrowserContext::NotifyWillBeDestroyed(BrowserContext* browser_context) { |
| 356 | // Service Workers must shutdown before the browser context is destroyed, |
| 357 | // since they keep render process hosts alive and the codebase assumes that |
| 358 | // render process hosts die before their profile (browser context) dies. |
| 359 | ForEachStoragePartition(browser_context, |
| 360 | base::Bind(ShutdownServiceWorkerContext)); |
falken | 04a6912a | 2016-09-23 21:06:29 | [diff] [blame] | 361 | |
| 362 | // Shared workers also keep render process hosts alive, and are expected to |
| 363 | // return ref counts to 0 after documents close. However, shared worker |
| 364 | // bookkeeping is done on the IO thread and we want to ensure the hosts are |
| 365 | // destructed now, so forcibly release their ref counts here. |
| 366 | for (RenderProcessHost::iterator host_iterator = |
| 367 | RenderProcessHost::AllHostsIterator(); |
| 368 | !host_iterator.IsAtEnd(); host_iterator.Advance()) { |
| 369 | RenderProcessHost* host = host_iterator.GetCurrentValue(); |
| 370 | if (host->GetBrowserContext() == browser_context) |
| 371 | host->ForceReleaseWorkerRefCounts(); |
| 372 | } |
falken | 41f417516 | 2014-10-29 07:03:41 | [diff] [blame] | 373 | } |
| 374 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 375 | void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) { |
[email protected] | 7e26ac9 | 2012-02-27 20:15:05 | [diff] [blame] | 376 | // This will be enough to tickle initialization of BrowserContext if |
| 377 | // necessary, which initializes ResourceContext. The reason we don't call |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 378 | // ResourceContext::InitializeResourceContext() directly here is that |
| 379 | // ResourceContext initialization may call back into BrowserContext |
| 380 | // and when that call returns it'll end rewriting its UserData map. It will |
| 381 | // end up rewriting the same value but this still causes a race condition. |
| 382 | // |
| 383 | // See http://crbug.com/115678. |
| 384 | GetDefaultStoragePartition(context); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 385 | } |
| 386 | |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 387 | void BrowserContext::SaveSessionState(BrowserContext* browser_context) { |
[email protected] | 5c8e67c | 2012-08-29 00:48:52 | [diff] [blame] | 388 | GetDefaultStoragePartition(browser_context)->GetDatabaseTracker()-> |
| 389 | SetForceKeepSessionState(); |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 390 | StoragePartition* storage_partition = |
| 391 | BrowserContext::GetDefaultStoragePartition(browser_context); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 392 | |
| 393 | if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
| 394 | BrowserThread::PostTask( |
| 395 | BrowserThread::IO, FROM_HERE, |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 396 | base::Bind( |
| 397 | &SaveSessionStateOnIOThread, |
jam | b84299e | 2016-04-12 16:58:59 | [diff] [blame] | 398 | make_scoped_refptr(BrowserContext::GetDefaultStoragePartition( |
| 399 | browser_context)->GetURLRequestContext()), |
[email protected] | 98d6d456 | 2014-06-25 20:57:55 | [diff] [blame] | 400 | static_cast<AppCacheServiceImpl*>( |
[email protected] | 63ef8551 | 2014-06-05 14:21:26 | [diff] [blame] | 401 | storage_partition->GetAppCacheService()))); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 402 | } |
| 403 | |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 404 | DOMStorageContextWrapper* dom_storage_context_proxy = |
| 405 | static_cast<DOMStorageContextWrapper*>( |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 406 | storage_partition->GetDOMStorageContext()); |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 407 | dom_storage_context_proxy->SetForceKeepSessionState(); |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 408 | |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 409 | IndexedDBContextImpl* indexed_db_context_impl = |
| 410 | static_cast<IndexedDBContextImpl*>( |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 411 | storage_partition->GetIndexedDBContext()); |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 412 | // No task runner in unit tests. |
| 413 | if (indexed_db_context_impl->TaskRunner()) { |
| 414 | indexed_db_context_impl->TaskRunner()->PostTask( |
| 415 | FROM_HERE, |
| 416 | base::Bind(&SaveSessionStateOnIndexedDBThread, |
| 417 | make_scoped_refptr(indexed_db_context_impl))); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 421 | void BrowserContext::SetDownloadManagerForTesting( |
| 422 | BrowserContext* browser_context, |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 423 | std::unique_ptr<content::DownloadManager> download_manager) { |
| 424 | SetDownloadManager(browser_context, std::move(download_manager)); |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 425 | } |
| 426 | |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 427 | // static |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 428 | void BrowserContext::Initialize( |
| 429 | BrowserContext* browser_context, |
| 430 | const base::FilePath& path) { |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 431 | |
| 432 | std::string new_id; |
| 433 | if (GetContentClient() && GetContentClient()->browser()) { |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 434 | new_id = GetContentClient()->browser()->GetServiceUserIdForBrowserContext( |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 435 | browser_context); |
| 436 | } else { |
| 437 | // Some test scenarios initialize a BrowserContext without a content client. |
ben | cccfe2a | 2016-03-05 16:54:14 | [diff] [blame] | 438 | new_id = base::GenerateGUID(); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 439 | } |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 440 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 441 | ServiceUserIdHolder* holder = static_cast<ServiceUserIdHolder*>( |
| 442 | browser_context->GetUserData(kServiceUserId)); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 443 | if (holder) |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 444 | file::ForgetServiceUserIdUserDirAssociation(holder->user_id()); |
| 445 | file::AssociateServiceUserIdWithUserDir(new_id, path); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 446 | RemoveBrowserContextFromUserIdMap(browser_context); |
| 447 | g_user_id_to_context.Get()[new_id] = browser_context; |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 448 | browser_context->SetUserData(kServiceUserId, |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 449 | base::MakeUnique<ServiceUserIdHolder>(new_id)); |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 450 | |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 451 | browser_context->SetUserData( |
| 452 | kMojoWasInitialized, base::MakeUnique<base::SupportsUserData::Data>()); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 453 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 454 | ServiceManagerConnection* service_manager_connection = |
| 455 | ServiceManagerConnection::GetForProcess(); |
fdoray | 4f155f0 | 2016-10-12 11:28:50 | [diff] [blame] | 456 | if (service_manager_connection && base::ThreadTaskRunnerHandle::IsSet()) { |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 457 | // NOTE: Many unit tests create a TestBrowserContext without initializing |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 458 | // Mojo or the global service manager connection. |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 459 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 460 | service_manager::mojom::ServicePtr service; |
blundell | c17a15d | 2016-12-21 13:52:10 | [diff] [blame] | 461 | service_manager::mojom::ServiceRequest service_request(&service); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 462 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 463 | service_manager::mojom::PIDReceiverPtr pid_receiver; |
ben | e6a9f01 | 2017-01-07 00:43:43 | [diff] [blame] | 464 | service_manager::Identity identity(mojom::kBrowserServiceName, new_id); |
ben | bd3c248 | 2017-01-07 05:48:21 | [diff] [blame] | 465 | service_manager_connection->GetConnector()->StartService( |
ben | e6a9f01 | 2017-01-07 00:43:43 | [diff] [blame] | 466 | identity, std::move(service), mojo::MakeRequest(&pid_receiver)); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 467 | pid_receiver->SetPID(base::GetCurrentProcId()); |
| 468 | |
ben | aad37ecd | 2017-04-12 22:08:20 | [diff] [blame] | 469 | service_manager_connection->GetConnector()->StartService(identity); |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 470 | BrowserContextServiceManagerConnectionHolder* connection_holder = |
| 471 | new BrowserContextServiceManagerConnectionHolder( |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 472 | std::move(service_request)); |
avi | 1ed4a437 | 2017-04-25 05:39:41 | [diff] [blame] | 473 | browser_context->SetUserData(kServiceManagerConnection, |
| 474 | base::WrapUnique(connection_holder)); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 475 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 476 | ServiceManagerConnection* connection = |
| 477 | connection_holder->service_manager_connection(); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 478 | |
ben | 146248de | 2016-06-14 15:24:59 | [diff] [blame] | 479 | // New embedded service factories should be added to |connection| here. |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 480 | |
| 481 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 482 | switches::kMojoLocalStorage)) { |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 483 | ServiceInfo info; |
| 484 | info.factory = |
ben | 768c8dc | 2016-08-12 00:26:50 | [diff] [blame] | 485 | base::Bind(&file::CreateFileService, |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 486 | BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), |
| 487 | BrowserThread::GetTaskRunnerForThread(BrowserThread::DB)); |
ben | aabad0b | 2016-11-16 23:54:17 | [diff] [blame] | 488 | connection->AddEmbeddedService(file::mojom::kServiceName, info); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 489 | } |
tibell | ab3d36b | 2017-03-10 02:57:25 | [diff] [blame] | 490 | |
| 491 | ContentBrowserClient::StaticServiceMap services; |
| 492 | browser_context->RegisterInProcessServices(&services); |
| 493 | for (const auto& entry : services) { |
| 494 | connection->AddEmbeddedService(entry.first, entry.second); |
| 495 | } |
Ken Rockot | c7a279c | 2017-05-04 23:51:45 | [diff] [blame^] | 496 | |
| 497 | RegisterCommonBrowserInterfaces(connection); |
sammc | 030f501 | 2017-03-13 02:28:45 | [diff] [blame] | 498 | connection->Start(); |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 499 | } |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 500 | } |
| 501 | |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 502 | // static |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 503 | const std::string& BrowserContext::GetServiceUserIdFor( |
ben | cccfe2a | 2016-03-05 16:54:14 | [diff] [blame] | 504 | BrowserContext* browser_context) { |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 505 | CHECK(browser_context->GetUserData(kMojoWasInitialized)) |
| 506 | << "Attempting to get the mojo user id for a BrowserContext that was " |
| 507 | << "never Initialize()ed."; |
| 508 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 509 | ServiceUserIdHolder* holder = static_cast<ServiceUserIdHolder*>( |
| 510 | browser_context->GetUserData(kServiceUserId)); |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 511 | return holder->user_id(); |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 512 | } |
| 513 | |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 514 | // static |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 515 | BrowserContext* BrowserContext::GetBrowserContextForServiceUserId( |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 516 | const std::string& user_id) { |
| 517 | auto it = g_user_id_to_context.Get().find(user_id); |
| 518 | return it != g_user_id_to_context.Get().end() ? it->second : nullptr; |
| 519 | } |
| 520 | |
| 521 | // static |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 522 | service_manager::Connector* BrowserContext::GetConnectorFor( |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 523 | BrowserContext* browser_context) { |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 524 | ServiceManagerConnection* connection = |
| 525 | GetServiceManagerConnectionFor(browser_context); |
ben | 5be0b913 | 2016-08-03 00:17:18 | [diff] [blame] | 526 | return connection ? connection->GetConnector() : nullptr; |
| 527 | } |
| 528 | |
| 529 | // static |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 530 | ServiceManagerConnection* BrowserContext::GetServiceManagerConnectionFor( |
ben | 5be0b913 | 2016-08-03 00:17:18 | [diff] [blame] | 531 | BrowserContext* browser_context) { |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 532 | BrowserContextServiceManagerConnectionHolder* connection_holder = |
| 533 | static_cast<BrowserContextServiceManagerConnectionHolder*>( |
| 534 | browser_context->GetUserData(kServiceManagerConnection)); |
| 535 | return connection_holder ? connection_holder->service_manager_connection() |
| 536 | : nullptr; |
rockot | 963ad3e8 | 2016-04-13 16:33:23 | [diff] [blame] | 537 | } |
| 538 | |
mmenke | c0b2b8b1 | 2017-04-21 16:27:52 | [diff] [blame] | 539 | BrowserContext::BrowserContext() |
| 540 | : media_device_id_salt_(CreateRandomMediaDeviceIDSalt()) {} |
| 541 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 542 | BrowserContext::~BrowserContext() { |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 543 | CHECK(GetUserData(kMojoWasInitialized)) |
| 544 | << "Attempting to destroy a BrowserContext that never called " |
| 545 | << "Initialize()"; |
| 546 | |
kinuko | f6ed359c | 2016-07-26 13:27:21 | [diff] [blame] | 547 | DCHECK(!GetUserData(kStoragePartitionMapKeyName)) |
| 548 | << "StoragePartitionMap is not shut down properly"; |
| 549 | |
ben | 6c85c449 | 2016-06-16 20:40:51 | [diff] [blame] | 550 | RemoveBrowserContextFromUserIdMap(this); |
| 551 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 552 | if (GetUserData(kDownloadManagerKeyName)) |
| 553 | GetDownloadManager(this)->Shutdown(); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 554 | } |
| 555 | |
kinuko | f6ed359c | 2016-07-26 13:27:21 | [diff] [blame] | 556 | void BrowserContext::ShutdownStoragePartitions() { |
| 557 | if (GetUserData(kStoragePartitionMapKeyName)) |
| 558 | RemoveUserData(kStoragePartitionMapKeyName); |
| 559 | } |
| 560 | |
mmenke | c0b2b8b1 | 2017-04-21 16:27:52 | [diff] [blame] | 561 | std::string BrowserContext::GetMediaDeviceIDSalt() { |
| 562 | return media_device_id_salt_; |
| 563 | } |
| 564 | |
| 565 | // static |
| 566 | std::string BrowserContext::CreateRandomMediaDeviceIDSalt() { |
| 567 | std::string salt; |
| 568 | base::Base64Encode(base::RandBytesAsString(16), &salt); |
| 569 | DCHECK(!salt.empty()); |
| 570 | return salt; |
| 571 | } |
| 572 | |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 573 | BrowsingDataRemoverDelegate* BrowserContext::GetBrowsingDataRemoverDelegate() { |
| 574 | return nullptr; |
| 575 | } |
| 576 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 577 | } // namespace content |