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 quota::StorageType type
,
76 size_t* deletion_task_count
,
77 const base::Closure
& callback
,
78 quota::QuotaStatusCode status
) {
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
80 DCHECK_GT(*deletion_task_count
, 0u);
81 if (status
!= quota::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
<quota::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
<quota::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
<quota::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
<quota::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
|= quota::QuotaClient::kFileSystem
;
230 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_WEBSQL
)
231 quota_client_mask
|= quota::QuotaClient::kDatabase
;
232 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_APPCACHE
)
233 quota_client_mask
|= quota::QuotaClient::kAppcache
;
234 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
)
235 quota_client_mask
|= quota::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
<quota::QuotaManager
>& quota_manager
,
261 const base::Time begin
,
262 const scoped_refptr
<quota::SpecialStoragePolicy
>& special_storage_policy
,
263 const StoragePartition::OriginMatcherFunction
& origin_matcher
);
265 void ClearOriginsOnIOThread(
266 quota::QuotaManager
* quota_manager
,
267 const scoped_refptr
<quota::SpecialStoragePolicy
>& special_storage_policy
,
268 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
269 const base::Closure
& callback
,
270 const std::set
<GURL
>& origins
,
271 quota::StorageType quota_storage_type
);
273 // All of these data are accessed on IO thread.
275 uint32 quota_storage_remove_mask
;
277 const base::Closure callback
;
281 // Helper for deleting all sorts of data from a partition, keeps track of
284 // StoragePartitionImpl creates an instance of this class to keep track of
285 // data deletion progress. Deletion requires deleting multiple bits of data
286 // (e.g. cookies, local storage, session storage etc.) and hopping between UI
287 // and IO thread. An instance of this class is created in the beginning of
288 // deletion process (StoragePartitionImpl::ClearDataImpl) and the instance is
289 // forwarded and updated on each (sub) deletion's callback. The instance is
290 // finally destroyed when deletion completes (and |callback| is invoked).
291 struct StoragePartitionImpl::DataDeletionHelper
{
292 DataDeletionHelper(uint32 remove_mask
,
293 uint32 quota_storage_remove_mask
,
294 const base::Closure
& callback
)
295 : remove_mask(remove_mask
),
296 quota_storage_remove_mask(quota_storage_remove_mask
),
301 void IncrementTaskCountOnUI();
302 void DecrementTaskCountOnUI();
304 void ClearDataOnUIThread(const GURL
& storage_origin
,
305 const OriginMatcherFunction
& origin_matcher
,
306 const base::FilePath
& path
,
307 net::URLRequestContextGetter
* rq_context
,
308 DOMStorageContextWrapper
* dom_storage_context
,
309 quota::QuotaManager
* quota_manager
,
310 quota::SpecialStoragePolicy
* special_storage_policy
,
311 WebRTCIdentityStore
* webrtc_identity_store
,
312 const base::Time begin
,
313 const base::Time end
);
315 void ClearQuotaManagedDataOnIOThread(
316 const scoped_refptr
<quota::QuotaManager
>& quota_manager
,
317 const base::Time begin
,
318 const GURL
& storage_origin
,
319 const scoped_refptr
<quota::SpecialStoragePolicy
>& special_storage_policy
,
320 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
321 const base::Closure
& callback
);
324 uint32 quota_storage_remove_mask
;
326 // Accessed on UI thread.
327 const base::Closure callback
;
328 // Accessed on UI thread.
332 void StoragePartitionImpl::DataDeletionHelper::ClearQuotaManagedDataOnIOThread(
333 const scoped_refptr
<quota::QuotaManager
>& quota_manager
,
334 const base::Time begin
,
335 const GURL
& storage_origin
,
336 const scoped_refptr
<quota::SpecialStoragePolicy
>& special_storage_policy
,
337 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
338 const base::Closure
& callback
) {
339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
341 StoragePartitionImpl::QuotaManagedDataDeletionHelper
* helper
=
342 new StoragePartitionImpl::QuotaManagedDataDeletionHelper(
344 quota_storage_remove_mask
,
347 helper
->ClearDataOnIOThread(quota_manager
, begin
, special_storage_policy
,
351 StoragePartitionImpl::StoragePartitionImpl(
352 const base::FilePath
& partition_path
,
353 quota::QuotaManager
* quota_manager
,
354 ChromeAppCacheService
* appcache_service
,
355 fileapi::FileSystemContext
* filesystem_context
,
356 webkit_database::DatabaseTracker
* database_tracker
,
357 DOMStorageContextWrapper
* dom_storage_context
,
358 IndexedDBContextImpl
* indexed_db_context
,
359 ServiceWorkerContextWrapper
* service_worker_context
,
360 WebRTCIdentityStore
* webrtc_identity_store
,
361 quota::SpecialStoragePolicy
* special_storage_policy
)
362 : partition_path_(partition_path
),
363 quota_manager_(quota_manager
),
364 appcache_service_(appcache_service
),
365 filesystem_context_(filesystem_context
),
366 database_tracker_(database_tracker
),
367 dom_storage_context_(dom_storage_context
),
368 indexed_db_context_(indexed_db_context
),
369 service_worker_context_(service_worker_context
),
370 webrtc_identity_store_(webrtc_identity_store
),
371 special_storage_policy_(special_storage_policy
) {}
373 StoragePartitionImpl::~StoragePartitionImpl() {
374 // These message loop checks are just to avoid leaks in unittests.
375 if (GetDatabaseTracker() &&
376 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
377 BrowserThread::PostTask(
378 BrowserThread::FILE, FROM_HERE
,
379 base::Bind(&webkit_database::DatabaseTracker::Shutdown
,
380 GetDatabaseTracker()));
383 if (GetFileSystemContext())
384 GetFileSystemContext()->Shutdown();
386 if (GetDOMStorageContext())
387 GetDOMStorageContext()->Shutdown();
389 if (GetServiceWorkerContext())
390 GetServiceWorkerContext()->Shutdown();
393 // TODO(ajwong): Break the direct dependency on |context|. We only
394 // need 3 pieces of info from it.
395 StoragePartitionImpl
* StoragePartitionImpl::Create(
396 BrowserContext
* context
,
398 const base::FilePath
& partition_path
) {
399 // Ensure that these methods are called on the UI thread, except for
400 // unittests where a UI thread might not have been created.
401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
) ||
402 !BrowserThread::IsMessageLoopValid(BrowserThread::UI
));
404 // All of the clients have to be created and registered with the
405 // QuotaManager prior to the QuotaManger being used. We do them
406 // all together here prior to handing out a reference to anything
407 // that utilizes the QuotaManager.
408 scoped_refptr
<quota::QuotaManager
> quota_manager
= new quota::QuotaManager(
411 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
).get(),
412 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB
).get(),
413 context
->GetSpecialStoragePolicy());
415 // Each consumer is responsible for registering its QuotaClient during
417 scoped_refptr
<fileapi::FileSystemContext
> filesystem_context
=
418 CreateFileSystemContext(context
,
419 partition_path
, in_memory
,
420 quota_manager
->proxy());
422 scoped_refptr
<webkit_database::DatabaseTracker
> database_tracker
=
423 new webkit_database::DatabaseTracker(
426 context
->GetSpecialStoragePolicy(),
427 quota_manager
->proxy(),
428 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)
431 base::FilePath path
= in_memory
? base::FilePath() : partition_path
;
432 scoped_refptr
<DOMStorageContextWrapper
> dom_storage_context
=
433 new DOMStorageContextWrapper(path
, context
->GetSpecialStoragePolicy());
435 // BrowserMainLoop may not be initialized in unit tests. Tests will
436 // need to inject their own task runner into the IndexedDBContext.
437 base::SequencedTaskRunner
* idb_task_runner
=
438 BrowserThread::CurrentlyOn(BrowserThread::UI
) &&
439 BrowserMainLoop::GetInstance()
440 ? BrowserMainLoop::GetInstance()->indexed_db_thread()
441 ->message_loop_proxy().get()
443 scoped_refptr
<IndexedDBContextImpl
> indexed_db_context
=
444 new IndexedDBContextImpl(path
,
445 context
->GetSpecialStoragePolicy(),
446 quota_manager
->proxy(),
449 scoped_refptr
<ServiceWorkerContextWrapper
> service_worker_context
=
450 new ServiceWorkerContextWrapper(context
);
451 service_worker_context
->Init(path
, quota_manager
->proxy());
453 scoped_refptr
<ChromeAppCacheService
> appcache_service
=
454 new ChromeAppCacheService(quota_manager
->proxy());
456 scoped_refptr
<WebRTCIdentityStore
> webrtc_identity_store(
457 new WebRTCIdentityStore(path
, context
->GetSpecialStoragePolicy()));
459 scoped_refptr
<quota::SpecialStoragePolicy
> special_storage_policy(
460 context
->GetSpecialStoragePolicy());
462 return new StoragePartitionImpl(partition_path
,
464 appcache_service
.get(),
465 filesystem_context
.get(),
466 database_tracker
.get(),
467 dom_storage_context
.get(),
468 indexed_db_context
.get(),
469 service_worker_context
.get(),
470 webrtc_identity_store
.get(),
471 special_storage_policy
.get());
474 base::FilePath
StoragePartitionImpl::GetPath() {
475 return partition_path_
;
478 net::URLRequestContextGetter
* StoragePartitionImpl::GetURLRequestContext() {
479 return url_request_context_
.get();
482 net::URLRequestContextGetter
*
483 StoragePartitionImpl::GetMediaURLRequestContext() {
484 return media_url_request_context_
.get();
487 quota::QuotaManager
* StoragePartitionImpl::GetQuotaManager() {
488 return quota_manager_
.get();
491 ChromeAppCacheService
* StoragePartitionImpl::GetAppCacheService() {
492 return appcache_service_
.get();
495 fileapi::FileSystemContext
* StoragePartitionImpl::GetFileSystemContext() {
496 return filesystem_context_
.get();
499 webkit_database::DatabaseTracker
* StoragePartitionImpl::GetDatabaseTracker() {
500 return database_tracker_
.get();
503 DOMStorageContextWrapper
* StoragePartitionImpl::GetDOMStorageContext() {
504 return dom_storage_context_
.get();
507 IndexedDBContextImpl
* StoragePartitionImpl::GetIndexedDBContext() {
508 return indexed_db_context_
.get();
511 ServiceWorkerContextWrapper
* StoragePartitionImpl::GetServiceWorkerContext() {
512 return service_worker_context_
.get();
515 void StoragePartitionImpl::ClearDataImpl(
517 uint32 quota_storage_remove_mask
,
518 const GURL
& storage_origin
,
519 const OriginMatcherFunction
& origin_matcher
,
520 net::URLRequestContextGetter
* rq_context
,
521 const base::Time begin
,
522 const base::Time end
,
523 const base::Closure
& callback
) {
524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
525 DataDeletionHelper
* helper
= new DataDeletionHelper(remove_mask
,
526 quota_storage_remove_mask
,
528 // |helper| deletes itself when done in
529 // DataDeletionHelper::DecrementTaskCountOnUI().
530 helper
->ClearDataOnUIThread(storage_origin
, origin_matcher
, GetPath(),
531 rq_context
, dom_storage_context_
, quota_manager_
,
532 special_storage_policy_
.get(),
533 webrtc_identity_store_
, begin
, end
);
536 void StoragePartitionImpl::
537 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() {
538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
542 void StoragePartitionImpl::
543 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() {
544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
545 DCHECK_GT(task_count
, 0);
554 void StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearDataOnIOThread(
555 const scoped_refptr
<quota::QuotaManager
>& quota_manager
,
556 const base::Time begin
,
557 const scoped_refptr
<quota::SpecialStoragePolicy
>& special_storage_policy
,
558 const StoragePartition::OriginMatcherFunction
& origin_matcher
) {
559 IncrementTaskCountOnIO();
560 base::Closure decrement_callback
= base::Bind(
561 &QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO
,
562 base::Unretained(this));
564 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
) {
565 IncrementTaskCountOnIO();
566 // Ask the QuotaManager for all origins with persistent quota modified
567 // within the user-specified timeframe, and deal with the resulting set in
568 // ClearQuotaManagedOriginsOnIOThread().
569 quota_manager
->GetOriginsModifiedSince(
570 quota::kStorageTypePersistent
, begin
,
571 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
572 base::Unretained(this),
574 special_storage_policy
,
576 decrement_callback
));
579 // Do the same for temporary quota.
580 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_TEMPORARY
) {
581 IncrementTaskCountOnIO();
582 quota_manager
->GetOriginsModifiedSince(
583 quota::kStorageTypeTemporary
, begin
,
584 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
585 base::Unretained(this),
587 special_storage_policy
,
589 decrement_callback
));
592 // Do the same for syncable quota.
593 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_SYNCABLE
) {
594 IncrementTaskCountOnIO();
595 quota_manager
->GetOriginsModifiedSince(
596 quota::kStorageTypeSyncable
, begin
,
597 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
598 base::Unretained(this),
600 special_storage_policy
,
602 decrement_callback
));
605 DecrementTaskCountOnIO();
608 void StoragePartitionImpl::
609 QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread(
610 quota::QuotaManager
* quota_manager
,
611 const scoped_refptr
<quota::SpecialStoragePolicy
>&
612 special_storage_policy
,
613 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
614 const base::Closure
& callback
,
615 const std::set
<GURL
>& origins
,
616 quota::StorageType quota_storage_type
) {
617 // The QuotaManager manages all storage other than cookies, LocalStorage,
618 // and SessionStorage. This loop wipes out most HTML5 storage for the given
620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
621 if (!origins
.size()) {
626 size_t* deletion_task_count
= new size_t(0u);
627 (*deletion_task_count
)++;
628 for (std::set
<GURL
>::const_iterator origin
= origins
.begin();
629 origin
!= origins
.end(); ++origin
) {
630 // TODO(mkwst): Clean this up, it's slow. http://crbug.com/130746
631 if (!storage_origin
.is_empty() && origin
->GetOrigin() != storage_origin
)
634 if (!origin_matcher
.is_null() &&
635 !origin_matcher
.Run(*origin
, special_storage_policy
.get())) {
639 (*deletion_task_count
)++;
640 quota_manager
->DeleteOriginData(
641 *origin
, quota_storage_type
,
642 StoragePartitionImpl::GenerateQuotaClientMask(remove_mask
),
643 base::Bind(&OnQuotaManagedOriginDeleted
,
644 origin
->GetOrigin(), quota_storage_type
,
645 deletion_task_count
, callback
));
647 (*deletion_task_count
)--;
649 CheckQuotaManagedDataDeletionStatus(deletion_task_count
, callback
);
652 void StoragePartitionImpl::DataDeletionHelper::IncrementTaskCountOnUI() {
653 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
657 void StoragePartitionImpl::DataDeletionHelper::DecrementTaskCountOnUI() {
658 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
659 BrowserThread::PostTask(
660 BrowserThread::UI
, FROM_HERE
,
661 base::Bind(&DataDeletionHelper::DecrementTaskCountOnUI
,
662 base::Unretained(this)));
665 DCHECK_GT(task_count
, 0);
673 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
674 const GURL
& storage_origin
,
675 const OriginMatcherFunction
& origin_matcher
,
676 const base::FilePath
& path
,
677 net::URLRequestContextGetter
* rq_context
,
678 DOMStorageContextWrapper
* dom_storage_context
,
679 quota::QuotaManager
* quota_manager
,
680 quota::SpecialStoragePolicy
* special_storage_policy
,
681 WebRTCIdentityStore
* webrtc_identity_store
,
682 const base::Time begin
,
683 const base::Time end
) {
684 DCHECK_NE(remove_mask
, 0u);
685 DCHECK(!callback
.is_null());
687 IncrementTaskCountOnUI();
688 base::Closure decrement_callback
= base::Bind(
689 &DataDeletionHelper::DecrementTaskCountOnUI
, base::Unretained(this));
691 if (remove_mask
& REMOVE_DATA_MASK_COOKIES
) {
692 // Handle the cookies.
693 IncrementTaskCountOnUI();
694 BrowserThread::PostTask(
695 BrowserThread::IO
, FROM_HERE
,
696 base::Bind(&ClearCookiesOnIOThread
,
697 make_scoped_refptr(rq_context
), begin
, end
, storage_origin
,
698 decrement_callback
));
701 if (remove_mask
& REMOVE_DATA_MASK_INDEXEDDB
||
702 remove_mask
& REMOVE_DATA_MASK_WEBSQL
||
703 remove_mask
& REMOVE_DATA_MASK_APPCACHE
||
704 remove_mask
& REMOVE_DATA_MASK_FILE_SYSTEMS
||
705 remove_mask
& REMOVE_DATA_MASK_SERVICE_WORKERS
) {
706 IncrementTaskCountOnUI();
707 BrowserThread::PostTask(
708 BrowserThread::IO
, FROM_HERE
,
709 base::Bind(&DataDeletionHelper::ClearQuotaManagedDataOnIOThread
,
710 base::Unretained(this),
711 make_scoped_refptr(quota_manager
),
714 make_scoped_refptr(special_storage_policy
),
716 decrement_callback
));
719 if (remove_mask
& REMOVE_DATA_MASK_LOCAL_STORAGE
) {
720 IncrementTaskCountOnUI();
721 ClearLocalStorageOnUIThread(
722 make_scoped_refptr(dom_storage_context
),
723 make_scoped_refptr(special_storage_policy
),
725 storage_origin
, begin
, end
,
728 // ClearDataImpl cannot clear session storage data when a particular origin
729 // is specified. Therefore we ignore clearing session storage in this case.
730 // TODO(lazyboy): Fix.
731 if (storage_origin
.is_empty()) {
732 IncrementTaskCountOnUI();
733 ClearSessionStorageOnUIThread(
734 make_scoped_refptr(dom_storage_context
),
735 make_scoped_refptr(special_storage_policy
),
741 if (remove_mask
& REMOVE_DATA_MASK_SHADER_CACHE
) {
742 IncrementTaskCountOnUI();
743 BrowserThread::PostTask(
744 BrowserThread::IO
, FROM_HERE
,
745 base::Bind(&ClearShaderCacheOnIOThread
,
746 path
, begin
, end
, decrement_callback
));
749 if (remove_mask
& REMOVE_DATA_MASK_WEBRTC_IDENTITY
) {
750 IncrementTaskCountOnUI();
751 BrowserThread::PostTask(
754 base::Bind(&WebRTCIdentityStore::DeleteBetween
,
755 webrtc_identity_store
,
758 decrement_callback
));
761 DecrementTaskCountOnUI();
764 void StoragePartitionImpl::ClearDataForOrigin(
766 uint32 quota_storage_remove_mask
,
767 const GURL
& storage_origin
,
768 net::URLRequestContextGetter
* request_context_getter
,
769 const base::Closure
& callback
) {
770 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
771 ClearDataImpl(remove_mask
,
772 quota_storage_remove_mask
,
774 OriginMatcherFunction(),
775 request_context_getter
,
781 void StoragePartitionImpl::ClearData(
783 uint32 quota_storage_remove_mask
,
784 const GURL
& storage_origin
,
785 const OriginMatcherFunction
& origin_matcher
,
786 const base::Time begin
,
787 const base::Time end
,
788 const base::Closure
& callback
) {
789 ClearDataImpl(remove_mask
, quota_storage_remove_mask
, storage_origin
,
790 origin_matcher
, GetURLRequestContext(), begin
, end
, callback
);
793 WebRTCIdentityStore
* StoragePartitionImpl::GetWebRTCIdentityStore() {
794 return webrtc_identity_store_
.get();
797 void StoragePartitionImpl::OverrideQuotaManagerForTesting(
798 quota::QuotaManager
* quota_manager
) {
799 quota_manager_
= quota_manager
;
802 void StoragePartitionImpl::OverrideSpecialStoragePolicyForTesting(
803 quota::SpecialStoragePolicy
* special_storage_policy
) {
804 special_storage_policy_
= special_storage_policy
;
807 void StoragePartitionImpl::SetURLRequestContext(
808 net::URLRequestContextGetter
* url_request_context
) {
809 url_request_context_
= url_request_context
;
812 void StoragePartitionImpl::SetMediaURLRequestContext(
813 net::URLRequestContextGetter
* media_url_request_context
) {
814 media_url_request_context_
= media_url_request_context
;
817 } // namespace content