[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> |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame^] | 9 | #include <utility> |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 10 | |
| 11 | #include "build/build_config.h" |
| 12 | |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 13 | #if !defined(OS_IOS) |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 14 | #include "content/browser/download/download_manager_impl.h" |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 15 | #include "content/browser/fileapi/chrome_blob_storage_context.h" |
[email protected] | c4d28166 | 2013-03-31 00:35:08 | [diff] [blame] | 16 | #include "content/browser/indexed_db/indexed_db_context_impl.h" |
[email protected] | 678c036 | 2012-12-05 08:02:44 | [diff] [blame] | 17 | #include "content/browser/loader/resource_dispatcher_host_impl.h" |
mvanouwerkerk | 17205ea | 2014-11-07 17:30:15 | [diff] [blame] | 18 | #include "content/browser/push_messaging/push_messaging_router.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 19 | #include "content/browser/storage_partition_impl_map.h" |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 20 | #include "content/common/child_process_host_impl.h" |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 21 | #include "content/public/browser/blob_handle.h" |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 22 | #include "content/public/browser/browser_thread.h" |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 23 | #include "content/public/browser/content_browser_client.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 24 | #include "content/public/browser/site_instance.h" |
[email protected] | 4d7c4ef | 2012-03-16 01:47:12 | [diff] [blame] | 25 | #include "net/cookies/cookie_monster.h" |
| 26 | #include "net/cookies/cookie_store.h" |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 27 | #include "net/ssl/channel_id_service.h" |
| 28 | #include "net/ssl/channel_id_store.h" |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 29 | #include "net/url_request/url_request_context.h" |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 30 | #include "net/url_request/url_request_context_getter.h" |
pilgrim | e92c5fcd | 2014-09-10 23:31:23 | [diff] [blame] | 31 | #include "storage/browser/database/database_tracker.h" |
| 32 | #include "storage/browser/fileapi/external_mount_points.h" |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 33 | #endif // !OS_IOS |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 34 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 35 | using base::UserDataAdapter; |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 36 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 37 | namespace content { |
| 38 | |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 39 | // Only ~BrowserContext() is needed on iOS. |
| 40 | #if !defined(OS_IOS) |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 41 | namespace { |
| 42 | |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 43 | // Key names on BrowserContext. |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 44 | const char kDownloadManagerKeyName[] = "download_manager"; |
a.cavalcanti | ffab7376 | 2015-08-15 02:55:48 | [diff] [blame] | 45 | const char kStoragePartitionMapKeyName[] = "content_storage_partition_map"; |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 46 | |
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 47 | #if defined(OS_CHROMEOS) |
| 48 | const char kMountPointsKey[] = "mount_points"; |
| 49 | #endif // defined(OS_CHROMEOS) |
| 50 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 51 | StoragePartitionImplMap* GetStoragePartitionMap( |
| 52 | BrowserContext* browser_context) { |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 53 | StoragePartitionImplMap* partition_map = |
| 54 | static_cast<StoragePartitionImplMap*>( |
a.cavalcanti | ffab7376 | 2015-08-15 02:55:48 | [diff] [blame] | 55 | browser_context->GetUserData(kStoragePartitionMapKeyName)); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 56 | if (!partition_map) { |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 57 | partition_map = new StoragePartitionImplMap(browser_context); |
a.cavalcanti | ffab7376 | 2015-08-15 02:55:48 | [diff] [blame] | 58 | browser_context->SetUserData(kStoragePartitionMapKeyName, partition_map); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 59 | } |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 60 | return partition_map; |
| 61 | } |
| 62 | |
| 63 | StoragePartition* GetStoragePartitionFromConfig( |
| 64 | BrowserContext* browser_context, |
| 65 | const std::string& partition_domain, |
| 66 | const std::string& partition_name, |
| 67 | bool in_memory) { |
| 68 | StoragePartitionImplMap* partition_map = |
| 69 | GetStoragePartitionMap(browser_context); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 70 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 71 | if (browser_context->IsOffTheRecord()) |
| 72 | in_memory = true; |
| 73 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 74 | return partition_map->Get(partition_domain, partition_name, in_memory); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 75 | } |
| 76 | |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 77 | void SaveSessionStateOnIOThread( |
| 78 | const scoped_refptr<net::URLRequestContextGetter>& context_getter, |
[email protected] | 98d6d456 | 2014-06-25 20:57:55 | [diff] [blame] | 79 | AppCacheServiceImpl* appcache_service) { |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 80 | net::URLRequestContext* context = context_getter->GetURLRequestContext(); |
| 81 | context->cookie_store()->GetCookieMonster()-> |
[email protected] | bf510ed | 2012-06-05 08:31:43 | [diff] [blame] | 82 | SetForceKeepSessionState(); |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 83 | context->channel_id_service()->GetChannelIDStore()-> |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 84 | SetForceKeepSessionState(); |
| 85 | appcache_service->set_force_keep_session_state(); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 86 | } |
| 87 | |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 88 | void SaveSessionStateOnIndexedDBThread( |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 89 | scoped_refptr<IndexedDBContextImpl> indexed_db_context) { |
[email protected] | bf510ed | 2012-06-05 08:31:43 | [diff] [blame] | 90 | indexed_db_context->SetForceKeepSessionState(); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 91 | } |
| 92 | |
falken | 41f417516 | 2014-10-29 07:03:41 | [diff] [blame] | 93 | void ShutdownServiceWorkerContext(StoragePartition* partition) { |
| 94 | ServiceWorkerContextWrapper* wrapper = |
| 95 | static_cast<ServiceWorkerContextWrapper*>( |
| 96 | partition->GetServiceWorkerContext()); |
| 97 | wrapper->process_manager()->Shutdown(); |
| 98 | } |
| 99 | |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 100 | void SetDownloadManager(BrowserContext* context, |
| 101 | content::DownloadManager* download_manager) { |
| 102 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 103 | DCHECK(download_manager); |
| 104 | context->SetUserData(kDownloadManagerKeyName, download_manager); |
| 105 | } |
| 106 | |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 107 | } // namespace |
| 108 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 109 | // static |
| 110 | void BrowserContext::AsyncObliterateStoragePartition( |
| 111 | BrowserContext* browser_context, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 112 | const GURL& site, |
| 113 | const base::Closure& on_gc_required) { |
| 114 | GetStoragePartitionMap(browser_context)->AsyncObliterate(site, |
| 115 | on_gc_required); |
| 116 | } |
| 117 | |
| 118 | // static |
| 119 | void BrowserContext::GarbageCollectStoragePartitions( |
| 120 | BrowserContext* browser_context, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 121 | scoped_ptr<base::hash_set<base::FilePath> > active_paths, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 122 | const base::Closure& done) { |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame^] | 123 | GetStoragePartitionMap(browser_context) |
| 124 | ->GarbageCollect(std::move(active_paths), done); |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 125 | } |
| 126 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 127 | DownloadManager* BrowserContext::GetDownloadManager( |
| 128 | BrowserContext* context) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 129 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 130 | if (!context->GetUserData(kDownloadManagerKeyName)) { |
[email protected] | eba4a4d | 2013-05-29 02:18:06 | [diff] [blame] | 131 | DownloadManager* download_manager = |
[email protected] | d25fda1 | 2012-06-12 17:05:03 | [diff] [blame] | 132 | new DownloadManagerImpl( |
[email protected] | 1679869 | 2013-04-23 18:08:38 | [diff] [blame] | 133 | GetContentClient()->browser()->GetNetLog(), context); |
[email protected] | d25fda1 | 2012-06-12 17:05:03 | [diff] [blame] | 134 | |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 135 | SetDownloadManager(context, download_manager); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 136 | download_manager->SetDelegate(context->GetDownloadManagerDelegate()); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 137 | } |
| 138 | |
[email protected] | eba4a4d | 2013-05-29 02:18:06 | [diff] [blame] | 139 | return static_cast<DownloadManager*>( |
| 140 | context->GetUserData(kDownloadManagerKeyName)); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 141 | } |
| 142 | |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 143 | // static |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 144 | storage::ExternalMountPoints* BrowserContext::GetMountPoints( |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 145 | BrowserContext* context) { |
| 146 | // Ensure that these methods are called on the UI thread, except for |
| 147 | // unittests where a UI thread might not have been created. |
| 148 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 149 | !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); |
| 150 | |
| 151 | #if defined(OS_CHROMEOS) |
| 152 | if (!context->GetUserData(kMountPointsKey)) { |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 153 | scoped_refptr<storage::ExternalMountPoints> mount_points = |
| 154 | storage::ExternalMountPoints::CreateRefCounted(); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 155 | context->SetUserData( |
| 156 | kMountPointsKey, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 157 | new UserDataAdapter<storage::ExternalMountPoints>(mount_points.get())); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 158 | } |
| 159 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 160 | return UserDataAdapter<storage::ExternalMountPoints>::Get(context, |
| 161 | kMountPointsKey); |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 162 | #else |
| 163 | return NULL; |
| 164 | #endif |
| 165 | } |
| 166 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 167 | StoragePartition* BrowserContext::GetStoragePartition( |
| 168 | BrowserContext* browser_context, |
| 169 | SiteInstance* site_instance) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 170 | std::string partition_domain; |
| 171 | std::string partition_name; |
| 172 | bool in_memory = false; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 173 | |
| 174 | // TODO(ajwong): After GetDefaultStoragePartition() is removed, get rid of |
| 175 | // this conditional and require that |site_instance| is non-NULL. |
| 176 | if (site_instance) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 177 | GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 178 | browser_context, site_instance->GetSiteURL(), true, |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 179 | &partition_domain, &partition_name, &in_memory); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 180 | } |
| 181 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 182 | return GetStoragePartitionFromConfig( |
| 183 | browser_context, partition_domain, partition_name, in_memory); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 184 | } |
| 185 | |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 186 | StoragePartition* BrowserContext::GetStoragePartitionForSite( |
| 187 | BrowserContext* browser_context, |
| 188 | const GURL& site) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 189 | std::string partition_domain; |
| 190 | std::string partition_name; |
| 191 | bool in_memory; |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 192 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 193 | GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 194 | browser_context, site, true, &partition_domain, &partition_name, |
| 195 | &in_memory); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 196 | |
| 197 | return GetStoragePartitionFromConfig( |
| 198 | browser_context, partition_domain, partition_name, in_memory); |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 199 | } |
| 200 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 201 | void BrowserContext::ForEachStoragePartition( |
| 202 | BrowserContext* browser_context, |
| 203 | const StoragePartitionCallback& callback) { |
| 204 | StoragePartitionImplMap* partition_map = |
| 205 | static_cast<StoragePartitionImplMap*>( |
a.cavalcanti | ffab7376 | 2015-08-15 02:55:48 | [diff] [blame] | 206 | browser_context->GetUserData(kStoragePartitionMapKeyName)); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 207 | if (!partition_map) |
| 208 | return; |
| 209 | |
| 210 | partition_map->ForEach(callback); |
| 211 | } |
| 212 | |
| 213 | StoragePartition* BrowserContext::GetDefaultStoragePartition( |
| 214 | BrowserContext* browser_context) { |
| 215 | return GetStoragePartition(browser_context, NULL); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 216 | } |
| 217 | |
tbarzic | db71268 | 2015-03-06 06:05:41 | [diff] [blame] | 218 | // static |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 219 | void BrowserContext::CreateMemoryBackedBlob(BrowserContext* browser_context, |
| 220 | const char* data, size_t length, |
| 221 | const BlobCallback& callback) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 222 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 393b6cb | 2014-05-15 00:55:12 | [diff] [blame] | 223 | |
| 224 | ChromeBlobStorageContext* blob_context = |
| 225 | ChromeBlobStorageContext::GetFor(browser_context); |
| 226 | BrowserThread::PostTaskAndReplyWithResult( |
| 227 | BrowserThread::IO, FROM_HERE, |
| 228 | base::Bind(&ChromeBlobStorageContext::CreateMemoryBackedBlob, |
| 229 | make_scoped_refptr(blob_context), data, length), |
| 230 | callback); |
| 231 | } |
| 232 | |
[email protected] | 66e53d028 | 2014-08-07 10:04:35 | [diff] [blame] | 233 | // static |
tbarzic | db71268 | 2015-03-06 06:05:41 | [diff] [blame] | 234 | void BrowserContext::CreateFileBackedBlob( |
| 235 | BrowserContext* browser_context, |
| 236 | const base::FilePath& path, |
| 237 | int64_t offset, |
| 238 | int64_t size, |
| 239 | const base::Time& expected_modification_time, |
| 240 | const BlobCallback& callback) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 241 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
tbarzic | db71268 | 2015-03-06 06:05:41 | [diff] [blame] | 242 | |
| 243 | ChromeBlobStorageContext* blob_context = |
| 244 | ChromeBlobStorageContext::GetFor(browser_context); |
| 245 | BrowserThread::PostTaskAndReplyWithResult( |
| 246 | BrowserThread::IO, FROM_HERE, |
| 247 | base::Bind(&ChromeBlobStorageContext::CreateFileBackedBlob, |
| 248 | make_scoped_refptr(blob_context), path, offset, size, |
| 249 | expected_modification_time), |
| 250 | callback); |
| 251 | } |
| 252 | |
| 253 | // static |
[email protected] | 66e53d028 | 2014-08-07 10:04:35 | [diff] [blame] | 254 | void BrowserContext::DeliverPushMessage( |
| 255 | BrowserContext* browser_context, |
| 256 | const GURL& origin, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 257 | int64_t service_worker_registration_id, |
[email protected] | 66e53d028 | 2014-08-07 10:04:35 | [diff] [blame] | 258 | const std::string& data, |
johnme | a80c255 | 2014-10-17 14:51:40 | [diff] [blame] | 259 | const base::Callback<void(PushDeliveryStatus)>& callback) { |
mostynb | fbcdc27a | 2015-03-13 17:58:52 | [diff] [blame] | 260 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 66e53d028 | 2014-08-07 10:04:35 | [diff] [blame] | 261 | PushMessagingRouter::DeliverMessage( |
| 262 | browser_context, origin, service_worker_registration_id, data, callback); |
| 263 | } |
| 264 | |
falken | 41f417516 | 2014-10-29 07:03:41 | [diff] [blame] | 265 | // static |
| 266 | void BrowserContext::NotifyWillBeDestroyed(BrowserContext* browser_context) { |
| 267 | // Service Workers must shutdown before the browser context is destroyed, |
| 268 | // since they keep render process hosts alive and the codebase assumes that |
| 269 | // render process hosts die before their profile (browser context) dies. |
| 270 | ForEachStoragePartition(browser_context, |
| 271 | base::Bind(ShutdownServiceWorkerContext)); |
| 272 | } |
| 273 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 274 | void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) { |
[email protected] | 7e26ac9 | 2012-02-27 20:15:05 | [diff] [blame] | 275 | // This will be enough to tickle initialization of BrowserContext if |
| 276 | // necessary, which initializes ResourceContext. The reason we don't call |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 277 | // ResourceContext::InitializeResourceContext() directly here is that |
| 278 | // ResourceContext initialization may call back into BrowserContext |
| 279 | // and when that call returns it'll end rewriting its UserData map. It will |
| 280 | // end up rewriting the same value but this still causes a race condition. |
| 281 | // |
| 282 | // See http://crbug.com/115678. |
| 283 | GetDefaultStoragePartition(context); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 284 | } |
| 285 | |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 286 | void BrowserContext::SaveSessionState(BrowserContext* browser_context) { |
[email protected] | 5c8e67c | 2012-08-29 00:48:52 | [diff] [blame] | 287 | GetDefaultStoragePartition(browser_context)->GetDatabaseTracker()-> |
| 288 | SetForceKeepSessionState(); |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 289 | StoragePartition* storage_partition = |
| 290 | BrowserContext::GetDefaultStoragePartition(browser_context); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 291 | |
| 292 | if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
| 293 | BrowserThread::PostTask( |
| 294 | BrowserThread::IO, FROM_HERE, |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 295 | base::Bind( |
| 296 | &SaveSessionStateOnIOThread, |
| 297 | make_scoped_refptr(browser_context->GetRequestContext()), |
[email protected] | 98d6d456 | 2014-06-25 20:57:55 | [diff] [blame] | 298 | static_cast<AppCacheServiceImpl*>( |
[email protected] | 63ef8551 | 2014-06-05 14:21:26 | [diff] [blame] | 299 | storage_partition->GetAppCacheService()))); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 300 | } |
| 301 | |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 302 | DOMStorageContextWrapper* dom_storage_context_proxy = |
| 303 | static_cast<DOMStorageContextWrapper*>( |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 304 | storage_partition->GetDOMStorageContext()); |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 305 | dom_storage_context_proxy->SetForceKeepSessionState(); |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 306 | |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 307 | IndexedDBContextImpl* indexed_db_context_impl = |
| 308 | static_cast<IndexedDBContextImpl*>( |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 309 | storage_partition->GetIndexedDBContext()); |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 310 | // No task runner in unit tests. |
| 311 | if (indexed_db_context_impl->TaskRunner()) { |
| 312 | indexed_db_context_impl->TaskRunner()->PostTask( |
| 313 | FROM_HERE, |
| 314 | base::Bind(&SaveSessionStateOnIndexedDBThread, |
| 315 | make_scoped_refptr(indexed_db_context_impl))); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
ttr314 | 81dc54b | 2015-08-06 20:11:26 | [diff] [blame] | 319 | void BrowserContext::SetDownloadManagerForTesting( |
| 320 | BrowserContext* browser_context, |
| 321 | DownloadManager* download_manager) { |
| 322 | SetDownloadManager(browser_context, download_manager); |
| 323 | } |
| 324 | |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 325 | #endif // !OS_IOS |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 326 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 327 | BrowserContext::~BrowserContext() { |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 328 | #if !defined(OS_IOS) |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 329 | if (GetUserData(kDownloadManagerKeyName)) |
| 330 | GetDownloadManager(this)->Shutdown(); |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 331 | #endif |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 332 | } |
| 333 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 334 | } // namespace content |