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 "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* GetStoragePartitionByPartitionId( | 40 StoragePartition* GetStoragePartitionFromConfig( |
|
awong
2012/11/07 18:14:30
Can the parameters move back up to the preceding l
nasko
2012/11/07 18:48:05
The partition_domain parameter exceeds 80 cols onc
| |
| 41 BrowserContext* browser_context, | 41 BrowserContext* browser_context, |
| 42 const std::string& partition_id) { | 42 const std::string& partition_domain, |
| 43 const std::string& partition_name, | |
| 44 bool in_memory) { | |
| 43 StoragePartitionImplMap* partition_map = | 45 StoragePartitionImplMap* partition_map = |
| 44 static_cast<StoragePartitionImplMap*>( | 46 static_cast<StoragePartitionImplMap*>( |
| 45 browser_context->GetUserData(kStorageParitionMapKeyName)); | 47 browser_context->GetUserData(kStorageParitionMapKeyName)); |
| 46 if (!partition_map) { | 48 if (!partition_map) { |
| 47 partition_map = new StoragePartitionImplMap(browser_context); | 49 partition_map = new StoragePartitionImplMap(browser_context); |
| 48 browser_context->SetUserData(kStorageParitionMapKeyName, partition_map); | 50 browser_context->SetUserData(kStorageParitionMapKeyName, partition_map); |
| 49 } | 51 } |
| 50 | 52 |
| 51 return partition_map->Get(partition_id); | 53 if (browser_context->IsOffTheRecord()) |
| 54 in_memory = true; | |
| 55 | |
| 56 // TODO(nasko): Webview tags with named partitions will have both | |
| 57 // partition_domain and partition_name set. In this case, mark them in-memory | |
| 58 // until the on-disk storage code has landed. http://crbug.com/159464 | |
| 59 if (!partition_domain.empty() && !partition_name.empty()) | |
| 60 in_memory = true; | |
| 61 | |
| 62 return partition_map->Get(partition_domain, partition_name, in_memory); | |
| 52 } | 63 } |
| 53 | 64 |
| 54 // Run |callback| on each DOMStorageContextImpl in |browser_context|. | 65 // Run |callback| on each DOMStorageContextImpl in |browser_context|. |
| 55 void PurgeDOMStorageContextInPartition(const std::string& id, | 66 void PurgeDOMStorageContextInPartition(StoragePartition* storage_partition) { |
| 56 StoragePartition* storage_partition) { | |
| 57 static_cast<StoragePartitionImpl*>(storage_partition)-> | 67 static_cast<StoragePartitionImpl*>(storage_partition)-> |
| 58 GetDOMStorageContext()->PurgeMemory(); | 68 GetDOMStorageContext()->PurgeMemory(); |
| 59 } | 69 } |
| 60 | 70 |
| 61 void SaveSessionStateOnIOThread( | 71 void SaveSessionStateOnIOThread( |
| 62 const scoped_refptr<net::URLRequestContextGetter>& context_getter, | 72 const scoped_refptr<net::URLRequestContextGetter>& context_getter, |
| 63 appcache::AppCacheService* appcache_service) { | 73 appcache::AppCacheService* appcache_service) { |
| 64 net::URLRequestContext* context = context_getter->GetURLRequestContext(); | 74 net::URLRequestContext* context = context_getter->GetURLRequestContext(); |
| 65 context->cookie_store()->GetCookieMonster()-> | 75 context->cookie_store()->GetCookieMonster()-> |
| 66 SetForceKeepSessionState(); | 76 SetForceKeepSessionState(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 97 download_manager->Init(context); | 107 download_manager->Init(context); |
| 98 } | 108 } |
| 99 | 109 |
| 100 return UserDataAdapter<DownloadManager>::Get( | 110 return UserDataAdapter<DownloadManager>::Get( |
| 101 context, kDownloadManagerKeyName); | 111 context, kDownloadManagerKeyName); |
| 102 } | 112 } |
| 103 | 113 |
| 104 StoragePartition* BrowserContext::GetStoragePartition( | 114 StoragePartition* BrowserContext::GetStoragePartition( |
| 105 BrowserContext* browser_context, | 115 BrowserContext* browser_context, |
| 106 SiteInstance* site_instance) { | 116 SiteInstance* site_instance) { |
| 107 std::string partition_id; // Default to "" for NULL |site_instance|. | 117 std::string partition_domain; |
| 118 std::string partition_name; | |
| 119 bool in_memory = false; | |
| 108 | 120 |
| 109 // TODO(ajwong): After GetDefaultStoragePartition() is removed, get rid of | 121 // TODO(ajwong): After GetDefaultStoragePartition() is removed, get rid of |
| 110 // this conditional and require that |site_instance| is non-NULL. | 122 // this conditional and require that |site_instance| is non-NULL. |
| 111 if (site_instance) { | 123 if (site_instance) { |
| 112 partition_id = GetContentClient()->browser()-> | 124 GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
| 113 GetStoragePartitionIdForSite(browser_context, | 125 browser_context, site_instance->GetSiteURL(), |
| 114 site_instance->GetSiteURL()); | 126 &partition_domain, &partition_name, &in_memory); |
| 115 } | 127 } |
| 116 | 128 |
| 117 return GetStoragePartitionByPartitionId(browser_context, partition_id); | 129 return GetStoragePartitionFromConfig( |
| 130 browser_context, partition_domain, partition_name, in_memory); | |
| 118 } | 131 } |
| 119 | 132 |
| 120 StoragePartition* BrowserContext::GetStoragePartitionForSite( | 133 StoragePartition* BrowserContext::GetStoragePartitionForSite( |
| 121 BrowserContext* browser_context, | 134 BrowserContext* browser_context, |
| 122 const GURL& site) { | 135 const GURL& site) { |
| 123 std::string partition_id = GetContentClient()->browser()-> | 136 std::string partition_domain; |
| 124 GetStoragePartitionIdForSite(browser_context, site); | 137 std::string partition_name; |
| 138 bool in_memory; | |
| 125 | 139 |
| 126 return GetStoragePartitionByPartitionId(browser_context, partition_id); | 140 GetContentClient()->browser()->GetStoragePartitionConfigForSite( |
| 141 browser_context, site, &partition_domain, &partition_name, &in_memory); | |
| 142 | |
| 143 return GetStoragePartitionFromConfig( | |
| 144 browser_context, partition_domain, partition_name, in_memory); | |
| 127 } | 145 } |
| 128 | 146 |
| 129 void BrowserContext::ForEachStoragePartition( | 147 void BrowserContext::ForEachStoragePartition( |
| 130 BrowserContext* browser_context, | 148 BrowserContext* browser_context, |
| 131 const StoragePartitionCallback& callback) { | 149 const StoragePartitionCallback& callback) { |
| 132 StoragePartitionImplMap* partition_map = | 150 StoragePartitionImplMap* partition_map = |
| 133 static_cast<StoragePartitionImplMap*>( | 151 static_cast<StoragePartitionImplMap*>( |
| 134 browser_context->GetUserData(kStorageParitionMapKeyName)); | 152 browser_context->GetUserData(kStorageParitionMapKeyName)); |
| 135 if (!partition_map) | 153 if (!partition_map) |
| 136 return; | 154 return; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 #endif // !OS_IOS | 219 #endif // !OS_IOS |
| 202 | 220 |
| 203 BrowserContext::~BrowserContext() { | 221 BrowserContext::~BrowserContext() { |
| 204 #if !defined(OS_IOS) | 222 #if !defined(OS_IOS) |
| 205 if (GetUserData(kDownloadManagerKeyName)) | 223 if (GetUserData(kDownloadManagerKeyName)) |
| 206 GetDownloadManager(this)->Shutdown(); | 224 GetDownloadManager(this)->Shutdown(); |
| 207 #endif | 225 #endif |
| 208 } | 226 } |
| 209 | 227 |
| 210 } // namespace content | 228 } // namespace content |
| OLD | NEW |