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
3 // found in the LICENSE file.
5 #include "content/browser/storage_partition_impl.h"
7 #include "base/sequenced_task_runner.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/browser_main_loop.h"
10 #include "content/browser/fileapi/browser_file_system_helper.h"
11 #include "content/browser/gpu/shader_disk_cache.h"
12 #include "content/common/dom_storage/dom_storage_types.h"
13 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/dom_storage_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"
19 #include "net/base/completion_callback.h"
20 #include "net/base/net_errors.h"
21 #include "net/cookies/cookie_monster.h"
22 #include "net/url_request/url_request_context.h"
23 #include "net/url_request/url_request_context_getter.h"
24 #include "webkit/browser/database/database_tracker.h"
25 #include "webkit/browser/quota/quota_manager.h"
31 void OnClearedCookies(const base::Closure
& callback
, int num_deleted
) {
32 // The final callback needs to happen from UI thread.
33 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
34 BrowserThread::PostTask(
35 BrowserThread::UI
, FROM_HERE
,
36 base::Bind(&OnClearedCookies
, callback
, num_deleted
));
43 void ClearCookiesOnIOThread(
44 const scoped_refptr
<net::URLRequestContextGetter
>& rq_context
,
45 const base::Time begin
,
47 const GURL
& storage_origin
,
48 const base::Closure
& callback
) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
50 net::CookieStore
* cookie_store
= rq_context
->
51 GetURLRequestContext()->cookie_store();
52 if (storage_origin
.is_empty()) {
53 cookie_store
->DeleteAllCreatedBetweenAsync(
56 base::Bind(&OnClearedCookies
, callback
));
58 cookie_store
->DeleteAllCreatedBetweenForHostAsync(
61 storage_origin
, base::Bind(&OnClearedCookies
, callback
));
65 void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count
,
66 const base::Closure
& callback
) {
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
68 if (*deletion_task_count
== 0) {
69 delete deletion_task_count
;
74 void OnQuotaManagedOriginDeleted(const GURL
& origin
,
75 storage::StorageType type
,
76 size_t* deletion_task_count
,
77 const base::Closure
& callback
,
78 storage::QuotaStatusCode status
) {
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
80 DCHECK_GT(*deletion_task_count
, 0u);
81 if (status
!= storage::kQuotaStatusOk
) {
82 DLOG(ERROR
) << "Couldn't remove data of type " << type
<< " for origin "
83 << origin
<< ". Status: " << status
;
86 (*deletion_task_count
)--;
87 CheckQuotaManagedDataDeletionStatus(deletion_task_count
, callback
);
90 void ClearedShaderCache(const base::Closure
& callback
) {
91 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
92 BrowserThread::PostTask(
93 BrowserThread::UI
, FROM_HERE
,
94 base::Bind(&ClearedShaderCache
, callback
));
100 void ClearShaderCacheOnIOThread(const base::FilePath
& path
,
101 const base::Time begin
,
102 const base::Time end
,
103 const base::Closure
& callback
) {
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
105 ShaderCacheFactory::GetInstance()->ClearByPath(
106 path
, begin
, end
, base::Bind(&ClearedShaderCache
, callback
));
109 void OnLocalStorageUsageInfo(
110 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
111 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
112 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
113 const base::Time delete_begin
,
114 const base::Time delete_end
,
115 const base::Closure
& callback
,
116 const std::vector
<LocalStorageUsageInfo
>& infos
) {
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
119 for (size_t i
= 0; i
< infos
.size(); ++i
) {
120 if (!origin_matcher
.is_null() &&
121 !origin_matcher
.Run(infos
[i
].origin
, special_storage_policy
.get())) {
125 if (infos
[i
].last_modified
>= delete_begin
&&
126 infos
[i
].last_modified
<= delete_end
) {
127 dom_storage_context
->DeleteLocalStorage(infos
[i
].origin
);
133 void OnSessionStorageUsageInfo(
134 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
135 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
136 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
137 const base::Closure
& callback
,
138 const std::vector
<SessionStorageUsageInfo
>& infos
) {
139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
141 for (size_t i
= 0; i
< infos
.size(); ++i
) {
142 if (!origin_matcher
.is_null() &&
143 !origin_matcher
.Run(infos
[i
].origin
, special_storage_policy
.get())) {
146 dom_storage_context
->DeleteSessionStorage(infos
[i
]);
152 void ClearLocalStorageOnUIThread(
153 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
154 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
155 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
156 const GURL
& storage_origin
,
157 const base::Time begin
,
158 const base::Time end
,
159 const base::Closure
& callback
) {
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
162 if (!storage_origin
.is_empty()) {
163 bool can_delete
= origin_matcher
.is_null() ||
164 origin_matcher
.Run(storage_origin
,
165 special_storage_policy
.get());
167 dom_storage_context
->DeleteLocalStorage(storage_origin
);
173 dom_storage_context
->GetLocalStorageUsage(
174 base::Bind(&OnLocalStorageUsageInfo
,
175 dom_storage_context
, special_storage_policy
, origin_matcher
,
176 begin
, end
, callback
));
179 void ClearSessionStorageOnUIThread(
180 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
181 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
182 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
183 const base::Closure
& callback
) {
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
186 dom_storage_context
->GetSessionStorageUsage(
187 base::Bind(&OnSessionStorageUsageInfo
, dom_storage_context
,
188 special_storage_policy
, origin_matcher
,
195 STATIC_CONST_MEMBER_DEFINITION
const uint32
196 StoragePartition::REMOVE_DATA_MASK_APPCACHE
;
197 STATIC_CONST_MEMBER_DEFINITION
const uint32
198 StoragePartition::REMOVE_DATA_MASK_COOKIES
;
199 STATIC_CONST_MEMBER_DEFINITION
const uint32
200 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
;
201 STATIC_CONST_MEMBER_DEFINITION
const uint32
202 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
;
203 STATIC_CONST_MEMBER_DEFINITION
const uint32
204 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE
;
205 STATIC_CONST_MEMBER_DEFINITION
const uint32
206 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
;
207 STATIC_CONST_MEMBER_DEFINITION
const uint32
208 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE
;
209 STATIC_CONST_MEMBER_DEFINITION
const uint32
210 StoragePartition::REMOVE_DATA_MASK_WEBSQL
;
211 STATIC_CONST_MEMBER_DEFINITION
const uint32
212 StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY
;
213 STATIC_CONST_MEMBER_DEFINITION
const uint32
214 StoragePartition::REMOVE_DATA_MASK_ALL
;
215 STATIC_CONST_MEMBER_DEFINITION
const uint32
216 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY
;
217 STATIC_CONST_MEMBER_DEFINITION
const uint32
218 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
;
219 STATIC_CONST_MEMBER_DEFINITION
const uint32
220 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_SYNCABLE
;
221 STATIC_CONST_MEMBER_DEFINITION
const uint32
222 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
;
225 int StoragePartitionImpl::GenerateQuotaClientMask(uint32 remove_mask
) {
226 int quota_client_mask
= 0;
228 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
)
229 quota_client_mask
|= storage::QuotaClient::kFileSystem
;
230 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_WEBSQL
)
231 quota_client_mask
|= storage::QuotaClient::kDatabase
;
232 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_APPCACHE
)
233 quota_client_mask
|= storage::QuotaClient::kAppcache
;
234 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
)
235 quota_client_mask
|= storage::QuotaClient::kIndexedDatabase
;
236 // TODO(jsbell): StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS)
238 return quota_client_mask
;
241 // Helper for deleting quota managed data from a partition.
243 // Most of the operations in this class are done on IO thread.
244 struct StoragePartitionImpl::QuotaManagedDataDeletionHelper
{
245 QuotaManagedDataDeletionHelper(uint32 remove_mask
,
246 uint32 quota_storage_remove_mask
,
247 const GURL
& storage_origin
,
248 const base::Closure
& callback
)
249 : remove_mask(remove_mask
),
250 quota_storage_remove_mask(quota_storage_remove_mask
),
251 storage_origin(storage_origin
),
256 void IncrementTaskCountOnIO();
257 void DecrementTaskCountOnIO();
259 void ClearDataOnIOThread(
260 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
261 const base::Time begin
,
262 const scoped_refptr
<storage::SpecialStoragePolicy
>&
263 special_storage_policy
,
264 const StoragePartition::OriginMatcherFunction
& origin_matcher
);
266 void ClearOriginsOnIOThread(
267 storage::QuotaManager
* quota_manager
,
268 const scoped_refptr
<storage::SpecialStoragePolicy
>&
269 special_storage_policy
,
270 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
271 const base::Closure
& callback
,
272 const std::set
<GURL
>& origins
,
273 storage::StorageType quota_storage_type
);
275 // All of these data are accessed on IO thread.
277 uint32 quota_storage_remove_mask
;
279 const base::Closure callback
;
283 // Helper for deleting all sorts of data from a partition, keeps track of
286 // StoragePartitionImpl creates an instance of this class to keep track of
287 // data deletion progress. Deletion requires deleting multiple bits of data
288 // (e.g. cookies, local storage, session storage etc.) and hopping between UI
289 // and IO thread. An instance of this class is created in the beginning of
290 // deletion process (StoragePartitionImpl::ClearDataImpl) and the instance is
291 // forwarded and updated on each (sub) deletion's callback. The instance is
292 // finally destroyed when deletion completes (and |callback| is invoked).
293 struct StoragePartitionImpl::DataDeletionHelper
{
294 DataDeletionHelper(uint32 remove_mask
,
295 uint32 quota_storage_remove_mask
,
296 const base::Closure
& callback
)
297 : remove_mask(remove_mask
),
298 quota_storage_remove_mask(quota_storage_remove_mask
),
303 void IncrementTaskCountOnUI();
304 void DecrementTaskCountOnUI();
306 void ClearDataOnUIThread(
307 const GURL
& storage_origin
,
308 const OriginMatcherFunction
& origin_matcher
,
309 const base::FilePath
& path
,
310 net::URLRequestContextGetter
* rq_context
,
311 DOMStorageContextWrapper
* dom_storage_context
,
312 storage::QuotaManager
* quota_manager
,
313 storage::SpecialStoragePolicy
* special_storage_policy
,
314 WebRTCIdentityStore
* webrtc_identity_store
,
315 const base::Time begin
,
316 const base::Time end
);
318 void ClearQuotaManagedDataOnIOThread(
319 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
320 const base::Time begin
,
321 const GURL
& storage_origin
,
322 const scoped_refptr
<storage::SpecialStoragePolicy
>&
323 special_storage_policy
,
324 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
325 const base::Closure
& callback
);
328 uint32 quota_storage_remove_mask
;
330 // Accessed on UI thread.
331 const base::Closure callback
;
332 // Accessed on UI thread.
336 void StoragePartitionImpl::DataDeletionHelper::ClearQuotaManagedDataOnIOThread(
337 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
338 const base::Time begin
,
339 const GURL
& storage_origin
,
340 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
341 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
342 const base::Closure
& callback
) {
343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
345 StoragePartitionImpl::QuotaManagedDataDeletionHelper
* helper
=
346 new StoragePartitionImpl::QuotaManagedDataDeletionHelper(
348 quota_storage_remove_mask
,
351 helper
->ClearDataOnIOThread(quota_manager
, begin
, special_storage_policy
,
355 StoragePartitionImpl::StoragePartitionImpl(
356 const base::FilePath
& partition_path
,
357 storage::QuotaManager
* quota_manager
,
358 ChromeAppCacheService
* appcache_service
,
359 storage::FileSystemContext
* filesystem_context
,
360 storage::DatabaseTracker
* database_tracker
,
361 DOMStorageContextWrapper
* dom_storage_context
,
362 IndexedDBContextImpl
* indexed_db_context
,
363 ServiceWorkerContextWrapper
* service_worker_context
,
364 WebRTCIdentityStore
* webrtc_identity_store
,
365 storage::SpecialStoragePolicy
* special_storage_policy
)
366 : partition_path_(partition_path
),
367 quota_manager_(quota_manager
),
368 appcache_service_(appcache_service
),
369 filesystem_context_(filesystem_context
),
370 database_tracker_(database_tracker
),
371 dom_storage_context_(dom_storage_context
),
372 indexed_db_context_(indexed_db_context
),
373 service_worker_context_(service_worker_context
),
374 webrtc_identity_store_(webrtc_identity_store
),
375 special_storage_policy_(special_storage_policy
) {
378 StoragePartitionImpl::~StoragePartitionImpl() {
379 // These message loop checks are just to avoid leaks in unittests.
380 if (GetDatabaseTracker() &&
381 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
382 BrowserThread::PostTask(
385 base::Bind(&storage::DatabaseTracker::Shutdown
, GetDatabaseTracker()));
388 if (GetFileSystemContext())
389 GetFileSystemContext()->Shutdown();
391 if (GetDOMStorageContext())
392 GetDOMStorageContext()->Shutdown();
394 if (GetServiceWorkerContext())
395 GetServiceWorkerContext()->Shutdown();
398 // TODO(ajwong): Break the direct dependency on |context|. We only
399 // need 3 pieces of info from it.
400 StoragePartitionImpl
* StoragePartitionImpl::Create(
401 BrowserContext
* context
,
403 const base::FilePath
& partition_path
) {
404 // Ensure that these methods are called on the UI thread, except for
405 // unittests where a UI thread might not have been created.
406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
) ||
407 !BrowserThread::IsMessageLoopValid(BrowserThread::UI
));
409 // All of the clients have to be created and registered with the
410 // QuotaManager prior to the QuotaManger being used. We do them
411 // all together here prior to handing out a reference to anything
412 // that utilizes the QuotaManager.
413 scoped_refptr
<storage::QuotaManager
> quota_manager
=
414 new storage::QuotaManager(
417 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
).get(),
418 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB
).get(),
419 context
->GetSpecialStoragePolicy());
421 // Each consumer is responsible for registering its QuotaClient during
423 scoped_refptr
<storage::FileSystemContext
> filesystem_context
=
424 CreateFileSystemContext(
425 context
, partition_path
, in_memory
, quota_manager
->proxy());
427 scoped_refptr
<storage::DatabaseTracker
> database_tracker
=
428 new storage::DatabaseTracker(partition_path
,
430 context
->GetSpecialStoragePolicy(),
431 quota_manager
->proxy(),
432 BrowserThread::GetMessageLoopProxyForThread(
433 BrowserThread::FILE).get());
435 base::FilePath path
= in_memory
? base::FilePath() : partition_path
;
436 scoped_refptr
<DOMStorageContextWrapper
> dom_storage_context
=
437 new DOMStorageContextWrapper(path
, context
->GetSpecialStoragePolicy());
439 // BrowserMainLoop may not be initialized in unit tests. Tests will
440 // need to inject their own task runner into the IndexedDBContext.
441 base::SequencedTaskRunner
* idb_task_runner
=
442 BrowserThread::CurrentlyOn(BrowserThread::UI
) &&
443 BrowserMainLoop::GetInstance()
444 ? BrowserMainLoop::GetInstance()->indexed_db_thread()
445 ->message_loop_proxy().get()
447 scoped_refptr
<IndexedDBContextImpl
> indexed_db_context
=
448 new IndexedDBContextImpl(path
,
449 context
->GetSpecialStoragePolicy(),
450 quota_manager
->proxy(),
453 scoped_refptr
<ServiceWorkerContextWrapper
> service_worker_context
=
454 new ServiceWorkerContextWrapper(context
);
455 service_worker_context
->Init(path
, quota_manager
->proxy());
457 scoped_refptr
<ChromeAppCacheService
> appcache_service
=
458 new ChromeAppCacheService(quota_manager
->proxy());
460 scoped_refptr
<WebRTCIdentityStore
> webrtc_identity_store(
461 new WebRTCIdentityStore(path
, context
->GetSpecialStoragePolicy()));
463 scoped_refptr
<storage::SpecialStoragePolicy
> special_storage_policy(
464 context
->GetSpecialStoragePolicy());
466 return new StoragePartitionImpl(partition_path
,
468 appcache_service
.get(),
469 filesystem_context
.get(),
470 database_tracker
.get(),
471 dom_storage_context
.get(),
472 indexed_db_context
.get(),
473 service_worker_context
.get(),
474 webrtc_identity_store
.get(),
475 special_storage_policy
.get());
478 base::FilePath
StoragePartitionImpl::GetPath() {
479 return partition_path_
;
482 net::URLRequestContextGetter
* StoragePartitionImpl::GetURLRequestContext() {
483 return url_request_context_
.get();
486 net::URLRequestContextGetter
*
487 StoragePartitionImpl::GetMediaURLRequestContext() {
488 return media_url_request_context_
.get();
491 storage::QuotaManager
* StoragePartitionImpl::GetQuotaManager() {
492 return quota_manager_
.get();
495 ChromeAppCacheService
* StoragePartitionImpl::GetAppCacheService() {
496 return appcache_service_
.get();
499 storage::FileSystemContext
* StoragePartitionImpl::GetFileSystemContext() {
500 return filesystem_context_
.get();
503 storage::DatabaseTracker
* StoragePartitionImpl::GetDatabaseTracker() {
504 return database_tracker_
.get();
507 DOMStorageContextWrapper
* StoragePartitionImpl::GetDOMStorageContext() {
508 return dom_storage_context_
.get();
511 IndexedDBContextImpl
* StoragePartitionImpl::GetIndexedDBContext() {
512 return indexed_db_context_
.get();
515 ServiceWorkerContextWrapper
* StoragePartitionImpl::GetServiceWorkerContext() {
516 return service_worker_context_
.get();
519 void StoragePartitionImpl::ClearDataImpl(
521 uint32 quota_storage_remove_mask
,
522 const GURL
& storage_origin
,
523 const OriginMatcherFunction
& origin_matcher
,
524 net::URLRequestContextGetter
* rq_context
,
525 const base::Time begin
,
526 const base::Time end
,
527 const base::Closure
& callback
) {
528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
529 DataDeletionHelper
* helper
= new DataDeletionHelper(remove_mask
,
530 quota_storage_remove_mask
,
532 // |helper| deletes itself when done in
533 // DataDeletionHelper::DecrementTaskCountOnUI().
534 helper
->ClearDataOnUIThread(storage_origin
,
538 dom_storage_context_
.get(),
539 quota_manager_
.get(),
540 special_storage_policy_
.get(),
541 webrtc_identity_store_
.get(),
546 void StoragePartitionImpl::
547 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() {
548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
552 void StoragePartitionImpl::
553 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() {
554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
555 DCHECK_GT(task_count
, 0);
564 void StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearDataOnIOThread(
565 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
566 const base::Time begin
,
567 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
568 const StoragePartition::OriginMatcherFunction
& origin_matcher
) {
569 IncrementTaskCountOnIO();
570 base::Closure decrement_callback
= base::Bind(
571 &QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO
,
572 base::Unretained(this));
574 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
) {
575 IncrementTaskCountOnIO();
576 // Ask the QuotaManager for all origins with persistent quota modified
577 // within the user-specified timeframe, and deal with the resulting set in
578 // ClearQuotaManagedOriginsOnIOThread().
579 quota_manager
->GetOriginsModifiedSince(
580 storage::kStorageTypePersistent
,
582 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
583 base::Unretained(this),
585 special_storage_policy
,
587 decrement_callback
));
590 // Do the same for temporary quota.
591 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_TEMPORARY
) {
592 IncrementTaskCountOnIO();
593 quota_manager
->GetOriginsModifiedSince(
594 storage::kStorageTypeTemporary
,
596 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
597 base::Unretained(this),
599 special_storage_policy
,
601 decrement_callback
));
604 // Do the same for syncable quota.
605 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_SYNCABLE
) {
606 IncrementTaskCountOnIO();
607 quota_manager
->GetOriginsModifiedSince(
608 storage::kStorageTypeSyncable
,
610 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
611 base::Unretained(this),
613 special_storage_policy
,
615 decrement_callback
));
618 DecrementTaskCountOnIO();
622 StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread(
623 storage::QuotaManager
* quota_manager
,
624 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
625 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
626 const base::Closure
& callback
,
627 const std::set
<GURL
>& origins
,
628 storage::StorageType quota_storage_type
) {
629 // The QuotaManager manages all storage other than cookies, LocalStorage,
630 // and SessionStorage. This loop wipes out most HTML5 storage for the given
632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
633 if (!origins
.size()) {
638 size_t* deletion_task_count
= new size_t(0u);
639 (*deletion_task_count
)++;
640 for (std::set
<GURL
>::const_iterator origin
= origins
.begin();
641 origin
!= origins
.end(); ++origin
) {
642 // TODO(mkwst): Clean this up, it's slow. http://crbug.com/130746
643 if (!storage_origin
.is_empty() && origin
->GetOrigin() != storage_origin
)
646 if (!origin_matcher
.is_null() &&
647 !origin_matcher
.Run(*origin
, special_storage_policy
.get())) {
651 (*deletion_task_count
)++;
652 quota_manager
->DeleteOriginData(
653 *origin
, quota_storage_type
,
654 StoragePartitionImpl::GenerateQuotaClientMask(remove_mask
),
655 base::Bind(&OnQuotaManagedOriginDeleted
,
656 origin
->GetOrigin(), quota_storage_type
,
657 deletion_task_count
, callback
));
659 (*deletion_task_count
)--;
661 CheckQuotaManagedDataDeletionStatus(deletion_task_count
, callback
);
664 void StoragePartitionImpl::DataDeletionHelper::IncrementTaskCountOnUI() {
665 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
669 void StoragePartitionImpl::DataDeletionHelper::DecrementTaskCountOnUI() {
670 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
671 BrowserThread::PostTask(
672 BrowserThread::UI
, FROM_HERE
,
673 base::Bind(&DataDeletionHelper::DecrementTaskCountOnUI
,
674 base::Unretained(this)));
677 DCHECK_GT(task_count
, 0);
685 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
686 const GURL
& storage_origin
,
687 const OriginMatcherFunction
& origin_matcher
,
688 const base::FilePath
& path
,
689 net::URLRequestContextGetter
* rq_context
,
690 DOMStorageContextWrapper
* dom_storage_context
,
691 storage::QuotaManager
* quota_manager
,
692 storage::SpecialStoragePolicy
* special_storage_policy
,
693 WebRTCIdentityStore
* webrtc_identity_store
,
694 const base::Time begin
,
695 const base::Time end
) {
696 DCHECK_NE(remove_mask
, 0u);
697 DCHECK(!callback
.is_null());
699 IncrementTaskCountOnUI();
700 base::Closure decrement_callback
= base::Bind(
701 &DataDeletionHelper::DecrementTaskCountOnUI
, base::Unretained(this));
703 if (remove_mask
& REMOVE_DATA_MASK_COOKIES
) {
704 // Handle the cookies.
705 IncrementTaskCountOnUI();
706 BrowserThread::PostTask(
707 BrowserThread::IO
, FROM_HERE
,
708 base::Bind(&ClearCookiesOnIOThread
,
709 make_scoped_refptr(rq_context
), begin
, end
, storage_origin
,
710 decrement_callback
));
713 if (remove_mask
& REMOVE_DATA_MASK_INDEXEDDB
||
714 remove_mask
& REMOVE_DATA_MASK_WEBSQL
||
715 remove_mask
& REMOVE_DATA_MASK_APPCACHE
||
716 remove_mask
& REMOVE_DATA_MASK_FILE_SYSTEMS
||
717 remove_mask
& REMOVE_DATA_MASK_SERVICE_WORKERS
) {
718 IncrementTaskCountOnUI();
719 BrowserThread::PostTask(
720 BrowserThread::IO
, FROM_HERE
,
721 base::Bind(&DataDeletionHelper::ClearQuotaManagedDataOnIOThread
,
722 base::Unretained(this),
723 make_scoped_refptr(quota_manager
),
726 make_scoped_refptr(special_storage_policy
),
728 decrement_callback
));
731 if (remove_mask
& REMOVE_DATA_MASK_LOCAL_STORAGE
) {
732 IncrementTaskCountOnUI();
733 ClearLocalStorageOnUIThread(
734 make_scoped_refptr(dom_storage_context
),
735 make_scoped_refptr(special_storage_policy
),
737 storage_origin
, begin
, end
,
740 // ClearDataImpl cannot clear session storage data when a particular origin
741 // is specified. Therefore we ignore clearing session storage in this case.
742 // TODO(lazyboy): Fix.
743 if (storage_origin
.is_empty()) {
744 IncrementTaskCountOnUI();
745 ClearSessionStorageOnUIThread(
746 make_scoped_refptr(dom_storage_context
),
747 make_scoped_refptr(special_storage_policy
),
753 if (remove_mask
& REMOVE_DATA_MASK_SHADER_CACHE
) {
754 IncrementTaskCountOnUI();
755 BrowserThread::PostTask(
756 BrowserThread::IO
, FROM_HERE
,
757 base::Bind(&ClearShaderCacheOnIOThread
,
758 path
, begin
, end
, decrement_callback
));
761 if (remove_mask
& REMOVE_DATA_MASK_WEBRTC_IDENTITY
) {
762 IncrementTaskCountOnUI();
763 BrowserThread::PostTask(
766 base::Bind(&WebRTCIdentityStore::DeleteBetween
,
767 webrtc_identity_store
,
770 decrement_callback
));
773 DecrementTaskCountOnUI();
776 void StoragePartitionImpl::ClearDataForOrigin(
778 uint32 quota_storage_remove_mask
,
779 const GURL
& storage_origin
,
780 net::URLRequestContextGetter
* request_context_getter
,
781 const base::Closure
& callback
) {
782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
783 ClearDataImpl(remove_mask
,
784 quota_storage_remove_mask
,
786 OriginMatcherFunction(),
787 request_context_getter
,
793 void StoragePartitionImpl::ClearData(
795 uint32 quota_storage_remove_mask
,
796 const GURL
& storage_origin
,
797 const OriginMatcherFunction
& origin_matcher
,
798 const base::Time begin
,
799 const base::Time end
,
800 const base::Closure
& callback
) {
801 ClearDataImpl(remove_mask
, quota_storage_remove_mask
, storage_origin
,
802 origin_matcher
, GetURLRequestContext(), begin
, end
, callback
);
805 WebRTCIdentityStore
* StoragePartitionImpl::GetWebRTCIdentityStore() {
806 return webrtc_identity_store_
.get();
809 void StoragePartitionImpl::OverrideQuotaManagerForTesting(
810 storage::QuotaManager
* quota_manager
) {
811 quota_manager_
= quota_manager
;
814 void StoragePartitionImpl::OverrideSpecialStoragePolicyForTesting(
815 storage::SpecialStoragePolicy
* special_storage_policy
) {
816 special_storage_policy_
= special_storage_policy
;
819 void StoragePartitionImpl::SetURLRequestContext(
820 net::URLRequestContextGetter
* url_request_context
) {
821 url_request_context_
= url_request_context
;
824 void StoragePartitionImpl::SetMediaURLRequestContext(
825 net::URLRequestContextGetter
* media_url_request_context
) {
826 media_url_request_context_
= media_url_request_context
;
829 } // namespace content