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* GetStoragePartitionByPartitionDescription( |
awong
2012/11/02 21:56:13
Name is too long. This is just a helper so it's a
nasko
2012/11/03 00:36:24
Done.
| |
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 const 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 return partition_map->Get(partition_domain, partition_name, in_memory); |
52 } | 54 } |
53 | 55 |
54 // Run |callback| on each DOMStorageContextImpl in |browser_context|. | 56 // Run |callback| on each DOMStorageContextImpl in |browser_context|. |
55 void PurgeDOMStorageContextInPartition(const std::string& id, | 57 void PurgeDOMStorageContextInPartition(StoragePartition* storage_partition) { |
56 StoragePartition* storage_partition) { | |
57 static_cast<StoragePartitionImpl*>(storage_partition)-> | 58 static_cast<StoragePartitionImpl*>(storage_partition)-> |
58 GetDOMStorageContext()->PurgeMemory(); | 59 GetDOMStorageContext()->PurgeMemory(); |
59 } | 60 } |
60 | 61 |
61 void SaveSessionStateOnIOThread( | 62 void SaveSessionStateOnIOThread( |
62 const scoped_refptr<net::URLRequestContextGetter>& context_getter, | 63 const scoped_refptr<net::URLRequestContextGetter>& context_getter, |
63 appcache::AppCacheService* appcache_service) { | 64 appcache::AppCacheService* appcache_service) { |
64 net::URLRequestContext* context = context_getter->GetURLRequestContext(); | 65 net::URLRequestContext* context = context_getter->GetURLRequestContext(); |
65 context->cookie_store()->GetCookieMonster()-> | 66 context->cookie_store()->GetCookieMonster()-> |
66 SetForceKeepSessionState(); | 67 SetForceKeepSessionState(); |
(...skipping 30 matching lines...) Expand all Loading... | |
97 download_manager->Init(context); | 98 download_manager->Init(context); |
98 } | 99 } |
99 | 100 |
100 return UserDataAdapter<DownloadManager>::Get( | 101 return UserDataAdapter<DownloadManager>::Get( |
101 context, kDownloadManagerKeyName); | 102 context, kDownloadManagerKeyName); |
102 } | 103 } |
103 | 104 |
104 StoragePartition* BrowserContext::GetStoragePartition( | 105 StoragePartition* BrowserContext::GetStoragePartition( |
105 BrowserContext* browser_context, | 106 BrowserContext* browser_context, |
106 SiteInstance* site_instance) { | 107 SiteInstance* site_instance) { |
107 std::string partition_id; // Default to "" for NULL |site_instance|. | 108 std::string partition_domain; |
109 std::string partition_name; | |
110 bool in_memory = false; | |
108 | 111 |
109 // TODO(ajwong): After GetDefaultStoragePartition() is removed, get rid of | 112 // TODO(ajwong): After GetDefaultStoragePartition() is removed, get rid of |
110 // this conditional and require that |site_instance| is non-NULL. | 113 // this conditional and require that |site_instance| is non-NULL. |
111 if (site_instance) { | 114 if (site_instance) { |
112 partition_id = GetContentClient()->browser()-> | 115 GetContentClient()->browser()->GetStoragePartitionDescriptionForSite( |
113 GetStoragePartitionIdForSite(browser_context, | 116 browser_context, site_instance->GetSiteURL(), |
114 site_instance->GetSiteURL()); | 117 &partition_domain, &partition_name, &in_memory); |
115 } | 118 } |
116 | 119 |
117 return GetStoragePartitionByPartitionId(browser_context, partition_id); | 120 return GetStoragePartitionByPartitionDescription( |
121 browser_context, partition_domain, partition_name, in_memory); | |
118 } | 122 } |
119 | 123 |
120 StoragePartition* BrowserContext::GetStoragePartitionForSite( | 124 StoragePartition* BrowserContext::GetStoragePartitionForSite( |
121 BrowserContext* browser_context, | 125 BrowserContext* browser_context, |
122 const GURL& site) { | 126 const GURL& site) { |
123 std::string partition_id = GetContentClient()->browser()-> | 127 std::string partition_domain; |
124 GetStoragePartitionIdForSite(browser_context, site); | 128 std::string partition_name; |
129 bool in_memory; | |
125 | 130 |
126 return GetStoragePartitionByPartitionId(browser_context, partition_id); | 131 GetContentClient()->browser()->GetStoragePartitionDescriptionForSite( |
132 browser_context, site, &partition_domain, &partition_name, &in_memory); | |
133 | |
134 return GetStoragePartitionByPartitionDescription( | |
135 browser_context, partition_domain, partition_name, in_memory); | |
127 } | 136 } |
128 | 137 |
129 void BrowserContext::ForEachStoragePartition( | 138 void BrowserContext::ForEachStoragePartition( |
130 BrowserContext* browser_context, | 139 BrowserContext* browser_context, |
131 const StoragePartitionCallback& callback) { | 140 const StoragePartitionCallback& callback) { |
132 StoragePartitionImplMap* partition_map = | 141 StoragePartitionImplMap* partition_map = |
133 static_cast<StoragePartitionImplMap*>( | 142 static_cast<StoragePartitionImplMap*>( |
134 browser_context->GetUserData(kStorageParitionMapKeyName)); | 143 browser_context->GetUserData(kStorageParitionMapKeyName)); |
135 if (!partition_map) | 144 if (!partition_map) |
136 return; | 145 return; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 #endif // !OS_IOS | 210 #endif // !OS_IOS |
202 | 211 |
203 BrowserContext::~BrowserContext() { | 212 BrowserContext::~BrowserContext() { |
204 #if !defined(OS_IOS) | 213 #if !defined(OS_IOS) |
205 if (GetUserData(kDownloadManagerKeyName)) | 214 if (GetUserData(kDownloadManagerKeyName)) |
206 GetDownloadManager(this)->Shutdown(); | 215 GetDownloadManager(this)->Shutdown(); |
207 #endif | 216 #endif |
208 } | 217 } |
209 | 218 |
210 } // namespace content | 219 } // namespace content |
OLD | NEW |