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 StashedPortManager
* stashed_port_manager
)
388 : partition_path_(partition_path
),
389 quota_manager_(quota_manager
),
390 appcache_service_(appcache_service
),
391 filesystem_context_(filesystem_context
),
392 database_tracker_(database_tracker
),
393 dom_storage_context_(dom_storage_context
),
394 indexed_db_context_(indexed_db_context
),
395 cache_storage_context_(cache_storage_context
),
396 service_worker_context_(service_worker_context
),
397 webrtc_identity_store_(webrtc_identity_store
),
398 special_storage_policy_(special_storage_policy
),
399 geofencing_manager_(geofencing_manager
),
400 host_zoom_level_context_(host_zoom_level_context
),
401 navigator_connect_context_(navigator_connect_context
),
402 platform_notification_context_(platform_notification_context
),
403 background_sync_context_(background_sync_context
),
404 stashed_port_manager_(stashed_port_manager
),
405 browser_context_(browser_context
) {
408 StoragePartitionImpl::~StoragePartitionImpl() {
409 browser_context_
= nullptr;
411 // These message loop checks are just to avoid leaks in unittests.
412 if (GetDatabaseTracker() &&
413 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
414 BrowserThread::PostTask(
417 base::Bind(&storage::DatabaseTracker::Shutdown
, GetDatabaseTracker()));
420 if (GetFileSystemContext())
421 GetFileSystemContext()->Shutdown();
423 if (GetDOMStorageContext())
424 GetDOMStorageContext()->Shutdown();
426 if (GetServiceWorkerContext())
427 GetServiceWorkerContext()->Shutdown();
429 if (GetCacheStorageContext())
430 GetCacheStorageContext()->Shutdown();
432 if (GetGeofencingManager())
433 GetGeofencingManager()->Shutdown();
435 if (GetPlatformNotificationContext())
436 GetPlatformNotificationContext()->Shutdown();
438 if (GetBackgroundSyncContext())
439 GetBackgroundSyncContext()->Shutdown();
441 if (GetStashedPortManager())
442 GetStashedPortManager()->Shutdown();
445 StoragePartitionImpl
* StoragePartitionImpl::Create(
446 BrowserContext
* context
,
448 const base::FilePath
& partition_path
) {
449 // Ensure that these methods are called on the UI thread, except for
450 // unittests where a UI thread might not have been created.
451 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
) ||
452 !BrowserThread::IsMessageLoopValid(BrowserThread::UI
));
454 // All of the clients have to be created and registered with the
455 // QuotaManager prior to the QuotaManger being used. We do them
456 // all together here prior to handing out a reference to anything
457 // that utilizes the QuotaManager.
458 scoped_refptr
<storage::QuotaManager
> quota_manager
=
459 new storage::QuotaManager(
462 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
).get(),
463 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB
).get(),
464 context
->GetSpecialStoragePolicy());
466 // Each consumer is responsible for registering its QuotaClient during
468 scoped_refptr
<storage::FileSystemContext
> filesystem_context
=
469 CreateFileSystemContext(
470 context
, partition_path
, in_memory
, quota_manager
->proxy());
472 scoped_refptr
<storage::DatabaseTracker
> database_tracker
=
473 new storage::DatabaseTracker(partition_path
,
475 context
->GetSpecialStoragePolicy(),
476 quota_manager
->proxy(),
477 BrowserThread::GetMessageLoopProxyForThread(
478 BrowserThread::FILE).get());
480 base::FilePath path
= in_memory
? base::FilePath() : partition_path
;
481 scoped_refptr
<DOMStorageContextWrapper
> dom_storage_context
=
482 new DOMStorageContextWrapper(path
, context
->GetSpecialStoragePolicy());
484 // BrowserMainLoop may not be initialized in unit tests. Tests will
485 // need to inject their own task runner into the IndexedDBContext.
486 base::SequencedTaskRunner
* idb_task_runner
=
487 BrowserThread::CurrentlyOn(BrowserThread::UI
) &&
488 BrowserMainLoop::GetInstance()
489 ? BrowserMainLoop::GetInstance()
490 ->indexed_db_thread()
494 scoped_refptr
<IndexedDBContextImpl
> indexed_db_context
=
495 new IndexedDBContextImpl(path
,
496 context
->GetSpecialStoragePolicy(),
497 quota_manager
->proxy(),
500 scoped_refptr
<CacheStorageContextImpl
> cache_storage_context
=
501 new CacheStorageContextImpl(context
);
502 cache_storage_context
->Init(path
, quota_manager
->proxy(),
503 context
->GetSpecialStoragePolicy());
505 scoped_refptr
<ServiceWorkerContextWrapper
> service_worker_context
=
506 new ServiceWorkerContextWrapper(context
);
507 service_worker_context
->Init(path
, quota_manager
->proxy(),
508 context
->GetSpecialStoragePolicy());
510 scoped_refptr
<ChromeAppCacheService
> appcache_service
=
511 new ChromeAppCacheService(quota_manager
->proxy());
513 scoped_refptr
<WebRTCIdentityStore
> webrtc_identity_store(
514 new WebRTCIdentityStore(path
, context
->GetSpecialStoragePolicy()));
516 scoped_refptr
<storage::SpecialStoragePolicy
> special_storage_policy(
517 context
->GetSpecialStoragePolicy());
519 scoped_refptr
<GeofencingManager
> geofencing_manager
=
520 new GeofencingManager(service_worker_context
);
521 geofencing_manager
->Init();
523 scoped_refptr
<HostZoomLevelContext
> host_zoom_level_context(
524 new HostZoomLevelContext(
525 context
->CreateZoomLevelDelegate(partition_path
)));
527 scoped_refptr
<NavigatorConnectContextImpl
> navigator_connect_context
=
528 new NavigatorConnectContextImpl();
529 navigator_connect_context
->AddFactory(make_scoped_ptr(
530 new NavigatorConnectServiceWorkerServiceFactory(service_worker_context
)));
532 scoped_refptr
<PlatformNotificationContextImpl
> platform_notification_context
=
533 new PlatformNotificationContextImpl(path
, context
,
534 service_worker_context
);
535 platform_notification_context
->Initialize();
537 scoped_refptr
<BackgroundSyncContextImpl
> background_sync_context
=
538 new BackgroundSyncContextImpl();
539 background_sync_context
->Init(service_worker_context
);
541 scoped_refptr
<StashedPortManager
> stashed_port_manager
=
542 new StashedPortManager(service_worker_context
);
543 stashed_port_manager
->Init();
545 StoragePartitionImpl
* storage_partition
= new StoragePartitionImpl(
546 context
, partition_path
, quota_manager
.get(), appcache_service
.get(),
547 filesystem_context
.get(), database_tracker
.get(),
548 dom_storage_context
.get(), indexed_db_context
.get(),
549 cache_storage_context
.get(), service_worker_context
.get(),
550 webrtc_identity_store
.get(), special_storage_policy
.get(),
551 geofencing_manager
.get(), host_zoom_level_context
.get(),
552 navigator_connect_context
.get(), platform_notification_context
.get(),
553 background_sync_context
.get(), stashed_port_manager
.get());
555 service_worker_context
->set_storage_partition(storage_partition
);
557 return storage_partition
;
560 base::FilePath
StoragePartitionImpl::GetPath() {
561 return partition_path_
;
564 net::URLRequestContextGetter
* StoragePartitionImpl::GetURLRequestContext() {
565 return url_request_context_
.get();
568 net::URLRequestContextGetter
*
569 StoragePartitionImpl::GetMediaURLRequestContext() {
570 return media_url_request_context_
.get();
573 storage::QuotaManager
* StoragePartitionImpl::GetQuotaManager() {
574 return quota_manager_
.get();
577 ChromeAppCacheService
* StoragePartitionImpl::GetAppCacheService() {
578 return appcache_service_
.get();
581 storage::FileSystemContext
* StoragePartitionImpl::GetFileSystemContext() {
582 return filesystem_context_
.get();
585 storage::DatabaseTracker
* StoragePartitionImpl::GetDatabaseTracker() {
586 return database_tracker_
.get();
589 DOMStorageContextWrapper
* StoragePartitionImpl::GetDOMStorageContext() {
590 return dom_storage_context_
.get();
593 IndexedDBContextImpl
* StoragePartitionImpl::GetIndexedDBContext() {
594 return indexed_db_context_
.get();
597 CacheStorageContextImpl
* StoragePartitionImpl::GetCacheStorageContext() {
598 return cache_storage_context_
.get();
601 ServiceWorkerContextWrapper
* StoragePartitionImpl::GetServiceWorkerContext() {
602 return service_worker_context_
.get();
605 GeofencingManager
* StoragePartitionImpl::GetGeofencingManager() {
606 return geofencing_manager_
.get();
609 HostZoomMap
* StoragePartitionImpl::GetHostZoomMap() {
610 DCHECK(host_zoom_level_context_
.get());
611 return host_zoom_level_context_
->GetHostZoomMap();
614 HostZoomLevelContext
* StoragePartitionImpl::GetHostZoomLevelContext() {
615 return host_zoom_level_context_
.get();
618 ZoomLevelDelegate
* StoragePartitionImpl::GetZoomLevelDelegate() {
619 DCHECK(host_zoom_level_context_
.get());
620 return host_zoom_level_context_
->GetZoomLevelDelegate();
623 NavigatorConnectContextImpl
*
624 StoragePartitionImpl::GetNavigatorConnectContext() {
625 return navigator_connect_context_
.get();
628 PlatformNotificationContextImpl
*
629 StoragePartitionImpl::GetPlatformNotificationContext() {
630 return platform_notification_context_
.get();
633 BackgroundSyncContextImpl
* StoragePartitionImpl::GetBackgroundSyncContext() {
634 return background_sync_context_
.get();
637 StashedPortManager
* StoragePartitionImpl::GetStashedPortManager() {
638 return stashed_port_manager_
.get();
641 void StoragePartitionImpl::ClearDataImpl(
643 uint32 quota_storage_remove_mask
,
644 const GURL
& storage_origin
,
645 const OriginMatcherFunction
& origin_matcher
,
646 net::URLRequestContextGetter
* rq_context
,
647 const base::Time begin
,
648 const base::Time end
,
649 const base::Closure
& callback
) {
650 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
651 DataDeletionHelper
* helper
= new DataDeletionHelper(remove_mask
,
652 quota_storage_remove_mask
,
654 // |helper| deletes itself when done in
655 // DataDeletionHelper::DecrementTaskCountOnUI().
656 helper
->ClearDataOnUIThread(storage_origin
,
660 dom_storage_context_
.get(),
661 quota_manager_
.get(),
662 special_storage_policy_
.get(),
663 webrtc_identity_store_
.get(),
668 void StoragePartitionImpl::
669 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() {
670 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
674 void StoragePartitionImpl::
675 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() {
676 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
677 DCHECK_GT(task_count
, 0);
686 void StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearDataOnIOThread(
687 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
688 const base::Time begin
,
689 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
690 const StoragePartition::OriginMatcherFunction
& origin_matcher
) {
691 IncrementTaskCountOnIO();
692 base::Closure decrement_callback
= base::Bind(
693 &QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO
,
694 base::Unretained(this));
696 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
) {
697 IncrementTaskCountOnIO();
698 // Ask the QuotaManager for all origins with persistent quota modified
699 // within the user-specified timeframe, and deal with the resulting set in
700 // ClearQuotaManagedOriginsOnIOThread().
701 quota_manager
->GetOriginsModifiedSince(
702 storage::kStorageTypePersistent
,
704 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
705 base::Unretained(this),
707 special_storage_policy
,
709 decrement_callback
));
712 // Do the same for temporary quota.
713 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_TEMPORARY
) {
714 IncrementTaskCountOnIO();
715 quota_manager
->GetOriginsModifiedSince(
716 storage::kStorageTypeTemporary
,
718 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
719 base::Unretained(this),
721 special_storage_policy
,
723 decrement_callback
));
726 // Do the same for syncable quota.
727 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_SYNCABLE
) {
728 IncrementTaskCountOnIO();
729 quota_manager
->GetOriginsModifiedSince(
730 storage::kStorageTypeSyncable
,
732 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
733 base::Unretained(this),
735 special_storage_policy
,
737 decrement_callback
));
740 DecrementTaskCountOnIO();
744 StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread(
745 storage::QuotaManager
* quota_manager
,
746 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
747 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
748 const base::Closure
& callback
,
749 const std::set
<GURL
>& origins
,
750 storage::StorageType quota_storage_type
) {
751 // The QuotaManager manages all storage other than cookies, LocalStorage,
752 // and SessionStorage. This loop wipes out most HTML5 storage for the given
754 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
755 if (!origins
.size()) {
760 size_t* deletion_task_count
= new size_t(0u);
761 (*deletion_task_count
)++;
762 for (std::set
<GURL
>::const_iterator origin
= origins
.begin();
763 origin
!= origins
.end(); ++origin
) {
764 // TODO(mkwst): Clean this up, it's slow. http://crbug.com/130746
765 if (!storage_origin
.is_empty() && origin
->GetOrigin() != storage_origin
)
768 if (!origin_matcher
.is_null() &&
769 !origin_matcher
.Run(*origin
, special_storage_policy
.get())) {
773 (*deletion_task_count
)++;
774 quota_manager
->DeleteOriginData(
775 *origin
, quota_storage_type
,
776 StoragePartitionImpl::GenerateQuotaClientMask(remove_mask
),
777 base::Bind(&OnQuotaManagedOriginDeleted
,
778 origin
->GetOrigin(), quota_storage_type
,
779 deletion_task_count
, callback
));
781 (*deletion_task_count
)--;
783 CheckQuotaManagedDataDeletionStatus(deletion_task_count
, callback
);
786 void StoragePartitionImpl::DataDeletionHelper::IncrementTaskCountOnUI() {
787 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
791 void StoragePartitionImpl::DataDeletionHelper::DecrementTaskCountOnUI() {
792 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
793 BrowserThread::PostTask(
794 BrowserThread::UI
, FROM_HERE
,
795 base::Bind(&DataDeletionHelper::DecrementTaskCountOnUI
,
796 base::Unretained(this)));
799 DCHECK_GT(task_count
, 0);
807 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
808 const GURL
& storage_origin
,
809 const OriginMatcherFunction
& origin_matcher
,
810 const base::FilePath
& path
,
811 net::URLRequestContextGetter
* rq_context
,
812 DOMStorageContextWrapper
* dom_storage_context
,
813 storage::QuotaManager
* quota_manager
,
814 storage::SpecialStoragePolicy
* special_storage_policy
,
815 WebRTCIdentityStore
* webrtc_identity_store
,
816 const base::Time begin
,
817 const base::Time end
) {
818 DCHECK_NE(remove_mask
, 0u);
819 DCHECK(!callback
.is_null());
821 IncrementTaskCountOnUI();
822 base::Closure decrement_callback
= base::Bind(
823 &DataDeletionHelper::DecrementTaskCountOnUI
, base::Unretained(this));
825 if (remove_mask
& REMOVE_DATA_MASK_COOKIES
) {
826 // Handle the cookies.
827 IncrementTaskCountOnUI();
828 BrowserThread::PostTask(
829 BrowserThread::IO
, FROM_HERE
,
830 base::Bind(&ClearCookiesOnIOThread
,
831 make_scoped_refptr(rq_context
), begin
, end
, storage_origin
,
832 decrement_callback
));
835 if (remove_mask
& REMOVE_DATA_MASK_INDEXEDDB
||
836 remove_mask
& REMOVE_DATA_MASK_WEBSQL
||
837 remove_mask
& REMOVE_DATA_MASK_APPCACHE
||
838 remove_mask
& REMOVE_DATA_MASK_FILE_SYSTEMS
||
839 remove_mask
& REMOVE_DATA_MASK_SERVICE_WORKERS
) {
840 IncrementTaskCountOnUI();
841 BrowserThread::PostTask(
842 BrowserThread::IO
, FROM_HERE
,
843 base::Bind(&DataDeletionHelper::ClearQuotaManagedDataOnIOThread
,
844 base::Unretained(this),
845 make_scoped_refptr(quota_manager
),
848 make_scoped_refptr(special_storage_policy
),
850 decrement_callback
));
853 if (remove_mask
& REMOVE_DATA_MASK_LOCAL_STORAGE
) {
854 IncrementTaskCountOnUI();
855 ClearLocalStorageOnUIThread(
856 make_scoped_refptr(dom_storage_context
),
857 make_scoped_refptr(special_storage_policy
),
859 storage_origin
, begin
, end
,
862 // ClearDataImpl cannot clear session storage data when a particular origin
863 // is specified. Therefore we ignore clearing session storage in this case.
864 // TODO(lazyboy): Fix.
865 if (storage_origin
.is_empty()) {
866 IncrementTaskCountOnUI();
867 ClearSessionStorageOnUIThread(
868 make_scoped_refptr(dom_storage_context
),
869 make_scoped_refptr(special_storage_policy
),
875 if (remove_mask
& REMOVE_DATA_MASK_SHADER_CACHE
) {
876 IncrementTaskCountOnUI();
877 BrowserThread::PostTask(
878 BrowserThread::IO
, FROM_HERE
,
879 base::Bind(&ClearShaderCacheOnIOThread
,
880 path
, begin
, end
, decrement_callback
));
883 if (remove_mask
& REMOVE_DATA_MASK_WEBRTC_IDENTITY
) {
884 IncrementTaskCountOnUI();
885 BrowserThread::PostTask(
888 base::Bind(&WebRTCIdentityStore::DeleteBetween
,
889 webrtc_identity_store
,
892 decrement_callback
));
895 DecrementTaskCountOnUI();
898 void StoragePartitionImpl::ClearDataForOrigin(
900 uint32 quota_storage_remove_mask
,
901 const GURL
& storage_origin
,
902 net::URLRequestContextGetter
* request_context_getter
,
903 const base::Closure
& callback
) {
904 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
905 ClearDataImpl(remove_mask
,
906 quota_storage_remove_mask
,
908 OriginMatcherFunction(),
909 request_context_getter
,
915 void StoragePartitionImpl::ClearData(
917 uint32 quota_storage_remove_mask
,
918 const GURL
& storage_origin
,
919 const OriginMatcherFunction
& origin_matcher
,
920 const base::Time begin
,
921 const base::Time end
,
922 const base::Closure
& callback
) {
923 ClearDataImpl(remove_mask
, quota_storage_remove_mask
, storage_origin
,
924 origin_matcher
, GetURLRequestContext(), begin
, end
, callback
);
927 void StoragePartitionImpl::Flush() {
928 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
929 if (GetDOMStorageContext())
930 GetDOMStorageContext()->Flush();
933 WebRTCIdentityStore
* StoragePartitionImpl::GetWebRTCIdentityStore() {
934 return webrtc_identity_store_
.get();
937 BrowserContext
* StoragePartitionImpl::browser_context() const {
938 return browser_context_
;
941 void StoragePartitionImpl::OverrideQuotaManagerForTesting(
942 storage::QuotaManager
* quota_manager
) {
943 quota_manager_
= quota_manager
;
946 void StoragePartitionImpl::OverrideSpecialStoragePolicyForTesting(
947 storage::SpecialStoragePolicy
* special_storage_policy
) {
948 special_storage_policy_
= special_storage_policy
;
951 void StoragePartitionImpl::SetURLRequestContext(
952 net::URLRequestContextGetter
* url_request_context
) {
953 url_request_context_
= url_request_context
;
956 void StoragePartitionImpl::SetMediaURLRequestContext(
957 net::URLRequestContextGetter
* media_url_request_context
) {
958 media_url_request_context_
= media_url_request_context
;
961 } // namespace content