[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] | 53ac00e8 | 2012-10-18 20:59:20 | [diff] [blame] | 27 | #include "webkit/database/database_tracker.h" |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 28 | #include "webkit/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 | |
| 109 | ui::Clipboard::SourceTag GetAsSourceTag() { |
| 110 | return ui::Clipboard::SourceTag(this); |
| 111 | } |
| 112 | |
| 113 | private: |
| 114 | void ExamineClipboard(ui::Clipboard* clipboard, |
| 115 | ui::Clipboard::Buffer buffer) { |
| 116 | ui::Clipboard::SourceTag source_tag = clipboard->ReadSourceTag(buffer); |
[email protected] | c978cb9b | 2013-02-27 11:06:23 | [diff] [blame] | 117 | if (source_tag == ui::Clipboard::SourceTag(this)) { |
| 118 | if (buffer == ui::Clipboard::BUFFER_STANDARD) { |
| 119 | // We want to leave invalid SourceTag in the clipboard in order to |
| 120 | // collect statistics later. |
| 121 | clipboard->WriteObjects(buffer, |
| 122 | ui::Clipboard::ObjectMap(), |
| 123 | ui::Clipboard::kInvalidSourceTag); |
| 124 | } else { |
| 125 | clipboard->Clear(buffer); |
| 126 | } |
| 127 | } |
[email protected] | 7061be9 | 2013-02-18 15:44:02 | [diff] [blame] | 128 | } |
| 129 | }; |
| 130 | |
| 131 | // Returns existing OffTheRecordClipboardDestroyer or creates one. |
| 132 | OffTheRecordClipboardDestroyer* GetClipboardDestroyerForBrowserContext( |
| 133 | BrowserContext* context) { |
| 134 | if (base::SupportsUserData::Data* data = context->GetUserData( |
| 135 | kClipboardDestroyerKey)) |
| 136 | return static_cast<OffTheRecordClipboardDestroyer*>(data); |
| 137 | OffTheRecordClipboardDestroyer* data = new OffTheRecordClipboardDestroyer; |
| 138 | context->SetUserData(kClipboardDestroyerKey, data); |
| 139 | return data; |
| 140 | } |
| 141 | |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 142 | } // namespace |
| 143 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 144 | // static |
| 145 | void BrowserContext::AsyncObliterateStoragePartition( |
| 146 | BrowserContext* browser_context, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 147 | const GURL& site, |
| 148 | const base::Closure& on_gc_required) { |
| 149 | GetStoragePartitionMap(browser_context)->AsyncObliterate(site, |
| 150 | on_gc_required); |
| 151 | } |
| 152 | |
| 153 | // static |
| 154 | void BrowserContext::GarbageCollectStoragePartitions( |
| 155 | BrowserContext* browser_context, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 156 | scoped_ptr<base::hash_set<base::FilePath> > active_paths, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 157 | const base::Closure& done) { |
| 158 | GetStoragePartitionMap(browser_context)->GarbageCollect( |
| 159 | active_paths.Pass(), done); |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 160 | } |
| 161 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 162 | DownloadManager* BrowserContext::GetDownloadManager( |
| 163 | BrowserContext* context) { |
[email protected] | ecd3ad2 | 2012-07-10 20:02:40 | [diff] [blame] | 164 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 165 | if (!context->GetUserData(kDownloadManagerKeyName)) { |
[email protected] | d25fda1 | 2012-06-12 17:05:03 | [diff] [blame] | 166 | ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
| 167 | DCHECK(rdh); |
[email protected] | d25fda1 | 2012-06-12 17:05:03 | [diff] [blame] | 168 | scoped_refptr<DownloadManager> download_manager = |
| 169 | new DownloadManagerImpl( |
[email protected] | d25fda1 | 2012-06-12 17:05:03 | [diff] [blame] | 170 | GetContentClient()->browser()->GetNetLog()); |
| 171 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 172 | context->SetUserData( |
| 173 | kDownloadManagerKeyName, |
| 174 | new UserDataAdapter<DownloadManager>(download_manager)); |
| 175 | download_manager->SetDelegate(context->GetDownloadManagerDelegate()); |
| 176 | download_manager->Init(context); |
| 177 | } |
| 178 | |
| 179 | return UserDataAdapter<DownloadManager>::Get( |
| 180 | context, kDownloadManagerKeyName); |
| 181 | } |
| 182 | |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 183 | // static |
| 184 | fileapi::ExternalMountPoints* BrowserContext::GetMountPoints( |
| 185 | BrowserContext* context) { |
| 186 | // Ensure that these methods are called on the UI thread, except for |
| 187 | // unittests where a UI thread might not have been created. |
| 188 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 189 | !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); |
| 190 | |
| 191 | #if defined(OS_CHROMEOS) |
| 192 | if (!context->GetUserData(kMountPointsKey)) { |
| 193 | scoped_refptr<fileapi::ExternalMountPoints> mount_points = |
| 194 | fileapi::ExternalMountPoints::CreateRefCounted(); |
| 195 | context->SetUserData( |
| 196 | kMountPointsKey, |
| 197 | new UserDataAdapter<fileapi::ExternalMountPoints>( |
| 198 | mount_points)); |
| 199 | |
| 200 | // Add Downloads mount point. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 201 | base::FilePath home_path; |
[email protected] | 6ef0c391 | 2013-01-25 22:46:34 | [diff] [blame] | 202 | if (PathService::Get(base::DIR_HOME, &home_path)) { |
| 203 | mount_points->RegisterFileSystem( |
| 204 | "Downloads", |
| 205 | fileapi::kFileSystemTypeNativeLocal, |
| 206 | home_path.AppendASCII("Downloads")); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | return UserDataAdapter<fileapi::ExternalMountPoints>::Get( |
| 211 | context, kMountPointsKey); |
| 212 | #else |
| 213 | return NULL; |
| 214 | #endif |
| 215 | } |
| 216 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 217 | StoragePartition* BrowserContext::GetStoragePartition( |
| 218 | BrowserContext* browser_context, |
| 219 | SiteInstance* site_instance) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 220 | std::string partition_domain; |
| 221 | std::string partition_name; |
| 222 | bool in_memory = false; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 223 | |
| 224 | // TODO(ajwong): After GetDefaultStoragePartition() is removed, get rid of |
| 225 | // this conditional and require that |site_instance| is non-NULL. |
| 226 | if (site_instance) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 227 | GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 228 | browser_context, site_instance->GetSiteURL(), true, |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 229 | &partition_domain, &partition_name, &in_memory); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 230 | } |
| 231 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 232 | return GetStoragePartitionFromConfig( |
| 233 | browser_context, partition_domain, partition_name, in_memory); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 234 | } |
| 235 | |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 236 | StoragePartition* BrowserContext::GetStoragePartitionForSite( |
| 237 | BrowserContext* browser_context, |
| 238 | const GURL& site) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 239 | std::string partition_domain; |
| 240 | std::string partition_name; |
| 241 | bool in_memory; |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 242 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 243 | GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 244 | browser_context, site, true, &partition_domain, &partition_name, |
| 245 | &in_memory); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 246 | |
| 247 | return GetStoragePartitionFromConfig( |
| 248 | browser_context, partition_domain, partition_name, in_memory); |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 249 | } |
| 250 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 251 | void BrowserContext::ForEachStoragePartition( |
| 252 | BrowserContext* browser_context, |
| 253 | const StoragePartitionCallback& callback) { |
| 254 | StoragePartitionImplMap* partition_map = |
| 255 | static_cast<StoragePartitionImplMap*>( |
| 256 | browser_context->GetUserData(kStorageParitionMapKeyName)); |
| 257 | if (!partition_map) |
| 258 | return; |
| 259 | |
| 260 | partition_map->ForEach(callback); |
| 261 | } |
| 262 | |
| 263 | StoragePartition* BrowserContext::GetDefaultStoragePartition( |
| 264 | BrowserContext* browser_context) { |
| 265 | return GetStoragePartition(browser_context, NULL); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 266 | } |
| 267 | |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 268 | void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) { |
[email protected] | 7e26ac9 | 2012-02-27 20:15:05 | [diff] [blame] | 269 | // This will be enough to tickle initialization of BrowserContext if |
| 270 | // necessary, which initializes ResourceContext. The reason we don't call |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 271 | // ResourceContext::InitializeResourceContext() directly here is that |
| 272 | // ResourceContext initialization may call back into BrowserContext |
| 273 | // and when that call returns it'll end rewriting its UserData map. It will |
| 274 | // end up rewriting the same value but this still causes a race condition. |
| 275 | // |
| 276 | // See http://crbug.com/115678. |
| 277 | GetDefaultStoragePartition(context); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 278 | } |
| 279 | |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 280 | void BrowserContext::SaveSessionState(BrowserContext* browser_context) { |
[email protected] | 5c8e67c | 2012-08-29 00:48:52 | [diff] [blame] | 281 | GetDefaultStoragePartition(browser_context)->GetDatabaseTracker()-> |
| 282 | SetForceKeepSessionState(); |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 283 | StoragePartition* storage_partition = |
| 284 | BrowserContext::GetDefaultStoragePartition(browser_context); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 285 | |
| 286 | if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
| 287 | BrowserThread::PostTask( |
| 288 | BrowserThread::IO, FROM_HERE, |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 289 | base::Bind( |
| 290 | &SaveSessionStateOnIOThread, |
| 291 | make_scoped_refptr(browser_context->GetRequestContext()), |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 292 | storage_partition->GetAppCacheService())); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 293 | } |
| 294 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 295 | DOMStorageContextImpl* dom_storage_context_impl = |
| 296 | static_cast<DOMStorageContextImpl*>( |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 297 | storage_partition->GetDOMStorageContext()); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 298 | dom_storage_context_impl->SetForceKeepSessionState(); |
[email protected] | 735e20c | 2012-03-20 01:16:59 | [diff] [blame] | 299 | |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 300 | if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 301 | IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 302 | storage_partition->GetIndexedDBContext()); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 303 | BrowserThread::PostTask( |
| 304 | BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
| 305 | base::Bind(&SaveSessionStateOnWebkitThread, |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 306 | make_scoped_refptr(indexed_db))); |
| 307 | } |
| 308 | } |
| 309 | |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 310 | void BrowserContext::PurgeMemory(BrowserContext* browser_context) { |
| 311 | if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
| 312 | BrowserThread::PostTask( |
| 313 | BrowserThread::IO, FROM_HERE, |
[email protected] | 6939075a | 2012-08-28 08:35:53 | [diff] [blame] | 314 | base::Bind( |
| 315 | &PurgeMemoryOnIOThread, |
| 316 | BrowserContext::GetDefaultStoragePartition(browser_context)-> |
| 317 | GetAppCacheService())); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 318 | } |
| 319 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 320 | ForEachStoragePartition(browser_context, |
| 321 | base::Bind(&PurgeDOMStorageContextInPartition)); |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 322 | } |
[email protected] | 7061be9 | 2013-02-18 15:44:02 | [diff] [blame] | 323 | |
| 324 | ui::Clipboard::SourceTag BrowserContext::GetMarkerForOffTheRecordContext( |
| 325 | BrowserContext* context) { |
| 326 | if (context && context->IsOffTheRecord()) { |
| 327 | OffTheRecordClipboardDestroyer* clipboard_destroyer = |
| 328 | GetClipboardDestroyerForBrowserContext(context); |
| 329 | |
| 330 | return clipboard_destroyer->GetAsSourceTag(); |
| 331 | } |
| 332 | return ui::Clipboard::SourceTag(); |
| 333 | } |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 334 | #endif // !OS_IOS |
[email protected] | 6e2d3d2 | 2012-02-24 18:10:36 | [diff] [blame] | 335 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 336 | BrowserContext::~BrowserContext() { |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 337 | #if !defined(OS_IOS) |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 338 | if (GetUserData(kDownloadManagerKeyName)) |
| 339 | GetDownloadManager(this)->Shutdown(); |
[email protected] | e0ce8a1e | 2012-09-18 10:26:36 | [diff] [blame] | 340 | #endif |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | } // namespace content |