[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_ |
| 6 | #define CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_ |
| 7 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 10 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 11 | #include "base/files/file_path.h" |
thestig | a0e18cd | 2015-09-25 04:58:36 | [diff] [blame] | 12 | #include "base/gtest_prod_util.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
| 15 | #include "content/browser/appcache/chrome_appcache_service.h" |
jkarlin | 901d507a | 2015-04-20 19:23:18 | [diff] [blame] | 16 | #include "content/browser/background_sync/background_sync_context_impl.h" |
jsbell | 279efb4 | 2015-03-31 17:02:46 | [diff] [blame] | 17 | #include "content/browser/cache_storage/cache_storage_context_impl.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 18 | #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 19 | #include "content/browser/host_zoom_level_context.h" |
[email protected] | c4d28166 | 2013-03-31 00:35:08 | [diff] [blame] | 20 | #include "content/browser/indexed_db/indexed_db_context_impl.h" |
mcasas | 6c910df | 2016-02-23 23:27:58 | [diff] [blame] | 21 | #include "content/browser/media/webrtc/webrtc_identity_store.h" |
mek | 59114f6 | 2015-01-27 01:13:52 | [diff] [blame] | 22 | #include "content/browser/navigator_connect/navigator_connect_context_impl.h" |
peter | 7ac37dd | 2015-03-18 14:57:30 | [diff] [blame] | 23 | #include "content/browser/notifications/platform_notification_context_impl.h" |
[email protected] | 1f1e856 | 2013-11-13 05:05:16 | [diff] [blame] | 24 | #include "content/browser/service_worker/service_worker_context_wrapper.h" |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 25 | #include "content/common/content_export.h" |
jam | c912ca3 | 2016-02-24 20:17:31 | [diff] [blame] | 26 | #include "content/common/storage_partition_service.mojom.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 27 | #include "content/public/browser/storage_partition.h" |
yzshen | d414dc34 | 2016-02-25 07:29:27 | [diff] [blame] | 28 | #include "mojo/public/cpp/bindings/binding_set.h" |
pilgrim | e92c5fcd | 2014-09-10 23:31:23 | [diff] [blame] | 29 | #include "storage/browser/quota/special_storage_policy.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 30 | |
| 31 | namespace content { |
| 32 | |
jam | c912ca3 | 2016-02-24 20:17:31 | [diff] [blame] | 33 | class StoragePartitionImpl : public StoragePartition, |
leon.han | 06e5566 | 2016-03-26 17:19:42 | [diff] [blame] | 34 | public mojom::StoragePartitionService { |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 35 | public: |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 36 | CONTENT_EXPORT ~StoragePartitionImpl() override; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 37 | |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 38 | // Quota managed data uses a different bitmask for types than |
| 39 | // StoragePartition uses. This method generates that mask. |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 40 | CONTENT_EXPORT static int GenerateQuotaClientMask(uint32_t remove_mask); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 41 | |
| 42 | CONTENT_EXPORT void OverrideQuotaManagerForTesting( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 43 | storage::QuotaManager* quota_manager); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 44 | CONTENT_EXPORT void OverrideSpecialStoragePolicyForTesting( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 45 | storage::SpecialStoragePolicy* special_storage_policy); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 46 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 47 | // StoragePartition interface. |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 48 | base::FilePath GetPath() override; |
| 49 | net::URLRequestContextGetter* GetURLRequestContext() override; |
| 50 | net::URLRequestContextGetter* GetMediaURLRequestContext() override; |
| 51 | storage::QuotaManager* GetQuotaManager() override; |
| 52 | ChromeAppCacheService* GetAppCacheService() override; |
| 53 | storage::FileSystemContext* GetFileSystemContext() override; |
| 54 | storage::DatabaseTracker* GetDatabaseTracker() override; |
| 55 | DOMStorageContextWrapper* GetDOMStorageContext() override; |
| 56 | IndexedDBContextImpl* GetIndexedDBContext() override; |
jsbell | e1fe969 | 2015-08-22 01:02:42 | [diff] [blame] | 57 | CacheStorageContextImpl* GetCacheStorageContext() override; |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 58 | ServiceWorkerContextWrapper* GetServiceWorkerContext() override; |
mek | 0c55c7f6 | 2014-10-23 22:06:09 | [diff] [blame] | 59 | GeofencingManager* GetGeofencingManager() override; |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 60 | HostZoomMap* GetHostZoomMap() override; |
| 61 | HostZoomLevelContext* GetHostZoomLevelContext() override; |
| 62 | ZoomLevelDelegate* GetZoomLevelDelegate() override; |
mek | 59114f6 | 2015-01-27 01:13:52 | [diff] [blame] | 63 | NavigatorConnectContextImpl* GetNavigatorConnectContext() override; |
peter | 7ac37dd | 2015-03-18 14:57:30 | [diff] [blame] | 64 | PlatformNotificationContextImpl* GetPlatformNotificationContext() override; |
jkarlin | 4e6b342d | 2015-07-31 11:27:57 | [diff] [blame] | 65 | BackgroundSyncContextImpl* GetBackgroundSyncContext() override; |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 66 | |
leon.han | 06e5566 | 2016-03-26 17:19:42 | [diff] [blame] | 67 | // mojom::StoragePartitionService interface. |
jam | c912ca3 | 2016-02-24 20:17:31 | [diff] [blame] | 68 | void OpenLocalStorage( |
jam | 3643404 | 2016-03-15 16:17:09 | [diff] [blame] | 69 | const url::Origin& origin, |
leon.han | 06e5566 | 2016-03-26 17:19:42 | [diff] [blame] | 70 | mojo::InterfaceRequest<mojom::LevelDBWrapper> request) override; |
jam | c912ca3 | 2016-02-24 20:17:31 | [diff] [blame] | 71 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 72 | void ClearDataForOrigin(uint32_t remove_mask, |
| 73 | uint32_t quota_storage_remove_mask, |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 74 | const GURL& storage_origin, |
| 75 | net::URLRequestContextGetter* request_context_getter, |
| 76 | const base::Closure& callback) override; |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 77 | void ClearData(uint32_t remove_mask, |
| 78 | uint32_t quota_storage_remove_mask, |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 79 | const GURL& storage_origin, |
| 80 | const OriginMatcherFunction& origin_matcher, |
| 81 | const base::Time begin, |
| 82 | const base::Time end, |
| 83 | const base::Closure& callback) override; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 84 | |
cmumford | 28d334c | 2015-05-07 22:18:44 | [diff] [blame] | 85 | void Flush() override; |
| 86 | |
[email protected] | d322066 | 2013-07-01 21:21:46 | [diff] [blame] | 87 | WebRTCIdentityStore* GetWebRTCIdentityStore(); |
| 88 | |
mlamouri | 6cdca91 | 2015-01-15 17:04:08 | [diff] [blame] | 89 | // Can return nullptr while |this| is being destroyed. |
| 90 | BrowserContext* browser_context() const; |
| 91 | |
jam | c912ca3 | 2016-02-24 20:17:31 | [diff] [blame] | 92 | // Called by each renderer process once. |
leon.han | 06e5566 | 2016-03-26 17:19:42 | [diff] [blame] | 93 | void Bind(mojo::InterfaceRequest<mojom::StoragePartitionService> request); |
jam | c912ca3 | 2016-02-24 20:17:31 | [diff] [blame] | 94 | |
[email protected] | fdf3e13c | 2013-07-31 06:23:46 | [diff] [blame] | 95 | struct DataDeletionHelper; |
| 96 | struct QuotaManagedDataDeletionHelper; |
| 97 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 98 | private: |
jkarlin | fe08f13 | 2015-11-06 13:18:41 | [diff] [blame] | 99 | friend class BackgroundSyncManagerTest; |
jkarlin | 428a4a3 | 2016-01-08 16:13:24 | [diff] [blame] | 100 | friend class BackgroundSyncServiceImplTest; |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 101 | friend class StoragePartitionImplMap; |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 102 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionShaderClearTest, ClearShaderCache); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 103 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 104 | RemoveQuotaManagedDataForeverBoth); |
| 105 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 106 | RemoveQuotaManagedDataForeverOnlyTemporary); |
| 107 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 108 | RemoveQuotaManagedDataForeverOnlyPersistent); |
| 109 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 110 | RemoveQuotaManagedDataForeverNeither); |
| 111 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 112 | RemoveQuotaManagedDataForeverSpecificOrigin); |
| 113 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 114 | RemoveQuotaManagedDataForLastHour); |
| 115 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 116 | RemoveQuotaManagedDataForLastWeek); |
| 117 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 118 | RemoveQuotaManagedUnprotectedOrigins); |
| 119 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 120 | RemoveQuotaManagedProtectedSpecificOrigin); |
| 121 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 122 | RemoveQuotaManagedProtectedOrigins); |
| 123 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 124 | RemoveQuotaManagedIgnoreDevTools); |
| 125 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, RemoveCookieForever); |
| 126 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, RemoveCookieLastHour); |
| 127 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 128 | RemoveUnprotectedLocalStorageForever); |
| 129 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 130 | RemoveProtectedLocalStorageForever); |
| 131 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 132 | RemoveLocalStorageForLastWeek); |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 133 | |
erg | c112794 | 2016-03-21 18:55:19 | [diff] [blame] | 134 | // |relative_partition_path| is the relative path under |profile_path| to the |
| 135 | // StoragePartition's on-disk-storage. |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 136 | // |
erg | c112794 | 2016-03-21 18:55:19 | [diff] [blame] | 137 | // If |in_memory| is true, the |relative_partition_path| is (ab)used as a way |
| 138 | // of distinguishing different in-memory partitions, but nothing is persisted |
[email protected] | b471cf4 | 2012-11-13 09:11:30 | [diff] [blame] | 139 | // on to disk. |
erg | c112794 | 2016-03-21 18:55:19 | [diff] [blame] | 140 | static StoragePartitionImpl* Create( |
| 141 | BrowserContext* context, |
| 142 | bool in_memory, |
| 143 | const base::FilePath& relative_partition_path); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 144 | |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 145 | CONTENT_EXPORT StoragePartitionImpl( |
mlamouri | 6cdca91 | 2015-01-15 17:04:08 | [diff] [blame] | 146 | BrowserContext* browser_context, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 147 | const base::FilePath& partition_path, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 148 | storage::QuotaManager* quota_manager, |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 149 | ChromeAppCacheService* appcache_service, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 150 | storage::FileSystemContext* filesystem_context, |
| 151 | storage::DatabaseTracker* database_tracker, |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 152 | DOMStorageContextWrapper* dom_storage_context, |
[email protected] | d322066 | 2013-07-01 21:21:46 | [diff] [blame] | 153 | IndexedDBContextImpl* indexed_db_context, |
jsbell | abadb9b | 2015-03-23 21:03:44 | [diff] [blame] | 154 | CacheStorageContextImpl* cache_storage_context, |
[email protected] | 1f1e856 | 2013-11-13 05:05:16 | [diff] [blame] | 155 | ServiceWorkerContextWrapper* service_worker_context, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 156 | WebRTCIdentityStore* webrtc_identity_store, |
mek | 0c55c7f6 | 2014-10-23 22:06:09 | [diff] [blame] | 157 | storage::SpecialStoragePolicy* special_storage_policy, |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 158 | GeofencingManager* geofencing_manager, |
mek | e6b8303 | 2014-12-19 23:35:34 | [diff] [blame] | 159 | HostZoomLevelContext* host_zoom_level_context, |
peter | 7ac37dd | 2015-03-18 14:57:30 | [diff] [blame] | 160 | NavigatorConnectContextImpl* navigator_connect_context, |
jkarlin | 901d507a | 2015-04-20 19:23:18 | [diff] [blame] | 161 | PlatformNotificationContextImpl* platform_notification_context, |
mek | efdd5a7 | 2015-07-22 18:34:49 | [diff] [blame] | 162 | BackgroundSyncContextImpl* background_sync_context); |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 163 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 164 | void ClearDataImpl(uint32_t remove_mask, |
| 165 | uint32_t quota_storage_remove_mask, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 166 | const GURL& remove_origin, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 167 | const OriginMatcherFunction& origin_matcher, |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 168 | net::URLRequestContextGetter* rq_context, |
[email protected] | fdf3e13c | 2013-07-31 06:23:46 | [diff] [blame] | 169 | const base::Time begin, |
| 170 | const base::Time end, |
| 171 | const base::Closure& callback); |
| 172 | |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 173 | // Used by StoragePartitionImplMap. |
| 174 | // |
| 175 | // TODO(ajwong): These should be taken in the constructor and in Create() but |
| 176 | // because the URLRequestContextGetter still lives in Profile with a tangled |
| 177 | // initialization, if we try to retrieve the URLRequestContextGetter() |
| 178 | // before the default StoragePartition is created, we end up reentering the |
| 179 | // construction and double-initializing. For now, we retain the legacy |
| 180 | // behavior while allowing StoragePartitionImpl to expose these accessors by |
| 181 | // letting StoragePartitionImplMap call these two private settings at the |
| 182 | // appropriate time. These should move back into the constructor once |
| 183 | // URLRequestContextGetter's lifetime is sorted out. We should also move the |
| 184 | // PostCreateInitialization() out of StoragePartitionImplMap. |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 185 | CONTENT_EXPORT void SetURLRequestContext( |
| 186 | net::URLRequestContextGetter* url_request_context); |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 187 | void SetMediaURLRequestContext( |
| 188 | net::URLRequestContextGetter* media_url_request_context); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 189 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 190 | base::FilePath partition_path_; |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 191 | scoped_refptr<net::URLRequestContextGetter> url_request_context_; |
| 192 | scoped_refptr<net::URLRequestContextGetter> media_url_request_context_; |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 193 | scoped_refptr<storage::QuotaManager> quota_manager_; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 194 | scoped_refptr<ChromeAppCacheService> appcache_service_; |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 195 | scoped_refptr<storage::FileSystemContext> filesystem_context_; |
| 196 | scoped_refptr<storage::DatabaseTracker> database_tracker_; |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 197 | scoped_refptr<DOMStorageContextWrapper> dom_storage_context_; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 198 | scoped_refptr<IndexedDBContextImpl> indexed_db_context_; |
jsbell | abadb9b | 2015-03-23 21:03:44 | [diff] [blame] | 199 | scoped_refptr<CacheStorageContextImpl> cache_storage_context_; |
[email protected] | 1f1e856 | 2013-11-13 05:05:16 | [diff] [blame] | 200 | scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
[email protected] | ec346e0 | 2013-08-08 22:03:53 | [diff] [blame] | 201 | scoped_refptr<WebRTCIdentityStore> webrtc_identity_store_; |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 202 | scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; |
mek | 0c55c7f6 | 2014-10-23 22:06:09 | [diff] [blame] | 203 | scoped_refptr<GeofencingManager> geofencing_manager_; |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 204 | scoped_refptr<HostZoomLevelContext> host_zoom_level_context_; |
mek | 59114f6 | 2015-01-27 01:13:52 | [diff] [blame] | 205 | scoped_refptr<NavigatorConnectContextImpl> navigator_connect_context_; |
peter | 7ac37dd | 2015-03-18 14:57:30 | [diff] [blame] | 206 | scoped_refptr<PlatformNotificationContextImpl> platform_notification_context_; |
jkarlin | 901d507a | 2015-04-20 19:23:18 | [diff] [blame] | 207 | scoped_refptr<BackgroundSyncContextImpl> background_sync_context_; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 208 | |
leon.han | 06e5566 | 2016-03-26 17:19:42 | [diff] [blame] | 209 | mojo::BindingSet<mojom::StoragePartitionService> bindings_; |
jam | c912ca3 | 2016-02-24 20:17:31 | [diff] [blame] | 210 | |
mlamouri | 6cdca91 | 2015-01-15 17:04:08 | [diff] [blame] | 211 | // Raw pointer that should always be valid. The BrowserContext owns the |
| 212 | // StoragePartitionImplMap which then owns StoragePartitionImpl. When the |
| 213 | // BrowserContext is destroyed, |this| will be destroyed too. |
| 214 | BrowserContext* browser_context_; |
| 215 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 216 | DISALLOW_COPY_AND_ASSIGN(StoragePartitionImpl); |
| 217 | }; |
| 218 | |
| 219 | } // namespace content |
| 220 | |
| 221 | #endif // CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_ |