1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/storage_partition_impl.h"
7 #include "base/sequenced_task_runner.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/browser_main_loop.h"
10 #include "content/browser/fileapi/browser_file_system_helper.h"
11 #include "content/browser/geofencing/geofencing_manager.h"
12 #include "content/browser/gpu/shader_disk_cache.h"
13 #include "content/browser/host_zoom_map_impl.h"
14 #include "content/browser/navigator_connect/navigator_connect_context_impl.h"
15 #include "content/browser/navigator_connect/navigator_connect_service_worker_service_factory.h"
16 #include "content/browser/notifications/platform_notification_context_impl.h"
17 #include "content/common/dom_storage/dom_storage_types.h"
18 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/dom_storage_context.h"
21 #include "content/public/browser/indexed_db_context.h"
22 #include "content/public/browser/local_storage_usage_info.h"
23 #include "content/public/browser/session_storage_usage_info.h"
24 #include "net/base/completion_callback.h"
25 #include "net/base/net_errors.h"
26 #include "net/cookies/cookie_monster.h"
27 #include "net/url_request/url_request_context.h"
28 #include "net/url_request/url_request_context_getter.h"
29 #include "storage/browser/database/database_tracker.h"
30 #include "storage/browser/quota/quota_manager.h"
36 void OnClearedCookies(const base::Closure
& callback
, int num_deleted
) {
37 // The final callback needs to happen from UI thread.
38 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
39 BrowserThread::PostTask(
40 BrowserThread::UI
, FROM_HERE
,
41 base::Bind(&OnClearedCookies
, callback
, num_deleted
));
48 void ClearCookiesOnIOThread(
49 const scoped_refptr
<net::URLRequestContextGetter
>& rq_context
,
50 const base::Time begin
,
52 const GURL
& storage_origin
,
53 const base::Closure
& callback
) {
54 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
55 net::CookieStore
* cookie_store
= rq_context
->
56 GetURLRequestContext()->cookie_store();
57 if (storage_origin
.is_empty()) {
58 cookie_store
->DeleteAllCreatedBetweenAsync(
61 base::Bind(&OnClearedCookies
, callback
));
63 cookie_store
->DeleteAllCreatedBetweenForHostAsync(
66 storage_origin
, base::Bind(&OnClearedCookies
, callback
));
70 void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count
,
71 const base::Closure
& callback
) {
72 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
73 if (*deletion_task_count
== 0) {
74 delete deletion_task_count
;
79 void OnQuotaManagedOriginDeleted(const GURL
& origin
,
80 storage::StorageType type
,
81 size_t* deletion_task_count
,
82 const base::Closure
& callback
,
83 storage::QuotaStatusCode status
) {
84 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
85 DCHECK_GT(*deletion_task_count
, 0u);
86 if (status
!= storage::kQuotaStatusOk
) {
87 DLOG(ERROR
) << "Couldn't remove data of type " << type
<< " for origin "
88 << origin
<< ". Status: " << status
;
91 (*deletion_task_count
)--;
92 CheckQuotaManagedDataDeletionStatus(deletion_task_count
, callback
);
95 void ClearedShaderCache(const base::Closure
& callback
) {
96 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
97 BrowserThread::PostTask(
98 BrowserThread::UI
, FROM_HERE
,
99 base::Bind(&ClearedShaderCache
, callback
));
105 void ClearShaderCacheOnIOThread(const base::FilePath
& path
,
106 const base::Time begin
,
107 const base::Time end
,
108 const base::Closure
& callback
) {
109 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
110 ShaderCacheFactory::GetInstance()->ClearByPath(
111 path
, begin
, end
, base::Bind(&ClearedShaderCache
, callback
));
114 void OnLocalStorageUsageInfo(
115 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
116 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
117 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
118 const base::Time delete_begin
,
119 const base::Time delete_end
,
120 const base::Closure
& callback
,
121 const std::vector
<LocalStorageUsageInfo
>& infos
) {
122 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
124 for (size_t i
= 0; i
< infos
.size(); ++i
) {
125 if (!origin_matcher
.is_null() &&
126 !origin_matcher
.Run(infos
[i
].origin
, special_storage_policy
.get())) {
130 if (infos
[i
].last_modified
>= delete_begin
&&
131 infos
[i
].last_modified
<= delete_end
) {
132 dom_storage_context
->DeleteLocalStorage(infos
[i
].origin
);
138 void OnSessionStorageUsageInfo(
139 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
140 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
141 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
142 const base::Closure
& callback
,
143 const std::vector
<SessionStorageUsageInfo
>& infos
) {
144 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
146 for (size_t i
= 0; i
< infos
.size(); ++i
) {
147 if (!origin_matcher
.is_null() &&
148 !origin_matcher
.Run(infos
[i
].origin
, special_storage_policy
.get())) {
151 dom_storage_context
->DeleteSessionStorage(infos
[i
]);
157 void ClearLocalStorageOnUIThread(
158 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
159 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
160 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
161 const GURL
& storage_origin
,
162 const base::Time begin
,
163 const base::Time end
,
164 const base::Closure
& callback
) {
165 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
167 if (!storage_origin
.is_empty()) {
168 bool can_delete
= origin_matcher
.is_null() ||
169 origin_matcher
.Run(storage_origin
,
170 special_storage_policy
.get());
172 dom_storage_context
->DeleteLocalStorage(storage_origin
);
178 dom_storage_context
->GetLocalStorageUsage(
179 base::Bind(&OnLocalStorageUsageInfo
,
180 dom_storage_context
, special_storage_policy
, origin_matcher
,
181 begin
, end
, callback
));
184 void ClearSessionStorageOnUIThread(
185 const scoped_refptr
<DOMStorageContextWrapper
>& dom_storage_context
,
186 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
187 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
188 const base::Closure
& callback
) {
189 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
191 dom_storage_context
->GetSessionStorageUsage(
192 base::Bind(&OnSessionStorageUsageInfo
, dom_storage_context
,
193 special_storage_policy
, origin_matcher
,
200 STATIC_CONST_MEMBER_DEFINITION
const uint32
201 StoragePartition::REMOVE_DATA_MASK_APPCACHE
;
202 STATIC_CONST_MEMBER_DEFINITION
const uint32
203 StoragePartition::REMOVE_DATA_MASK_COOKIES
;
204 STATIC_CONST_MEMBER_DEFINITION
const uint32
205 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
;
206 STATIC_CONST_MEMBER_DEFINITION
const uint32
207 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
;
208 STATIC_CONST_MEMBER_DEFINITION
const uint32
209 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE
;
210 STATIC_CONST_MEMBER_DEFINITION
const uint32
211 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
;
212 STATIC_CONST_MEMBER_DEFINITION
const uint32
213 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE
;
214 STATIC_CONST_MEMBER_DEFINITION
const uint32
215 StoragePartition::REMOVE_DATA_MASK_WEBSQL
;
216 STATIC_CONST_MEMBER_DEFINITION
const uint32
217 StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY
;
218 STATIC_CONST_MEMBER_DEFINITION
const uint32
219 StoragePartition::REMOVE_DATA_MASK_ALL
;
220 STATIC_CONST_MEMBER_DEFINITION
const uint32
221 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY
;
222 STATIC_CONST_MEMBER_DEFINITION
const uint32
223 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
;
224 STATIC_CONST_MEMBER_DEFINITION
const uint32
225 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_SYNCABLE
;
226 STATIC_CONST_MEMBER_DEFINITION
const uint32
227 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
;
230 int StoragePartitionImpl::GenerateQuotaClientMask(uint32 remove_mask
) {
231 int quota_client_mask
= 0;
233 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
)
234 quota_client_mask
|= storage::QuotaClient::kFileSystem
;
235 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_WEBSQL
)
236 quota_client_mask
|= storage::QuotaClient::kDatabase
;
237 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_APPCACHE
)
238 quota_client_mask
|= storage::QuotaClient::kAppcache
;
239 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
)
240 quota_client_mask
|= storage::QuotaClient::kIndexedDatabase
;
241 if (remove_mask
& StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
) {
242 quota_client_mask
|= storage::QuotaClient::kServiceWorker
;
243 quota_client_mask
|= storage::QuotaClient::kServiceWorkerCache
;
247 return quota_client_mask
;
250 // Helper for deleting quota managed data from a partition.
252 // Most of the operations in this class are done on IO thread.
253 struct StoragePartitionImpl::QuotaManagedDataDeletionHelper
{
254 QuotaManagedDataDeletionHelper(uint32 remove_mask
,
255 uint32 quota_storage_remove_mask
,
256 const GURL
& storage_origin
,
257 const base::Closure
& callback
)
258 : remove_mask(remove_mask
),
259 quota_storage_remove_mask(quota_storage_remove_mask
),
260 storage_origin(storage_origin
),
265 void IncrementTaskCountOnIO();
266 void DecrementTaskCountOnIO();
268 void ClearDataOnIOThread(
269 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
270 const base::Time begin
,
271 const scoped_refptr
<storage::SpecialStoragePolicy
>&
272 special_storage_policy
,
273 const StoragePartition::OriginMatcherFunction
& origin_matcher
);
275 void ClearOriginsOnIOThread(
276 storage::QuotaManager
* quota_manager
,
277 const scoped_refptr
<storage::SpecialStoragePolicy
>&
278 special_storage_policy
,
279 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
280 const base::Closure
& callback
,
281 const std::set
<GURL
>& origins
,
282 storage::StorageType quota_storage_type
);
284 // All of these data are accessed on IO thread.
286 uint32 quota_storage_remove_mask
;
288 const base::Closure callback
;
292 // Helper for deleting all sorts of data from a partition, keeps track of
295 // StoragePartitionImpl creates an instance of this class to keep track of
296 // data deletion progress. Deletion requires deleting multiple bits of data
297 // (e.g. cookies, local storage, session storage etc.) and hopping between UI
298 // and IO thread. An instance of this class is created in the beginning of
299 // deletion process (StoragePartitionImpl::ClearDataImpl) and the instance is
300 // forwarded and updated on each (sub) deletion's callback. The instance is
301 // finally destroyed when deletion completes (and |callback| is invoked).
302 struct StoragePartitionImpl::DataDeletionHelper
{
303 DataDeletionHelper(uint32 remove_mask
,
304 uint32 quota_storage_remove_mask
,
305 const base::Closure
& callback
)
306 : remove_mask(remove_mask
),
307 quota_storage_remove_mask(quota_storage_remove_mask
),
312 void IncrementTaskCountOnUI();
313 void DecrementTaskCountOnUI();
315 void ClearDataOnUIThread(
316 const GURL
& storage_origin
,
317 const OriginMatcherFunction
& origin_matcher
,
318 const base::FilePath
& path
,
319 net::URLRequestContextGetter
* rq_context
,
320 DOMStorageContextWrapper
* dom_storage_context
,
321 storage::QuotaManager
* quota_manager
,
322 storage::SpecialStoragePolicy
* special_storage_policy
,
323 WebRTCIdentityStore
* webrtc_identity_store
,
324 const base::Time begin
,
325 const base::Time end
);
327 void ClearQuotaManagedDataOnIOThread(
328 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
329 const base::Time begin
,
330 const GURL
& storage_origin
,
331 const scoped_refptr
<storage::SpecialStoragePolicy
>&
332 special_storage_policy
,
333 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
334 const base::Closure
& callback
);
337 uint32 quota_storage_remove_mask
;
339 // Accessed on UI thread.
340 const base::Closure callback
;
341 // Accessed on UI thread.
345 void StoragePartitionImpl::DataDeletionHelper::ClearQuotaManagedDataOnIOThread(
346 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
347 const base::Time begin
,
348 const GURL
& storage_origin
,
349 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
350 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
351 const base::Closure
& callback
) {
352 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
354 StoragePartitionImpl::QuotaManagedDataDeletionHelper
* helper
=
355 new StoragePartitionImpl::QuotaManagedDataDeletionHelper(
357 quota_storage_remove_mask
,
360 helper
->ClearDataOnIOThread(quota_manager
, begin
, special_storage_policy
,
364 StoragePartitionImpl::StoragePartitionImpl(
365 BrowserContext
* browser_context
,
366 const base::FilePath
& partition_path
,
367 storage::QuotaManager
* quota_manager
,
368 ChromeAppCacheService
* appcache_service
,
369 storage::FileSystemContext
* filesystem_context
,
370 storage::DatabaseTracker
* database_tracker
,
371 DOMStorageContextWrapper
* dom_storage_context
,
372 IndexedDBContextImpl
* indexed_db_context
,
373 CacheStorageContextImpl
* cache_storage_context
,
374 ServiceWorkerContextWrapper
* service_worker_context
,
375 WebRTCIdentityStore
* webrtc_identity_store
,
376 storage::SpecialStoragePolicy
* special_storage_policy
,
377 GeofencingManager
* geofencing_manager
,
378 HostZoomLevelContext
* host_zoom_level_context
,
379 NavigatorConnectContextImpl
* navigator_connect_context
,
380 PlatformNotificationContextImpl
* platform_notification_context
)
381 : partition_path_(partition_path
),
382 quota_manager_(quota_manager
),
383 appcache_service_(appcache_service
),
384 filesystem_context_(filesystem_context
),
385 database_tracker_(database_tracker
),
386 dom_storage_context_(dom_storage_context
),
387 indexed_db_context_(indexed_db_context
),
388 cache_storage_context_(cache_storage_context
),
389 service_worker_context_(service_worker_context
),
390 webrtc_identity_store_(webrtc_identity_store
),
391 special_storage_policy_(special_storage_policy
),
392 geofencing_manager_(geofencing_manager
),
393 host_zoom_level_context_(host_zoom_level_context
),
394 navigator_connect_context_(navigator_connect_context
),
395 platform_notification_context_(platform_notification_context
),
396 browser_context_(browser_context
) {
399 StoragePartitionImpl::~StoragePartitionImpl() {
400 browser_context_
= nullptr;
402 // These message loop checks are just to avoid leaks in unittests.
403 if (GetDatabaseTracker() &&
404 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
405 BrowserThread::PostTask(
408 base::Bind(&storage::DatabaseTracker::Shutdown
, GetDatabaseTracker()));
411 if (GetFileSystemContext())
412 GetFileSystemContext()->Shutdown();
414 if (GetDOMStorageContext())
415 GetDOMStorageContext()->Shutdown();
417 if (GetServiceWorkerContext())
418 GetServiceWorkerContext()->Shutdown();
420 if (GetCacheStorageContext())
421 GetCacheStorageContext()->Shutdown();
423 if (GetGeofencingManager())
424 GetGeofencingManager()->Shutdown();
426 if (GetPlatformNotificationContext())
427 GetPlatformNotificationContext()->Shutdown();
430 StoragePartitionImpl
* StoragePartitionImpl::Create(
431 BrowserContext
* context
,
433 const base::FilePath
& partition_path
) {
434 // Ensure that these methods are called on the UI thread, except for
435 // unittests where a UI thread might not have been created.
436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
) ||
437 !BrowserThread::IsMessageLoopValid(BrowserThread::UI
));
439 // All of the clients have to be created and registered with the
440 // QuotaManager prior to the QuotaManger being used. We do them
441 // all together here prior to handing out a reference to anything
442 // that utilizes the QuotaManager.
443 scoped_refptr
<storage::QuotaManager
> quota_manager
=
444 new storage::QuotaManager(
447 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO
).get(),
448 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB
).get(),
449 context
->GetSpecialStoragePolicy());
451 // Each consumer is responsible for registering its QuotaClient during
453 scoped_refptr
<storage::FileSystemContext
> filesystem_context
=
454 CreateFileSystemContext(
455 context
, partition_path
, in_memory
, quota_manager
->proxy());
457 scoped_refptr
<storage::DatabaseTracker
> database_tracker
=
458 new storage::DatabaseTracker(partition_path
,
460 context
->GetSpecialStoragePolicy(),
461 quota_manager
->proxy(),
462 BrowserThread::GetMessageLoopProxyForThread(
463 BrowserThread::FILE).get());
465 base::FilePath path
= in_memory
? base::FilePath() : partition_path
;
466 scoped_refptr
<DOMStorageContextWrapper
> dom_storage_context
=
467 new DOMStorageContextWrapper(path
, context
->GetSpecialStoragePolicy());
469 // BrowserMainLoop may not be initialized in unit tests. Tests will
470 // need to inject their own task runner into the IndexedDBContext.
471 base::SequencedTaskRunner
* idb_task_runner
=
472 BrowserThread::CurrentlyOn(BrowserThread::UI
) &&
473 BrowserMainLoop::GetInstance()
474 ? BrowserMainLoop::GetInstance()->indexed_db_thread()
475 ->message_loop_proxy().get()
477 scoped_refptr
<IndexedDBContextImpl
> indexed_db_context
=
478 new IndexedDBContextImpl(path
,
479 context
->GetSpecialStoragePolicy(),
480 quota_manager
->proxy(),
483 scoped_refptr
<CacheStorageContextImpl
> cache_storage_context
=
484 new CacheStorageContextImpl(context
);
485 cache_storage_context
->Init(path
, quota_manager
->proxy(),
486 context
->GetSpecialStoragePolicy());
488 scoped_refptr
<ServiceWorkerContextWrapper
> service_worker_context
=
489 new ServiceWorkerContextWrapper(context
);
490 service_worker_context
->Init(path
, quota_manager
->proxy(),
491 context
->GetSpecialStoragePolicy());
493 scoped_refptr
<ChromeAppCacheService
> appcache_service
=
494 new ChromeAppCacheService(quota_manager
->proxy());
496 scoped_refptr
<WebRTCIdentityStore
> webrtc_identity_store(
497 new WebRTCIdentityStore(path
, context
->GetSpecialStoragePolicy()));
499 scoped_refptr
<storage::SpecialStoragePolicy
> special_storage_policy(
500 context
->GetSpecialStoragePolicy());
502 scoped_refptr
<GeofencingManager
> geofencing_manager
=
503 new GeofencingManager(service_worker_context
);
504 geofencing_manager
->Init();
506 scoped_refptr
<HostZoomLevelContext
> host_zoom_level_context(
507 new HostZoomLevelContext(
508 context
->CreateZoomLevelDelegate(partition_path
)));
510 scoped_refptr
<NavigatorConnectContextImpl
> navigator_connect_context
=
511 new NavigatorConnectContextImpl();
512 navigator_connect_context
->AddFactory(make_scoped_ptr(
513 new NavigatorConnectServiceWorkerServiceFactory(service_worker_context
)));
515 scoped_refptr
<PlatformNotificationContextImpl
> platform_notification_context
=
516 new PlatformNotificationContextImpl(path
, service_worker_context
);
517 platform_notification_context
->Initialize();
519 StoragePartitionImpl
* storage_partition
= new StoragePartitionImpl(
520 context
, partition_path
, quota_manager
.get(), appcache_service
.get(),
521 filesystem_context
.get(), database_tracker
.get(),
522 dom_storage_context
.get(), indexed_db_context
.get(),
523 cache_storage_context
.get(), service_worker_context
.get(),
524 webrtc_identity_store
.get(), special_storage_policy
.get(),
525 geofencing_manager
.get(), host_zoom_level_context
.get(),
526 navigator_connect_context
.get(),
527 platform_notification_context
.get());
529 service_worker_context
->set_storage_partition(storage_partition
);
531 return storage_partition
;
534 base::FilePath
StoragePartitionImpl::GetPath() {
535 return partition_path_
;
538 net::URLRequestContextGetter
* StoragePartitionImpl::GetURLRequestContext() {
539 return url_request_context_
.get();
542 net::URLRequestContextGetter
*
543 StoragePartitionImpl::GetMediaURLRequestContext() {
544 return media_url_request_context_
.get();
547 storage::QuotaManager
* StoragePartitionImpl::GetQuotaManager() {
548 return quota_manager_
.get();
551 ChromeAppCacheService
* StoragePartitionImpl::GetAppCacheService() {
552 return appcache_service_
.get();
555 storage::FileSystemContext
* StoragePartitionImpl::GetFileSystemContext() {
556 return filesystem_context_
.get();
559 storage::DatabaseTracker
* StoragePartitionImpl::GetDatabaseTracker() {
560 return database_tracker_
.get();
563 DOMStorageContextWrapper
* StoragePartitionImpl::GetDOMStorageContext() {
564 return dom_storage_context_
.get();
567 IndexedDBContextImpl
* StoragePartitionImpl::GetIndexedDBContext() {
568 return indexed_db_context_
.get();
571 CacheStorageContextImpl
* StoragePartitionImpl::GetCacheStorageContext() {
572 return cache_storage_context_
.get();
575 ServiceWorkerContextWrapper
* StoragePartitionImpl::GetServiceWorkerContext() {
576 return service_worker_context_
.get();
579 GeofencingManager
* StoragePartitionImpl::GetGeofencingManager() {
580 return geofencing_manager_
.get();
583 HostZoomMap
* StoragePartitionImpl::GetHostZoomMap() {
584 DCHECK(host_zoom_level_context_
.get());
585 return host_zoom_level_context_
->GetHostZoomMap();
588 HostZoomLevelContext
* StoragePartitionImpl::GetHostZoomLevelContext() {
589 return host_zoom_level_context_
.get();
592 ZoomLevelDelegate
* StoragePartitionImpl::GetZoomLevelDelegate() {
593 DCHECK(host_zoom_level_context_
.get());
594 return host_zoom_level_context_
->GetZoomLevelDelegate();
597 NavigatorConnectContextImpl
*
598 StoragePartitionImpl::GetNavigatorConnectContext() {
599 return navigator_connect_context_
.get();
602 PlatformNotificationContextImpl
*
603 StoragePartitionImpl::GetPlatformNotificationContext() {
604 return platform_notification_context_
.get();
607 void StoragePartitionImpl::ClearDataImpl(
609 uint32 quota_storage_remove_mask
,
610 const GURL
& storage_origin
,
611 const OriginMatcherFunction
& origin_matcher
,
612 net::URLRequestContextGetter
* rq_context
,
613 const base::Time begin
,
614 const base::Time end
,
615 const base::Closure
& callback
) {
616 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
617 DataDeletionHelper
* helper
= new DataDeletionHelper(remove_mask
,
618 quota_storage_remove_mask
,
620 // |helper| deletes itself when done in
621 // DataDeletionHelper::DecrementTaskCountOnUI().
622 helper
->ClearDataOnUIThread(storage_origin
,
626 dom_storage_context_
.get(),
627 quota_manager_
.get(),
628 special_storage_policy_
.get(),
629 webrtc_identity_store_
.get(),
634 void StoragePartitionImpl::
635 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() {
636 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
640 void StoragePartitionImpl::
641 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() {
642 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
643 DCHECK_GT(task_count
, 0);
652 void StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearDataOnIOThread(
653 const scoped_refptr
<storage::QuotaManager
>& quota_manager
,
654 const base::Time begin
,
655 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
656 const StoragePartition::OriginMatcherFunction
& origin_matcher
) {
657 IncrementTaskCountOnIO();
658 base::Closure decrement_callback
= base::Bind(
659 &QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO
,
660 base::Unretained(this));
662 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
) {
663 IncrementTaskCountOnIO();
664 // Ask the QuotaManager for all origins with persistent quota modified
665 // within the user-specified timeframe, and deal with the resulting set in
666 // ClearQuotaManagedOriginsOnIOThread().
667 quota_manager
->GetOriginsModifiedSince(
668 storage::kStorageTypePersistent
,
670 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
671 base::Unretained(this),
673 special_storage_policy
,
675 decrement_callback
));
678 // Do the same for temporary quota.
679 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_TEMPORARY
) {
680 IncrementTaskCountOnIO();
681 quota_manager
->GetOriginsModifiedSince(
682 storage::kStorageTypeTemporary
,
684 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
685 base::Unretained(this),
687 special_storage_policy
,
689 decrement_callback
));
692 // Do the same for syncable quota.
693 if (quota_storage_remove_mask
& QUOTA_MANAGED_STORAGE_MASK_SYNCABLE
) {
694 IncrementTaskCountOnIO();
695 quota_manager
->GetOriginsModifiedSince(
696 storage::kStorageTypeSyncable
,
698 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread
,
699 base::Unretained(this),
701 special_storage_policy
,
703 decrement_callback
));
706 DecrementTaskCountOnIO();
710 StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread(
711 storage::QuotaManager
* quota_manager
,
712 const scoped_refptr
<storage::SpecialStoragePolicy
>& special_storage_policy
,
713 const StoragePartition::OriginMatcherFunction
& origin_matcher
,
714 const base::Closure
& callback
,
715 const std::set
<GURL
>& origins
,
716 storage::StorageType quota_storage_type
) {
717 // The QuotaManager manages all storage other than cookies, LocalStorage,
718 // and SessionStorage. This loop wipes out most HTML5 storage for the given
720 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
721 if (!origins
.size()) {
726 size_t* deletion_task_count
= new size_t(0u);
727 (*deletion_task_count
)++;
728 for (std::set
<GURL
>::const_iterator origin
= origins
.begin();
729 origin
!= origins
.end(); ++origin
) {
730 // TODO(mkwst): Clean this up, it's slow. http://crbug.com/130746
731 if (!storage_origin
.is_empty() && origin
->GetOrigin() != storage_origin
)
734 if (!origin_matcher
.is_null() &&
735 !origin_matcher
.Run(*origin
, special_storage_policy
.get())) {
739 (*deletion_task_count
)++;
740 quota_manager
->DeleteOriginData(
741 *origin
, quota_storage_type
,
742 StoragePartitionImpl::GenerateQuotaClientMask(remove_mask
),
743 base::Bind(&OnQuotaManagedOriginDeleted
,
744 origin
->GetOrigin(), quota_storage_type
,
745 deletion_task_count
, callback
));
747 (*deletion_task_count
)--;
749 CheckQuotaManagedDataDeletionStatus(deletion_task_count
, callback
);
752 void StoragePartitionImpl::DataDeletionHelper::IncrementTaskCountOnUI() {
753 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
757 void StoragePartitionImpl::DataDeletionHelper::DecrementTaskCountOnUI() {
758 if (!BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
759 BrowserThread::PostTask(
760 BrowserThread::UI
, FROM_HERE
,
761 base::Bind(&DataDeletionHelper::DecrementTaskCountOnUI
,
762 base::Unretained(this)));
765 DCHECK_GT(task_count
, 0);
773 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
774 const GURL
& storage_origin
,
775 const OriginMatcherFunction
& origin_matcher
,
776 const base::FilePath
& path
,
777 net::URLRequestContextGetter
* rq_context
,
778 DOMStorageContextWrapper
* dom_storage_context
,
779 storage::QuotaManager
* quota_manager
,
780 storage::SpecialStoragePolicy
* special_storage_policy
,
781 WebRTCIdentityStore
* webrtc_identity_store
,
782 const base::Time begin
,
783 const base::Time end
) {
784 DCHECK_NE(remove_mask
, 0u);
785 DCHECK(!callback
.is_null());
787 IncrementTaskCountOnUI();
788 base::Closure decrement_callback
= base::Bind(
789 &DataDeletionHelper::DecrementTaskCountOnUI
, base::Unretained(this));
791 if (remove_mask
& REMOVE_DATA_MASK_COOKIES
) {
792 // Handle the cookies.
793 IncrementTaskCountOnUI();
794 BrowserThread::PostTask(
795 BrowserThread::IO
, FROM_HERE
,
796 base::Bind(&ClearCookiesOnIOThread
,
797 make_scoped_refptr(rq_context
), begin
, end
, storage_origin
,
798 decrement_callback
));
801 if (remove_mask
& REMOVE_DATA_MASK_INDEXEDDB
||
802 remove_mask
& REMOVE_DATA_MASK_WEBSQL
||
803 remove_mask
& REMOVE_DATA_MASK_APPCACHE
||
804 remove_mask
& REMOVE_DATA_MASK_FILE_SYSTEMS
||
805 remove_mask
& REMOVE_DATA_MASK_SERVICE_WORKERS
) {
806 IncrementTaskCountOnUI();
807 BrowserThread::PostTask(
808 BrowserThread::IO
, FROM_HERE
,
809 base::Bind(&DataDeletionHelper::ClearQuotaManagedDataOnIOThread
,
810 base::Unretained(this),
811 make_scoped_refptr(quota_manager
),
814 make_scoped_refptr(special_storage_policy
),
816 decrement_callback
));
819 if (remove_mask
& REMOVE_DATA_MASK_LOCAL_STORAGE
) {
820 IncrementTaskCountOnUI();
821 ClearLocalStorageOnUIThread(
822 make_scoped_refptr(dom_storage_context
),
823 make_scoped_refptr(special_storage_policy
),
825 storage_origin
, begin
, end
,
828 // ClearDataImpl cannot clear session storage data when a particular origin
829 // is specified. Therefore we ignore clearing session storage in this case.
830 // TODO(lazyboy): Fix.
831 if (storage_origin
.is_empty()) {
832 IncrementTaskCountOnUI();
833 ClearSessionStorageOnUIThread(
834 make_scoped_refptr(dom_storage_context
),
835 make_scoped_refptr(special_storage_policy
),
841 if (remove_mask
& REMOVE_DATA_MASK_SHADER_CACHE
) {
842 IncrementTaskCountOnUI();
843 BrowserThread::PostTask(
844 BrowserThread::IO
, FROM_HERE
,
845 base::Bind(&ClearShaderCacheOnIOThread
,
846 path
, begin
, end
, decrement_callback
));
849 if (remove_mask
& REMOVE_DATA_MASK_WEBRTC_IDENTITY
) {
850 IncrementTaskCountOnUI();
851 BrowserThread::PostTask(
854 base::Bind(&WebRTCIdentityStore::DeleteBetween
,
855 webrtc_identity_store
,
858 decrement_callback
));
861 DecrementTaskCountOnUI();
864 void StoragePartitionImpl::ClearDataForOrigin(
866 uint32 quota_storage_remove_mask
,
867 const GURL
& storage_origin
,
868 net::URLRequestContextGetter
* request_context_getter
,
869 const base::Closure
& callback
) {
870 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
871 ClearDataImpl(remove_mask
,
872 quota_storage_remove_mask
,
874 OriginMatcherFunction(),
875 request_context_getter
,
881 void StoragePartitionImpl::ClearData(
883 uint32 quota_storage_remove_mask
,
884 const GURL
& storage_origin
,
885 const OriginMatcherFunction
& origin_matcher
,
886 const base::Time begin
,
887 const base::Time end
,
888 const base::Closure
& callback
) {
889 ClearDataImpl(remove_mask
, quota_storage_remove_mask
, storage_origin
,
890 origin_matcher
, GetURLRequestContext(), begin
, end
, callback
);
893 WebRTCIdentityStore
* StoragePartitionImpl::GetWebRTCIdentityStore() {
894 return webrtc_identity_store_
.get();
897 BrowserContext
* StoragePartitionImpl::browser_context() const {
898 return browser_context_
;
901 void StoragePartitionImpl::OverrideQuotaManagerForTesting(
902 storage::QuotaManager
* quota_manager
) {
903 quota_manager_
= quota_manager
;
906 void StoragePartitionImpl::OverrideSpecialStoragePolicyForTesting(
907 storage::SpecialStoragePolicy
* special_storage_policy
) {
908 special_storage_policy_
= special_storage_policy
;
911 void StoragePartitionImpl::SetURLRequestContext(
912 net::URLRequestContextGetter
* url_request_context
) {
913 url_request_context_
= url_request_context
;
916 void StoragePartitionImpl::SetMediaURLRequestContext(
917 net::URLRequestContextGetter
* media_url_request_context
) {
918 media_url_request_context_
= media_url_request_context
;
921 } // namespace content