blob: 3028b616444c9800b65541b9ba82c4bc0923e658 [file] [log] [blame]
[email protected]4c3a23582012-08-18 08:54:341// 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.
4
5#ifndef CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_
6#define CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_
7
8#include "base/compiler_specific.h"
[email protected]57999812013-02-24 05:40:529#include "base/files/file_path.h"
[email protected]4c3a23582012-08-18 08:54:3410#include "base/memory/ref_counted.h"
11#include "content/browser/appcache/chrome_appcache_service.h"
jkarlin901d507a2015-04-20 19:23:1812#include "content/browser/background_sync/background_sync_context_impl.h"
jsbell279efb42015-03-31 17:02:4613#include "content/browser/cache_storage/cache_storage_context_impl.h"
[email protected]5f2aa722013-08-07 16:59:4114#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
wjmacleancaa7d6d2014-11-12 16:42:1115#include "content/browser/host_zoom_level_context.h"
[email protected]c4d281662013-03-31 00:35:0816#include "content/browser/indexed_db/indexed_db_context_impl.h"
[email protected]d3220662013-07-01 21:21:4617#include "content/browser/media/webrtc_identity_store.h"
mek59114f62015-01-27 01:13:5218#include "content/browser/navigator_connect/navigator_connect_context_impl.h"
peter7ac37dd2015-03-18 14:57:3019#include "content/browser/notifications/platform_notification_context_impl.h"
[email protected]1f1e8562013-11-13 05:05:1620#include "content/browser/service_worker/service_worker_context_wrapper.h"
[email protected]877e2612013-04-05 05:58:1821#include "content/common/content_export.h"
[email protected]4c3a23582012-08-18 08:54:3422#include "content/public/browser/storage_partition.h"
pilgrime92c5fcd2014-09-10 23:31:2323#include "storage/browser/quota/special_storage_policy.h"
[email protected]4c3a23582012-08-18 08:54:3424
25namespace content {
26
27class StoragePartitionImpl : public StoragePartition {
28 public:
dchengc2282aa2014-10-21 12:07:5829 CONTENT_EXPORT ~StoragePartitionImpl() override;
[email protected]4c3a23582012-08-18 08:54:3430
[email protected]88562b512013-11-06 21:10:4431 // Quota managed data uses a different bitmask for types than
32 // StoragePartition uses. This method generates that mask.
33 CONTENT_EXPORT static int GenerateQuotaClientMask(uint32 remove_mask);
34
35 CONTENT_EXPORT void OverrideQuotaManagerForTesting(
[email protected]cd501a72014-08-22 19:58:3136 storage::QuotaManager* quota_manager);
[email protected]88562b512013-11-06 21:10:4437 CONTENT_EXPORT void OverrideSpecialStoragePolicyForTesting(
[email protected]cd501a72014-08-22 19:58:3138 storage::SpecialStoragePolicy* special_storage_policy);
[email protected]88562b512013-11-06 21:10:4439
[email protected]4c3a23582012-08-18 08:54:3440 // StoragePartition interface.
dchengc2282aa2014-10-21 12:07:5841 base::FilePath GetPath() override;
42 net::URLRequestContextGetter* GetURLRequestContext() override;
43 net::URLRequestContextGetter* GetMediaURLRequestContext() override;
44 storage::QuotaManager* GetQuotaManager() override;
45 ChromeAppCacheService* GetAppCacheService() override;
46 storage::FileSystemContext* GetFileSystemContext() override;
47 storage::DatabaseTracker* GetDatabaseTracker() override;
48 DOMStorageContextWrapper* GetDOMStorageContext() override;
49 IndexedDBContextImpl* GetIndexedDBContext() override;
jsbellabadb9b2015-03-23 21:03:4450 // TODO(jsbell): Expose this on the public API as well. crbug.com/466371
51 CacheStorageContextImpl* GetCacheStorageContext();
dchengc2282aa2014-10-21 12:07:5852 ServiceWorkerContextWrapper* GetServiceWorkerContext() override;
mek0c55c7f62014-10-23 22:06:0953 GeofencingManager* GetGeofencingManager() override;
wjmacleancaa7d6d2014-11-12 16:42:1154 HostZoomMap* GetHostZoomMap() override;
55 HostZoomLevelContext* GetHostZoomLevelContext() override;
56 ZoomLevelDelegate* GetZoomLevelDelegate() override;
mek59114f62015-01-27 01:13:5257 NavigatorConnectContextImpl* GetNavigatorConnectContext() override;
peter7ac37dd2015-03-18 14:57:3058 PlatformNotificationContextImpl* GetPlatformNotificationContext() override;
jkarlin901d507a2015-04-20 19:23:1859 BackgroundSyncContextImpl* GetBackgroundSyncContext();
[email protected]33ad6ce92013-08-27 14:39:0860
dchengc2282aa2014-10-21 12:07:5861 void ClearDataForOrigin(uint32 remove_mask,
62 uint32 quota_storage_remove_mask,
63 const GURL& storage_origin,
64 net::URLRequestContextGetter* request_context_getter,
65 const base::Closure& callback) override;
66 void ClearData(uint32 remove_mask,
67 uint32 quota_storage_remove_mask,
68 const GURL& storage_origin,
69 const OriginMatcherFunction& origin_matcher,
70 const base::Time begin,
71 const base::Time end,
72 const base::Closure& callback) override;
[email protected]4c3a23582012-08-18 08:54:3473
[email protected]d3220662013-07-01 21:21:4674 WebRTCIdentityStore* GetWebRTCIdentityStore();
75
mlamouri6cdca912015-01-15 17:04:0876 // Can return nullptr while |this| is being destroyed.
77 BrowserContext* browser_context() const;
78
[email protected]fdf3e13c2013-07-31 06:23:4679 struct DataDeletionHelper;
80 struct QuotaManagedDataDeletionHelper;
81
[email protected]4c3a23582012-08-18 08:54:3482 private:
[email protected]10eb28162012-09-18 03:04:0983 friend class StoragePartitionImplMap;
[email protected]877e2612013-04-05 05:58:1884 FRIEND_TEST_ALL_PREFIXES(StoragePartitionShaderClearTest, ClearShaderCache);
[email protected]88562b512013-11-06 21:10:4485 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
86 RemoveQuotaManagedDataForeverBoth);
87 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
88 RemoveQuotaManagedDataForeverOnlyTemporary);
89 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
90 RemoveQuotaManagedDataForeverOnlyPersistent);
91 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
92 RemoveQuotaManagedDataForeverNeither);
93 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
94 RemoveQuotaManagedDataForeverSpecificOrigin);
95 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
96 RemoveQuotaManagedDataForLastHour);
97 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
98 RemoveQuotaManagedDataForLastWeek);
99 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
100 RemoveQuotaManagedUnprotectedOrigins);
101 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
102 RemoveQuotaManagedProtectedSpecificOrigin);
103 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
104 RemoveQuotaManagedProtectedOrigins);
105 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
106 RemoveQuotaManagedIgnoreDevTools);
107 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, RemoveCookieForever);
108 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, RemoveCookieLastHour);
109 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
110 RemoveUnprotectedLocalStorageForever);
111 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
112 RemoveProtectedLocalStorageForever);
113 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
114 RemoveLocalStorageForLastWeek);
[email protected]10eb28162012-09-18 03:04:09115
[email protected]b471cf42012-11-13 09:11:30116 // The |partition_path| is the absolute path to the root of this
117 // StoragePartition's on-disk storage.
[email protected]1bc28312012-11-08 08:31:53118 //
[email protected]33ad6ce92013-08-27 14:39:08119 // If |in_memory| is true, the |partition_path| is (ab)used as a way of
[email protected]b471cf42012-11-13 09:11:30120 // distinguishing different in-memory partitions, but nothing is persisted
121 // on to disk.
[email protected]33ad6ce92013-08-27 14:39:08122 static StoragePartitionImpl* Create(BrowserContext* context,
123 bool in_memory,
124 const base::FilePath& profile_path);
[email protected]1bc28312012-11-08 08:31:53125
[email protected]877e2612013-04-05 05:58:18126 CONTENT_EXPORT StoragePartitionImpl(
mlamouri6cdca912015-01-15 17:04:08127 BrowserContext* browser_context,
[email protected]2dec8ec2013-02-07 19:20:34128 const base::FilePath& partition_path,
[email protected]cd501a72014-08-22 19:58:31129 storage::QuotaManager* quota_manager,
[email protected]10eb28162012-09-18 03:04:09130 ChromeAppCacheService* appcache_service,
[email protected]cd501a72014-08-22 19:58:31131 storage::FileSystemContext* filesystem_context,
132 storage::DatabaseTracker* database_tracker,
[email protected]5f2aa722013-08-07 16:59:41133 DOMStorageContextWrapper* dom_storage_context,
[email protected]d3220662013-07-01 21:21:46134 IndexedDBContextImpl* indexed_db_context,
jsbellabadb9b2015-03-23 21:03:44135 CacheStorageContextImpl* cache_storage_context,
[email protected]1f1e8562013-11-13 05:05:16136 ServiceWorkerContextWrapper* service_worker_context,
[email protected]88562b512013-11-06 21:10:44137 WebRTCIdentityStore* webrtc_identity_store,
mek0c55c7f62014-10-23 22:06:09138 storage::SpecialStoragePolicy* special_storage_policy,
wjmacleancaa7d6d2014-11-12 16:42:11139 GeofencingManager* geofencing_manager,
meke6b83032014-12-19 23:35:34140 HostZoomLevelContext* host_zoom_level_context,
peter7ac37dd2015-03-18 14:57:30141 NavigatorConnectContextImpl* navigator_connect_context,
jkarlin901d507a2015-04-20 19:23:18142 PlatformNotificationContextImpl* platform_notification_context,
143 BackgroundSyncContextImpl* background_sync_context);
[email protected]10eb28162012-09-18 03:04:09144
[email protected]fdf3e13c2013-07-31 06:23:46145 void ClearDataImpl(uint32 remove_mask,
146 uint32 quota_storage_remove_mask,
[email protected]5ff8b2a2013-12-28 06:51:42147 const GURL& remove_origin,
[email protected]88562b512013-11-06 21:10:44148 const OriginMatcherFunction& origin_matcher,
[email protected]33ad6ce92013-08-27 14:39:08149 net::URLRequestContextGetter* rq_context,
[email protected]fdf3e13c2013-07-31 06:23:46150 const base::Time begin,
151 const base::Time end,
152 const base::Closure& callback);
153
[email protected]10eb28162012-09-18 03:04:09154 // Used by StoragePartitionImplMap.
155 //
156 // TODO(ajwong): These should be taken in the constructor and in Create() but
157 // because the URLRequestContextGetter still lives in Profile with a tangled
158 // initialization, if we try to retrieve the URLRequestContextGetter()
159 // before the default StoragePartition is created, we end up reentering the
160 // construction and double-initializing. For now, we retain the legacy
161 // behavior while allowing StoragePartitionImpl to expose these accessors by
162 // letting StoragePartitionImplMap call these two private settings at the
163 // appropriate time. These should move back into the constructor once
164 // URLRequestContextGetter's lifetime is sorted out. We should also move the
165 // PostCreateInitialization() out of StoragePartitionImplMap.
[email protected]88562b512013-11-06 21:10:44166 CONTENT_EXPORT void SetURLRequestContext(
167 net::URLRequestContextGetter* url_request_context);
[email protected]10eb28162012-09-18 03:04:09168 void SetMediaURLRequestContext(
169 net::URLRequestContextGetter* media_url_request_context);
[email protected]4c3a23582012-08-18 08:54:34170
[email protected]2dec8ec2013-02-07 19:20:34171 base::FilePath partition_path_;
[email protected]10eb28162012-09-18 03:04:09172 scoped_refptr<net::URLRequestContextGetter> url_request_context_;
173 scoped_refptr<net::URLRequestContextGetter> media_url_request_context_;
[email protected]cd501a72014-08-22 19:58:31174 scoped_refptr<storage::QuotaManager> quota_manager_;
[email protected]4c3a23582012-08-18 08:54:34175 scoped_refptr<ChromeAppCacheService> appcache_service_;
[email protected]cd501a72014-08-22 19:58:31176 scoped_refptr<storage::FileSystemContext> filesystem_context_;
177 scoped_refptr<storage::DatabaseTracker> database_tracker_;
[email protected]5f2aa722013-08-07 16:59:41178 scoped_refptr<DOMStorageContextWrapper> dom_storage_context_;
[email protected]4c3a23582012-08-18 08:54:34179 scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
jsbellabadb9b2015-03-23 21:03:44180 scoped_refptr<CacheStorageContextImpl> cache_storage_context_;
[email protected]1f1e8562013-11-13 05:05:16181 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
[email protected]ec346e02013-08-08 22:03:53182 scoped_refptr<WebRTCIdentityStore> webrtc_identity_store_;
[email protected]cd501a72014-08-22 19:58:31183 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
mek0c55c7f62014-10-23 22:06:09184 scoped_refptr<GeofencingManager> geofencing_manager_;
wjmacleancaa7d6d2014-11-12 16:42:11185 scoped_refptr<HostZoomLevelContext> host_zoom_level_context_;
mek59114f62015-01-27 01:13:52186 scoped_refptr<NavigatorConnectContextImpl> navigator_connect_context_;
peter7ac37dd2015-03-18 14:57:30187 scoped_refptr<PlatformNotificationContextImpl> platform_notification_context_;
jkarlin901d507a2015-04-20 19:23:18188 scoped_refptr<BackgroundSyncContextImpl> background_sync_context_;
[email protected]4c3a23582012-08-18 08:54:34189
mlamouri6cdca912015-01-15 17:04:08190 // Raw pointer that should always be valid. The BrowserContext owns the
191 // StoragePartitionImplMap which then owns StoragePartitionImpl. When the
192 // BrowserContext is destroyed, |this| will be destroyed too.
193 BrowserContext* browser_context_;
194
[email protected]4c3a23582012-08-18 08:54:34195 DISALLOW_COPY_AND_ASSIGN(StoragePartitionImpl);
196};
197
198} // namespace content
199
200#endif // CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_