Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / content / browser / storage_partition_impl.h
blobff922f713c1b060754efdc8d2a5527985174f21a
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/common/content_export.h"
22 #include "content/public/browser/storage_partition.h"
23 #include "storage/browser/quota/special_storage_policy.h"
25 namespace content {
27 class StoragePartitionImpl : public StoragePartition {
28 public:
29 CONTENT_EXPORT ~StoragePartitionImpl() override;
31 // 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);
35 CONTENT_EXPORT void OverrideQuotaManagerForTesting(
36 storage::QuotaManager* quota_manager);
37 CONTENT_EXPORT void OverrideSpecialStoragePolicyForTesting(
38 storage::SpecialStoragePolicy* special_storage_policy);
40 // StoragePartition interface.
41 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;
50 CacheStorageContextImpl* GetCacheStorageContext() override;
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;
58 BackgroundSyncContextImpl* GetBackgroundSyncContext() override;
60 void ClearDataForOrigin(uint32 remove_mask,
61 uint32 quota_storage_remove_mask,
62 const GURL& storage_origin,
63 net::URLRequestContextGetter* request_context_getter,
64 const base::Closure& callback) override;
65 void ClearData(uint32 remove_mask,
66 uint32 quota_storage_remove_mask,
67 const GURL& storage_origin,
68 const OriginMatcherFunction& origin_matcher,
69 const base::Time begin,
70 const base::Time end,
71 const base::Closure& callback) override;
73 void Flush() override;
75 WebRTCIdentityStore* GetWebRTCIdentityStore();
77 // Can return nullptr while |this| is being destroyed.
78 BrowserContext* browser_context() const;
80 struct DataDeletionHelper;
81 struct QuotaManagedDataDeletionHelper;
83 private:
84 friend class StoragePartitionImplMap;
85 FRIEND_TEST_ALL_PREFIXES(StoragePartitionShaderClearTest, ClearShaderCache);
86 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
87 RemoveQuotaManagedDataForeverBoth);
88 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
89 RemoveQuotaManagedDataForeverOnlyTemporary);
90 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
91 RemoveQuotaManagedDataForeverOnlyPersistent);
92 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
93 RemoveQuotaManagedDataForeverNeither);
94 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
95 RemoveQuotaManagedDataForeverSpecificOrigin);
96 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
97 RemoveQuotaManagedDataForLastHour);
98 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
99 RemoveQuotaManagedDataForLastWeek);
100 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
101 RemoveQuotaManagedUnprotectedOrigins);
102 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
103 RemoveQuotaManagedProtectedSpecificOrigin);
104 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
105 RemoveQuotaManagedProtectedOrigins);
106 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
107 RemoveQuotaManagedIgnoreDevTools);
108 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, RemoveCookieForever);
109 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, RemoveCookieLastHour);
110 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
111 RemoveUnprotectedLocalStorageForever);
112 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
113 RemoveProtectedLocalStorageForever);
114 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest,
115 RemoveLocalStorageForLastWeek);
117 // The |partition_path| is the absolute path to the root of this
118 // StoragePartition's on-disk storage.
120 // If |in_memory| is true, the |partition_path| is (ab)used as a way of
121 // distinguishing different in-memory partitions, but nothing is persisted
122 // on to disk.
123 static StoragePartitionImpl* Create(BrowserContext* context,
124 bool in_memory,
125 const base::FilePath& profile_path);
127 CONTENT_EXPORT StoragePartitionImpl(
128 BrowserContext* browser_context,
129 const base::FilePath& partition_path,
130 storage::QuotaManager* quota_manager,
131 ChromeAppCacheService* appcache_service,
132 storage::FileSystemContext* filesystem_context,
133 storage::DatabaseTracker* database_tracker,
134 DOMStorageContextWrapper* dom_storage_context,
135 IndexedDBContextImpl* indexed_db_context,
136 CacheStorageContextImpl* cache_storage_context,
137 ServiceWorkerContextWrapper* service_worker_context,
138 WebRTCIdentityStore* webrtc_identity_store,
139 storage::SpecialStoragePolicy* special_storage_policy,
140 GeofencingManager* geofencing_manager,
141 HostZoomLevelContext* host_zoom_level_context,
142 NavigatorConnectContextImpl* navigator_connect_context,
143 PlatformNotificationContextImpl* platform_notification_context,
144 BackgroundSyncContextImpl* background_sync_context);
146 void ClearDataImpl(uint32 remove_mask,
147 uint32 quota_storage_remove_mask,
148 const GURL& remove_origin,
149 const OriginMatcherFunction& origin_matcher,
150 net::URLRequestContextGetter* rq_context,
151 const base::Time begin,
152 const base::Time end,
153 const base::Closure& callback);
155 // Used by StoragePartitionImplMap.
157 // TODO(ajwong): These should be taken in the constructor and in Create() but
158 // because the URLRequestContextGetter still lives in Profile with a tangled
159 // initialization, if we try to retrieve the URLRequestContextGetter()
160 // before the default StoragePartition is created, we end up reentering the
161 // construction and double-initializing. For now, we retain the legacy
162 // behavior while allowing StoragePartitionImpl to expose these accessors by
163 // letting StoragePartitionImplMap call these two private settings at the
164 // appropriate time. These should move back into the constructor once
165 // URLRequestContextGetter's lifetime is sorted out. We should also move the
166 // PostCreateInitialization() out of StoragePartitionImplMap.
167 CONTENT_EXPORT void SetURLRequestContext(
168 net::URLRequestContextGetter* url_request_context);
169 void SetMediaURLRequestContext(
170 net::URLRequestContextGetter* media_url_request_context);
172 base::FilePath partition_path_;
173 scoped_refptr<net::URLRequestContextGetter> url_request_context_;
174 scoped_refptr<net::URLRequestContextGetter> media_url_request_context_;
175 scoped_refptr<storage::QuotaManager> quota_manager_;
176 scoped_refptr<ChromeAppCacheService> appcache_service_;
177 scoped_refptr<storage::FileSystemContext> filesystem_context_;
178 scoped_refptr<storage::DatabaseTracker> database_tracker_;
179 scoped_refptr<DOMStorageContextWrapper> dom_storage_context_;
180 scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
181 scoped_refptr<CacheStorageContextImpl> cache_storage_context_;
182 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
183 scoped_refptr<WebRTCIdentityStore> webrtc_identity_store_;
184 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
185 scoped_refptr<GeofencingManager> geofencing_manager_;
186 scoped_refptr<HostZoomLevelContext> host_zoom_level_context_;
187 scoped_refptr<NavigatorConnectContextImpl> navigator_connect_context_;
188 scoped_refptr<PlatformNotificationContextImpl> platform_notification_context_;
189 scoped_refptr<BackgroundSyncContextImpl> background_sync_context_;
191 // Raw pointer that should always be valid. The BrowserContext owns the
192 // StoragePartitionImplMap which then owns StoragePartitionImpl. When the
193 // BrowserContext is destroyed, |this| will be destroyed too.
194 BrowserContext* browser_context_;
196 DISALLOW_COPY_AND_ASSIGN(StoragePartitionImpl);
199 } // namespace content
201 #endif // CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_