Reland: Plugin Placeholders: Refactor for platforms that don't support plugins
[chromium-blink-merge.git] / content / browser / storage_partition_impl.h
blob2500045039f2bdb1d27f175870ff59e29af55638
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 #ifndef CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_
6 #define CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_
8 #include "base/compiler_specific.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/ref_counted.h"
11 #include "content/browser/appcache/chrome_appcache_service.h"
12 #include "content/browser/background_sync/background_sync_context_impl.h"
13 #include "content/browser/cache_storage/cache_storage_context_impl.h"
14 #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
15 #include "content/browser/host_zoom_level_context.h"
16 #include "content/browser/indexed_db/indexed_db_context_impl.h"
17 #include "content/browser/media/webrtc_identity_store.h"
18 #include "content/browser/navigator_connect/navigator_connect_context_impl.h"
19 #include "content/browser/notifications/platform_notification_context_impl.h"
20 #include "content/browser/service_worker/service_worker_context_wrapper.h"
21 #include "content/browser/service_worker/stashed_port_manager.h"
22 #include "content/common/content_export.h"
23 #include "content/public/browser/storage_partition.h"
24 #include "storage/browser/quota/special_storage_policy.h"
26 namespace content {
28 class StoragePartitionImpl : public StoragePartition {
29 public:
30 CONTENT_EXPORT ~StoragePartitionImpl() override;
32 // Quota managed data uses a different bitmask for types than
33 // StoragePartition uses. This method generates that mask.
34 CONTENT_EXPORT static int GenerateQuotaClientMask(uint32 remove_mask);
36 CONTENT_EXPORT void OverrideQuotaManagerForTesting(
37 storage::QuotaManager* quota_manager);
38 CONTENT_EXPORT void OverrideSpecialStoragePolicyForTesting(
39 storage::SpecialStoragePolicy* special_storage_policy);
41 // StoragePartition interface.
42 base::FilePath GetPath() override;
43 net::URLRequestContextGetter* GetURLRequestContext() override;
44 net::URLRequestContextGetter* GetMediaURLRequestContext() override;
45 storage::QuotaManager* GetQuotaManager() override;
46 ChromeAppCacheService* GetAppCacheService() override;
47 storage::FileSystemContext* GetFileSystemContext() override;
48 storage::DatabaseTracker* GetDatabaseTracker() override;
49 DOMStorageContextWrapper* GetDOMStorageContext() override;
50 IndexedDBContextImpl* GetIndexedDBContext() override;
51 // TODO(jsbell): Expose this on the public API as well. crbug.com/466371
52 CacheStorageContextImpl* GetCacheStorageContext();
53 ServiceWorkerContextWrapper* GetServiceWorkerContext() override;
54 GeofencingManager* GetGeofencingManager() override;
55 HostZoomMap* GetHostZoomMap() override;
56 HostZoomLevelContext* GetHostZoomLevelContext() override;
57 ZoomLevelDelegate* GetZoomLevelDelegate() override;
58 NavigatorConnectContextImpl* GetNavigatorConnectContext() override;
59 PlatformNotificationContextImpl* GetPlatformNotificationContext() override;
60 BackgroundSyncContextImpl* GetBackgroundSyncContext();
61 StashedPortManager* GetStashedPortManager();
63 void ClearDataForOrigin(uint32 remove_mask,
64 uint32 quota_storage_remove_mask,
65 const GURL& storage_origin,
66 net::URLRequestContextGetter* request_context_getter,
67 const base::Closure& callback) override;
68 void ClearData(uint32 remove_mask,
69 uint32 quota_storage_remove_mask,
70 const GURL& storage_origin,
71 const OriginMatcherFunction& origin_matcher,
72 const base::Time begin,
73 const base::Time end,
74 const base::Closure& callback) override;
76 void Flush() override;
78 WebRTCIdentityStore* GetWebRTCIdentityStore();
80 // Can return nullptr while |this| is being destroyed.
81 BrowserContext* browser_context() const;
83 struct DataDeletionHelper;
84 struct QuotaManagedDataDeletionHelper;
86 private:
87 friend class StoragePartitionImplMap;
88 FRIEND_TEST_ALL_PREFIXES(StoragePartitionShaderClearTest, ClearShaderCache);
89 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
90 RemoveQuotaManagedDataForeverBoth);
91 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
92 RemoveQuotaManagedDataForeverOnlyTemporary);
93 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
94 RemoveQuotaManagedDataForeverOnlyPersistent);
95 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
96 RemoveQuotaManagedDataForeverNeither);
97 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
98 RemoveQuotaManagedDataForeverSpecificOrigin);
99 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
100 RemoveQuotaManagedDataForLastHour);
101 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
102 RemoveQuotaManagedDataForLastWeek);
103 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
104 RemoveQuotaManagedUnprotectedOrigins);
105 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
106 RemoveQuotaManagedProtectedSpecificOrigin);
107 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
108 RemoveQuotaManagedProtectedOrigins);
109 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
110 RemoveQuotaManagedIgnoreDevTools);
111 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, RemoveCookieForever);
112 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, RemoveCookieLastHour);
113 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
114 RemoveUnprotectedLocalStorageForever);
115 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
116 RemoveProtectedLocalStorageForever);
117 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
118 RemoveLocalStorageForLastWeek);
120 // The |partition_path| is the absolute path to the root of this
121 // StoragePartition's on-disk storage.
123 // If |in_memory| is true, the |partition_path| is (ab)used as a way of
124 // distinguishing different in-memory partitions, but nothing is persisted
125 // on to disk.
126 static StoragePartitionImpl* Create(BrowserContext* context,
127 bool in_memory,
128 const base::FilePath& profile_path);
130 CONTENT_EXPORT StoragePartitionImpl(
131 BrowserContext* browser_context,
132 const base::FilePath& partition_path,
133 storage::QuotaManager* quota_manager,
134 ChromeAppCacheService* appcache_service,
135 storage::FileSystemContext* filesystem_context,
136 storage::DatabaseTracker* database_tracker,
137 DOMStorageContextWrapper* dom_storage_context,
138 IndexedDBContextImpl* indexed_db_context,
139 CacheStorageContextImpl* cache_storage_context,
140 ServiceWorkerContextWrapper* service_worker_context,
141 WebRTCIdentityStore* webrtc_identity_store,
142 storage::SpecialStoragePolicy* special_storage_policy,
143 GeofencingManager* geofencing_manager,
144 HostZoomLevelContext* host_zoom_level_context,
145 NavigatorConnectContextImpl* navigator_connect_context,
146 PlatformNotificationContextImpl* platform_notification_context,
147 BackgroundSyncContextImpl* background_sync_context,
148 StashedPortManager* stashed_port_manager);
150 void ClearDataImpl(uint32 remove_mask,
151 uint32 quota_storage_remove_mask,
152 const GURL& remove_origin,
153 const OriginMatcherFunction& origin_matcher,
154 net::URLRequestContextGetter* rq_context,
155 const base::Time begin,
156 const base::Time end,
157 const base::Closure& callback);
159 // Used by StoragePartitionImplMap.
161 // TODO(ajwong): These should be taken in the constructor and in Create() but
162 // because the URLRequestContextGetter still lives in Profile with a tangled
163 // initialization, if we try to retrieve the URLRequestContextGetter()
164 // before the default StoragePartition is created, we end up reentering the
165 // construction and double-initializing. For now, we retain the legacy
166 // behavior while allowing StoragePartitionImpl to expose these accessors by
167 // letting StoragePartitionImplMap call these two private settings at the
168 // appropriate time. These should move back into the constructor once
169 // URLRequestContextGetter's lifetime is sorted out. We should also move the
170 // PostCreateInitialization() out of StoragePartitionImplMap.
171 CONTENT_EXPORT void SetURLRequestContext(
172 net::URLRequestContextGetter* url_request_context);
173 void SetMediaURLRequestContext(
174 net::URLRequestContextGetter* media_url_request_context);
176 base::FilePath partition_path_;
177 scoped_refptr<net::URLRequestContextGetter> url_request_context_;
178 scoped_refptr<net::URLRequestContextGetter> media_url_request_context_;
179 scoped_refptr<storage::QuotaManager> quota_manager_;
180 scoped_refptr<ChromeAppCacheService> appcache_service_;
181 scoped_refptr<storage::FileSystemContext> filesystem_context_;
182 scoped_refptr<storage::DatabaseTracker> database_tracker_;
183 scoped_refptr<DOMStorageContextWrapper> dom_storage_context_;
184 scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
185 scoped_refptr<CacheStorageContextImpl> cache_storage_context_;
186 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
187 scoped_refptr<WebRTCIdentityStore> webrtc_identity_store_;
188 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
189 scoped_refptr<GeofencingManager> geofencing_manager_;
190 scoped_refptr<HostZoomLevelContext> host_zoom_level_context_;
191 scoped_refptr<NavigatorConnectContextImpl> navigator_connect_context_;
192 scoped_refptr<PlatformNotificationContextImpl> platform_notification_context_;
193 scoped_refptr<BackgroundSyncContextImpl> background_sync_context_;
194 scoped_refptr<StashedPortManager> stashed_port_manager_;
196 // Raw pointer that should always be valid. The BrowserContext owns the
197 // StoragePartitionImplMap which then owns StoragePartitionImpl. When the
198 // BrowserContext is destroyed, |this| will be destroyed too.
199 BrowserContext* browser_context_;
201 DISALLOW_COPY_AND_ASSIGN(StoragePartitionImpl);
204 } // namespace content
206 #endif // CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_