| 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" |
| 26 #include "webkit/database/database_tracker.h" | 27 #include "webkit/database/database_tracker.h" |
| 27 #include "webkit/fileapi/external_mount_points.h" | 28 #include "webkit/fileapi/external_mount_points.h" |
| 28 #endif // !OS_IOS | 29 #endif // !OS_IOS |
| 29 | 30 |
| 30 using base::UserDataAdapter; | 31 using base::UserDataAdapter; |
| 31 | 32 |
| 32 namespace content { | 33 namespace content { |
| 33 | 34 |
| 34 // Only ~BrowserContext() is needed on iOS. | 35 // Only ~BrowserContext() is needed on iOS. |
| 35 #if !defined(OS_IOS) | 36 #if !defined(OS_IOS) |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 // Key names on BrowserContext. | 39 // Key names on BrowserContext. |
| 40 const char kClipboardDestroyerKey[] = "clipboard_destroyer"; |
| 39 const char kDownloadManagerKeyName[] = "download_manager"; | 41 const char kDownloadManagerKeyName[] = "download_manager"; |
| 40 const char kMountPointsKey[] = "mount_points"; | 42 const char kMountPointsKey[] = "mount_points"; |
| 41 const char kStorageParitionMapKeyName[] = "content_storage_partition_map"; | 43 const char kStorageParitionMapKeyName[] = "content_storage_partition_map"; |
| 42 | 44 |
| 43 StoragePartitionImplMap* GetStoragePartitionMap( | 45 StoragePartitionImplMap* GetStoragePartitionMap( |
| 44 BrowserContext* browser_context) { | 46 BrowserContext* browser_context) { |
| 45 StoragePartitionImplMap* partition_map = | 47 StoragePartitionImplMap* partition_map = |
| 46 static_cast<StoragePartitionImplMap*>( | 48 static_cast<StoragePartitionImplMap*>( |
| 47 browser_context->GetUserData(kStorageParitionMapKeyName)); | 49 browser_context->GetUserData(kStorageParitionMapKeyName)); |
| 48 if (!partition_map) { | 50 if (!partition_map) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 87 |
| 86 void SaveSessionStateOnWebkitThread( | 88 void SaveSessionStateOnWebkitThread( |
| 87 scoped_refptr<IndexedDBContextImpl> indexed_db_context) { | 89 scoped_refptr<IndexedDBContextImpl> indexed_db_context) { |
| 88 indexed_db_context->SetForceKeepSessionState(); | 90 indexed_db_context->SetForceKeepSessionState(); |
| 89 } | 91 } |
| 90 | 92 |
| 91 void PurgeMemoryOnIOThread(appcache::AppCacheService* appcache_service) { | 93 void PurgeMemoryOnIOThread(appcache::AppCacheService* appcache_service) { |
| 92 appcache_service->PurgeMemory(); | 94 appcache_service->PurgeMemory(); |
| 93 } | 95 } |
| 94 | 96 |
| 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::SourceTag source_tag = |
| 104 ui::Clipboard::GetForCurrentThread()->ReadSourceTag(); |
| 105 if (source_tag == ui::Clipboard::SourceTag(this)) { |
| 106 ui::Clipboard::GetForCurrentThread()->Clear( |
| 107 ui::Clipboard::BUFFER_STANDARD); |
| 108 } |
| 109 } |
| 110 }; |
| 111 |
| 112 // Returns existing OffTheRecordClipboardDestroyer or creates one. |
| 113 OffTheRecordClipboardDestroyer* GetClipboardDestroyerForBrowserContext( |
| 114 BrowserContext* context) { |
| 115 if (base::SupportsUserData::Data* data = context->GetUserData( |
| 116 kClipboardDestroyerKey)) |
| 117 return static_cast<OffTheRecordClipboardDestroyer*>(data); |
| 118 OffTheRecordClipboardDestroyer* data = new OffTheRecordClipboardDestroyer; |
| 119 context->SetUserData(kClipboardDestroyerKey, data); |
| 120 return data; |
| 121 } |
| 122 |
| 95 } // namespace | 123 } // namespace |
| 96 | 124 |
| 97 // static | 125 // static |
| 98 void BrowserContext::AsyncObliterateStoragePartition( | 126 void BrowserContext::AsyncObliterateStoragePartition( |
| 99 BrowserContext* browser_context, | 127 BrowserContext* browser_context, |
| 100 const GURL& site, | 128 const GURL& site, |
| 101 const base::Closure& on_gc_required) { | 129 const base::Closure& on_gc_required) { |
| 102 GetStoragePartitionMap(browser_context)->AsyncObliterate(site, | 130 GetStoragePartitionMap(browser_context)->AsyncObliterate(site, |
| 103 on_gc_required); | 131 on_gc_required); |
| 104 } | 132 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 BrowserThread::IO, FROM_HERE, | 294 BrowserThread::IO, FROM_HERE, |
| 267 base::Bind( | 295 base::Bind( |
| 268 &PurgeMemoryOnIOThread, | 296 &PurgeMemoryOnIOThread, |
| 269 BrowserContext::GetDefaultStoragePartition(browser_context)-> | 297 BrowserContext::GetDefaultStoragePartition(browser_context)-> |
| 270 GetAppCacheService())); | 298 GetAppCacheService())); |
| 271 } | 299 } |
| 272 | 300 |
| 273 ForEachStoragePartition(browser_context, | 301 ForEachStoragePartition(browser_context, |
| 274 base::Bind(&PurgeDOMStorageContextInPartition)); | 302 base::Bind(&PurgeDOMStorageContextInPartition)); |
| 275 } | 303 } |
| 304 |
| 305 ui::Clipboard::SourceTag BrowserContext::GetMarkerForOffTheRecordContext( |
| 306 BrowserContext* context) { |
| 307 if (context && context->IsOffTheRecord()) { |
| 308 OffTheRecordClipboardDestroyer* clipboard_destroyer = |
| 309 GetClipboardDestroyerForBrowserContext(context); |
| 310 |
| 311 return ui::Clipboard::SourceTag(clipboard_destroyer); |
| 312 } |
| 313 return ui::Clipboard::SourceTag(); |
| 314 } |
| 276 #endif // !OS_IOS | 315 #endif // !OS_IOS |
| 277 | 316 |
| 278 BrowserContext::~BrowserContext() { | 317 BrowserContext::~BrowserContext() { |
| 279 #if !defined(OS_IOS) | 318 #if !defined(OS_IOS) |
| 280 if (GetUserData(kDownloadManagerKeyName)) | 319 if (GetUserData(kDownloadManagerKeyName)) |
| 281 GetDownloadManager(this)->Shutdown(); | 320 GetDownloadManager(this)->Shutdown(); |
| 282 #endif | 321 #endif |
| 283 } | 322 } |
| 284 | 323 |
| 285 } // namespace content | 324 } // namespace content |
| OLD | NEW |