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