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/browser/storage_partition_impl.h" | 5 #include "content/browser/storage_partition_impl.h" |
6 | 6 |
7 #include "base/sequenced_task_runner.h" | 7 #include "base/sequenced_task_runner.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/browser/browser_main_loop.h" | 9 #include "content/browser/browser_main_loop.h" |
10 #include "content/browser/fileapi/browser_file_system_helper.h" | 10 #include "content/browser/fileapi/browser_file_system_helper.h" |
11 #include "content/browser/gpu/shader_disk_cache.h" | 11 #include "content/browser/gpu/shader_disk_cache.h" |
| 12 #include "content/common/dom_storage/dom_storage_types.h" |
12 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/browser/dom_storage_context.h" | 15 #include "content/public/browser/dom_storage_context.h" |
15 #include "content/public/browser/indexed_db_context.h" | 16 #include "content/public/browser/indexed_db_context.h" |
| 17 #include "content/public/browser/local_storage_usage_info.h" |
| 18 #include "content/public/browser/session_storage_usage_info.h" |
16 #include "net/base/completion_callback.h" | 19 #include "net/base/completion_callback.h" |
17 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
18 #include "net/cookies/cookie_monster.h" | 21 #include "net/cookies/cookie_monster.h" |
19 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
20 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
21 #include "webkit/browser/database/database_tracker.h" | 24 #include "webkit/browser/database/database_tracker.h" |
22 #include "webkit/browser/quota/quota_manager.h" | 25 #include "webkit/browser/quota/quota_manager.h" |
23 #include "webkit/common/dom_storage/dom_storage_types.h" | |
24 | 26 |
25 namespace content { | 27 namespace content { |
26 | 28 |
27 namespace { | 29 namespace { |
28 | 30 |
29 int GenerateQuotaClientMask(uint32 remove_mask) { | 31 int GenerateQuotaClientMask(uint32 remove_mask) { |
30 int quota_client_mask = 0; | 32 int quota_client_mask = 0; |
31 | 33 |
32 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS) | 34 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS) |
33 quota_client_mask |= quota::QuotaClient::kFileSystem; | 35 quota_client_mask |= quota::QuotaClient::kFileSystem; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 void ClearShaderCacheOnIOThread(const base::FilePath& path, | 128 void ClearShaderCacheOnIOThread(const base::FilePath& path, |
127 const base::Time begin, | 129 const base::Time begin, |
128 const base::Time end, | 130 const base::Time end, |
129 const base::Closure& callback) { | 131 const base::Closure& callback) { |
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
131 ShaderCacheFactory::GetInstance()->ClearByPath( | 133 ShaderCacheFactory::GetInstance()->ClearByPath( |
132 path, begin, end, base::Bind(&ClearedShaderCache, callback)); | 134 path, begin, end, base::Bind(&ClearedShaderCache, callback)); |
133 } | 135 } |
134 | 136 |
135 void OnLocalStorageUsageInfo( | 137 void OnLocalStorageUsageInfo( |
136 const scoped_refptr<DOMStorageContextImpl>& dom_storage_context, | 138 const scoped_refptr<DOMStorageContextWrapper>& dom_storage_context, |
137 const base::Time delete_begin, | 139 const base::Time delete_begin, |
138 const base::Time delete_end, | 140 const base::Time delete_end, |
139 const base::Closure& callback, | 141 const base::Closure& callback, |
140 const std::vector<dom_storage::LocalStorageUsageInfo>& infos) { | 142 const std::vector<LocalStorageUsageInfo>& infos) { |
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
142 | 144 |
143 for (size_t i = 0; i < infos.size(); ++i) { | 145 for (size_t i = 0; i < infos.size(); ++i) { |
144 if (infos[i].last_modified >= delete_begin && | 146 if (infos[i].last_modified >= delete_begin && |
145 infos[i].last_modified <= delete_end) { | 147 infos[i].last_modified <= delete_end) { |
146 dom_storage_context->DeleteLocalStorage(infos[i].origin); | 148 dom_storage_context->DeleteLocalStorage(infos[i].origin); |
147 } | 149 } |
148 } | 150 } |
149 callback.Run(); | 151 callback.Run(); |
150 } | 152 } |
151 | 153 |
152 void OnSessionStorageUsageInfo( | 154 void OnSessionStorageUsageInfo( |
153 const scoped_refptr<DOMStorageContextImpl>& dom_storage_context, | 155 const scoped_refptr<DOMStorageContextWrapper>& dom_storage_context, |
154 const base::Closure& callback, | 156 const base::Closure& callback, |
155 const std::vector<dom_storage::SessionStorageUsageInfo>& infos) { | 157 const std::vector<SessionStorageUsageInfo>& infos) { |
156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
157 | 159 |
158 for (size_t i = 0; i < infos.size(); ++i) | 160 for (size_t i = 0; i < infos.size(); ++i) |
159 dom_storage_context->DeleteSessionStorage(infos[i]); | 161 dom_storage_context->DeleteSessionStorage(infos[i]); |
160 | 162 |
161 callback.Run(); | 163 callback.Run(); |
162 } | 164 } |
163 | 165 |
164 void ClearLocalStorageOnUIThread( | 166 void ClearLocalStorageOnUIThread( |
165 const scoped_refptr<DOMStorageContextImpl>& dom_storage_context, | 167 const scoped_refptr<DOMStorageContextWrapper>& dom_storage_context, |
166 const GURL& remove_origin, | 168 const GURL& remove_origin, |
167 const base::Time begin, | 169 const base::Time begin, |
168 const base::Time end, | 170 const base::Time end, |
169 const base::Closure& callback) { | 171 const base::Closure& callback) { |
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
171 | 173 |
172 if (!remove_origin.is_empty()) { | 174 if (!remove_origin.is_empty()) { |
173 dom_storage_context->DeleteLocalStorage(remove_origin); | 175 dom_storage_context->DeleteLocalStorage(remove_origin); |
174 callback.Run(); | 176 callback.Run(); |
175 return; | 177 return; |
176 } | 178 } |
177 | 179 |
178 dom_storage_context->GetLocalStorageUsage( | 180 dom_storage_context->GetLocalStorageUsage( |
179 base::Bind(&OnLocalStorageUsageInfo, | 181 base::Bind(&OnLocalStorageUsageInfo, |
180 dom_storage_context, begin, end, callback)); | 182 dom_storage_context, begin, end, callback)); |
181 } | 183 } |
182 | 184 |
183 void ClearSessionStorageOnUIThread( | 185 void ClearSessionStorageOnUIThread( |
184 const scoped_refptr<DOMStorageContextImpl>& dom_storage_context, | 186 const scoped_refptr<DOMStorageContextWrapper>& dom_storage_context, |
185 const base::Closure& callback) { | 187 const base::Closure& callback) { |
186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
187 | 189 |
188 dom_storage_context->GetSessionStorageUsage( | 190 dom_storage_context->GetSessionStorageUsage( |
189 base::Bind(&OnSessionStorageUsageInfo, dom_storage_context, callback)); | 191 base::Bind(&OnSessionStorageUsageInfo, dom_storage_context, callback)); |
190 } | 192 } |
191 | 193 |
192 } // namespace | 194 } // namespace |
193 | 195 |
194 // Helper for deleting quota managed data from a partition. | 196 // Helper for deleting quota managed data from a partition. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 233 } |
232 | 234 |
233 void IncrementTaskCountOnUI(); | 235 void IncrementTaskCountOnUI(); |
234 void DecrementTaskCountOnUI(); | 236 void DecrementTaskCountOnUI(); |
235 | 237 |
236 void ClearDataOnUIThread(uint32 remove_mask, | 238 void ClearDataOnUIThread(uint32 remove_mask, |
237 uint32 quota_storage_remove_mask, | 239 uint32 quota_storage_remove_mask, |
238 const GURL& remove_origin, | 240 const GURL& remove_origin, |
239 const base::FilePath& path, | 241 const base::FilePath& path, |
240 net::URLRequestContextGetter* rq_context, | 242 net::URLRequestContextGetter* rq_context, |
241 DOMStorageContextImpl* dom_storage_context, | 243 DOMStorageContextWrapper* dom_storage_context, |
242 quota::QuotaManager* quota_manager, | 244 quota::QuotaManager* quota_manager, |
243 const base::Time begin, | 245 const base::Time begin, |
244 const base::Time end); | 246 const base::Time end); |
245 | 247 |
246 // Accessed on UI thread. | 248 // Accessed on UI thread. |
247 const base::Closure callback; | 249 const base::Closure callback; |
248 // Accessed on UI thread. | 250 // Accessed on UI thread. |
249 int task_count; | 251 int task_count; |
250 }; | 252 }; |
251 | 253 |
(...skipping 11 matching lines...) Expand all Loading... |
263 helper->ClearDataOnIOThread(quota_manager, begin, | 265 helper->ClearDataOnIOThread(quota_manager, begin, |
264 remove_mask, quota_storage_remove_mask, remove_origin); | 266 remove_mask, quota_storage_remove_mask, remove_origin); |
265 } | 267 } |
266 | 268 |
267 StoragePartitionImpl::StoragePartitionImpl( | 269 StoragePartitionImpl::StoragePartitionImpl( |
268 const base::FilePath& partition_path, | 270 const base::FilePath& partition_path, |
269 quota::QuotaManager* quota_manager, | 271 quota::QuotaManager* quota_manager, |
270 ChromeAppCacheService* appcache_service, | 272 ChromeAppCacheService* appcache_service, |
271 fileapi::FileSystemContext* filesystem_context, | 273 fileapi::FileSystemContext* filesystem_context, |
272 webkit_database::DatabaseTracker* database_tracker, | 274 webkit_database::DatabaseTracker* database_tracker, |
273 DOMStorageContextImpl* dom_storage_context, | 275 DOMStorageContextWrapper* dom_storage_context, |
274 IndexedDBContextImpl* indexed_db_context, | 276 IndexedDBContextImpl* indexed_db_context, |
275 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store) | 277 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store) |
276 : partition_path_(partition_path), | 278 : partition_path_(partition_path), |
277 quota_manager_(quota_manager), | 279 quota_manager_(quota_manager), |
278 appcache_service_(appcache_service), | 280 appcache_service_(appcache_service), |
279 filesystem_context_(filesystem_context), | 281 filesystem_context_(filesystem_context), |
280 database_tracker_(database_tracker), | 282 database_tracker_(database_tracker), |
281 dom_storage_context_(dom_storage_context), | 283 dom_storage_context_(dom_storage_context), |
282 indexed_db_context_(indexed_db_context), | 284 indexed_db_context_(indexed_db_context), |
283 webrtc_identity_store_(webrtc_identity_store.Pass()) {} | 285 webrtc_identity_store_(webrtc_identity_store.Pass()) {} |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 scoped_refptr<webkit_database::DatabaseTracker> database_tracker = | 330 scoped_refptr<webkit_database::DatabaseTracker> database_tracker = |
329 new webkit_database::DatabaseTracker( | 331 new webkit_database::DatabaseTracker( |
330 partition_path, | 332 partition_path, |
331 in_memory, | 333 in_memory, |
332 context->GetSpecialStoragePolicy(), | 334 context->GetSpecialStoragePolicy(), |
333 quota_manager->proxy(), | 335 quota_manager->proxy(), |
334 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) | 336 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) |
335 .get()); | 337 .get()); |
336 | 338 |
337 base::FilePath path = in_memory ? base::FilePath() : partition_path; | 339 base::FilePath path = in_memory ? base::FilePath() : partition_path; |
338 scoped_refptr<DOMStorageContextImpl> dom_storage_context = | 340 scoped_refptr<DOMStorageContextWrapper> dom_storage_context = |
339 new DOMStorageContextImpl(path, context->GetSpecialStoragePolicy()); | 341 new DOMStorageContextWrapper(path, context->GetSpecialStoragePolicy()); |
340 | 342 |
341 // BrowserMainLoop may not be initialized in unit tests. Tests will | 343 // BrowserMainLoop may not be initialized in unit tests. Tests will |
342 // need to inject their own task runner into the IndexedDBContext. | 344 // need to inject their own task runner into the IndexedDBContext. |
343 base::SequencedTaskRunner* idb_task_runner = | 345 base::SequencedTaskRunner* idb_task_runner = |
344 BrowserThread::CurrentlyOn(BrowserThread::UI) && | 346 BrowserThread::CurrentlyOn(BrowserThread::UI) && |
345 BrowserMainLoop::GetInstance() | 347 BrowserMainLoop::GetInstance() |
346 ? BrowserMainLoop::GetInstance()->indexed_db_thread() | 348 ? BrowserMainLoop::GetInstance()->indexed_db_thread() |
347 ->message_loop_proxy().get() | 349 ->message_loop_proxy().get() |
348 : NULL; | 350 : NULL; |
349 scoped_refptr<IndexedDBContextImpl> indexed_db_context = | 351 scoped_refptr<IndexedDBContextImpl> indexed_db_context = |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 } | 392 } |
391 | 393 |
392 fileapi::FileSystemContext* StoragePartitionImpl::GetFileSystemContext() { | 394 fileapi::FileSystemContext* StoragePartitionImpl::GetFileSystemContext() { |
393 return filesystem_context_.get(); | 395 return filesystem_context_.get(); |
394 } | 396 } |
395 | 397 |
396 webkit_database::DatabaseTracker* StoragePartitionImpl::GetDatabaseTracker() { | 398 webkit_database::DatabaseTracker* StoragePartitionImpl::GetDatabaseTracker() { |
397 return database_tracker_.get(); | 399 return database_tracker_.get(); |
398 } | 400 } |
399 | 401 |
400 DOMStorageContextImpl* StoragePartitionImpl::GetDOMStorageContext() { | 402 DOMStorageContextWrapper* StoragePartitionImpl::GetDOMStorageContext() { |
401 return dom_storage_context_.get(); | 403 return dom_storage_context_.get(); |
402 } | 404 } |
403 | 405 |
404 IndexedDBContextImpl* StoragePartitionImpl::GetIndexedDBContext() { | 406 IndexedDBContextImpl* StoragePartitionImpl::GetIndexedDBContext() { |
405 return indexed_db_context_.get(); | 407 return indexed_db_context_.get(); |
406 } | 408 } |
407 | 409 |
408 void StoragePartitionImpl::ClearDataImpl( | 410 void StoragePartitionImpl::ClearDataImpl( |
409 uint32 remove_mask, | 411 uint32 remove_mask, |
410 uint32 quota_storage_remove_mask, | 412 uint32 quota_storage_remove_mask, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 delete this; | 527 delete this; |
526 } | 528 } |
527 } | 529 } |
528 | 530 |
529 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( | 531 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( |
530 uint32 remove_mask, | 532 uint32 remove_mask, |
531 uint32 quota_storage_remove_mask, | 533 uint32 quota_storage_remove_mask, |
532 const GURL& remove_origin, | 534 const GURL& remove_origin, |
533 const base::FilePath& path, | 535 const base::FilePath& path, |
534 net::URLRequestContextGetter* rq_context, | 536 net::URLRequestContextGetter* rq_context, |
535 DOMStorageContextImpl* dom_storage_context, | 537 DOMStorageContextWrapper* dom_storage_context, |
536 quota::QuotaManager* quota_manager, | 538 quota::QuotaManager* quota_manager, |
537 const base::Time begin, | 539 const base::Time begin, |
538 const base::Time end) { | 540 const base::Time end) { |
539 DCHECK_NE(remove_mask, 0u); | 541 DCHECK_NE(remove_mask, 0u); |
540 DCHECK(!callback.is_null()); | 542 DCHECK(!callback.is_null()); |
541 | 543 |
542 IncrementTaskCountOnUI(); | 544 IncrementTaskCountOnUI(); |
543 base::Closure decrement_callback = base::Bind( | 545 base::Closure decrement_callback = base::Bind( |
544 &DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this)); | 546 &DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this)); |
545 | 547 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 net::URLRequestContextGetter* url_request_context) { | 632 net::URLRequestContextGetter* url_request_context) { |
631 url_request_context_ = url_request_context; | 633 url_request_context_ = url_request_context; |
632 } | 634 } |
633 | 635 |
634 void StoragePartitionImpl::SetMediaURLRequestContext( | 636 void StoragePartitionImpl::SetMediaURLRequestContext( |
635 net::URLRequestContextGetter* media_url_request_context) { | 637 net::URLRequestContextGetter* media_url_request_context) { |
636 media_url_request_context_ = media_url_request_context; | 638 media_url_request_context_ = media_url_request_context; |
637 } | 639 } |
638 | 640 |
639 } // namespace content | 641 } // namespace content |
OLD | NEW |