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"
10 #include "base/location.h"
11 #include "base/sequenced_task_runner.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "content/browser/browser_main_loop.h"
15 #include "content/browser/fileapi/browser_file_system_helper.h"
16 #include "content/browser/geofencing/geofencing_manager.h"
17 #include "content/browser/gpu/shader_disk_cache.h"
18 #include "content/browser/host_zoom_map_impl.h"
19 #include "content/browser/navigator_connect/navigator_connect_context_impl.h"
20 #include "content/browser/navigator_connect/navigator_connect_service_worker_service_factory.h"
21 #include "content/browser/notifications/platform_notification_context_impl.h"
22 #include "content/common/dom_storage/dom_storage_types.h"
23 #include "content/public/browser/browser_context.h"
24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/dom_storage_context.h"
26 #include "content/public/browser/indexed_db_context.h"
27 #include "content/public/browser/local_storage_usage_info.h"
28 #include "content/public/browser/session_storage_usage_info.h"
29 #include "net/base/completion_callback.h"
30 #include "net/base/net_errors.h"
31 #include "net/cookies/cookie_monster.h"
32 #include "net/url_request/url_request_context.h"
33 #include "net/url_request/url_request_context_getter.h"
34 #include "storage/browser/database/database_tracker.h"
35 #include "storage/browser/quota/quota_manager.h"
41 void OnClearedCookies(const base::Closure
& callback
, int num_deleted
) {
42 // The final callback needs to happen from UI thread.
43 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
44 BrowserThread::PostTask(
45 BrowserThread::UI
, FROM_HERE
,
46 base::Bind(&OnClearedCookies
, callback
, num_deleted
));
53 void ClearCookiesOnIOThread(
54 const scoped_refptr
<net::URLRequestContextGetter
>& rq_context
,
55 const base::Time begin
,
57 const GURL
& storage_origin
,
58 const base::Closure
& callback
) {
59 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
60 net::CookieStore
* cookie_store
= rq_context
->
61 GetURLRequestContext()->cookie_store();
62 if (storage_origin
.is_empty()) {
63 cookie_store
->DeleteAllCreatedBetweenAsync(
66 base::Bind(&OnClearedCookies
, callback
));
68 cookie_store
->DeleteAllCreatedBetweenForHostAsync(
71 storage_origin
, base::Bind(&OnClearedCookies
, callback
));
75 void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count
,
76 const base::Closure
& callback
) {
77 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
78 if (*deletion_task_count
== 0) {
79 delete deletion_task_count
;
84 void OnQuotaManagedOriginDeleted(const GURL
& origin
,
85 storage::StorageType type
,
86 size_t* deletion_task_count
,
87 const base::Closure
& callback
,
88 storage::QuotaStatusCode status
) {
89 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
90 DCHECK_GT(*deletion_task_count
, 0u);
91 if (status
!= storage::kQuotaStatusOk
) {
92 DLOG(ERROR
) << "Couldn't remove data of type " << type
<< " for origin "
93 << origin
<< ". Status: " << status
;
96 (*deletion_task_count
)--;
97 CheckQuotaManagedDataDeletionStatus(deletion_task_count
, callback
);
100 void ClearedShaderCache(const base::Closure
& callback
) {
101 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
102 BrowserThread::PostTask(
103 BrowserThread::UI
, FROM_HERE
,
104 base::Bind(&ClearedShaderCache
, callback
));
110 void ClearShaderCacheOnIOThread(const base::FilePath
& path
,
111 const base::Time begin
,
112 const base::Time end
,
113 const base::Closure
& callback
) {
114 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
115 ShaderCacheFactory::GetInstance()->ClearByPath(
116 path
, begin
, end
, base::Bind(&ClearedShaderCache
, callback
));
119 void OnLocalStorageUsageInfo(
120 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
121 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
122 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
123 const base::Time delete_begin
,
124 const base::Time delete_end
,
125 const base::Closure
& callback
,
126 const std::vector
<LocalStorageUsageInfo
>& infos
) {
127 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
129 for (size_t i
= 0; i
< infos
.size(); ++i
) {
130 if (!origin_matcher
.is_null() &&
131 !origin_matcher
.Run(infos
[i
].origin
, special_storage_policy
.get())) {
135 if (infos
[i
].last_modified
>= delete_begin
&&
136 infos
[i
].last_modified
<= delete_end
) {
137 dom_storage_context
->DeleteLocalStorage(infos
[i
].origin
);
143 void OnSessionStorageUsageInfo(
144 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
145 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
146 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
147 const base::Closure
& callback
,
148 const std::vector
<SessionStorageUsageInfo
>& infos
) {
149 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
151 for (size_t i
= 0; i
< infos
.size(); ++i
) {
152 if (!origin_matcher
.is_null() &&
153 !origin_matcher
.Run(infos
[i
].origin
, special_storage_policy
.get())) {
156 dom_storage_context
->DeleteSessionStorage(infos
[i
]);
162 void ClearLocalStorageOnUIThread(
163 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
164 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
165 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
166 const GURL
& storage_origin
,
167 const base::Time begin
,
168 const base::Time end
,
169 const base::Closure
& callback
) {
170 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
172 if (!storage_origin
.is_empty()) {
173 bool can_delete
= origin_matcher
.is_null() ||
174 origin_matcher
.Run(storage_origin
,
175 special_storage_policy
.get());
177 dom_storage_context
->DeleteLocalStorage(storage_origin
);
183 dom_storage_context
->GetLocalStorageUsage(
184 base::Bind(&OnLocalStorageUsageInfo
,
185 dom_storage_context
, special_storage_policy
, origin_matcher
,
186 begin
, end
, callback
));
189 void ClearSessionStorageOnUIThread(
190 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
191 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
192 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
193 const base::Closure
& callback
) {
194 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
196 dom_storage_context
->GetSessionStorageUsage(
197 base::Bind(&OnSessionStorageUsageInfo
, dom_storage_context
,
198 special_storage_policy
, origin_matcher
,
205 STATIC_CONST_MEMBER_DEFINITION
const uint32
206 StoragePartition::REMOVE_DATA_MASK_APPCACHE
;
207 STATIC_CONST_MEMBER_DEFINITION
const uint32
208 StoragePartition::REMOVE_DATA_MASK_COOKIES
;
209 STATIC_CONST_MEMBER_DEFINITION
const uint32
210 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
;
211 STATIC_CONST_MEMBER_DEFINITION
const uint32
212 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
;
213 STATIC_CONST_MEMBER_DEFINITION
const uint32
214 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE
;
215 STATIC_CONST_MEMBER_DEFINITION
const uint32
216 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
;
217 STATIC_CONST_MEMBER_DEFINITION
const uint32
218 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE
;
219 STATIC_CONST_MEMBER_DEFINITION
const uint32
220 StoragePartition::REMOVE_DATA_MASK_WEBSQL
;
221 STATIC_CONST_MEMBER_DEFINITION
const uint32
222 StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY
;
223 STATIC_CONST_MEMBER_DEFINITION
const uint32
224 StoragePartition::REMOVE_DATA_MASK_ALL
;
225 STATIC_CONST_MEMBER_DEFINITION
const uint32
226 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY
;
227 STATIC_CONST_MEMBER_DEFINITION
const uint32
228 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
;
229 STATIC_CONST_MEMBER_DEFINITION
const uint32
230 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_SYNCABLE
;
231 STATIC_CONST_MEMBER_DEFINITION
const uint32
232 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
;
235 int StoragePartitionImpl::GenerateQuotaClientMask(uint32 remove_mask
) {
236 int quota_client_mask
= 0;
238 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
)
239 quota_client_mask
|= storage::QuotaClient::kFileSystem
;
240 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_WEBSQL
)
241 quota_client_mask
|= storage::QuotaClient::kDatabase
;
242 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_APPCACHE
)
243 quota_client_mask
|= storage::QuotaClient::kAppcache
;
244 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
)
245 quota_client_mask
|= storage::QuotaClient::kIndexedDatabase
;
246 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
) {
247 quota_client_mask
|= storage::QuotaClient::kServiceWorker
;
248 quota_client_mask
|= storage::QuotaClient::kServiceWorkerCache
;
252 return quota_client_mask
;
255 // Helper for deleting quota managed data from a partition.
257 // Most of the operations in this class are done on IO thread.
258 struct StoragePartitionImpl::QuotaManagedDataDeletionHelper
{
259 QuotaManagedDataDeletionHelper(uint32 remove_mask
,
260 uint32 quota_storage_remove_mask
,
261 const GURL
& storage_origin
,
262 const base::Closure
& callback
)
263 : remove_mask(remove_mask
),
264 quota_storage_remove_mask(quota_storage_remove_mask
),
265 storage_origin(storage_origin
),
270 void IncrementTaskCountOnIO();
271 void DecrementTaskCountOnIO();
273 void ClearDataOnIOThread(
274 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
275 const base::Time begin
,
276 const scoped_refptr
<storage::SpecialStoragePolicy
>&
277 special_storage_policy
,
278 const StoragePartition::OriginMatcherFunction
& origin_matcher
);
280 void ClearOriginsOnIOThread(
281 storage::QuotaManager
* quota_manager
,
282 const scoped_refptr
<storage::SpecialStoragePolicy
>&
283 special_storage_policy
,
284 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
285 const base::Closure
& callback
,
286 const std::set
<GURL
>& origins
,
287 storage::StorageType quota_storage_type
);
289 // All of these data are accessed on IO thread.
291 uint32 quota_storage_remove_mask
;
293 const base::Closure callback
;
297 // Helper for deleting all sorts of data from a partition, keeps track of
300 // StoragePartitionImpl creates an instance of this class to keep track of
301 // data deletion progress. Deletion requires deleting multiple bits of data
302 // (e.g. cookies, local storage, session storage etc.) and hopping between UI
303 // and IO thread. An instance of this class is created in the beginning of
304 // deletion process (StoragePartitionImpl::ClearDataImpl) and the instance is
305 // forwarded and updated on each (sub) deletion's callback. The instance is
306 // finally destroyed when deletion completes (and |callback| is invoked).
307 struct StoragePartitionImpl::DataDeletionHelper
{
308 DataDeletionHelper(uint32 remove_mask
,
309 uint32 quota_storage_remove_mask
,
310 const base::Closure
& callback
)
311 : remove_mask(remove_mask
),
312 quota_storage_remove_mask(quota_storage_remove_mask
),
317 void IncrementTaskCountOnUI();
318 void DecrementTaskCountOnUI();
320 void ClearDataOnUIThread(
321 const GURL
& storage_origin
,
322 const OriginMatcherFunction
& origin_matcher
,
323 const base::FilePath
& path
,
324 net::URLRequestContextGetter
* rq_context
,
325 DOMStorageContextWrapper
* dom_storage_context
,
326 storage::QuotaManager
* quota_manager
,
327 storage::SpecialStoragePolicy
* special_storage_policy
,
328 WebRTCIdentityStore
* webrtc_identity_store
,
329 const base::Time begin
,
330 const base::Time end
);
332 void ClearQuotaManagedDataOnIOThread(
333 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
334 const base::Time begin
,
335 const GURL
& storage_origin
,
336 const scoped_refptr
<storage::SpecialStoragePolicy
>&
337 special_storage_policy
,
338 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
339 const base::Closure
& callback
);
342 uint32 quota_storage_remove_mask
;
344 // Accessed on UI thread.
345 const base::Closure callback
;
346 // Accessed on UI thread.
350 void StoragePartitionImpl::DataDeletionHelper::ClearQuotaManagedDataOnIOThread(
351 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
352 const base::Time begin
,
353 const GURL
& storage_origin
,
354 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
355 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
356 const base::Closure
& callback
) {
357 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
359 StoragePartitionImpl::QuotaManagedDataDeletionHelper
* helper
=
360 new StoragePartitionImpl::QuotaManagedDataDeletionHelper(
362 quota_storage_remove_mask
,
365 helper
->ClearDataOnIOThread(quota_manager
, begin
, special_storage_policy
,
369 StoragePartitionImpl::StoragePartitionImpl(
370 BrowserContext
* browser_context
,
371 const base::FilePath
& partition_path
,
372 storage::QuotaManager
* quota_manager
,
373 ChromeAppCacheService
* appcache_service
,
374 storage::FileSystemContext
* filesystem_context
,
375 storage::DatabaseTracker
* database_tracker
,
376 DOMStorageContextWrapper
* dom_storage_context
,
377 IndexedDBContextImpl
* indexed_db_context
,
378 CacheStorageContextImpl
* cache_storage_context
,
379 ServiceWorkerContextWrapper
* service_worker_context
,
380 WebRTCIdentityStore
* webrtc_identity_store
,
381 storage::SpecialStoragePolicy
* special_storage_policy
,
382 GeofencingManager
* geofencing_manager
,
383 HostZoomLevelContext
* host_zoom_level_context
,
384 NavigatorConnectContextImpl
* navigator_connect_context
,
385 PlatformNotificationContextImpl
* platform_notification_context
,
386 BackgroundSyncContextImpl
* background_sync_context
)
387 : partition_path_(partition_path
),
388 quota_manager_(quota_manager
),
389 appcache_service_(appcache_service
),
390 filesystem_context_(filesystem_context
),
391 database_tracker_(database_tracker
),
392 dom_storage_context_(dom_storage_context
),
393 indexed_db_context_(indexed_db_context
),
394 cache_storage_context_(cache_storage_context
),
395 service_worker_context_(service_worker_context
),
396 webrtc_identity_store_(webrtc_identity_store
),
397 special_storage_policy_(special_storage_policy
),
398 geofencing_manager_(geofencing_manager
),
399 host_zoom_level_context_(host_zoom_level_context
),
400 navigator_connect_context_(navigator_connect_context
),
401 platform_notification_context_(platform_notification_context
),
402 background_sync_context_(background_sync_context
),
403 browser_context_(browser_context
) {
406 StoragePartitionImpl::~StoragePartitionImpl() {
407 browser_context_
= nullptr;
409 // These message loop checks are just to avoid leaks in unittests.
410 if (GetDatabaseTracker() &&
411 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
412 BrowserThread::PostTask(
415 base::Bind(&storage::DatabaseTracker::Shutdown
, GetDatabaseTracker()));
418 if (GetFileSystemContext())
419 GetFileSystemContext()->Shutdown();
421 if (GetDOMStorageContext())
422 GetDOMStorageContext()->Shutdown();
424 if (GetServiceWorkerContext())
425 GetServiceWorkerContext()->Shutdown();
427 if (GetCacheStorageContext())
428 GetCacheStorageContext()->Shutdown();
430 if (GetGeofencingManager())
431 GetGeofencingManager()->Shutdown();
433 if (GetPlatformNotificationContext())
434 GetPlatformNotificationContext()->Shutdown();
436 if (GetBackgroundSyncContext())
437 GetBackgroundSyncContext()->Shutdown();
440 StoragePartitionImpl
* StoragePartitionImpl::Create(
441 BrowserContext
* context
,
443 const base::FilePath
& partition_path
) {
444 // Ensure that these methods are called on the UI thread, except for
445 // unittests where a UI thread might not have been created.
446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
) ||
447 !BrowserThread::IsMessageLoopValid(BrowserThread::UI
));
449 // All of the clients have to be created and registered with the
450 // QuotaManager prior to the QuotaManger being used. We do them
451 // all together here prior to handing out a reference to anything
452 // that utilizes the QuotaManager.
453 scoped_refptr
<storage::QuotaManager
> quota_manager
=
454 new storage::QuotaManager(
457 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
).get(),
458 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB
).get(),
459 context
->GetSpecialStoragePolicy());
461 // Each consumer is responsible for registering its QuotaClient during
463 scoped_refptr
<storage::FileSystemContext
> filesystem_context
=
464 CreateFileSystemContext(
465 context
, partition_path
, in_memory
, quota_manager
->proxy());
467 scoped_refptr
<storage::DatabaseTracker
> database_tracker
=
468 new storage::DatabaseTracker(partition_path
,
470 context
->GetSpecialStoragePolicy(),
471 quota_manager
->proxy(),
472 BrowserThread::GetMessageLoopProxyForThread(
473 BrowserThread::FILE).get());
475 base::FilePath path
= in_memory
? base::FilePath() : partition_path
;
476 scoped_refptr
<DOMStorageContextWrapper
> dom_storage_context
=
477 new DOMStorageContextWrapper(path
, context
->GetSpecialStoragePolicy());
479 // BrowserMainLoop may not be initialized in unit tests. Tests will
480 // need to inject their own task runner into the IndexedDBContext.
481 base::SequencedTaskRunner
* idb_task_runner
=
482 BrowserThread::CurrentlyOn(BrowserThread::UI
) &&
483 BrowserMainLoop::GetInstance()
484 ? BrowserMainLoop::GetInstance()
485 ->indexed_db_thread()
489 scoped_refptr
<IndexedDBContextImpl
> indexed_db_context
=
490 new IndexedDBContextImpl(path
,
491 context
->GetSpecialStoragePolicy(),
492 quota_manager
->proxy(),
495 scoped_refptr
<CacheStorageContextImpl
> cache_storage_context
=
496 new CacheStorageContextImpl(context
);
497 cache_storage_context
->Init(path
, quota_manager
->proxy(),
498 context
->GetSpecialStoragePolicy());
500 scoped_refptr
<ServiceWorkerContextWrapper
> service_worker_context
=
501 new ServiceWorkerContextWrapper(context
);
502 service_worker_context
->Init(path
, quota_manager
->proxy(),
503 context
->GetSpecialStoragePolicy());
505 scoped_refptr
<ChromeAppCacheService
> appcache_service
=
506 new ChromeAppCacheService(quota_manager
->proxy());
508 scoped_refptr
<WebRTCIdentityStore
> webrtc_identity_store(
509 new WebRTCIdentityStore(path
, context
->GetSpecialStoragePolicy()));
511 scoped_refptr
<storage::SpecialStoragePolicy
> special_storage_policy(
512 context
->GetSpecialStoragePolicy());
514 scoped_refptr
<GeofencingManager
> geofencing_manager
=
515 new GeofencingManager(service_worker_context
);
516 geofencing_manager
->Init();
518 scoped_refptr
<HostZoomLevelContext
> host_zoom_level_context(
519 new HostZoomLevelContext(
520 context
->CreateZoomLevelDelegate(partition_path
)));
522 scoped_refptr
<NavigatorConnectContextImpl
> navigator_connect_context
=
523 new NavigatorConnectContextImpl();
524 navigator_connect_context
->AddFactory(make_scoped_ptr(
525 new NavigatorConnectServiceWorkerServiceFactory(service_worker_context
)));
527 scoped_refptr
<PlatformNotificationContextImpl
> platform_notification_context
=
528 new PlatformNotificationContextImpl(path
, context
,
529 service_worker_context
);
530 platform_notification_context
->Initialize();
532 scoped_refptr
<BackgroundSyncContextImpl
> background_sync_context
=
533 new BackgroundSyncContextImpl();
534 background_sync_context
->Init(service_worker_context
);
536 StoragePartitionImpl
* storage_partition
= new StoragePartitionImpl(
537 context
, partition_path
, quota_manager
.get(), appcache_service
.get(),
538 filesystem_context
.get(), database_tracker
.get(),
539 dom_storage_context
.get(), indexed_db_context
.get(),
540 cache_storage_context
.get(), service_worker_context
.get(),
541 webrtc_identity_store
.get(), special_storage_policy
.get(),
542 geofencing_manager
.get(), host_zoom_level_context
.get(),
543 navigator_connect_context
.get(), platform_notification_context
.get(),
544 background_sync_context
.get());
546 service_worker_context
->set_storage_partition(storage_partition
);
548 return storage_partition
;
551 base::FilePath
StoragePartitionImpl::GetPath() {
552 return partition_path_
;
555 net::URLRequestContextGetter
* StoragePartitionImpl::GetURLRequestContext() {
556 return url_request_context_
.get();
559 net::URLRequestContextGetter
*
560 StoragePartitionImpl::GetMediaURLRequestContext() {
561 return media_url_request_context_
.get();
564 storage::QuotaManager
* StoragePartitionImpl::GetQuotaManager() {
565 return quota_manager_
.get();
568 ChromeAppCacheService
* StoragePartitionImpl::GetAppCacheService() {
569 return appcache_service_
.get();
572 storage::FileSystemContext
* StoragePartitionImpl::GetFileSystemContext() {
573 return filesystem_context_
.get();
576 storage::DatabaseTracker
* StoragePartitionImpl::GetDatabaseTracker() {
577 return database_tracker_
.get();
580 DOMStorageContextWrapper
* StoragePartitionImpl::GetDOMStorageContext() {
581 return dom_storage_context_
.get();
584 IndexedDBContextImpl
* StoragePartitionImpl::GetIndexedDBContext() {
585 return indexed_db_context_
.get();
588 CacheStorageContextImpl
* StoragePartitionImpl::GetCacheStorageContext() {
589 return cache_storage_context_
.get();
592 ServiceWorkerContextWrapper
* StoragePartitionImpl::GetServiceWorkerContext() {
593 return service_worker_context_
.get();
596 GeofencingManager
* StoragePartitionImpl::GetGeofencingManager() {
597 return geofencing_manager_
.get();
600 HostZoomMap
* StoragePartitionImpl::GetHostZoomMap() {
601 DCHECK(host_zoom_level_context_
.get());
602 return host_zoom_level_context_
->GetHostZoomMap();
605 HostZoomLevelContext
* StoragePartitionImpl::GetHostZoomLevelContext() {
606 return host_zoom_level_context_
.get();
609 ZoomLevelDelegate
* StoragePartitionImpl::GetZoomLevelDelegate() {
610 DCHECK(host_zoom_level_context_
.get());
611 return host_zoom_level_context_
->GetZoomLevelDelegate();
614 NavigatorConnectContextImpl
*
615 StoragePartitionImpl::GetNavigatorConnectContext() {
616 return navigator_connect_context_
.get();
619 PlatformNotificationContextImpl
*
620 StoragePartitionImpl::GetPlatformNotificationContext() {
621 return platform_notification_context_
.get();
624 BackgroundSyncContextImpl
* StoragePartitionImpl::GetBackgroundSyncContext() {
625 return background_sync_context_
.get();
628 void StoragePartitionImpl::ClearDataImpl(
630 uint32 quota_storage_remove_mask
,
631 const GURL
& storage_origin
,
632 const OriginMatcherFunction
& origin_matcher
,
633 net::URLRequestContextGetter
* rq_context
,
634 const base::Time begin
,
635 const base::Time end
,
636 const base::Closure
& callback
) {
637 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
638 DataDeletionHelper
* helper
= new DataDeletionHelper(remove_mask
,
639 quota_storage_remove_mask
,
641 // |helper| deletes itself when done in
642 // DataDeletionHelper::DecrementTaskCountOnUI().
643 helper
->ClearDataOnUIThread(storage_origin
,
647 dom_storage_context_
.get(),
648 quota_manager_
.get(),
649 special_storage_policy_
.get(),
650 webrtc_identity_store_
.get(),
655 void StoragePartitionImpl::
656 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() {
657 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
661 void StoragePartitionImpl::
662 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() {
663 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
664 DCHECK_GT(task_count
, 0);
673 void StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearDataOnIOThread(
674 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
675 const base::Time begin
,
676 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
677 const StoragePartition::OriginMatcherFunction
& origin_matcher
) {
678 IncrementTaskCountOnIO();
679 base::Closure decrement_callback
= base::Bind(
680 &QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO
,
681 base::Unretained(this));
683 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
) {
684 IncrementTaskCountOnIO();
685 // Ask the QuotaManager for all origins with persistent quota modified
686 // within the user-specified timeframe, and deal with the resulting set in
687 // ClearQuotaManagedOriginsOnIOThread().
688 quota_manager
->GetOriginsModifiedSince(
689 storage::kStorageTypePersistent
,
691 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
692 base::Unretained(this),
694 special_storage_policy
,
696 decrement_callback
));
699 // Do the same for temporary quota.
700 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_TEMPORARY
) {
701 IncrementTaskCountOnIO();
702 quota_manager
->GetOriginsModifiedSince(
703 storage::kStorageTypeTemporary
,
705 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
706 base::Unretained(this),
708 special_storage_policy
,
710 decrement_callback
));
713 // Do the same for syncable quota.
714 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_SYNCABLE
) {
715 IncrementTaskCountOnIO();
716 quota_manager
->GetOriginsModifiedSince(
717 storage::kStorageTypeSyncable
,
719 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
720 base::Unretained(this),
722 special_storage_policy
,
724 decrement_callback
));
727 DecrementTaskCountOnIO();
731 StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread(
732 storage::QuotaManager
* quota_manager
,
733 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
734 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
735 const base::Closure
& callback
,
736 const std::set
<GURL
>& origins
,
737 storage::StorageType quota_storage_type
) {
738 // The QuotaManager manages all storage other than cookies, LocalStorage,
739 // and SessionStorage. This loop wipes out most HTML5 storage for the given
741 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
742 if (!origins
.size()) {
747 size_t* deletion_task_count
= new size_t(0u);
748 (*deletion_task_count
)++;
749 for (std::set
<GURL
>::const_iterator origin
= origins
.begin();
750 origin
!= origins
.end(); ++origin
) {
751 // TODO(mkwst): Clean this up, it's slow. http://crbug.com/130746
752 if (!storage_origin
.is_empty() && origin
->GetOrigin() != storage_origin
)
755 if (!origin_matcher
.is_null() &&
756 !origin_matcher
.Run(*origin
, special_storage_policy
.get())) {
760 (*deletion_task_count
)++;
761 quota_manager
->DeleteOriginData(
762 *origin
, quota_storage_type
,
763 StoragePartitionImpl::GenerateQuotaClientMask(remove_mask
),
764 base::Bind(&OnQuotaManagedOriginDeleted
,
765 origin
->GetOrigin(), quota_storage_type
,
766 deletion_task_count
, callback
));
768 (*deletion_task_count
)--;
770 CheckQuotaManagedDataDeletionStatus(deletion_task_count
, callback
);
773 void StoragePartitionImpl::DataDeletionHelper::IncrementTaskCountOnUI() {
774 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
778 void StoragePartitionImpl::DataDeletionHelper::DecrementTaskCountOnUI() {
779 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
780 BrowserThread::PostTask(
781 BrowserThread::UI
, FROM_HERE
,
782 base::Bind(&DataDeletionHelper::DecrementTaskCountOnUI
,
783 base::Unretained(this)));
786 DCHECK_GT(task_count
, 0);
794 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
795 const GURL
& storage_origin
,
796 const OriginMatcherFunction
& origin_matcher
,
797 const base::FilePath
& path
,
798 net::URLRequestContextGetter
* rq_context
,
799 DOMStorageContextWrapper
* dom_storage_context
,
800 storage::QuotaManager
* quota_manager
,
801 storage::SpecialStoragePolicy
* special_storage_policy
,
802 WebRTCIdentityStore
* webrtc_identity_store
,
803 const base::Time begin
,
804 const base::Time end
) {
805 DCHECK_NE(remove_mask
, 0u);
806 DCHECK(!callback
.is_null());
808 IncrementTaskCountOnUI();
809 base::Closure decrement_callback
= base::Bind(
810 &DataDeletionHelper::DecrementTaskCountOnUI
, base::Unretained(this));
812 if (remove_mask
& REMOVE_DATA_MASK_COOKIES
) {
813 // Handle the cookies.
814 IncrementTaskCountOnUI();
815 BrowserThread::PostTask(
816 BrowserThread::IO
, FROM_HERE
,
817 base::Bind(&ClearCookiesOnIOThread
,
818 make_scoped_refptr(rq_context
), begin
, end
, storage_origin
,
819 decrement_callback
));
822 if (remove_mask
& REMOVE_DATA_MASK_INDEXEDDB
||
823 remove_mask
& REMOVE_DATA_MASK_WEBSQL
||
824 remove_mask
& REMOVE_DATA_MASK_APPCACHE
||
825 remove_mask
& REMOVE_DATA_MASK_FILE_SYSTEMS
||
826 remove_mask
& REMOVE_DATA_MASK_SERVICE_WORKERS
) {
827 IncrementTaskCountOnUI();
828 BrowserThread::PostTask(
829 BrowserThread::IO
, FROM_HERE
,
830 base::Bind(&DataDeletionHelper::ClearQuotaManagedDataOnIOThread
,
831 base::Unretained(this),
832 make_scoped_refptr(quota_manager
),
835 make_scoped_refptr(special_storage_policy
),
837 decrement_callback
));
840 if (remove_mask
& REMOVE_DATA_MASK_LOCAL_STORAGE
) {
841 IncrementTaskCountOnUI();
842 ClearLocalStorageOnUIThread(
843 make_scoped_refptr(dom_storage_context
),
844 make_scoped_refptr(special_storage_policy
),
846 storage_origin
, begin
, end
,
849 // ClearDataImpl cannot clear session storage data when a particular origin
850 // is specified. Therefore we ignore clearing session storage in this case.
851 // TODO(lazyboy): Fix.
852 if (storage_origin
.is_empty()) {
853 IncrementTaskCountOnUI();
854 ClearSessionStorageOnUIThread(
855 make_scoped_refptr(dom_storage_context
),
856 make_scoped_refptr(special_storage_policy
),
862 if (remove_mask
& REMOVE_DATA_MASK_SHADER_CACHE
) {
863 IncrementTaskCountOnUI();
864 BrowserThread::PostTask(
865 BrowserThread::IO
, FROM_HERE
,
866 base::Bind(&ClearShaderCacheOnIOThread
,
867 path
, begin
, end
, decrement_callback
));
870 if (remove_mask
& REMOVE_DATA_MASK_WEBRTC_IDENTITY
) {
871 IncrementTaskCountOnUI();
872 BrowserThread::PostTask(
875 base::Bind(&WebRTCIdentityStore::DeleteBetween
,
876 webrtc_identity_store
,
879 decrement_callback
));
882 DecrementTaskCountOnUI();
885 void StoragePartitionImpl::ClearDataForOrigin(
887 uint32 quota_storage_remove_mask
,
888 const GURL
& storage_origin
,
889 net::URLRequestContextGetter
* request_context_getter
,
890 const base::Closure
& callback
) {
891 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
892 ClearDataImpl(remove_mask
,
893 quota_storage_remove_mask
,
895 OriginMatcherFunction(),
896 request_context_getter
,
902 void StoragePartitionImpl::ClearData(
904 uint32 quota_storage_remove_mask
,
905 const GURL
& storage_origin
,
906 const OriginMatcherFunction
& origin_matcher
,
907 const base::Time begin
,
908 const base::Time end
,
909 const base::Closure
& callback
) {
910 ClearDataImpl(remove_mask
, quota_storage_remove_mask
, storage_origin
,
911 origin_matcher
, GetURLRequestContext(), begin
, end
, callback
);
914 void StoragePartitionImpl::Flush() {
915 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
916 if (GetDOMStorageContext())
917 GetDOMStorageContext()->Flush();
920 WebRTCIdentityStore
* StoragePartitionImpl::GetWebRTCIdentityStore() {
921 return webrtc_identity_store_
.get();
924 BrowserContext
* StoragePartitionImpl::browser_context() const {
925 return browser_context_
;
928 void StoragePartitionImpl::OverrideQuotaManagerForTesting(
929 storage::QuotaManager
* quota_manager
) {
930 quota_manager_
= quota_manager
;
933 void StoragePartitionImpl::OverrideSpecialStoragePolicyForTesting(
934 storage::SpecialStoragePolicy
* special_storage_policy
) {
935 special_storage_policy_
= special_storage_policy
;
938 void StoragePartitionImpl::SetURLRequestContext(
939 net::URLRequestContextGetter
* url_request_context
) {
940 url_request_context_
= url_request_context
;
943 void StoragePartitionImpl::SetMediaURLRequestContext(
944 net::URLRequestContextGetter
* media_url_request_context
) {
945 media_url_request_context_
= media_url_request_context
;
948 } // namespace content