[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 | |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 7 | #if !defined(OS_IOS) |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 8 | #include "base/path_service.h" |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 9 | #include "content/browser/appcache/chrome_appcache_service.h" |
[email protected] | 1ea3c79 | 2012-04-17 01:25:04 | [diff] [blame] | 10 | #include "content/browser/dom_storage/dom_storage_context_impl.h" |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 11 | #include "content/browser/download/download_manager_impl.h" |
[email protected] | c4d28166 | 2013-03-31 00:35:08 | [diff] [blame] | 12 | #include "content/browser/indexed_db/indexed_db_context_impl.h" |
[email protected] | 678c036 | 2012-12-05 08:02:44 | [diff] [blame] | 13 | #include "content/browser/loader/resource_dispatcher_host_impl.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 14 | #include "content/browser/storage_partition_impl.h" |
| 15 | #include "content/browser/storage_partition_impl_map.h" |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 16 | #include "content/common/child_process_host_impl.h" |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 17 | #include "content/public/browser/browser_thread.h" |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 18 | #include "content/public/browser/content_browser_client.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 19 | #include "content/public/browser/site_instance.h" |
[email protected] | 4d7c4ef | 2012-03-16 01:47:12 | [diff] [blame] | 20 | #include "net/cookies/cookie_monster.h" |
| 21 | #include "net/cookies/cookie_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 22 | #include "net/ssl/server_bound_cert_service.h" |
| 23 | #include "net/ssl/server_bound_cert_store.h" |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 24 | #include "net/url_request/url_request_context.h" |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 25 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | 7061be9 | 2013-02-18 15:44:02 | [diff] [blame] | 26 | #include "ui/base/clipboard/clipboard.h" |
[email protected] | 08b1f75f | 2013-05-22 22:02:38 | [diff] [blame] | 27 | #include "webkit/browser/database/database_tracker.h" |
[email protected] | f25e113 | 2013-05-24 13:58:04 | [diff] [blame^] | 28 | #include "webkit/browser/fileapi/external_mount_points.h" |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 29 | #endif // !OS_IOS |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 30 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 31 | using base::UserDataAdapter; |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 32 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 33 | namespace content { |
| 34 | |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 35 | // Only ~BrowserContext() is needed on iOS. |
| 36 | #if !defined(OS_IOS) |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 37 | namespace { |
| 38 | |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 39 | // Key names on BrowserContext. |
[email protected] | 7061be9 | 2013-02-18 15:44:02 | [diff] [blame] | 40 | const char kClipboardDestroyerKey[] = "clipboard_destroyer"; |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 41 | const char kDownloadManagerKeyName[] = "download_manager"; |
| 42 | const char kMountPointsKey[] = "mount_points"; |
| 43 | const char kStorageParitionMapKeyName[] = "content_storage_partition_map"; |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 44 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 45 | StoragePartitionImplMap* GetStoragePartitionMap( |
| 46 | BrowserContext* browser_context) { |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 47 | StoragePartitionImplMap* partition_map = |
| 48 | static_cast<StoragePartitionImplMap*>( |
| 49 | browser_context->GetUserData(kStorageParitionMapKeyName)); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 50 | if (!partition_map) { |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 51 | partition_map = new StoragePartitionImplMap(browser_context); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 52 | browser_context->SetUserData(kStorageParitionMapKeyName, partition_map); |
| 53 | } |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 54 | return partition_map; |
| 55 | } |
| 56 | |
| 57 | StoragePartition* GetStoragePartitionFromConfig( |
| 58 | BrowserContext* browser_context, |
| 59 | const std::string& partition_domain, |
| 60 | const std::string& partition_name, |
| 61 | bool in_memory) { |
| 62 | StoragePartitionImplMap* partition_map = |
| 63 | GetStoragePartitionMap(browser_context); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 64 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 65 | if (browser_context->IsOffTheRecord()) |
| 66 | in_memory = true; |
| 67 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 68 | return partition_map->Get(partition_domain, partition_name, in_memory); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 69 | } |
| 70 | |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 71 | // Run |callback| on each DOMStorageContextImpl in |browser_context|. |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 72 | void PurgeDOMStorageContextInPartition(StoragePartition* storage_partition) { |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 73 | static_cast<StoragePartitionImpl*>(storage_partition)-> |
| 74 | GetDOMStorageContext()->PurgeMemory(); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [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, |
| 79 | appcache::AppCacheService* appcache_service) { |
| 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] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 83 | context->server_bound_cert_service()->GetCertStore()-> |
| 84 | SetForceKeepSessionState(); |
| 85 | appcache_service->set_force_keep_session_state(); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void SaveSessionStateOnWebkitThread( |
[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 | |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 93 | void PurgeMemoryOnIOThread(appcache::AppCacheService* appcache_service) { |
| 94 | appcache_service->PurgeMemory(); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 95 | } |
| 96 | |
[email protected] | 7061be9 | 2013-02-18 15:44:02 | [diff] [blame] | 97 | // OffTheRecordClipboardDestroyer is supposed to clear the clipboard in |
| 98 | // destructor if current clipboard content came from corresponding OffTheRecord |
| 99 | // browser context. |
| 100 | class OffTheRecordClipboardDestroyer : public base::SupportsUserData::Data { |
| 101 | public: |
| 102 | virtual ~OffTheRecordClipboardDestroyer() { |
| 103 | ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); |
| 104 | ExamineClipboard(clipboard, ui::Clipboard::BUFFER_STANDARD); |
| 105 | if (ui::Clipboard::IsValidBuffer(ui::Clipboard::BUFFER_SELECTION)) |
| 106 | ExamineClipboard(clipboard, ui::Clipboard::BUFFER_SELECTION); |
| 107 | } |
| 108 | |
[email protected] | 02fb6a40 | 2013-04-26 07:20:57 | [diff] [blame] | 109 | ui::SourceTag GetAsSourceTag() { |
| 110 | return ui::SourceTag(this); |
[email protected] | 7061be9 | 2013-02-18 15:44:02 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | private: |
| 114 | void ExamineClipboard(ui::Clipboard* clipboard, |
| 115 | ui::Clipboard::Buffer buffer) { |
[email protected] | 02fb6a40 | 2013-04-26 07:20:57 | [diff] [blame] | 116 | ui::SourceTag source_tag = clipboard->ReadSourceTag(buffer); |
| 117 | if (source_tag == ui::SourceTag(this)) |
[email protected] | 45c4fe63c | 2013-04-02 17:36:30 | [diff] [blame] | 118 | clipboard->Clear(buffer); |
[email protected] | 7061be9 | 2013-02-18 15:44:02 | [diff] [blame] | 119 | } |
| 120 | }; |
| 121 | |
| 122 | // Returns existing OffTheRecordClipboardDestroyer or creates one. |
| 123 | OffTheRecordClipboardDestroyer* GetClipboardDestroyerForBrowserContext( |
| 124 | BrowserContext* context) { |
| 125 | if (base::SupportsUserData::Data* data = context->GetUserData( |
| 126 | kClipboardDestroyerKey)) |
| 127 | return static_cast<OffTheRecordClipboardDestroyer*>(data); |
| 128 | OffTheRecordClipboardDestroyer* data = new OffTheRecordClipboardDestroyer; |
| 129 | context->SetUserData(kClipboardDestroyerKey, data); |
| 130 | return data; |
| 131 | } |
| 132 | |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 133 | } // namespace |
| 134 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 135 | // static |
| 136 | void BrowserContext::AsyncObliterateStoragePartition( |
| 137 | BrowserContext* browser_context, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 138 | const GURL& site, |
| 139 | const base::Closure& on_gc_required) { |
| 140 | GetStoragePartitionMap(browser_context)->AsyncObliterate(site, |
| 141 | on_gc_required); |
| 142 | } |
| 143 | |
| 144 | // static |
| 145 | void BrowserContext::GarbageCollectStoragePartitions( |
| 146 | BrowserContext* browser_context, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 147 | scoped_ptr<base::hash_set<base::FilePath> > active_paths, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 148 | const base::Closure& done) { |
| 149 | GetStoragePartitionMap(browser_context)->GarbageCollect( |
| 150 | active_paths.Pass(), done); |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 151 | } |
| 152 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 153 | DownloadManager* BrowserContext::GetDownloadManager( |
| 154 | BrowserContext* context) { |
[email protected] | ecd3ad2 | 2012-07-10 20:02:40 | [diff] [blame] | 155 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 156 | if (!context->GetUserData(kDownloadManagerKeyName)) { |
[email protected] | d25fda1 | 2012-06-12 17:05:03 | [diff] [blame] | 157 | ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
| 158 | DCHECK(rdh); |
[email protected] | d25fda1 | 2012-06-12 17:05:03 | [diff] [blame] | 159 | scoped_refptr<DownloadManager> download_manager = |
| 160 | new DownloadManagerImpl( |
[email protected] | 1679869 | 2013-04-23 18:08:38 | [diff] [blame] | 161 | GetContentClient()->browser()->GetNetLog(), context); |
[email protected] | d25fda1 | 2012-06-12 17:05:03 | [diff] [blame] | 162 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 163 | context->SetUserData( |
| 164 | kDownloadManagerKeyName, |
| 165 | new UserDataAdapter<DownloadManager>(download_manager)); |
| 166 | download_manager->SetDelegate(context->GetDownloadManagerDelegate()); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | return UserDataAdapter<DownloadManager>::Get( |
| 170 | context, kDownloadManagerKeyName); |
| 171 | } |
| 172 | |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 173 | // static |
| 174 | fileapi::ExternalMountPoints* BrowserContext::GetMountPoints( |
| 175 | BrowserContext* context) { |
| 176 | // Ensure that these methods are called on the UI thread, except for |
| 177 | // unittests where a UI thread might not have been created. |
| 178 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 179 | !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); |
| 180 | |
| 181 | #if defined(OS_CHROMEOS) |
| 182 | if (!context->GetUserData(kMountPointsKey)) { |
| 183 | scoped_refptr<fileapi::ExternalMountPoints> mount_points = |
| 184 | fileapi::ExternalMountPoints::CreateRefCounted(); |
| 185 | context->SetUserData( |
| 186 | kMountPointsKey, |
| 187 | new UserDataAdapter<fileapi::ExternalMountPoints>( |
| 188 | mount_points)); |
| 189 | |
| 190 | // Add Downloads mount point. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 191 | base::FilePath home_path; |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 192 | if (PathService::Get(base::DIR_HOME, &home_path)) { |
| 193 | mount_points->RegisterFileSystem( |
| 194 | "Downloads", |
| 195 | fileapi::kFileSystemTypeNativeLocal, |
| 196 | home_path.AppendASCII("Downloads")); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | return UserDataAdapter<fileapi::ExternalMountPoints>::Get( |
| 201 | context, kMountPointsKey); |
| 202 | #else |
| 203 | return NULL; |
| 204 | #endif |
| 205 | } |
| 206 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 207 | StoragePartition* BrowserContext::GetStoragePartition( |
| 208 | BrowserContext* browser_context, |
| 209 | SiteInstance* site_instance) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 210 | std::string partition_domain; |
| 211 | std::string partition_name; |
| 212 | bool in_memory = false; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 213 | |
| 214 | // TODO(ajwong): After GetDefaultStoragePartition() is removed, get rid of |
| 215 | // this conditional and require that |site_instance| is non-NULL. |
| 216 | if (site_instance) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 217 | GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 218 | browser_context, site_instance->GetSiteURL(), true, |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 219 | &partition_domain, &partition_name, &in_memory); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 220 | } |
| 221 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 222 | return GetStoragePartitionFromConfig( |
| 223 | browser_context, partition_domain, partition_name, in_memory); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 224 | } |
| 225 | |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 226 | StoragePartition* BrowserContext::GetStoragePartitionForSite( |
| 227 | BrowserContext* browser_context, |
| 228 | const GURL& site) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 229 | std::string partition_domain; |
| 230 | std::string partition_name; |
| 231 | bool in_memory; |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 232 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 233 | GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 234 | browser_context, site, true, &partition_domain, &partition_name, |
| 235 | &in_memory); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 236 | |
| 237 | return GetStoragePartitionFromConfig( |
| 238 | browser_context, partition_domain, partition_name, in_memory); |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 239 | } |
| 240 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 241 | void BrowserContext::ForEachStoragePartition( |
| 242 | BrowserContext* browser_context, |
| 243 | const StoragePartitionCallback& callback) { |
| 244 | StoragePartitionImplMap* partition_map = |
| 245 | static_cast<StoragePartitionImplMap*>( |
| 246 | browser_context->GetUserData(kStorageParitionMapKeyName)); |
| 247 | if (!partition_map) |
| 248 | return; |
| 249 | |
| 250 | partition_map->ForEach(callback); |
| 251 | } |
| 252 | |
| 253 | StoragePartition* BrowserContext::GetDefaultStoragePartition( |
| 254 | BrowserContext* browser_context) { |
| 255 | return GetStoragePartition(browser_context, NULL); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 256 | } |
| 257 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 258 | void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) { |
[email protected] | 7e26ac9 | 2012-02-27 20:15:05 | [diff] [blame] | 259 | // This will be enough to tickle initialization of BrowserContext if |
| 260 | // necessary, which initializes ResourceContext. The reason we don't call |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 261 | // ResourceContext::InitializeResourceContext() directly here is that |
| 262 | // ResourceContext initialization may call back into BrowserContext |
| 263 | // and when that call returns it'll end rewriting its UserData map. It will |
| 264 | // end up rewriting the same value but this still causes a race condition. |
| 265 | // |
| 266 | // See http://crbug.com/115678. |
| 267 | GetDefaultStoragePartition(context); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 268 | } |
| 269 | |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 270 | void BrowserContext::SaveSessionState(BrowserContext* browser_context) { |
[email protected] | 5c8e67c | 2012-08-29 00:48:52 | [diff] [blame] | 271 | GetDefaultStoragePartition(browser_context)->GetDatabaseTracker()-> |
| 272 | SetForceKeepSessionState(); |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 273 | StoragePartition* storage_partition = |
| 274 | BrowserContext::GetDefaultStoragePartition(browser_context); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 275 | |
| 276 | if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
| 277 | BrowserThread::PostTask( |
| 278 | BrowserThread::IO, FROM_HERE, |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 279 | base::Bind( |
| 280 | &SaveSessionStateOnIOThread, |
| 281 | make_scoped_refptr(browser_context->GetRequestContext()), |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 282 | storage_partition->GetAppCacheService())); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 283 | } |
| 284 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 285 | DOMStorageContextImpl* dom_storage_context_impl = |
| 286 | static_cast<DOMStorageContextImpl*>( |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 287 | storage_partition->GetDOMStorageContext()); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 288 | dom_storage_context_impl->SetForceKeepSessionState(); |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 289 | |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 290 | if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 291 | IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 292 | storage_partition->GetIndexedDBContext()); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 293 | BrowserThread::PostTask( |
| 294 | BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
| 295 | base::Bind(&SaveSessionStateOnWebkitThread, |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 296 | make_scoped_refptr(indexed_db))); |
| 297 | } |
| 298 | } |
| 299 | |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 300 | void BrowserContext::PurgeMemory(BrowserContext* browser_context) { |
| 301 | if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
| 302 | BrowserThread::PostTask( |
| 303 | BrowserThread::IO, FROM_HERE, |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 304 | base::Bind( |
| 305 | &PurgeMemoryOnIOThread, |
| 306 | BrowserContext::GetDefaultStoragePartition(browser_context)-> |
| 307 | GetAppCacheService())); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 308 | } |
| 309 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 310 | ForEachStoragePartition(browser_context, |
| 311 | base::Bind(&PurgeDOMStorageContextInPartition)); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 312 | } |
[email protected] | 7061be9 | 2013-02-18 15:44:02 | [diff] [blame] | 313 | |
[email protected] | 02fb6a40 | 2013-04-26 07:20:57 | [diff] [blame] | 314 | ui::SourceTag BrowserContext::GetMarkerForOffTheRecordContext( |
[email protected] | 7061be9 | 2013-02-18 15:44:02 | [diff] [blame] | 315 | BrowserContext* context) { |
| 316 | if (context && context->IsOffTheRecord()) { |
| 317 | OffTheRecordClipboardDestroyer* clipboard_destroyer = |
| 318 | GetClipboardDestroyerForBrowserContext(context); |
| 319 | |
| 320 | return clipboard_destroyer->GetAsSourceTag(); |
| 321 | } |
[email protected] | 02fb6a40 | 2013-04-26 07:20:57 | [diff] [blame] | 322 | return ui::SourceTag(); |
[email protected] | 7061be9 | 2013-02-18 15:44:02 | [diff] [blame] | 323 | } |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 324 | #endif // !OS_IOS |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 325 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 326 | BrowserContext::~BrowserContext() { |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 327 | #if !defined(OS_IOS) |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 328 | if (GetUserData(kDownloadManagerKeyName)) |
| 329 | GetDownloadManager(this)->Shutdown(); |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 330 | #endif |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | } // namespace content |