| 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 "content/browser/appcache/chrome_appcache_service.h" | 8 #include "content/browser/appcache/chrome_appcache_service.h" |
| 9 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 9 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
| 10 #include "content/browser/download/download_manager_impl.h" | 10 #include "content/browser/download/download_manager_impl.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 namespace content { | 30 namespace content { |
| 31 | 31 |
| 32 // Only ~BrowserContext() is needed on iOS. | 32 // Only ~BrowserContext() is needed on iOS. |
| 33 #if !defined(OS_IOS) | 33 #if !defined(OS_IOS) |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // Key names on BrowserContext. | 36 // Key names on BrowserContext. |
| 37 const char* kDownloadManagerKeyName = "download_manager"; | 37 const char* kDownloadManagerKeyName = "download_manager"; |
| 38 const char* kStorageParitionMapKeyName = "content_storage_partition_map"; | 38 const char* kStorageParitionMapKeyName = "content_storage_partition_map"; |
| 39 | 39 |
| 40 StoragePartition* GetStoragePartitionFromConfig( | 40 StoragePartitionImplMap* GetStoragePartitionMap( |
| 41 BrowserContext* browser_context, | 41 BrowserContext* browser_context) { |
| 42 const std::string& partition_domain, | |
| 43 const std::string& partition_name, | |
| 44 bool in_memory) { | |
| 45 StoragePartitionImplMap* partition_map = | 42 StoragePartitionImplMap* partition_map = |
| 46 static_cast<StoragePartitionImplMap*>( | 43 static_cast<StoragePartitionImplMap*>( |
| 47 browser_context->GetUserData(kStorageParitionMapKeyName)); | 44 browser_context->GetUserData(kStorageParitionMapKeyName)); |
| 48 if (!partition_map) { | 45 if (!partition_map) { |
| 49 partition_map = new StoragePartitionImplMap(browser_context); | 46 partition_map = new StoragePartitionImplMap(browser_context); |
| 50 browser_context->SetUserData(kStorageParitionMapKeyName, partition_map); | 47 browser_context->SetUserData(kStorageParitionMapKeyName, partition_map); |
| 51 } | 48 } |
| 49 return partition_map; |
| 50 } |
| 51 |
| 52 StoragePartition* GetStoragePartitionFromConfig( |
| 53 BrowserContext* browser_context, |
| 54 const std::string& partition_domain, |
| 55 const std::string& partition_name, |
| 56 bool in_memory) { |
| 57 StoragePartitionImplMap* partition_map = |
| 58 GetStoragePartitionMap(browser_context); |
| 52 | 59 |
| 53 if (browser_context->IsOffTheRecord()) | 60 if (browser_context->IsOffTheRecord()) |
| 54 in_memory = true; | 61 in_memory = true; |
| 55 | 62 |
| 56 return partition_map->Get(partition_domain, partition_name, in_memory); | 63 return partition_map->Get(partition_domain, partition_name, in_memory); |
| 57 } | 64 } |
| 58 | 65 |
| 59 // Run |callback| on each DOMStorageContextImpl in |browser_context|. | 66 // Run |callback| on each DOMStorageContextImpl in |browser_context|. |
| 60 void PurgeDOMStorageContextInPartition(StoragePartition* storage_partition) { | 67 void PurgeDOMStorageContextInPartition(StoragePartition* storage_partition) { |
| 61 static_cast<StoragePartitionImpl*>(storage_partition)-> | 68 static_cast<StoragePartitionImpl*>(storage_partition)-> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 77 scoped_refptr<IndexedDBContextImpl> indexed_db_context) { | 84 scoped_refptr<IndexedDBContextImpl> indexed_db_context) { |
| 78 indexed_db_context->SetForceKeepSessionState(); | 85 indexed_db_context->SetForceKeepSessionState(); |
| 79 } | 86 } |
| 80 | 87 |
| 81 void PurgeMemoryOnIOThread(appcache::AppCacheService* appcache_service) { | 88 void PurgeMemoryOnIOThread(appcache::AppCacheService* appcache_service) { |
| 82 appcache_service->PurgeMemory(); | 89 appcache_service->PurgeMemory(); |
| 83 } | 90 } |
| 84 | 91 |
| 85 } // namespace | 92 } // namespace |
| 86 | 93 |
| 94 // static |
| 95 void BrowserContext::AsyncObliterateStoragePartition( |
| 96 BrowserContext* browser_context, |
| 97 const GURL& site) { |
| 98 GetStoragePartitionMap(browser_context)->AsyncObliterate(site); |
| 99 } |
| 100 |
| 87 DownloadManager* BrowserContext::GetDownloadManager( | 101 DownloadManager* BrowserContext::GetDownloadManager( |
| 88 BrowserContext* context) { | 102 BrowserContext* context) { |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 90 if (!context->GetUserData(kDownloadManagerKeyName)) { | 104 if (!context->GetUserData(kDownloadManagerKeyName)) { |
| 91 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | 105 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
| 92 DCHECK(rdh); | 106 DCHECK(rdh); |
| 93 scoped_refptr<DownloadManager> download_manager = | 107 scoped_refptr<DownloadManager> download_manager = |
| 94 new DownloadManagerImpl( | 108 new DownloadManagerImpl( |
| 95 GetContentClient()->browser()->GetNetLog()); | 109 GetContentClient()->browser()->GetNetLog()); |
| 96 | 110 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 109 BrowserContext* browser_context, | 123 BrowserContext* browser_context, |
| 110 SiteInstance* site_instance) { | 124 SiteInstance* site_instance) { |
| 111 std::string partition_domain; | 125 std::string partition_domain; |
| 112 std::string partition_name; | 126 std::string partition_name; |
| 113 bool in_memory = false; | 127 bool in_memory = false; |
| 114 | 128 |
| 115 // TODO(ajwong): After GetDefaultStoragePartition() is removed, get rid of | 129 // TODO(ajwong): After GetDefaultStoragePartition() is removed, get rid of |
| 116 // this conditional and require that |site_instance| is non-NULL. | 130 // this conditional and require that |site_instance| is non-NULL. |
| 117 if (site_instance) { | 131 if (site_instance) { |
| 118 GetContentClient()->browser()->GetStoragePartitionConfigForSite( | 132 GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
| 119 browser_context, site_instance->GetSiteURL(), | 133 browser_context, site_instance->GetSiteURL(), true, |
| 120 &partition_domain, &partition_name, &in_memory); | 134 &partition_domain, &partition_name, &in_memory); |
| 121 } | 135 } |
| 122 | 136 |
| 123 return GetStoragePartitionFromConfig( | 137 return GetStoragePartitionFromConfig( |
| 124 browser_context, partition_domain, partition_name, in_memory); | 138 browser_context, partition_domain, partition_name, in_memory); |
| 125 } | 139 } |
| 126 | 140 |
| 127 StoragePartition* BrowserContext::GetStoragePartitionForSite( | 141 StoragePartition* BrowserContext::GetStoragePartitionForSite( |
| 128 BrowserContext* browser_context, | 142 BrowserContext* browser_context, |
| 129 const GURL& site) { | 143 const GURL& site) { |
| 130 std::string partition_domain; | 144 std::string partition_domain; |
| 131 std::string partition_name; | 145 std::string partition_name; |
| 132 bool in_memory; | 146 bool in_memory; |
| 133 | 147 |
| 134 GetContentClient()->browser()->GetStoragePartitionConfigForSite( | 148 GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
| 135 browser_context, site, &partition_domain, &partition_name, &in_memory); | 149 browser_context, site, true, &partition_domain, &partition_name, |
| 150 &in_memory); |
| 136 | 151 |
| 137 return GetStoragePartitionFromConfig( | 152 return GetStoragePartitionFromConfig( |
| 138 browser_context, partition_domain, partition_name, in_memory); | 153 browser_context, partition_domain, partition_name, in_memory); |
| 139 } | 154 } |
| 140 | 155 |
| 141 void BrowserContext::ForEachStoragePartition( | 156 void BrowserContext::ForEachStoragePartition( |
| 142 BrowserContext* browser_context, | 157 BrowserContext* browser_context, |
| 143 const StoragePartitionCallback& callback) { | 158 const StoragePartitionCallback& callback) { |
| 144 StoragePartitionImplMap* partition_map = | 159 StoragePartitionImplMap* partition_map = |
| 145 static_cast<StoragePartitionImplMap*>( | 160 static_cast<StoragePartitionImplMap*>( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 #endif // !OS_IOS | 228 #endif // !OS_IOS |
| 214 | 229 |
| 215 BrowserContext::~BrowserContext() { | 230 BrowserContext::~BrowserContext() { |
| 216 #if !defined(OS_IOS) | 231 #if !defined(OS_IOS) |
| 217 if (GetUserData(kDownloadManagerKeyName)) | 232 if (GetUserData(kDownloadManagerKeyName)) |
| 218 GetDownloadManager(this)->Shutdown(); | 233 GetDownloadManager(this)->Shutdown(); |
| 219 #endif | 234 #endif |
| 220 } | 235 } |
| 221 | 236 |
| 222 } // namespace content | 237 } // namespace content |
| OLD | NEW |