| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/public/browser/browser_context.h" | 5 #include "content/public/browser/browser_context.h" |
| 6 | 6 |
| 7 #if !defined(OS_IOS) | 7 #if !defined(OS_IOS) |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "content/browser/appcache/chrome_appcache_service.h" | 9 #include "content/browser/appcache/chrome_appcache_service.h" |
| 10 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 10 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
| 11 #include "content/browser/download/download_manager_impl.h" | 11 #include "content/browser/download/download_manager_impl.h" |
| 12 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" | 12 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" |
| 13 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 13 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 14 #include "content/public/browser/site_instance.h" | 14 #include "content/public/browser/site_instance.h" |
| 15 #include "content/browser/storage_partition_impl.h" | 15 #include "content/browser/storage_partition_impl.h" |
| 16 #include "content/browser/storage_partition_impl_map.h" | 16 #include "content/browser/storage_partition_impl_map.h" |
| 17 #include "content/common/child_process_host_impl.h" | 17 #include "content/common/child_process_host_impl.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
| 20 #include "net/base/server_bound_cert_service.h" | 20 #include "net/base/server_bound_cert_service.h" |
| 21 #include "net/base/server_bound_cert_store.h" | 21 #include "net/base/server_bound_cert_store.h" |
| 22 #include "net/cookies/cookie_monster.h" | 22 #include "net/cookies/cookie_monster.h" |
| 23 #include "net/cookies/cookie_store.h" | 23 #include "net/cookies/cookie_store.h" |
| 24 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
| 25 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
| 26 #include "ui/base/clipboard/clipboard.h" | |
| 27 #include "webkit/database/database_tracker.h" | 26 #include "webkit/database/database_tracker.h" |
| 28 #include "webkit/fileapi/external_mount_points.h" | 27 #include "webkit/fileapi/external_mount_points.h" |
| 29 #endif // !OS_IOS | 28 #endif // !OS_IOS |
| 30 | 29 |
| 31 using base::UserDataAdapter; | 30 using base::UserDataAdapter; |
| 32 | 31 |
| 33 namespace content { | 32 namespace content { |
| 34 | 33 |
| 35 // Only ~BrowserContext() is needed on iOS. | 34 // Only ~BrowserContext() is needed on iOS. |
| 36 #if !defined(OS_IOS) | 35 #if !defined(OS_IOS) |
| 37 namespace { | 36 namespace { |
| 38 | 37 |
| 39 // Key names on BrowserContext. | 38 // Key names on BrowserContext. |
| 40 const char kClipboardDestroyerKey[] = "clipboard_destroyer"; | |
| 41 const char kDownloadManagerKeyName[] = "download_manager"; | 39 const char kDownloadManagerKeyName[] = "download_manager"; |
| 42 const char kMountPointsKey[] = "mount_points"; | 40 const char kMountPointsKey[] = "mount_points"; |
| 43 const char kStorageParitionMapKeyName[] = "content_storage_partition_map"; | 41 const char kStorageParitionMapKeyName[] = "content_storage_partition_map"; |
| 44 | 42 |
| 45 StoragePartitionImplMap* GetStoragePartitionMap( | 43 StoragePartitionImplMap* GetStoragePartitionMap( |
| 46 BrowserContext* browser_context) { | 44 BrowserContext* browser_context) { |
| 47 StoragePartitionImplMap* partition_map = | 45 StoragePartitionImplMap* partition_map = |
| 48 static_cast<StoragePartitionImplMap*>( | 46 static_cast<StoragePartitionImplMap*>( |
| 49 browser_context->GetUserData(kStorageParitionMapKeyName)); | 47 browser_context->GetUserData(kStorageParitionMapKeyName)); |
| 50 if (!partition_map) { | 48 if (!partition_map) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 85 |
| 88 void SaveSessionStateOnWebkitThread( | 86 void SaveSessionStateOnWebkitThread( |
| 89 scoped_refptr<IndexedDBContextImpl> indexed_db_context) { | 87 scoped_refptr<IndexedDBContextImpl> indexed_db_context) { |
| 90 indexed_db_context->SetForceKeepSessionState(); | 88 indexed_db_context->SetForceKeepSessionState(); |
| 91 } | 89 } |
| 92 | 90 |
| 93 void PurgeMemoryOnIOThread(appcache::AppCacheService* appcache_service) { | 91 void PurgeMemoryOnIOThread(appcache::AppCacheService* appcache_service) { |
| 94 appcache_service->PurgeMemory(); | 92 appcache_service->PurgeMemory(); |
| 95 } | 93 } |
| 96 | 94 |
| 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); | |
| 117 if (source_tag == ui::Clipboard::SourceTag(this)) | |
| 118 clipboard->Clear(buffer); | |
| 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 | |
| 133 } // namespace | 95 } // namespace |
| 134 | 96 |
| 135 // static | 97 // static |
| 136 void BrowserContext::AsyncObliterateStoragePartition( | 98 void BrowserContext::AsyncObliterateStoragePartition( |
| 137 BrowserContext* browser_context, | 99 BrowserContext* browser_context, |
| 138 const GURL& site, | 100 const GURL& site, |
| 139 const base::Closure& on_gc_required) { | 101 const base::Closure& on_gc_required) { |
| 140 GetStoragePartitionMap(browser_context)->AsyncObliterate(site, | 102 GetStoragePartitionMap(browser_context)->AsyncObliterate(site, |
| 141 on_gc_required); | 103 on_gc_required); |
| 142 } | 104 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 BrowserThread::IO, FROM_HERE, | 266 BrowserThread::IO, FROM_HERE, |
| 305 base::Bind( | 267 base::Bind( |
| 306 &PurgeMemoryOnIOThread, | 268 &PurgeMemoryOnIOThread, |
| 307 BrowserContext::GetDefaultStoragePartition(browser_context)-> | 269 BrowserContext::GetDefaultStoragePartition(browser_context)-> |
| 308 GetAppCacheService())); | 270 GetAppCacheService())); |
| 309 } | 271 } |
| 310 | 272 |
| 311 ForEachStoragePartition(browser_context, | 273 ForEachStoragePartition(browser_context, |
| 312 base::Bind(&PurgeDOMStorageContextInPartition)); | 274 base::Bind(&PurgeDOMStorageContextInPartition)); |
| 313 } | 275 } |
| 314 | |
| 315 ui::Clipboard::SourceTag BrowserContext::GetMarkerForOffTheRecordContext( | |
| 316 BrowserContext* context) { | |
| 317 if (context && context->IsOffTheRecord()) { | |
| 318 OffTheRecordClipboardDestroyer* clipboard_destroyer = | |
| 319 GetClipboardDestroyerForBrowserContext(context); | |
| 320 | |
| 321 return clipboard_destroyer->GetAsSourceTag(); | |
| 322 } | |
| 323 return ui::Clipboard::SourceTag(); | |
| 324 } | |
| 325 #endif // !OS_IOS | 276 #endif // !OS_IOS |
| 326 | 277 |
| 327 BrowserContext::~BrowserContext() { | 278 BrowserContext::~BrowserContext() { |
| 328 #if !defined(OS_IOS) | 279 #if !defined(OS_IOS) |
| 329 if (GetUserData(kDownloadManagerKeyName)) | 280 if (GetUserData(kDownloadManagerKeyName)) |
| 330 GetDownloadManager(this)->Shutdown(); | 281 GetDownloadManager(this)->Shutdown(); |
| 331 #endif | 282 #endif |
| 332 } | 283 } |
| 333 | 284 |
| 334 } // namespace content | 285 } // namespace content |
| OLD | NEW |