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/geofencing/geofencing_manager.h"
12 #include "content/browser/gpu/shader_disk_cache.h"
13 #include "content/browser/host_zoom_map_impl.h"
14 #include "content/browser/navigator_connect/navigator_connect_context_impl.h"
15 #include "content/browser/navigator_connect/navigator_connect_service_worker_service_factory.h"
16 #include "content/common/dom_storage/dom_storage_types.h"
17 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/dom_storage_context.h"
20 #include "content/public/browser/indexed_db_context.h"
21 #include "content/public/browser/local_storage_usage_info.h"
22 #include "content/public/browser/session_storage_usage_info.h"
23 #include "net/base/completion_callback.h"
24 #include "net/base/net_errors.h"
25 #include "net/cookies/cookie_monster.h"
26 #include "net/url_request/url_request_context.h"
27 #include "net/url_request/url_request_context_getter.h"
28 #include "storage/browser/database/database_tracker.h"
29 #include "storage/browser/quota/quota_manager.h"
35 void OnClearedCookies(const base::Closure
& callback
, int num_deleted
) {
36 // The final callback needs to happen from UI thread.
37 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
38 BrowserThread::PostTask(
39 BrowserThread::UI
, FROM_HERE
,
40 base::Bind(&OnClearedCookies
, callback
, num_deleted
));
47 void ClearCookiesOnIOThread(
48 const scoped_refptr
<net::URLRequestContextGetter
>& rq_context
,
49 const base::Time begin
,
51 const GURL
& storage_origin
,
52 const base::Closure
& callback
) {
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
54 net::CookieStore
* cookie_store
= rq_context
->
55 GetURLRequestContext()->cookie_store();
56 if (storage_origin
.is_empty()) {
57 cookie_store
->DeleteAllCreatedBetweenAsync(
60 base::Bind(&OnClearedCookies
, callback
));
62 cookie_store
->DeleteAllCreatedBetweenForHostAsync(
65 storage_origin
, base::Bind(&OnClearedCookies
, callback
));
69 void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count
,
70 const base::Closure
& callback
) {
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
72 if (*deletion_task_count
== 0) {
73 delete deletion_task_count
;
78 void OnQuotaManagedOriginDeleted(const GURL
& origin
,
79 storage::StorageType type
,
80 size_t* deletion_task_count
,
81 const base::Closure
& callback
,
82 storage::QuotaStatusCode status
) {
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
84 DCHECK_GT(*deletion_task_count
, 0u);
85 if (status
!= storage::kQuotaStatusOk
) {
86 DLOG(ERROR
) << "Couldn't remove data of type " << type
<< " for origin "
87 << origin
<< ". Status: " << status
;
90 (*deletion_task_count
)--;
91 CheckQuotaManagedDataDeletionStatus(deletion_task_count
, callback
);
94 void ClearedShaderCache(const base::Closure
& callback
) {
95 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
96 BrowserThread::PostTask(
97 BrowserThread::UI
, FROM_HERE
,
98 base::Bind(&ClearedShaderCache
, callback
));
104 void ClearShaderCacheOnIOThread(const base::FilePath
& path
,
105 const base::Time begin
,
106 const base::Time end
,
107 const base::Closure
& callback
) {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
109 ShaderCacheFactory::GetInstance()->ClearByPath(
110 path
, begin
, end
, base::Bind(&ClearedShaderCache
, callback
));
113 void OnLocalStorageUsageInfo(
114 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
115 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
116 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
117 const base::Time delete_begin
,
118 const base::Time delete_end
,
119 const base::Closure
& callback
,
120 const std::vector
<LocalStorageUsageInfo
>& infos
) {
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
123 for (size_t i
= 0; i
< infos
.size(); ++i
) {
124 if (!origin_matcher
.is_null() &&
125 !origin_matcher
.Run(infos
[i
].origin
, special_storage_policy
.get())) {
129 if (infos
[i
].last_modified
>= delete_begin
&&
130 infos
[i
].last_modified
<= delete_end
) {
131 dom_storage_context
->DeleteLocalStorage(infos
[i
].origin
);
137 void OnSessionStorageUsageInfo(
138 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
139 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
140 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
141 const base::Closure
& callback
,
142 const std::vector
<SessionStorageUsageInfo
>& infos
) {
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
145 for (size_t i
= 0; i
< infos
.size(); ++i
) {
146 if (!origin_matcher
.is_null() &&
147 !origin_matcher
.Run(infos
[i
].origin
, special_storage_policy
.get())) {
150 dom_storage_context
->DeleteSessionStorage(infos
[i
]);
156 void ClearLocalStorageOnUIThread(
157 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
158 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
159 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
160 const GURL
& storage_origin
,
161 const base::Time begin
,
162 const base::Time end
,
163 const base::Closure
& callback
) {
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
166 if (!storage_origin
.is_empty()) {
167 bool can_delete
= origin_matcher
.is_null() ||
168 origin_matcher
.Run(storage_origin
,
169 special_storage_policy
.get());
171 dom_storage_context
->DeleteLocalStorage(storage_origin
);
177 dom_storage_context
->GetLocalStorageUsage(
178 base::Bind(&OnLocalStorageUsageInfo
,
179 dom_storage_context
, special_storage_policy
, origin_matcher
,
180 begin
, end
, callback
));
183 void ClearSessionStorageOnUIThread(
184 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
185 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
186 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
187 const base::Closure
& callback
) {
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
190 dom_storage_context
->GetSessionStorageUsage(
191 base::Bind(&OnSessionStorageUsageInfo
, dom_storage_context
,
192 special_storage_policy
, origin_matcher
,
199 STATIC_CONST_MEMBER_DEFINITION
const uint32
200 StoragePartition::REMOVE_DATA_MASK_APPCACHE
;
201 STATIC_CONST_MEMBER_DEFINITION
const uint32
202 StoragePartition::REMOVE_DATA_MASK_COOKIES
;
203 STATIC_CONST_MEMBER_DEFINITION
const uint32
204 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
;
205 STATIC_CONST_MEMBER_DEFINITION
const uint32
206 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
;
207 STATIC_CONST_MEMBER_DEFINITION
const uint32
208 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE
;
209 STATIC_CONST_MEMBER_DEFINITION
const uint32
210 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
;
211 STATIC_CONST_MEMBER_DEFINITION
const uint32
212 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE
;
213 STATIC_CONST_MEMBER_DEFINITION
const uint32
214 StoragePartition::REMOVE_DATA_MASK_WEBSQL
;
215 STATIC_CONST_MEMBER_DEFINITION
const uint32
216 StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY
;
217 STATIC_CONST_MEMBER_DEFINITION
const uint32
218 StoragePartition::REMOVE_DATA_MASK_ALL
;
219 STATIC_CONST_MEMBER_DEFINITION
const uint32
220 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY
;
221 STATIC_CONST_MEMBER_DEFINITION
const uint32
222 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
;
223 STATIC_CONST_MEMBER_DEFINITION
const uint32
224 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_SYNCABLE
;
225 STATIC_CONST_MEMBER_DEFINITION
const uint32
226 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
;
229 int StoragePartitionImpl::GenerateQuotaClientMask(uint32 remove_mask
) {
230 int quota_client_mask
= 0;
232 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
)
233 quota_client_mask
|= storage::QuotaClient::kFileSystem
;
234 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_WEBSQL
)
235 quota_client_mask
|= storage::QuotaClient::kDatabase
;
236 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_APPCACHE
)
237 quota_client_mask
|= storage::QuotaClient::kAppcache
;
238 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
)
239 quota_client_mask
|= storage::QuotaClient::kIndexedDatabase
;
240 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
) {
241 quota_client_mask
|= storage::QuotaClient::kServiceWorker
;
242 quota_client_mask
|= storage::QuotaClient::kServiceWorkerCache
;
246 return quota_client_mask
;
249 // Helper for deleting quota managed data from a partition.
251 // Most of the operations in this class are done on IO thread.
252 struct StoragePartitionImpl::QuotaManagedDataDeletionHelper
{
253 QuotaManagedDataDeletionHelper(uint32 remove_mask
,
254 uint32 quota_storage_remove_mask
,
255 const GURL
& storage_origin
,
256 const base::Closure
& callback
)
257 : remove_mask(remove_mask
),
258 quota_storage_remove_mask(quota_storage_remove_mask
),
259 storage_origin(storage_origin
),
264 void IncrementTaskCountOnIO();
265 void DecrementTaskCountOnIO();
267 void ClearDataOnIOThread(
268 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
269 const base::Time begin
,
270 const scoped_refptr
<storage::SpecialStoragePolicy
>&
271 special_storage_policy
,
272 const StoragePartition::OriginMatcherFunction
& origin_matcher
);
274 void ClearOriginsOnIOThread(
275 storage::QuotaManager
* quota_manager
,
276 const scoped_refptr
<storage::SpecialStoragePolicy
>&
277 special_storage_policy
,
278 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
279 const base::Closure
& callback
,
280 const std::set
<GURL
>& origins
,
281 storage::StorageType quota_storage_type
);
283 // All of these data are accessed on IO thread.
285 uint32 quota_storage_remove_mask
;
287 const base::Closure callback
;
291 // Helper for deleting all sorts of data from a partition, keeps track of
294 // StoragePartitionImpl creates an instance of this class to keep track of
295 // data deletion progress. Deletion requires deleting multiple bits of data
296 // (e.g. cookies, local storage, session storage etc.) and hopping between UI
297 // and IO thread. An instance of this class is created in the beginning of
298 // deletion process (StoragePartitionImpl::ClearDataImpl) and the instance is
299 // forwarded and updated on each (sub) deletion's callback. The instance is
300 // finally destroyed when deletion completes (and |callback| is invoked).
301 struct StoragePartitionImpl::DataDeletionHelper
{
302 DataDeletionHelper(uint32 remove_mask
,
303 uint32 quota_storage_remove_mask
,
304 const base::Closure
& callback
)
305 : remove_mask(remove_mask
),
306 quota_storage_remove_mask(quota_storage_remove_mask
),
311 void IncrementTaskCountOnUI();
312 void DecrementTaskCountOnUI();
314 void ClearDataOnUIThread(
315 const GURL
& storage_origin
,
316 const OriginMatcherFunction
& origin_matcher
,
317 const base::FilePath
& path
,
318 net::URLRequestContextGetter
* rq_context
,
319 DOMStorageContextWrapper
* dom_storage_context
,
320 storage::QuotaManager
* quota_manager
,
321 storage::SpecialStoragePolicy
* special_storage_policy
,
322 WebRTCIdentityStore
* webrtc_identity_store
,
323 const base::Time begin
,
324 const base::Time end
);
326 void ClearQuotaManagedDataOnIOThread(
327 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
328 const base::Time begin
,
329 const GURL
& storage_origin
,
330 const scoped_refptr
<storage::SpecialStoragePolicy
>&
331 special_storage_policy
,
332 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
333 const base::Closure
& callback
);
336 uint32 quota_storage_remove_mask
;
338 // Accessed on UI thread.
339 const base::Closure callback
;
340 // Accessed on UI thread.
344 void StoragePartitionImpl::DataDeletionHelper::ClearQuotaManagedDataOnIOThread(
345 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
346 const base::Time begin
,
347 const GURL
& storage_origin
,
348 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
349 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
350 const base::Closure
& callback
) {
351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
353 StoragePartitionImpl::QuotaManagedDataDeletionHelper
* helper
=
354 new StoragePartitionImpl::QuotaManagedDataDeletionHelper(
356 quota_storage_remove_mask
,
359 helper
->ClearDataOnIOThread(quota_manager
, begin
, special_storage_policy
,
363 StoragePartitionImpl::StoragePartitionImpl(
364 BrowserContext
* browser_context
,
365 const base::FilePath
& partition_path
,
366 storage::QuotaManager
* quota_manager
,
367 ChromeAppCacheService
* appcache_service
,
368 storage::FileSystemContext
* filesystem_context
,
369 storage::DatabaseTracker
* database_tracker
,
370 DOMStorageContextWrapper
* dom_storage_context
,
371 IndexedDBContextImpl
* indexed_db_context
,
372 ServiceWorkerContextWrapper
* service_worker_context
,
373 WebRTCIdentityStore
* webrtc_identity_store
,
374 storage::SpecialStoragePolicy
* special_storage_policy
,
375 GeofencingManager
* geofencing_manager
,
376 HostZoomLevelContext
* host_zoom_level_context
,
377 NavigatorConnectContextImpl
* navigator_connect_context
)
378 : partition_path_(partition_path
),
379 quota_manager_(quota_manager
),
380 appcache_service_(appcache_service
),
381 filesystem_context_(filesystem_context
),
382 database_tracker_(database_tracker
),
383 dom_storage_context_(dom_storage_context
),
384 indexed_db_context_(indexed_db_context
),
385 service_worker_context_(service_worker_context
),
386 webrtc_identity_store_(webrtc_identity_store
),
387 special_storage_policy_(special_storage_policy
),
388 geofencing_manager_(geofencing_manager
),
389 host_zoom_level_context_(host_zoom_level_context
),
390 navigator_connect_context_(navigator_connect_context
),
391 browser_context_(browser_context
) {
394 StoragePartitionImpl::~StoragePartitionImpl() {
395 browser_context_
= nullptr;
397 // These message loop checks are just to avoid leaks in unittests.
398 if (GetDatabaseTracker() &&
399 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
400 BrowserThread::PostTask(
403 base::Bind(&storage::DatabaseTracker::Shutdown
, GetDatabaseTracker()));
406 if (GetFileSystemContext())
407 GetFileSystemContext()->Shutdown();
409 if (GetDOMStorageContext())
410 GetDOMStorageContext()->Shutdown();
412 if (GetServiceWorkerContext())
413 GetServiceWorkerContext()->Shutdown();
415 if (GetGeofencingManager())
416 GetGeofencingManager()->Shutdown();
419 StoragePartitionImpl
* StoragePartitionImpl::Create(
420 BrowserContext
* context
,
422 const base::FilePath
& partition_path
) {
423 // Ensure that these methods are called on the UI thread, except for
424 // unittests where a UI thread might not have been created.
425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
) ||
426 !BrowserThread::IsMessageLoopValid(BrowserThread::UI
));
428 // All of the clients have to be created and registered with the
429 // QuotaManager prior to the QuotaManger being used. We do them
430 // all together here prior to handing out a reference to anything
431 // that utilizes the QuotaManager.
432 scoped_refptr
<storage::QuotaManager
> quota_manager
=
433 new storage::QuotaManager(
436 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
).get(),
437 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB
).get(),
438 context
->GetSpecialStoragePolicy());
440 // Each consumer is responsible for registering its QuotaClient during
442 scoped_refptr
<storage::FileSystemContext
> filesystem_context
=
443 CreateFileSystemContext(
444 context
, partition_path
, in_memory
, quota_manager
->proxy());
446 scoped_refptr
<storage::DatabaseTracker
> database_tracker
=
447 new storage::DatabaseTracker(partition_path
,
449 context
->GetSpecialStoragePolicy(),
450 quota_manager
->proxy(),
451 BrowserThread::GetMessageLoopProxyForThread(
452 BrowserThread::FILE).get());
454 base::FilePath path
= in_memory
? base::FilePath() : partition_path
;
455 scoped_refptr
<DOMStorageContextWrapper
> dom_storage_context
=
456 new DOMStorageContextWrapper(path
, context
->GetSpecialStoragePolicy());
458 // BrowserMainLoop may not be initialized in unit tests. Tests will
459 // need to inject their own task runner into the IndexedDBContext.
460 base::SequencedTaskRunner
* idb_task_runner
=
461 BrowserThread::CurrentlyOn(BrowserThread::UI
) &&
462 BrowserMainLoop::GetInstance()
463 ? BrowserMainLoop::GetInstance()->indexed_db_thread()
464 ->message_loop_proxy().get()
466 scoped_refptr
<IndexedDBContextImpl
> indexed_db_context
=
467 new IndexedDBContextImpl(path
,
468 context
->GetSpecialStoragePolicy(),
469 quota_manager
->proxy(),
472 scoped_refptr
<ServiceWorkerContextWrapper
> service_worker_context
=
473 new ServiceWorkerContextWrapper(context
);
474 service_worker_context
->Init(
475 path
, quota_manager
->proxy(), context
->GetSpecialStoragePolicy());
477 scoped_refptr
<ChromeAppCacheService
> appcache_service
=
478 new ChromeAppCacheService(quota_manager
->proxy());
480 scoped_refptr
<WebRTCIdentityStore
> webrtc_identity_store(
481 new WebRTCIdentityStore(path
, context
->GetSpecialStoragePolicy()));
483 scoped_refptr
<storage::SpecialStoragePolicy
> special_storage_policy(
484 context
->GetSpecialStoragePolicy());
486 scoped_refptr
<GeofencingManager
> geofencing_manager
=
487 new GeofencingManager(service_worker_context
);
488 geofencing_manager
->Init();
490 scoped_refptr
<HostZoomLevelContext
> host_zoom_level_context(
491 new HostZoomLevelContext(
492 context
->CreateZoomLevelDelegate(partition_path
)));
494 scoped_refptr
<NavigatorConnectContextImpl
> navigator_connect_context
=
495 new NavigatorConnectContextImpl();
496 navigator_connect_context
->AddFactory(make_scoped_ptr(
497 new NavigatorConnectServiceWorkerServiceFactory(service_worker_context
)));
499 StoragePartitionImpl
* storage_partition
= new StoragePartitionImpl(
500 context
, partition_path
, quota_manager
.get(), appcache_service
.get(),
501 filesystem_context
.get(), database_tracker
.get(),
502 dom_storage_context
.get(), indexed_db_context
.get(),
503 service_worker_context
.get(), webrtc_identity_store
.get(),
504 special_storage_policy
.get(), geofencing_manager
.get(),
505 host_zoom_level_context
.get(), navigator_connect_context
.get());
507 service_worker_context
->set_storage_partition(storage_partition
);
509 return storage_partition
;
512 base::FilePath
StoragePartitionImpl::GetPath() {
513 return partition_path_
;
516 net::URLRequestContextGetter
* StoragePartitionImpl::GetURLRequestContext() {
517 return url_request_context_
.get();
520 net::URLRequestContextGetter
*
521 StoragePartitionImpl::GetMediaURLRequestContext() {
522 return media_url_request_context_
.get();
525 storage::QuotaManager
* StoragePartitionImpl::GetQuotaManager() {
526 return quota_manager_
.get();
529 ChromeAppCacheService
* StoragePartitionImpl::GetAppCacheService() {
530 return appcache_service_
.get();
533 storage::FileSystemContext
* StoragePartitionImpl::GetFileSystemContext() {
534 return filesystem_context_
.get();
537 storage::DatabaseTracker
* StoragePartitionImpl::GetDatabaseTracker() {
538 return database_tracker_
.get();
541 DOMStorageContextWrapper
* StoragePartitionImpl::GetDOMStorageContext() {
542 return dom_storage_context_
.get();
545 IndexedDBContextImpl
* StoragePartitionImpl::GetIndexedDBContext() {
546 return indexed_db_context_
.get();
549 ServiceWorkerContextWrapper
* StoragePartitionImpl::GetServiceWorkerContext() {
550 return service_worker_context_
.get();
553 GeofencingManager
* StoragePartitionImpl::GetGeofencingManager() {
554 return geofencing_manager_
.get();
557 HostZoomMap
* StoragePartitionImpl::GetHostZoomMap() {
558 DCHECK(host_zoom_level_context_
.get());
559 return host_zoom_level_context_
->GetHostZoomMap();
562 HostZoomLevelContext
* StoragePartitionImpl::GetHostZoomLevelContext() {
563 return host_zoom_level_context_
.get();
566 ZoomLevelDelegate
* StoragePartitionImpl::GetZoomLevelDelegate() {
567 DCHECK(host_zoom_level_context_
.get());
568 return host_zoom_level_context_
->GetZoomLevelDelegate();
571 NavigatorConnectContextImpl
*
572 StoragePartitionImpl::GetNavigatorConnectContext() {
573 return navigator_connect_context_
.get();
576 void StoragePartitionImpl::ClearDataImpl(
578 uint32 quota_storage_remove_mask
,
579 const GURL
& storage_origin
,
580 const OriginMatcherFunction
& origin_matcher
,
581 net::URLRequestContextGetter
* rq_context
,
582 const base::Time begin
,
583 const base::Time end
,
584 const base::Closure
& callback
) {
585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
586 DataDeletionHelper
* helper
= new DataDeletionHelper(remove_mask
,
587 quota_storage_remove_mask
,
589 // |helper| deletes itself when done in
590 // DataDeletionHelper::DecrementTaskCountOnUI().
591 helper
->ClearDataOnUIThread(storage_origin
,
595 dom_storage_context_
.get(),
596 quota_manager_
.get(),
597 special_storage_policy_
.get(),
598 webrtc_identity_store_
.get(),
603 void StoragePartitionImpl::
604 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() {
605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
609 void StoragePartitionImpl::
610 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() {
611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
612 DCHECK_GT(task_count
, 0);
621 void StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearDataOnIOThread(
622 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
623 const base::Time begin
,
624 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
625 const StoragePartition::OriginMatcherFunction
& origin_matcher
) {
626 IncrementTaskCountOnIO();
627 base::Closure decrement_callback
= base::Bind(
628 &QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO
,
629 base::Unretained(this));
631 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
) {
632 IncrementTaskCountOnIO();
633 // Ask the QuotaManager for all origins with persistent quota modified
634 // within the user-specified timeframe, and deal with the resulting set in
635 // ClearQuotaManagedOriginsOnIOThread().
636 quota_manager
->GetOriginsModifiedSince(
637 storage::kStorageTypePersistent
,
639 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
640 base::Unretained(this),
642 special_storage_policy
,
644 decrement_callback
));
647 // Do the same for temporary quota.
648 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_TEMPORARY
) {
649 IncrementTaskCountOnIO();
650 quota_manager
->GetOriginsModifiedSince(
651 storage::kStorageTypeTemporary
,
653 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
654 base::Unretained(this),
656 special_storage_policy
,
658 decrement_callback
));
661 // Do the same for syncable quota.
662 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_SYNCABLE
) {
663 IncrementTaskCountOnIO();
664 quota_manager
->GetOriginsModifiedSince(
665 storage::kStorageTypeSyncable
,
667 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
668 base::Unretained(this),
670 special_storage_policy
,
672 decrement_callback
));
675 DecrementTaskCountOnIO();
679 StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread(
680 storage::QuotaManager
* quota_manager
,
681 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
682 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
683 const base::Closure
& callback
,
684 const std::set
<GURL
>& origins
,
685 storage::StorageType quota_storage_type
) {
686 // The QuotaManager manages all storage other than cookies, LocalStorage,
687 // and SessionStorage. This loop wipes out most HTML5 storage for the given
689 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO
));
690 if (!origins
.size()) {
695 size_t* deletion_task_count
= new size_t(0u);
696 (*deletion_task_count
)++;
697 for (std::set
<GURL
>::const_iterator origin
= origins
.begin();
698 origin
!= origins
.end(); ++origin
) {
699 // TODO(mkwst): Clean this up, it's slow. http://crbug.com/130746
700 if (!storage_origin
.is_empty() && origin
->GetOrigin() != storage_origin
)
703 if (!origin_matcher
.is_null() &&
704 !origin_matcher
.Run(*origin
, special_storage_policy
.get())) {
708 (*deletion_task_count
)++;
709 quota_manager
->DeleteOriginData(
710 *origin
, quota_storage_type
,
711 StoragePartitionImpl::GenerateQuotaClientMask(remove_mask
),
712 base::Bind(&OnQuotaManagedOriginDeleted
,
713 origin
->GetOrigin(), quota_storage_type
,
714 deletion_task_count
, callback
));
716 (*deletion_task_count
)--;
718 CheckQuotaManagedDataDeletionStatus(deletion_task_count
, callback
);
721 void StoragePartitionImpl::DataDeletionHelper::IncrementTaskCountOnUI() {
722 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
726 void StoragePartitionImpl::DataDeletionHelper::DecrementTaskCountOnUI() {
727 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
728 BrowserThread::PostTask(
729 BrowserThread::UI
, FROM_HERE
,
730 base::Bind(&DataDeletionHelper::DecrementTaskCountOnUI
,
731 base::Unretained(this)));
734 DCHECK_GT(task_count
, 0);
742 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
743 const GURL
& storage_origin
,
744 const OriginMatcherFunction
& origin_matcher
,
745 const base::FilePath
& path
,
746 net::URLRequestContextGetter
* rq_context
,
747 DOMStorageContextWrapper
* dom_storage_context
,
748 storage::QuotaManager
* quota_manager
,
749 storage::SpecialStoragePolicy
* special_storage_policy
,
750 WebRTCIdentityStore
* webrtc_identity_store
,
751 const base::Time begin
,
752 const base::Time end
) {
753 DCHECK_NE(remove_mask
, 0u);
754 DCHECK(!callback
.is_null());
756 IncrementTaskCountOnUI();
757 base::Closure decrement_callback
= base::Bind(
758 &DataDeletionHelper::DecrementTaskCountOnUI
, base::Unretained(this));
760 if (remove_mask
& REMOVE_DATA_MASK_COOKIES
) {
761 // Handle the cookies.
762 IncrementTaskCountOnUI();
763 BrowserThread::PostTask(
764 BrowserThread::IO
, FROM_HERE
,
765 base::Bind(&ClearCookiesOnIOThread
,
766 make_scoped_refptr(rq_context
), begin
, end
, storage_origin
,
767 decrement_callback
));
770 if (remove_mask
& REMOVE_DATA_MASK_INDEXEDDB
||
771 remove_mask
& REMOVE_DATA_MASK_WEBSQL
||
772 remove_mask
& REMOVE_DATA_MASK_APPCACHE
||
773 remove_mask
& REMOVE_DATA_MASK_FILE_SYSTEMS
||
774 remove_mask
& REMOVE_DATA_MASK_SERVICE_WORKERS
) {
775 IncrementTaskCountOnUI();
776 BrowserThread::PostTask(
777 BrowserThread::IO
, FROM_HERE
,
778 base::Bind(&DataDeletionHelper::ClearQuotaManagedDataOnIOThread
,
779 base::Unretained(this),
780 make_scoped_refptr(quota_manager
),
783 make_scoped_refptr(special_storage_policy
),
785 decrement_callback
));
788 if (remove_mask
& REMOVE_DATA_MASK_LOCAL_STORAGE
) {
789 IncrementTaskCountOnUI();
790 ClearLocalStorageOnUIThread(
791 make_scoped_refptr(dom_storage_context
),
792 make_scoped_refptr(special_storage_policy
),
794 storage_origin
, begin
, end
,
797 // ClearDataImpl cannot clear session storage data when a particular origin
798 // is specified. Therefore we ignore clearing session storage in this case.
799 // TODO(lazyboy): Fix.
800 if (storage_origin
.is_empty()) {
801 IncrementTaskCountOnUI();
802 ClearSessionStorageOnUIThread(
803 make_scoped_refptr(dom_storage_context
),
804 make_scoped_refptr(special_storage_policy
),
810 if (remove_mask
& REMOVE_DATA_MASK_SHADER_CACHE
) {
811 IncrementTaskCountOnUI();
812 BrowserThread::PostTask(
813 BrowserThread::IO
, FROM_HERE
,
814 base::Bind(&ClearShaderCacheOnIOThread
,
815 path
, begin
, end
, decrement_callback
));
818 if (remove_mask
& REMOVE_DATA_MASK_WEBRTC_IDENTITY
) {
819 IncrementTaskCountOnUI();
820 BrowserThread::PostTask(
823 base::Bind(&WebRTCIdentityStore::DeleteBetween
,
824 webrtc_identity_store
,
827 decrement_callback
));
830 DecrementTaskCountOnUI();
833 void StoragePartitionImpl::ClearDataForOrigin(
835 uint32 quota_storage_remove_mask
,
836 const GURL
& storage_origin
,
837 net::URLRequestContextGetter
* request_context_getter
,
838 const base::Closure
& callback
) {
839 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
840 ClearDataImpl(remove_mask
,
841 quota_storage_remove_mask
,
843 OriginMatcherFunction(),
844 request_context_getter
,
850 void StoragePartitionImpl::ClearData(
852 uint32 quota_storage_remove_mask
,
853 const GURL
& storage_origin
,
854 const OriginMatcherFunction
& origin_matcher
,
855 const base::Time begin
,
856 const base::Time end
,
857 const base::Closure
& callback
) {
858 ClearDataImpl(remove_mask
, quota_storage_remove_mask
, storage_origin
,
859 origin_matcher
, GetURLRequestContext(), begin
, end
, callback
);
862 WebRTCIdentityStore
* StoragePartitionImpl::GetWebRTCIdentityStore() {
863 return webrtc_identity_store_
.get();
866 BrowserContext
* StoragePartitionImpl::browser_context() const {
867 return browser_context_
;
870 void StoragePartitionImpl::OverrideQuotaManagerForTesting(
871 storage::QuotaManager
* quota_manager
) {
872 quota_manager_
= quota_manager
;
875 void StoragePartitionImpl::OverrideSpecialStoragePolicyForTesting(
876 storage::SpecialStoragePolicy
* special_storage_policy
) {
877 special_storage_policy_
= special_storage_policy
;
880 void StoragePartitionImpl::SetURLRequestContext(
881 net::URLRequestContextGetter
* url_request_context
) {
882 url_request_context_
= url_request_context
;
885 void StoragePartitionImpl::SetMediaURLRequestContext(
886 net::URLRequestContextGetter
* media_url_request_context
) {
887 media_url_request_context_
= media_url_request_context
;
890 } // namespace content