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 #include "content/browser/appcache/chrome_appcache_service.h" | 7 #include "content/browser/appcache/chrome_appcache_service.h" |
8 #include "webkit/database/database_tracker.h" | 8 #include "webkit/database/database_tracker.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_file_manager.h" | 10 #include "content/browser/download/download_file_manager.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 using base::UserDataAdapter; | 26 using base::UserDataAdapter; |
27 | 27 |
28 // Key names on BrowserContext. | 28 // Key names on BrowserContext. |
29 static const char* kDownloadManagerKeyName = "download_manager"; | 29 static const char* kDownloadManagerKeyName = "download_manager"; |
30 static const char* kStorageParitionMapKeyName = "content_storage_partition_map"; | 30 static const char* kStorageParitionMapKeyName = "content_storage_partition_map"; |
31 | 31 |
32 namespace content { | 32 namespace content { |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 StoragePartition* GetStoragePartitionByPartitionId( | |
37 BrowserContext* browser_context, | |
38 const std::string& partition_id) { | |
39 StoragePartitionImplMap* partition_map = | |
40 static_cast<StoragePartitionImplMap*>( | |
41 browser_context->GetUserData(kStorageParitionMapKeyName)); | |
42 if (!partition_map) { | |
43 partition_map = new StoragePartitionImplMap(browser_context); | |
44 browser_context->SetUserData(kStorageParitionMapKeyName, partition_map); | |
45 } | |
46 | |
47 return partition_map->Get(partition_id); | |
48 } | |
49 | |
50 // Run |callback| on each DOMStorageContextImpl in |browser_context|. | |
51 void PurgeDOMStorageContextInPartition(const std::string& id, | 36 void PurgeDOMStorageContextInPartition(const std::string& id, |
52 StoragePartition* storage_partition) { | 37 StoragePartition* storage_partition) { |
53 static_cast<StoragePartitionImpl*>(storage_partition)-> | 38 static_cast<StoragePartitionImpl*>(storage_partition)-> |
54 GetDOMStorageContext()->PurgeMemory(); | 39 GetDOMStorageContext()->PurgeMemory(); |
55 } | 40 } |
56 | 41 |
| 42 void KeepSessionStateInPartition(const std::string& id, |
| 43 StoragePartition* storage_partition) { |
| 44 static_cast<StoragePartitionImpl*>(storage_partition)-> |
| 45 GetDOMStorageContext()->SetForceKeepSessionState(); |
| 46 } |
| 47 |
57 void SaveSessionStateOnIOThread(ResourceContext* resource_context) { | 48 void SaveSessionStateOnIOThread(ResourceContext* resource_context) { |
58 resource_context->GetRequestContext()->cookie_store()->GetCookieMonster()-> | 49 resource_context->GetRequestContext()->cookie_store()->GetCookieMonster()-> |
59 SetForceKeepSessionState(); | 50 SetForceKeepSessionState(); |
60 resource_context->GetRequestContext()->server_bound_cert_service()-> | 51 resource_context->GetRequestContext()->server_bound_cert_service()-> |
61 GetCertStore()->SetForceKeepSessionState(); | 52 GetCertStore()->SetForceKeepSessionState(); |
62 ResourceContext::GetAppCacheService(resource_context)-> | 53 ResourceContext::GetAppCacheService(resource_context)-> |
63 set_force_keep_session_state(); | 54 set_force_keep_session_state(); |
64 } | 55 } |
65 | 56 |
66 void SaveSessionStateOnWebkitThread( | 57 void SaveSessionStateOnWebkitThread( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 return GetDefaultStoragePartition(browser_context)->GetAppCacheService(); | 118 return GetDefaultStoragePartition(browser_context)->GetAppCacheService(); |
128 } | 119 } |
129 | 120 |
130 fileapi::FileSystemContext* BrowserContext::GetFileSystemContext( | 121 fileapi::FileSystemContext* BrowserContext::GetFileSystemContext( |
131 BrowserContext* browser_context) { | 122 BrowserContext* browser_context) { |
132 // TODO(ajwong): Change this API to require a SiteInstance instead of | 123 // TODO(ajwong): Change this API to require a SiteInstance instead of |
133 // using GetDefaultStoragePartition(). | 124 // using GetDefaultStoragePartition(). |
134 return GetDefaultStoragePartition(browser_context)->GetFileSystemContext(); | 125 return GetDefaultStoragePartition(browser_context)->GetFileSystemContext(); |
135 } | 126 } |
136 | 127 |
| 128 bool BrowserContext::IsValidPartitionId(BrowserContext* browser_context, |
| 129 const std::string& partition_id) { |
| 130 return GetContentClient()->browser()->IsValidStoragePartitionId( |
| 131 browser_context, partition_id); |
| 132 } |
| 133 |
137 StoragePartition* BrowserContext::GetStoragePartition( | 134 StoragePartition* BrowserContext::GetStoragePartition( |
138 BrowserContext* browser_context, | 135 BrowserContext* browser_context, |
139 SiteInstance* site_instance) { | 136 SiteInstance* site_instance) { |
140 std::string partition_id; // Default to "" for NULL |site_instance|. | 137 std::string partition_id; // Default to "" for NULL |site_instance|. |
141 | 138 |
142 // TODO(ajwong): After GetDefaultStoragePartition() is removed, get rid of | 139 // TODO(ajwong): After GetDefaultStoragePartition() is removed, get rid of |
143 // this conditional and require that |site_instance| is non-NULL. | 140 // this conditional and require that |site_instance| is non-NULL. |
144 if (site_instance) { | 141 if (site_instance) { |
145 partition_id = GetContentClient()->browser()-> | 142 partition_id = GetContentClient()->browser()-> |
146 GetStoragePartitionIdForSiteInstance(browser_context, | 143 GetStoragePartitionIdForSiteInstance(browser_context, |
147 site_instance); | 144 site_instance); |
148 } | 145 } |
149 | 146 |
150 return GetStoragePartitionByPartitionId(browser_context, partition_id); | 147 return GetStoragePartitionById(browser_context, partition_id); |
| 148 } |
| 149 |
| 150 StoragePartition* BrowserContext::GetStoragePartitionById( |
| 151 BrowserContext* browser_context, |
| 152 const std::string& partition_id) { |
| 153 StoragePartitionImplMap* partition_map = |
| 154 static_cast<StoragePartitionImplMap*>( |
| 155 browser_context->GetUserData(kStorageParitionMapKeyName)); |
| 156 if (!partition_map) { |
| 157 partition_map = new StoragePartitionImplMap(browser_context); |
| 158 browser_context->SetUserData(kStorageParitionMapKeyName, partition_map); |
| 159 } |
| 160 |
| 161 return partition_map->Get(partition_id); |
151 } | 162 } |
152 | 163 |
153 void BrowserContext::ForEachStoragePartition( | 164 void BrowserContext::ForEachStoragePartition( |
154 BrowserContext* browser_context, | 165 BrowserContext* browser_context, |
155 const StoragePartitionCallback& callback) { | 166 const StoragePartitionCallback& callback) { |
156 StoragePartitionImplMap* partition_map = | 167 StoragePartitionImplMap* partition_map = |
157 static_cast<StoragePartitionImplMap*>( | 168 static_cast<StoragePartitionImplMap*>( |
158 browser_context->GetUserData(kStorageParitionMapKeyName)); | 169 browser_context->GetUserData(kStorageParitionMapKeyName)); |
159 if (!partition_map) | 170 if (!partition_map) |
160 return; | 171 return; |
(...skipping 21 matching lines...) Expand all Loading... |
182 void BrowserContext::SaveSessionState(BrowserContext* browser_context) { | 193 void BrowserContext::SaveSessionState(BrowserContext* browser_context) { |
183 GetDatabaseTracker(browser_context)->SetForceKeepSessionState(); | 194 GetDatabaseTracker(browser_context)->SetForceKeepSessionState(); |
184 | 195 |
185 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 196 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
186 BrowserThread::PostTask( | 197 BrowserThread::PostTask( |
187 BrowserThread::IO, FROM_HERE, | 198 BrowserThread::IO, FROM_HERE, |
188 base::Bind(&SaveSessionStateOnIOThread, | 199 base::Bind(&SaveSessionStateOnIOThread, |
189 browser_context->GetResourceContext())); | 200 browser_context->GetResourceContext())); |
190 } | 201 } |
191 | 202 |
192 DOMStorageContextImpl* dom_storage_context_impl = | 203 ForEachStoragePartition(browser_context, |
193 static_cast<DOMStorageContextImpl*>( | 204 base::Bind(&KeepSessionStateInPartition)); |
194 GetDefaultStoragePartition(browser_context)->GetDOMStorageContext()); | |
195 dom_storage_context_impl->SetForceKeepSessionState(); | |
196 | 205 |
197 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { | 206 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { |
198 IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( | 207 IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( |
199 GetIndexedDBContext(browser_context)); | 208 GetIndexedDBContext(browser_context)); |
200 BrowserThread::PostTask( | 209 BrowserThread::PostTask( |
201 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 210 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
202 base::Bind(&SaveSessionStateOnWebkitThread, | 211 base::Bind(&SaveSessionStateOnWebkitThread, |
203 make_scoped_refptr(indexed_db))); | 212 make_scoped_refptr(indexed_db))); |
204 } | 213 } |
205 } | 214 } |
206 | 215 |
207 void BrowserContext::PurgeMemory(BrowserContext* browser_context) { | 216 void BrowserContext::PurgeMemory(BrowserContext* browser_context) { |
208 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 217 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
209 BrowserThread::PostTask( | 218 BrowserThread::PostTask( |
210 BrowserThread::IO, FROM_HERE, | 219 BrowserThread::IO, FROM_HERE, |
211 base::Bind(&PurgeMemoryOnIOThread, | 220 base::Bind(&PurgeMemoryOnIOThread, |
212 browser_context->GetResourceContext())); | 221 browser_context->GetResourceContext())); |
213 } | 222 } |
214 | 223 |
215 ForEachStoragePartition(browser_context, | 224 ForEachStoragePartition(browser_context, |
216 base::Bind(&PurgeDOMStorageContextInPartition)); | 225 base::Bind(&PurgeDOMStorageContextInPartition)); |
217 } | 226 } |
218 | 227 |
219 BrowserContext::~BrowserContext() { | 228 BrowserContext::~BrowserContext() { |
220 if (GetUserData(kDownloadManagerKeyName)) | 229 if (GetUserData(kDownloadManagerKeyName)) |
221 GetDownloadManager(this)->Shutdown(); | 230 GetDownloadManager(this)->Shutdown(); |
222 } | 231 } |
223 | 232 |
224 } // namespace content | 233 } // namespace content |
OLD | NEW |