Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / storage_partition_impl.cc
blob5f4e789fc9ec87558aae601578ebaa2a40dd506c
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"
32 namespace content {
34 namespace {
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));
42 return;
45 callback.Run();
48 void ClearCookiesOnIOThread(
49 const scoped_refptr<net::URLRequestContextGetter>& rq_context,
50 const base::Time begin,
51 const base::Time end,
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(
59 begin,
60 end,
61 base::Bind(&OnClearedCookies, callback));
62 } else {
63 cookie_store->DeleteAllCreatedBetweenForHostAsync(
64 begin,
65 end,
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;
75 callback.Run();
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));
100 return;
102 callback.Run();
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())) {
127 continue;
130 if (infos[i].last_modified >= delete_begin &&
131 infos[i].last_modified <= delete_end) {
132 dom_storage_context->DeleteLocalStorage(infos[i].origin);
135 callback.Run();
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())) {
149 continue;
151 dom_storage_context->DeleteSessionStorage(infos[i]);
154 callback.Run();
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());
171 if (can_delete)
172 dom_storage_context->DeleteLocalStorage(storage_origin);
174 callback.Run();
175 return;
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,
194 callback));
197 } // namespace
199 // static
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;
229 // Static.
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),
261 callback(callback),
262 task_count(0) {
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.
285 uint32 remove_mask;
286 uint32 quota_storage_remove_mask;
287 GURL storage_origin;
288 const base::Closure callback;
289 int task_count;
292 // Helper for deleting all sorts of data from a partition, keeps track of
293 // deletion status.
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),
308 callback(callback),
309 task_count(0) {
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);
336 uint32 remove_mask;
337 uint32 quota_storage_remove_mask;
339 // Accessed on UI thread.
340 const base::Closure callback;
341 // Accessed on UI thread.
342 int task_count;
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(
356 remove_mask,
357 quota_storage_remove_mask,
358 storage_origin,
359 callback);
360 helper->ClearDataOnIOThread(quota_manager, begin, special_storage_policy,
361 origin_matcher);
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 BackgroundSyncContextImpl* background_sync_context)
382 : partition_path_(partition_path),
383 quota_manager_(quota_manager),
384 appcache_service_(appcache_service),
385 filesystem_context_(filesystem_context),
386 database_tracker_(database_tracker),
387 dom_storage_context_(dom_storage_context),
388 indexed_db_context_(indexed_db_context),
389 cache_storage_context_(cache_storage_context),
390 service_worker_context_(service_worker_context),
391 webrtc_identity_store_(webrtc_identity_store),
392 special_storage_policy_(special_storage_policy),
393 geofencing_manager_(geofencing_manager),
394 host_zoom_level_context_(host_zoom_level_context),
395 navigator_connect_context_(navigator_connect_context),
396 platform_notification_context_(platform_notification_context),
397 background_sync_context_(background_sync_context),
398 browser_context_(browser_context) {
401 StoragePartitionImpl::~StoragePartitionImpl() {
402 browser_context_ = nullptr;
404 // These message loop checks are just to avoid leaks in unittests.
405 if (GetDatabaseTracker() &&
406 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
407 BrowserThread::PostTask(
408 BrowserThread::FILE,
409 FROM_HERE,
410 base::Bind(&storage::DatabaseTracker::Shutdown, GetDatabaseTracker()));
413 if (GetFileSystemContext())
414 GetFileSystemContext()->Shutdown();
416 if (GetDOMStorageContext())
417 GetDOMStorageContext()->Shutdown();
419 if (GetServiceWorkerContext())
420 GetServiceWorkerContext()->Shutdown();
422 if (GetCacheStorageContext())
423 GetCacheStorageContext()->Shutdown();
425 if (GetGeofencingManager())
426 GetGeofencingManager()->Shutdown();
428 if (GetPlatformNotificationContext())
429 GetPlatformNotificationContext()->Shutdown();
431 if (GetBackgroundSyncContext())
432 GetBackgroundSyncContext()->Shutdown();
435 StoragePartitionImpl* StoragePartitionImpl::Create(
436 BrowserContext* context,
437 bool in_memory,
438 const base::FilePath& partition_path) {
439 // Ensure that these methods are called on the UI thread, except for
440 // unittests where a UI thread might not have been created.
441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
442 !BrowserThread::IsMessageLoopValid(BrowserThread::UI));
444 // All of the clients have to be created and registered with the
445 // QuotaManager prior to the QuotaManger being used. We do them
446 // all together here prior to handing out a reference to anything
447 // that utilizes the QuotaManager.
448 scoped_refptr<storage::QuotaManager> quota_manager =
449 new storage::QuotaManager(
450 in_memory,
451 partition_path,
452 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(),
453 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(),
454 context->GetSpecialStoragePolicy());
456 // Each consumer is responsible for registering its QuotaClient during
457 // its construction.
458 scoped_refptr<storage::FileSystemContext> filesystem_context =
459 CreateFileSystemContext(
460 context, partition_path, in_memory, quota_manager->proxy());
462 scoped_refptr<storage::DatabaseTracker> database_tracker =
463 new storage::DatabaseTracker(partition_path,
464 in_memory,
465 context->GetSpecialStoragePolicy(),
466 quota_manager->proxy(),
467 BrowserThread::GetMessageLoopProxyForThread(
468 BrowserThread::FILE).get());
470 base::FilePath path = in_memory ? base::FilePath() : partition_path;
471 scoped_refptr<DOMStorageContextWrapper> dom_storage_context =
472 new DOMStorageContextWrapper(path, context->GetSpecialStoragePolicy());
474 // BrowserMainLoop may not be initialized in unit tests. Tests will
475 // need to inject their own task runner into the IndexedDBContext.
476 base::SequencedTaskRunner* idb_task_runner =
477 BrowserThread::CurrentlyOn(BrowserThread::UI) &&
478 BrowserMainLoop::GetInstance()
479 ? BrowserMainLoop::GetInstance()->indexed_db_thread()
480 ->message_loop_proxy().get()
481 : NULL;
482 scoped_refptr<IndexedDBContextImpl> indexed_db_context =
483 new IndexedDBContextImpl(path,
484 context->GetSpecialStoragePolicy(),
485 quota_manager->proxy(),
486 idb_task_runner);
488 scoped_refptr<CacheStorageContextImpl> cache_storage_context =
489 new CacheStorageContextImpl(context);
490 cache_storage_context->Init(path, quota_manager->proxy(),
491 context->GetSpecialStoragePolicy());
493 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context =
494 new ServiceWorkerContextWrapper(context);
495 service_worker_context->Init(path, quota_manager->proxy(),
496 context->GetSpecialStoragePolicy());
498 scoped_refptr<ChromeAppCacheService> appcache_service =
499 new ChromeAppCacheService(quota_manager->proxy());
501 scoped_refptr<WebRTCIdentityStore> webrtc_identity_store(
502 new WebRTCIdentityStore(path, context->GetSpecialStoragePolicy()));
504 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy(
505 context->GetSpecialStoragePolicy());
507 scoped_refptr<GeofencingManager> geofencing_manager =
508 new GeofencingManager(service_worker_context);
509 geofencing_manager->Init();
511 scoped_refptr<HostZoomLevelContext> host_zoom_level_context(
512 new HostZoomLevelContext(
513 context->CreateZoomLevelDelegate(partition_path)));
515 scoped_refptr<NavigatorConnectContextImpl> navigator_connect_context =
516 new NavigatorConnectContextImpl();
517 navigator_connect_context->AddFactory(make_scoped_ptr(
518 new NavigatorConnectServiceWorkerServiceFactory(service_worker_context)));
520 scoped_refptr<PlatformNotificationContextImpl> platform_notification_context =
521 new PlatformNotificationContextImpl(path, service_worker_context);
522 platform_notification_context->Initialize();
524 scoped_refptr<BackgroundSyncContextImpl> background_sync_context =
525 new BackgroundSyncContextImpl();
526 background_sync_context->Init(service_worker_context);
528 StoragePartitionImpl* storage_partition = new StoragePartitionImpl(
529 context, partition_path, quota_manager.get(), appcache_service.get(),
530 filesystem_context.get(), database_tracker.get(),
531 dom_storage_context.get(), indexed_db_context.get(),
532 cache_storage_context.get(), service_worker_context.get(),
533 webrtc_identity_store.get(), special_storage_policy.get(),
534 geofencing_manager.get(), host_zoom_level_context.get(),
535 navigator_connect_context.get(), platform_notification_context.get(),
536 background_sync_context.get());
538 service_worker_context->set_storage_partition(storage_partition);
540 return storage_partition;
543 base::FilePath StoragePartitionImpl::GetPath() {
544 return partition_path_;
547 net::URLRequestContextGetter* StoragePartitionImpl::GetURLRequestContext() {
548 return url_request_context_.get();
551 net::URLRequestContextGetter*
552 StoragePartitionImpl::GetMediaURLRequestContext() {
553 return media_url_request_context_.get();
556 storage::QuotaManager* StoragePartitionImpl::GetQuotaManager() {
557 return quota_manager_.get();
560 ChromeAppCacheService* StoragePartitionImpl::GetAppCacheService() {
561 return appcache_service_.get();
564 storage::FileSystemContext* StoragePartitionImpl::GetFileSystemContext() {
565 return filesystem_context_.get();
568 storage::DatabaseTracker* StoragePartitionImpl::GetDatabaseTracker() {
569 return database_tracker_.get();
572 DOMStorageContextWrapper* StoragePartitionImpl::GetDOMStorageContext() {
573 return dom_storage_context_.get();
576 IndexedDBContextImpl* StoragePartitionImpl::GetIndexedDBContext() {
577 return indexed_db_context_.get();
580 CacheStorageContextImpl* StoragePartitionImpl::GetCacheStorageContext() {
581 return cache_storage_context_.get();
584 ServiceWorkerContextWrapper* StoragePartitionImpl::GetServiceWorkerContext() {
585 return service_worker_context_.get();
588 GeofencingManager* StoragePartitionImpl::GetGeofencingManager() {
589 return geofencing_manager_.get();
592 HostZoomMap* StoragePartitionImpl::GetHostZoomMap() {
593 DCHECK(host_zoom_level_context_.get());
594 return host_zoom_level_context_->GetHostZoomMap();
597 HostZoomLevelContext* StoragePartitionImpl::GetHostZoomLevelContext() {
598 return host_zoom_level_context_.get();
601 ZoomLevelDelegate* StoragePartitionImpl::GetZoomLevelDelegate() {
602 DCHECK(host_zoom_level_context_.get());
603 return host_zoom_level_context_->GetZoomLevelDelegate();
606 NavigatorConnectContextImpl*
607 StoragePartitionImpl::GetNavigatorConnectContext() {
608 return navigator_connect_context_.get();
611 PlatformNotificationContextImpl*
612 StoragePartitionImpl::GetPlatformNotificationContext() {
613 return platform_notification_context_.get();
616 BackgroundSyncContextImpl* StoragePartitionImpl::GetBackgroundSyncContext() {
617 return background_sync_context_.get();
620 void StoragePartitionImpl::ClearDataImpl(
621 uint32 remove_mask,
622 uint32 quota_storage_remove_mask,
623 const GURL& storage_origin,
624 const OriginMatcherFunction& origin_matcher,
625 net::URLRequestContextGetter* rq_context,
626 const base::Time begin,
627 const base::Time end,
628 const base::Closure& callback) {
629 DCHECK_CURRENTLY_ON(BrowserThread::UI);
630 DataDeletionHelper* helper = new DataDeletionHelper(remove_mask,
631 quota_storage_remove_mask,
632 callback);
633 // |helper| deletes itself when done in
634 // DataDeletionHelper::DecrementTaskCountOnUI().
635 helper->ClearDataOnUIThread(storage_origin,
636 origin_matcher,
637 GetPath(),
638 rq_context,
639 dom_storage_context_.get(),
640 quota_manager_.get(),
641 special_storage_policy_.get(),
642 webrtc_identity_store_.get(),
643 begin,
644 end);
647 void StoragePartitionImpl::
648 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() {
649 DCHECK_CURRENTLY_ON(BrowserThread::IO);
650 ++task_count;
653 void StoragePartitionImpl::
654 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() {
655 DCHECK_CURRENTLY_ON(BrowserThread::IO);
656 DCHECK_GT(task_count, 0);
657 --task_count;
658 if (task_count)
659 return;
661 callback.Run();
662 delete this;
665 void StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearDataOnIOThread(
666 const scoped_refptr<storage::QuotaManager>& quota_manager,
667 const base::Time begin,
668 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy,
669 const StoragePartition::OriginMatcherFunction& origin_matcher) {
670 IncrementTaskCountOnIO();
671 base::Closure decrement_callback = base::Bind(
672 &QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO,
673 base::Unretained(this));
675 if (quota_storage_remove_mask & QUOTA_MANAGED_STORAGE_MASK_PERSISTENT) {
676 IncrementTaskCountOnIO();
677 // Ask the QuotaManager for all origins with persistent quota modified
678 // within the user-specified timeframe, and deal with the resulting set in
679 // ClearQuotaManagedOriginsOnIOThread().
680 quota_manager->GetOriginsModifiedSince(
681 storage::kStorageTypePersistent,
682 begin,
683 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread,
684 base::Unretained(this),
685 quota_manager,
686 special_storage_policy,
687 origin_matcher,
688 decrement_callback));
691 // Do the same for temporary quota.
692 if (quota_storage_remove_mask & QUOTA_MANAGED_STORAGE_MASK_TEMPORARY) {
693 IncrementTaskCountOnIO();
694 quota_manager->GetOriginsModifiedSince(
695 storage::kStorageTypeTemporary,
696 begin,
697 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread,
698 base::Unretained(this),
699 quota_manager,
700 special_storage_policy,
701 origin_matcher,
702 decrement_callback));
705 // Do the same for syncable quota.
706 if (quota_storage_remove_mask & QUOTA_MANAGED_STORAGE_MASK_SYNCABLE) {
707 IncrementTaskCountOnIO();
708 quota_manager->GetOriginsModifiedSince(
709 storage::kStorageTypeSyncable,
710 begin,
711 base::Bind(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread,
712 base::Unretained(this),
713 quota_manager,
714 special_storage_policy,
715 origin_matcher,
716 decrement_callback));
719 DecrementTaskCountOnIO();
722 void
723 StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread(
724 storage::QuotaManager* quota_manager,
725 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy,
726 const StoragePartition::OriginMatcherFunction& origin_matcher,
727 const base::Closure& callback,
728 const std::set<GURL>& origins,
729 storage::StorageType quota_storage_type) {
730 // The QuotaManager manages all storage other than cookies, LocalStorage,
731 // and SessionStorage. This loop wipes out most HTML5 storage for the given
732 // origins.
733 DCHECK_CURRENTLY_ON(BrowserThread::IO);
734 if (!origins.size()) {
735 callback.Run();
736 return;
739 size_t* deletion_task_count = new size_t(0u);
740 (*deletion_task_count)++;
741 for (std::set<GURL>::const_iterator origin = origins.begin();
742 origin != origins.end(); ++origin) {
743 // TODO(mkwst): Clean this up, it's slow. http://crbug.com/130746
744 if (!storage_origin.is_empty() && origin->GetOrigin() != storage_origin)
745 continue;
747 if (!origin_matcher.is_null() &&
748 !origin_matcher.Run(*origin, special_storage_policy.get())) {
749 continue;
752 (*deletion_task_count)++;
753 quota_manager->DeleteOriginData(
754 *origin, quota_storage_type,
755 StoragePartitionImpl::GenerateQuotaClientMask(remove_mask),
756 base::Bind(&OnQuotaManagedOriginDeleted,
757 origin->GetOrigin(), quota_storage_type,
758 deletion_task_count, callback));
760 (*deletion_task_count)--;
762 CheckQuotaManagedDataDeletionStatus(deletion_task_count, callback);
765 void StoragePartitionImpl::DataDeletionHelper::IncrementTaskCountOnUI() {
766 DCHECK_CURRENTLY_ON(BrowserThread::UI);
767 ++task_count;
770 void StoragePartitionImpl::DataDeletionHelper::DecrementTaskCountOnUI() {
771 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
772 BrowserThread::PostTask(
773 BrowserThread::UI, FROM_HERE,
774 base::Bind(&DataDeletionHelper::DecrementTaskCountOnUI,
775 base::Unretained(this)));
776 return;
778 DCHECK_GT(task_count, 0);
779 --task_count;
780 if (!task_count) {
781 callback.Run();
782 delete this;
786 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
787 const GURL& storage_origin,
788 const OriginMatcherFunction& origin_matcher,
789 const base::FilePath& path,
790 net::URLRequestContextGetter* rq_context,
791 DOMStorageContextWrapper* dom_storage_context,
792 storage::QuotaManager* quota_manager,
793 storage::SpecialStoragePolicy* special_storage_policy,
794 WebRTCIdentityStore* webrtc_identity_store,
795 const base::Time begin,
796 const base::Time end) {
797 DCHECK_NE(remove_mask, 0u);
798 DCHECK(!callback.is_null());
800 IncrementTaskCountOnUI();
801 base::Closure decrement_callback = base::Bind(
802 &DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this));
804 if (remove_mask & REMOVE_DATA_MASK_COOKIES) {
805 // Handle the cookies.
806 IncrementTaskCountOnUI();
807 BrowserThread::PostTask(
808 BrowserThread::IO, FROM_HERE,
809 base::Bind(&ClearCookiesOnIOThread,
810 make_scoped_refptr(rq_context), begin, end, storage_origin,
811 decrement_callback));
814 if (remove_mask & REMOVE_DATA_MASK_INDEXEDDB ||
815 remove_mask & REMOVE_DATA_MASK_WEBSQL ||
816 remove_mask & REMOVE_DATA_MASK_APPCACHE ||
817 remove_mask & REMOVE_DATA_MASK_FILE_SYSTEMS ||
818 remove_mask & REMOVE_DATA_MASK_SERVICE_WORKERS) {
819 IncrementTaskCountOnUI();
820 BrowserThread::PostTask(
821 BrowserThread::IO, FROM_HERE,
822 base::Bind(&DataDeletionHelper::ClearQuotaManagedDataOnIOThread,
823 base::Unretained(this),
824 make_scoped_refptr(quota_manager),
825 begin,
826 storage_origin,
827 make_scoped_refptr(special_storage_policy),
828 origin_matcher,
829 decrement_callback));
832 if (remove_mask & REMOVE_DATA_MASK_LOCAL_STORAGE) {
833 IncrementTaskCountOnUI();
834 ClearLocalStorageOnUIThread(
835 make_scoped_refptr(dom_storage_context),
836 make_scoped_refptr(special_storage_policy),
837 origin_matcher,
838 storage_origin, begin, end,
839 decrement_callback);
841 // ClearDataImpl cannot clear session storage data when a particular origin
842 // is specified. Therefore we ignore clearing session storage in this case.
843 // TODO(lazyboy): Fix.
844 if (storage_origin.is_empty()) {
845 IncrementTaskCountOnUI();
846 ClearSessionStorageOnUIThread(
847 make_scoped_refptr(dom_storage_context),
848 make_scoped_refptr(special_storage_policy),
849 origin_matcher,
850 decrement_callback);
854 if (remove_mask & REMOVE_DATA_MASK_SHADER_CACHE) {
855 IncrementTaskCountOnUI();
856 BrowserThread::PostTask(
857 BrowserThread::IO, FROM_HERE,
858 base::Bind(&ClearShaderCacheOnIOThread,
859 path, begin, end, decrement_callback));
862 if (remove_mask & REMOVE_DATA_MASK_WEBRTC_IDENTITY) {
863 IncrementTaskCountOnUI();
864 BrowserThread::PostTask(
865 BrowserThread::IO,
866 FROM_HERE,
867 base::Bind(&WebRTCIdentityStore::DeleteBetween,
868 webrtc_identity_store,
869 begin,
870 end,
871 decrement_callback));
874 DecrementTaskCountOnUI();
877 void StoragePartitionImpl::ClearDataForOrigin(
878 uint32 remove_mask,
879 uint32 quota_storage_remove_mask,
880 const GURL& storage_origin,
881 net::URLRequestContextGetter* request_context_getter,
882 const base::Closure& callback) {
883 DCHECK_CURRENTLY_ON(BrowserThread::UI);
884 ClearDataImpl(remove_mask,
885 quota_storage_remove_mask,
886 storage_origin,
887 OriginMatcherFunction(),
888 request_context_getter,
889 base::Time(),
890 base::Time::Max(),
891 callback);
894 void StoragePartitionImpl::ClearData(
895 uint32 remove_mask,
896 uint32 quota_storage_remove_mask,
897 const GURL& storage_origin,
898 const OriginMatcherFunction& origin_matcher,
899 const base::Time begin,
900 const base::Time end,
901 const base::Closure& callback) {
902 ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin,
903 origin_matcher, GetURLRequestContext(), begin, end, callback);
906 WebRTCIdentityStore* StoragePartitionImpl::GetWebRTCIdentityStore() {
907 return webrtc_identity_store_.get();
910 BrowserContext* StoragePartitionImpl::browser_context() const {
911 return browser_context_;
914 void StoragePartitionImpl::OverrideQuotaManagerForTesting(
915 storage::QuotaManager* quota_manager) {
916 quota_manager_ = quota_manager;
919 void StoragePartitionImpl::OverrideSpecialStoragePolicyForTesting(
920 storage::SpecialStoragePolicy* special_storage_policy) {
921 special_storage_policy_ = special_storage_policy;
924 void StoragePartitionImpl::SetURLRequestContext(
925 net::URLRequestContextGetter* url_request_context) {
926 url_request_context_ = url_request_context;
929 void StoragePartitionImpl::SetMediaURLRequestContext(
930 net::URLRequestContextGetter* media_url_request_context) {
931 media_url_request_context_ = media_url_request_context;
934 } // namespace content