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