Chromium Code Reviews| 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* 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 } | |
|
battre
2013/02/12 12:50:59
nit: new lien before private:
vasilii
2013/02/12 15:58:32
Done.
| |
| 108 private: | |
| 109 void ExamineClipboard(ui::Clipboard* clipboard, | |
| 110 ui::Clipboard::Buffer buffer) { | |
|
battre
2013/02/12 12:50:59
nit: indentation
vasilii
2013/02/12 15:58:32
Done.
| |
| 111 ui::Clipboard::SourceTag source_tag = clipboard->ReadSourceTag(buffer); | |
| 112 if (source_tag == ui::Clipboard::SourceTag(this)) | |
| 113 clipboard->Clear(buffer); | |
| 114 } | |
| 115 }; | |
| 116 | |
| 117 // Returns existing OffTheRecordClipboardDestroyer or creates one. | |
| 118 OffTheRecordClipboardDestroyer* GetClipboardDestroyerForBrowserContext( | |
| 119 BrowserContext* context) { | |
| 120 if (base::SupportsUserData::Data* data = context->GetUserData( | |
| 121 kClipboardDestroyerKey)) | |
|
battre
2013/02/12 12:50:59
nit: +4 spaces indentation
vasilii
2013/02/12 15:58:32
Done.
| |
| 122 return static_cast<OffTheRecordClipboardDestroyer*>(data); | |
| 123 OffTheRecordClipboardDestroyer* data = new OffTheRecordClipboardDestroyer; | |
| 124 context->SetUserData(kClipboardDestroyerKey, data); | |
| 125 return data; | |
| 126 } | |
| 127 | |
| 95 } // namespace | 128 } // namespace |
| 96 | 129 |
| 97 // static | 130 // static |
| 98 void BrowserContext::AsyncObliterateStoragePartition( | 131 void BrowserContext::AsyncObliterateStoragePartition( |
| 99 BrowserContext* browser_context, | 132 BrowserContext* browser_context, |
| 100 const GURL& site, | 133 const GURL& site, |
| 101 const base::Closure& on_gc_required) { | 134 const base::Closure& on_gc_required) { |
| 102 GetStoragePartitionMap(browser_context)->AsyncObliterate(site, | 135 GetStoragePartitionMap(browser_context)->AsyncObliterate(site, |
| 103 on_gc_required); | 136 on_gc_required); |
| 104 } | 137 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 BrowserThread::IO, FROM_HERE, | 299 BrowserThread::IO, FROM_HERE, |
| 267 base::Bind( | 300 base::Bind( |
| 268 &PurgeMemoryOnIOThread, | 301 &PurgeMemoryOnIOThread, |
| 269 BrowserContext::GetDefaultStoragePartition(browser_context)-> | 302 BrowserContext::GetDefaultStoragePartition(browser_context)-> |
| 270 GetAppCacheService())); | 303 GetAppCacheService())); |
| 271 } | 304 } |
| 272 | 305 |
| 273 ForEachStoragePartition(browser_context, | 306 ForEachStoragePartition(browser_context, |
| 274 base::Bind(&PurgeDOMStorageContextInPartition)); | 307 base::Bind(&PurgeDOMStorageContextInPartition)); |
| 275 } | 308 } |
| 309 | |
| 310 ui::Clipboard::SourceTag BrowserContext::GetMarkerForOffTheRecordContext( | |
| 311 BrowserContext* context) { | |
| 312 if (context && context->IsOffTheRecord()) { | |
| 313 OffTheRecordClipboardDestroyer* clipboard_destroyer = | |
| 314 GetClipboardDestroyerForBrowserContext(context); | |
| 315 | |
| 316 return ui::Clipboard::SourceTag(clipboard_destroyer); | |
|
battre
2013/02/12 12:50:59
How about adding a function
ui::Clipboard::Source
vasilii
2013/02/12 15:58:32
Done.
| |
| 317 } | |
| 318 return ui::Clipboard::SourceTag(); | |
| 319 } | |
| 276 #endif // !OS_IOS | 320 #endif // !OS_IOS |
| 277 | 321 |
| 278 BrowserContext::~BrowserContext() { | 322 BrowserContext::~BrowserContext() { |
| 279 #if !defined(OS_IOS) | 323 #if !defined(OS_IOS) |
| 280 if (GetUserData(kDownloadManagerKeyName)) | 324 if (GetUserData(kDownloadManagerKeyName)) |
| 281 GetDownloadManager(this)->Shutdown(); | 325 GetDownloadManager(this)->Shutdown(); |
| 282 #endif | 326 #endif |
| 283 } | 327 } |
| 284 | 328 |
| 285 } // namespace content | 329 } // namespace content |
| OLD | NEW |