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