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/notifications/platform_notification_context_impl.h"
21 #include "content/common/dom_storage/dom_storage_types.h"
22 #include "content/public/browser/browser_context.h"
23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/dom_storage_context.h"
25 #include "content/public/browser/indexed_db_context.h"
26 #include "content/public/browser/local_storage_usage_info.h"
27 #include "content/public/browser/session_storage_usage_info.h"
28 #include "net/base/completion_callback.h"
29 #include "net/base/net_errors.h"
30 #include "net/cookies/cookie_monster.h"
31 #include "net/url_request/url_request_context.h"
32 #include "net/url_request/url_request_context_getter.h"
33 #include "storage/browser/database/database_tracker.h"
34 #include "storage/browser/quota/quota_manager.h"
40 void OnClearedCookies(const base::Closure
& callback
, int num_deleted
) {
41 // The final callback needs to happen from UI thread.
42 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
43 BrowserThread::PostTask(
44 BrowserThread::UI
, FROM_HERE
,
45 base::Bind(&OnClearedCookies
, callback
, num_deleted
));
52 void ClearCookiesOnIOThread(
53 const scoped_refptr
<net::URLRequestContextGetter
>& rq_context
,
54 const base::Time begin
,
56 const GURL
& storage_origin
,
57 const base::Closure
& callback
) {
58 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
59 net::CookieStore
* cookie_store
= rq_context
->
60 GetURLRequestContext()->cookie_store();
61 if (storage_origin
.is_empty()) {
62 cookie_store
->DeleteAllCreatedBetweenAsync(
65 base::Bind(&OnClearedCookies
, callback
));
67 cookie_store
->DeleteAllCreatedBetweenForHostAsync(
70 storage_origin
, base::Bind(&OnClearedCookies
, callback
));
74 void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count
,
75 const base::Closure
& callback
) {
76 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
77 if (*deletion_task_count
== 0) {
78 delete deletion_task_count
;
83 void OnQuotaManagedOriginDeleted(const GURL
& origin
,
84 storage::StorageType type
,
85 size_t* deletion_task_count
,
86 const base::Closure
& callback
,
87 storage::QuotaStatusCode status
) {
88 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
89 DCHECK_GT(*deletion_task_count
, 0u);
90 if (status
!= storage::kQuotaStatusOk
) {
91 DLOG(ERROR
) << "Couldn't remove data of type " << type
<< " for origin "
92 << origin
<< ". Status: " << status
;
95 (*deletion_task_count
)--;
96 CheckQuotaManagedDataDeletionStatus(deletion_task_count
, callback
);
99 void ClearedShaderCache(const base::Closure
& callback
) {
100 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
101 BrowserThread::PostTask(
102 BrowserThread::UI
, FROM_HERE
,
103 base::Bind(&ClearedShaderCache
, callback
));
109 void ClearShaderCacheOnIOThread(const base::FilePath
& path
,
110 const base::Time begin
,
111 const base::Time end
,
112 const base::Closure
& callback
) {
113 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
114 ShaderCacheFactory::GetInstance()->ClearByPath(
115 path
, begin
, end
, base::Bind(&ClearedShaderCache
, callback
));
118 void OnLocalStorageUsageInfo(
119 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
120 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
121 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
122 const base::Time delete_begin
,
123 const base::Time delete_end
,
124 const base::Closure
& callback
,
125 const std::vector
<LocalStorageUsageInfo
>& infos
) {
126 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
128 for (size_t i
= 0; i
< infos
.size(); ++i
) {
129 if (!origin_matcher
.is_null() &&
130 !origin_matcher
.Run(infos
[i
].origin
, special_storage_policy
.get())) {
134 if (infos
[i
].last_modified
>= delete_begin
&&
135 infos
[i
].last_modified
<= delete_end
) {
136 dom_storage_context
->DeleteLocalStorage(infos
[i
].origin
);
142 void OnSessionStorageUsageInfo(
143 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
144 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
145 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
146 const base::Closure
& callback
,
147 const std::vector
<SessionStorageUsageInfo
>& infos
) {
148 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
150 for (size_t i
= 0; i
< infos
.size(); ++i
) {
151 if (!origin_matcher
.is_null() &&
152 !origin_matcher
.Run(infos
[i
].origin
, special_storage_policy
.get())) {
155 dom_storage_context
->DeleteSessionStorage(infos
[i
]);
161 void ClearLocalStorageOnUIThread(
162 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
163 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
164 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
165 const GURL
& storage_origin
,
166 const base::Time begin
,
167 const base::Time end
,
168 const base::Closure
& callback
) {
169 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
171 if (!storage_origin
.is_empty()) {
172 bool can_delete
= origin_matcher
.is_null() ||
173 origin_matcher
.Run(storage_origin
,
174 special_storage_policy
.get());
176 dom_storage_context
->DeleteLocalStorage(storage_origin
);
182 dom_storage_context
->GetLocalStorageUsage(
183 base::Bind(&OnLocalStorageUsageInfo
,
184 dom_storage_context
, special_storage_policy
, origin_matcher
,
185 begin
, end
, callback
));
188 void ClearSessionStorageOnUIThread(
189 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
190 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
191 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
192 const base::Closure
& callback
) {
193 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
195 dom_storage_context
->GetSessionStorageUsage(
196 base::Bind(&OnSessionStorageUsageInfo
, dom_storage_context
,
197 special_storage_policy
, origin_matcher
,
204 STATIC_CONST_MEMBER_DEFINITION
const uint32
205 StoragePartition::REMOVE_DATA_MASK_APPCACHE
;
206 STATIC_CONST_MEMBER_DEFINITION
const uint32
207 StoragePartition::REMOVE_DATA_MASK_COOKIES
;
208 STATIC_CONST_MEMBER_DEFINITION
const uint32
209 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
;
210 STATIC_CONST_MEMBER_DEFINITION
const uint32
211 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
;
212 STATIC_CONST_MEMBER_DEFINITION
const uint32
213 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE
;
214 STATIC_CONST_MEMBER_DEFINITION
const uint32
215 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
;
216 STATIC_CONST_MEMBER_DEFINITION
const uint32
217 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE
;
218 STATIC_CONST_MEMBER_DEFINITION
const uint32
219 StoragePartition::REMOVE_DATA_MASK_WEBSQL
;
220 STATIC_CONST_MEMBER_DEFINITION
const uint32
221 StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY
;
222 STATIC_CONST_MEMBER_DEFINITION
const uint32
223 StoragePartition::REMOVE_DATA_MASK_ALL
;
224 STATIC_CONST_MEMBER_DEFINITION
const uint32
225 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY
;
226 STATIC_CONST_MEMBER_DEFINITION
const uint32
227 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
;
228 STATIC_CONST_MEMBER_DEFINITION
const uint32
229 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_SYNCABLE
;
230 STATIC_CONST_MEMBER_DEFINITION
const uint32
231 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
;
234 int StoragePartitionImpl::GenerateQuotaClientMask(uint32 remove_mask
) {
235 int quota_client_mask
= 0;
237 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
)
238 quota_client_mask
|= storage::QuotaClient::kFileSystem
;
239 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_WEBSQL
)
240 quota_client_mask
|= storage::QuotaClient::kDatabase
;
241 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_APPCACHE
)
242 quota_client_mask
|= storage::QuotaClient::kAppcache
;
243 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
)
244 quota_client_mask
|= storage::QuotaClient::kIndexedDatabase
;
245 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
) {
246 quota_client_mask
|= storage::QuotaClient::kServiceWorker
;
247 quota_client_mask
|= storage::QuotaClient::kServiceWorkerCache
;
251 return quota_client_mask
;
254 // Helper for deleting quota managed data from a partition.
256 // Most of the operations in this class are done on IO thread.
257 struct StoragePartitionImpl::QuotaManagedDataDeletionHelper
{
258 QuotaManagedDataDeletionHelper(uint32 remove_mask
,
259 uint32 quota_storage_remove_mask
,
260 const GURL
& storage_origin
,
261 const base::Closure
& callback
)
262 : remove_mask(remove_mask
),
263 quota_storage_remove_mask(quota_storage_remove_mask
),
264 storage_origin(storage_origin
),
269 void IncrementTaskCountOnIO();
270 void DecrementTaskCountOnIO();
272 void ClearDataOnIOThread(
273 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
274 const base::Time begin
,
275 const scoped_refptr
<storage::SpecialStoragePolicy
>&
276 special_storage_policy
,
277 const StoragePartition::OriginMatcherFunction
& origin_matcher
);
279 void ClearOriginsOnIOThread(
280 storage::QuotaManager
* quota_manager
,
281 const scoped_refptr
<storage::SpecialStoragePolicy
>&
282 special_storage_policy
,
283 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
284 const base::Closure
& callback
,
285 const std::set
<GURL
>& origins
,
286 storage::StorageType quota_storage_type
);
288 // All of these data are accessed on IO thread.
290 uint32 quota_storage_remove_mask
;
292 const base::Closure callback
;
296 // Helper for deleting all sorts of data from a partition, keeps track of
299 // StoragePartitionImpl creates an instance of this class to keep track of
300 // data deletion progress. Deletion requires deleting multiple bits of data
301 // (e.g. cookies, local storage, session storage etc.) and hopping between UI
302 // and IO thread. An instance of this class is created in the beginning of
303 // deletion process (StoragePartitionImpl::ClearDataImpl) and the instance is
304 // forwarded and updated on each (sub) deletion's callback. The instance is
305 // finally destroyed when deletion completes (and |callback| is invoked).
306 struct StoragePartitionImpl::DataDeletionHelper
{
307 DataDeletionHelper(uint32 remove_mask
,
308 uint32 quota_storage_remove_mask
,
309 const base::Closure
& callback
)
310 : remove_mask(remove_mask
),
311 quota_storage_remove_mask(quota_storage_remove_mask
),
316 void IncrementTaskCountOnUI();
317 void DecrementTaskCountOnUI();
319 void ClearDataOnUIThread(
320 const GURL
& storage_origin
,
321 const OriginMatcherFunction
& origin_matcher
,
322 const base::FilePath
& path
,
323 net::URLRequestContextGetter
* rq_context
,
324 DOMStorageContextWrapper
* dom_storage_context
,
325 storage::QuotaManager
* quota_manager
,
326 storage::SpecialStoragePolicy
* special_storage_policy
,
327 WebRTCIdentityStore
* webrtc_identity_store
,
328 const base::Time begin
,
329 const base::Time end
);
331 void ClearQuotaManagedDataOnIOThread(
332 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
333 const base::Time begin
,
334 const GURL
& storage_origin
,
335 const scoped_refptr
<storage::SpecialStoragePolicy
>&
336 special_storage_policy
,
337 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
338 const base::Closure
& callback
);
341 uint32 quota_storage_remove_mask
;
343 // Accessed on UI thread.
344 const base::Closure callback
;
345 // Accessed on UI thread.
349 void StoragePartitionImpl::DataDeletionHelper::ClearQuotaManagedDataOnIOThread(
350 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
351 const base::Time begin
,
352 const GURL
& storage_origin
,
353 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
354 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
355 const base::Closure
& callback
) {
356 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
358 StoragePartitionImpl::QuotaManagedDataDeletionHelper
* helper
=
359 new StoragePartitionImpl::QuotaManagedDataDeletionHelper(
361 quota_storage_remove_mask
,
364 helper
->ClearDataOnIOThread(quota_manager
, begin
, special_storage_policy
,
368 StoragePartitionImpl::StoragePartitionImpl(
369 BrowserContext
* browser_context
,
370 const base::FilePath
& partition_path
,
371 storage::QuotaManager
* quota_manager
,
372 ChromeAppCacheService
* appcache_service
,
373 storage::FileSystemContext
* filesystem_context
,
374 storage::DatabaseTracker
* database_tracker
,
375 DOMStorageContextWrapper
* dom_storage_context
,
376 IndexedDBContextImpl
* indexed_db_context
,
377 CacheStorageContextImpl
* cache_storage_context
,
378 ServiceWorkerContextWrapper
* service_worker_context
,
379 WebRTCIdentityStore
* webrtc_identity_store
,
380 storage::SpecialStoragePolicy
* special_storage_policy
,
381 GeofencingManager
* geofencing_manager
,
382 HostZoomLevelContext
* host_zoom_level_context
,
383 NavigatorConnectContextImpl
* navigator_connect_context
,
384 PlatformNotificationContextImpl
* platform_notification_context
,
385 BackgroundSyncContextImpl
* background_sync_context
)
386 : partition_path_(partition_path
),
387 quota_manager_(quota_manager
),
388 appcache_service_(appcache_service
),
389 filesystem_context_(filesystem_context
),
390 database_tracker_(database_tracker
),
391 dom_storage_context_(dom_storage_context
),
392 indexed_db_context_(indexed_db_context
),
393 cache_storage_context_(cache_storage_context
),
394 service_worker_context_(service_worker_context
),
395 webrtc_identity_store_(webrtc_identity_store
),
396 special_storage_policy_(special_storage_policy
),
397 geofencing_manager_(geofencing_manager
),
398 host_zoom_level_context_(host_zoom_level_context
),
399 navigator_connect_context_(navigator_connect_context
),
400 platform_notification_context_(platform_notification_context
),
401 background_sync_context_(background_sync_context
),
402 browser_context_(browser_context
) {
405 StoragePartitionImpl::~StoragePartitionImpl() {
406 browser_context_
= nullptr;
408 // These message loop checks are just to avoid leaks in unittests.
409 if (GetDatabaseTracker() &&
410 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
411 BrowserThread::PostTask(
414 base::Bind(&storage::DatabaseTracker::Shutdown
, GetDatabaseTracker()));
417 if (GetFileSystemContext())
418 GetFileSystemContext()->Shutdown();
420 if (GetDOMStorageContext())
421 GetDOMStorageContext()->Shutdown();
423 if (GetServiceWorkerContext())
424 GetServiceWorkerContext()->Shutdown();
426 if (GetCacheStorageContext())
427 GetCacheStorageContext()->Shutdown();
429 if (GetGeofencingManager())
430 GetGeofencingManager()->Shutdown();
432 if (GetPlatformNotificationContext())
433 GetPlatformNotificationContext()->Shutdown();
435 if (GetBackgroundSyncContext())
436 GetBackgroundSyncContext()->Shutdown();
439 StoragePartitionImpl
* StoragePartitionImpl::Create(
440 BrowserContext
* context
,
442 const base::FilePath
& partition_path
) {
443 // Ensure that these methods are called on the UI thread, except for
444 // unittests where a UI thread might not have been created.
445 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
) ||
446 !BrowserThread::IsMessageLoopValid(BrowserThread::UI
));
448 // All of the clients have to be created and registered with the
449 // QuotaManager prior to the QuotaManger being used. We do them
450 // all together here prior to handing out a reference to anything
451 // that utilizes the QuotaManager.
452 scoped_refptr
<storage::QuotaManager
> quota_manager
=
453 new storage::QuotaManager(
456 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
).get(),
457 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB
).get(),
458 context
->GetSpecialStoragePolicy());
460 // Each consumer is responsible for registering its QuotaClient during
462 scoped_refptr
<storage::FileSystemContext
> filesystem_context
=
463 CreateFileSystemContext(
464 context
, partition_path
, in_memory
, quota_manager
->proxy());
466 scoped_refptr
<storage::DatabaseTracker
> database_tracker
=
467 new storage::DatabaseTracker(partition_path
,
469 context
->GetSpecialStoragePolicy(),
470 quota_manager
->proxy(),
471 BrowserThread::GetMessageLoopProxyForThread(
472 BrowserThread::FILE).get());
474 base::FilePath path
= in_memory
? base::FilePath() : partition_path
;
475 scoped_refptr
<DOMStorageContextWrapper
> dom_storage_context
=
476 new DOMStorageContextWrapper(path
, context
->GetSpecialStoragePolicy());
478 // BrowserMainLoop may not be initialized in unit tests. Tests will
479 // need to inject their own task runner into the IndexedDBContext.
480 base::SequencedTaskRunner
* idb_task_runner
=
481 BrowserThread::CurrentlyOn(BrowserThread::UI
) &&
482 BrowserMainLoop::GetInstance()
483 ? BrowserMainLoop::GetInstance()
484 ->indexed_db_thread()
488 scoped_refptr
<IndexedDBContextImpl
> indexed_db_context
=
489 new IndexedDBContextImpl(path
,
490 context
->GetSpecialStoragePolicy(),
491 quota_manager
->proxy(),
494 scoped_refptr
<CacheStorageContextImpl
> cache_storage_context
=
495 new CacheStorageContextImpl(context
);
496 cache_storage_context
->Init(path
, quota_manager
->proxy(),
497 context
->GetSpecialStoragePolicy());
499 scoped_refptr
<ServiceWorkerContextWrapper
> service_worker_context
=
500 new ServiceWorkerContextWrapper(context
);
501 service_worker_context
->Init(path
, quota_manager
->proxy(),
502 context
->GetSpecialStoragePolicy());
504 scoped_refptr
<ChromeAppCacheService
> appcache_service
=
505 new ChromeAppCacheService(quota_manager
->proxy());
507 scoped_refptr
<WebRTCIdentityStore
> webrtc_identity_store(
508 new WebRTCIdentityStore(path
, context
->GetSpecialStoragePolicy()));
510 scoped_refptr
<storage::SpecialStoragePolicy
> special_storage_policy(
511 context
->GetSpecialStoragePolicy());
513 scoped_refptr
<GeofencingManager
> geofencing_manager
=
514 new GeofencingManager(service_worker_context
);
515 geofencing_manager
->Init();
517 scoped_refptr
<HostZoomLevelContext
> host_zoom_level_context(
518 new HostZoomLevelContext(
519 context
->CreateZoomLevelDelegate(partition_path
)));
521 scoped_refptr
<NavigatorConnectContextImpl
> navigator_connect_context
=
522 new NavigatorConnectContextImpl(service_worker_context
);
524 scoped_refptr
<PlatformNotificationContextImpl
> platform_notification_context
=
525 new PlatformNotificationContextImpl(path
, context
,
526 service_worker_context
);
527 platform_notification_context
->Initialize();
529 scoped_refptr
<BackgroundSyncContextImpl
> background_sync_context
=
530 new BackgroundSyncContextImpl();
531 background_sync_context
->Init(service_worker_context
);
533 StoragePartitionImpl
* storage_partition
= new StoragePartitionImpl(
534 context
, partition_path
, quota_manager
.get(), appcache_service
.get(),
535 filesystem_context
.get(), database_tracker
.get(),
536 dom_storage_context
.get(), indexed_db_context
.get(),
537 cache_storage_context
.get(), service_worker_context
.get(),
538 webrtc_identity_store
.get(), special_storage_policy
.get(),
539 geofencing_manager
.get(), host_zoom_level_context
.get(),
540 navigator_connect_context
.get(), platform_notification_context
.get(),
541 background_sync_context
.get());
543 service_worker_context
->set_storage_partition(storage_partition
);
545 return storage_partition
;
548 base::FilePath
StoragePartitionImpl::GetPath() {
549 return partition_path_
;
552 net::URLRequestContextGetter
* StoragePartitionImpl::GetURLRequestContext() {
553 return url_request_context_
.get();
556 net::URLRequestContextGetter
*
557 StoragePartitionImpl::GetMediaURLRequestContext() {
558 return media_url_request_context_
.get();
561 storage::QuotaManager
* StoragePartitionImpl::GetQuotaManager() {
562 return quota_manager_
.get();
565 ChromeAppCacheService
* StoragePartitionImpl::GetAppCacheService() {
566 return appcache_service_
.get();
569 storage::FileSystemContext
* StoragePartitionImpl::GetFileSystemContext() {
570 return filesystem_context_
.get();
573 storage::DatabaseTracker
* StoragePartitionImpl::GetDatabaseTracker() {
574 return database_tracker_
.get();
577 DOMStorageContextWrapper
* StoragePartitionImpl::GetDOMStorageContext() {
578 return dom_storage_context_
.get();
581 IndexedDBContextImpl
* StoragePartitionImpl::GetIndexedDBContext() {
582 return indexed_db_context_
.get();
585 CacheStorageContextImpl
* StoragePartitionImpl::GetCacheStorageContext() {
586 return cache_storage_context_
.get();
589 ServiceWorkerContextWrapper
* StoragePartitionImpl::GetServiceWorkerContext() {
590 return service_worker_context_
.get();
593 GeofencingManager
* StoragePartitionImpl::GetGeofencingManager() {
594 return geofencing_manager_
.get();
597 HostZoomMap
* StoragePartitionImpl::GetHostZoomMap() {
598 DCHECK(host_zoom_level_context_
.get());
599 return host_zoom_level_context_
->GetHostZoomMap();
602 HostZoomLevelContext
* StoragePartitionImpl::GetHostZoomLevelContext() {
603 return host_zoom_level_context_
.get();
606 ZoomLevelDelegate
* StoragePartitionImpl::GetZoomLevelDelegate() {
607 DCHECK(host_zoom_level_context_
.get());
608 return host_zoom_level_context_
->GetZoomLevelDelegate();
611 NavigatorConnectContextImpl
*
612 StoragePartitionImpl::GetNavigatorConnectContext() {
613 return navigator_connect_context_
.get();
616 PlatformNotificationContextImpl
*
617 StoragePartitionImpl::GetPlatformNotificationContext() {
618 return platform_notification_context_
.get();
621 BackgroundSyncContextImpl
* StoragePartitionImpl::GetBackgroundSyncContext() {
622 return background_sync_context_
.get();
625 void StoragePartitionImpl::ClearDataImpl(
627 uint32 quota_storage_remove_mask
,
628 const GURL
& storage_origin
,
629 const OriginMatcherFunction
& origin_matcher
,
630 net::URLRequestContextGetter
* rq_context
,
631 const base::Time begin
,
632 const base::Time end
,
633 const base::Closure
& callback
) {
634 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
635 DataDeletionHelper
* helper
= new DataDeletionHelper(remove_mask
,
636 quota_storage_remove_mask
,
638 // |helper| deletes itself when done in
639 // DataDeletionHelper::DecrementTaskCountOnUI().
640 helper
->ClearDataOnUIThread(storage_origin
,
644 dom_storage_context_
.get(),
645 quota_manager_
.get(),
646 special_storage_policy_
.get(),
647 webrtc_identity_store_
.get(),
652 void StoragePartitionImpl::
653 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() {
654 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
658 void StoragePartitionImpl::
659 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() {
660 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
661 DCHECK_GT(task_count
, 0);
670 void StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearDataOnIOThread(
671 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
672 const base::Time begin
,
673 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
674 const StoragePartition::OriginMatcherFunction
& origin_matcher
) {
675 IncrementTaskCountOnIO();
676 base::Closure decrement_callback
= base::Bind(
677 &QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO
,
678 base::Unretained(this));
680 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
) {
681 IncrementTaskCountOnIO();
682 // Ask the QuotaManager for all origins with persistent quota modified
683 // within the user-specified timeframe, and deal with the resulting set in
684 // ClearQuotaManagedOriginsOnIOThread().
685 quota_manager
->GetOriginsModifiedSince(
686 storage::kStorageTypePersistent
,
688 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
689 base::Unretained(this),
691 special_storage_policy
,
693 decrement_callback
));
696 // Do the same for temporary quota.
697 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_TEMPORARY
) {
698 IncrementTaskCountOnIO();
699 quota_manager
->GetOriginsModifiedSince(
700 storage::kStorageTypeTemporary
,
702 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
703 base::Unretained(this),
705 special_storage_policy
,
707 decrement_callback
));
710 // Do the same for syncable quota.
711 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_SYNCABLE
) {
712 IncrementTaskCountOnIO();
713 quota_manager
->GetOriginsModifiedSince(
714 storage::kStorageTypeSyncable
,
716 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
717 base::Unretained(this),
719 special_storage_policy
,
721 decrement_callback
));
724 DecrementTaskCountOnIO();
728 StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread(
729 storage::QuotaManager
* quota_manager
,
730 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
731 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
732 const base::Closure
& callback
,
733 const std::set
<GURL
>& origins
,
734 storage::StorageType quota_storage_type
) {
735 // The QuotaManager manages all storage other than cookies, LocalStorage,
736 // and SessionStorage. This loop wipes out most HTML5 storage for the given
738 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
739 if (!origins
.size()) {
744 size_t* deletion_task_count
= new size_t(0u);
745 (*deletion_task_count
)++;
746 for (std::set
<GURL
>::const_iterator origin
= origins
.begin();
747 origin
!= origins
.end(); ++origin
) {
748 // TODO(mkwst): Clean this up, it's slow. http://crbug.com/130746
749 if (!storage_origin
.is_empty() && origin
->GetOrigin() != storage_origin
)
752 if (!origin_matcher
.is_null() &&
753 !origin_matcher
.Run(*origin
, special_storage_policy
.get())) {
757 (*deletion_task_count
)++;
758 quota_manager
->DeleteOriginData(
759 *origin
, quota_storage_type
,
760 StoragePartitionImpl::GenerateQuotaClientMask(remove_mask
),
761 base::Bind(&OnQuotaManagedOriginDeleted
,
762 origin
->GetOrigin(), quota_storage_type
,
763 deletion_task_count
, callback
));
765 (*deletion_task_count
)--;
767 CheckQuotaManagedDataDeletionStatus(deletion_task_count
, callback
);
770 void StoragePartitionImpl::DataDeletionHelper::IncrementTaskCountOnUI() {
771 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
775 void StoragePartitionImpl::DataDeletionHelper::DecrementTaskCountOnUI() {
776 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
777 BrowserThread::PostTask(
778 BrowserThread::UI
, FROM_HERE
,
779 base::Bind(&DataDeletionHelper::DecrementTaskCountOnUI
,
780 base::Unretained(this)));
783 DCHECK_GT(task_count
, 0);
791 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
792 const GURL
& storage_origin
,
793 const OriginMatcherFunction
& origin_matcher
,
794 const base::FilePath
& path
,
795 net::URLRequestContextGetter
* rq_context
,
796 DOMStorageContextWrapper
* dom_storage_context
,
797 storage::QuotaManager
* quota_manager
,
798 storage::SpecialStoragePolicy
* special_storage_policy
,
799 WebRTCIdentityStore
* webrtc_identity_store
,
800 const base::Time begin
,
801 const base::Time end
) {
802 DCHECK_NE(remove_mask
, 0u);
803 DCHECK(!callback
.is_null());
805 IncrementTaskCountOnUI();
806 base::Closure decrement_callback
= base::Bind(
807 &DataDeletionHelper::DecrementTaskCountOnUI
, base::Unretained(this));
809 if (remove_mask
& REMOVE_DATA_MASK_COOKIES
) {
810 // Handle the cookies.
811 IncrementTaskCountOnUI();
812 BrowserThread::PostTask(
813 BrowserThread::IO
, FROM_HERE
,
814 base::Bind(&ClearCookiesOnIOThread
,
815 make_scoped_refptr(rq_context
), begin
, end
, storage_origin
,
816 decrement_callback
));
819 if (remove_mask
& REMOVE_DATA_MASK_INDEXEDDB
||
820 remove_mask
& REMOVE_DATA_MASK_WEBSQL
||
821 remove_mask
& REMOVE_DATA_MASK_APPCACHE
||
822 remove_mask
& REMOVE_DATA_MASK_FILE_SYSTEMS
||
823 remove_mask
& REMOVE_DATA_MASK_SERVICE_WORKERS
) {
824 IncrementTaskCountOnUI();
825 BrowserThread::PostTask(
826 BrowserThread::IO
, FROM_HERE
,
827 base::Bind(&DataDeletionHelper::ClearQuotaManagedDataOnIOThread
,
828 base::Unretained(this),
829 make_scoped_refptr(quota_manager
),
832 make_scoped_refptr(special_storage_policy
),
834 decrement_callback
));
837 if (remove_mask
& REMOVE_DATA_MASK_LOCAL_STORAGE
) {
838 IncrementTaskCountOnUI();
839 ClearLocalStorageOnUIThread(
840 make_scoped_refptr(dom_storage_context
),
841 make_scoped_refptr(special_storage_policy
),
843 storage_origin
, begin
, end
,
846 // ClearDataImpl cannot clear session storage data when a particular origin
847 // is specified. Therefore we ignore clearing session storage in this case.
848 // TODO(lazyboy): Fix.
849 if (storage_origin
.is_empty()) {
850 IncrementTaskCountOnUI();
851 ClearSessionStorageOnUIThread(
852 make_scoped_refptr(dom_storage_context
),
853 make_scoped_refptr(special_storage_policy
),
859 if (remove_mask
& REMOVE_DATA_MASK_SHADER_CACHE
) {
860 IncrementTaskCountOnUI();
861 BrowserThread::PostTask(
862 BrowserThread::IO
, FROM_HERE
,
863 base::Bind(&ClearShaderCacheOnIOThread
,
864 path
, begin
, end
, decrement_callback
));
867 if (remove_mask
& REMOVE_DATA_MASK_WEBRTC_IDENTITY
) {
868 IncrementTaskCountOnUI();
869 BrowserThread::PostTask(
872 base::Bind(&WebRTCIdentityStore::DeleteBetween
,
873 webrtc_identity_store
,
876 decrement_callback
));
879 DecrementTaskCountOnUI();
882 void StoragePartitionImpl::ClearDataForOrigin(
884 uint32 quota_storage_remove_mask
,
885 const GURL
& storage_origin
,
886 net::URLRequestContextGetter
* request_context_getter
,
887 const base::Closure
& callback
) {
888 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
889 ClearDataImpl(remove_mask
,
890 quota_storage_remove_mask
,
892 OriginMatcherFunction(),
893 request_context_getter
,
899 void StoragePartitionImpl::ClearData(
901 uint32 quota_storage_remove_mask
,
902 const GURL
& storage_origin
,
903 const OriginMatcherFunction
& origin_matcher
,
904 const base::Time begin
,
905 const base::Time end
,
906 const base::Closure
& callback
) {
907 ClearDataImpl(remove_mask
, quota_storage_remove_mask
, storage_origin
,
908 origin_matcher
, GetURLRequestContext(), begin
, end
, callback
);
911 void StoragePartitionImpl::Flush() {
912 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
913 if (GetDOMStorageContext())
914 GetDOMStorageContext()->Flush();
917 WebRTCIdentityStore
* StoragePartitionImpl::GetWebRTCIdentityStore() {
918 return webrtc_identity_store_
.get();
921 BrowserContext
* StoragePartitionImpl::browser_context() const {
922 return browser_context_
;
925 void StoragePartitionImpl::OverrideQuotaManagerForTesting(
926 storage::QuotaManager
* quota_manager
) {
927 quota_manager_
= quota_manager
;
930 void StoragePartitionImpl::OverrideSpecialStoragePolicyForTesting(
931 storage::SpecialStoragePolicy
* special_storage_policy
) {
932 special_storage_policy_
= special_storage_policy
;
935 void StoragePartitionImpl::SetURLRequestContext(
936 net::URLRequestContextGetter
* url_request_context
) {
937 url_request_context_
= url_request_context
;
940 void StoragePartitionImpl::SetMediaURLRequestContext(
941 net::URLRequestContextGetter
* media_url_request_context
) {
942 media_url_request_context_
= media_url_request_context
;
945 } // namespace content