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