[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 | |
| 8 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 9 | #include "base/files/file_path.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 10 | #include "base/memory/ref_counted.h" |
| 11 | #include "content/browser/appcache/chrome_appcache_service.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 12 | #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
[email protected] | c4d28166 | 2013-03-31 00:35:08 | [diff] [blame] | 13 | #include "content/browser/indexed_db/indexed_db_context_impl.h" |
[email protected] | d322066 | 2013-07-01 21:21:46 | [diff] [blame] | 14 | #include "content/browser/media/webrtc_identity_store.h" |
[email protected] | 1f1e856 | 2013-11-13 05:05:16 | [diff] [blame] | 15 | #include "content/browser/service_worker/service_worker_context_wrapper.h" |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 16 | #include "content/common/content_export.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 17 | #include "content/public/browser/storage_partition.h" |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 18 | #include "webkit/browser/quota/special_storage_policy.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 19 | |
| 20 | namespace content { |
| 21 | |
| 22 | class StoragePartitionImpl : public StoragePartition { |
| 23 | public: |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 24 | CONTENT_EXPORT virtual ~StoragePartitionImpl(); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 25 | |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 26 | // Quota managed data uses a different bitmask for types than |
| 27 | // StoragePartition uses. This method generates that mask. |
| 28 | CONTENT_EXPORT static int GenerateQuotaClientMask(uint32 remove_mask); |
| 29 | |
| 30 | CONTENT_EXPORT void OverrideQuotaManagerForTesting( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 31 | storage::QuotaManager* quota_manager); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 32 | CONTENT_EXPORT void OverrideSpecialStoragePolicyForTesting( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 33 | storage::SpecialStoragePolicy* special_storage_policy); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 34 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 35 | // StoragePartition interface. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 36 | virtual base::FilePath GetPath() OVERRIDE; |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 37 | virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE; |
| 38 | virtual net::URLRequestContextGetter* GetMediaURLRequestContext() OVERRIDE; |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 39 | virtual storage::QuotaManager* GetQuotaManager() OVERRIDE; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 40 | virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE; |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 41 | virtual storage::FileSystemContext* GetFileSystemContext() OVERRIDE; |
| 42 | virtual storage::DatabaseTracker* GetDatabaseTracker() OVERRIDE; |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 43 | virtual DOMStorageContextWrapper* GetDOMStorageContext() OVERRIDE; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 44 | virtual IndexedDBContextImpl* GetIndexedDBContext() OVERRIDE; |
[email protected] | 59f7d17 | 2014-01-15 19:31:27 | [diff] [blame] | 45 | virtual ServiceWorkerContextWrapper* GetServiceWorkerContext() OVERRIDE; |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 46 | |
[email protected] | fdf3e13c | 2013-07-31 06:23:46 | [diff] [blame] | 47 | virtual void ClearDataForOrigin( |
| 48 | uint32 remove_mask, |
| 49 | uint32 quota_storage_remove_mask, |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 50 | const GURL& storage_origin, |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 51 | net::URLRequestContextGetter* request_context_getter, |
| 52 | const base::Closure& callback) OVERRIDE; |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 53 | virtual void ClearData(uint32 remove_mask, |
| 54 | uint32 quota_storage_remove_mask, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 55 | const GURL& storage_origin, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 56 | const OriginMatcherFunction& origin_matcher, |
| 57 | const base::Time begin, |
| 58 | const base::Time end, |
| 59 | const base::Closure& callback) OVERRIDE; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 60 | |
[email protected] | d322066 | 2013-07-01 21:21:46 | [diff] [blame] | 61 | WebRTCIdentityStore* GetWebRTCIdentityStore(); |
| 62 | |
[email protected] | fdf3e13c | 2013-07-31 06:23:46 | [diff] [blame] | 63 | struct DataDeletionHelper; |
| 64 | struct QuotaManagedDataDeletionHelper; |
| 65 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 66 | private: |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 67 | friend class StoragePartitionImplMap; |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 68 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionShaderClearTest, ClearShaderCache); |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 69 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 70 | RemoveQuotaManagedDataForeverBoth); |
| 71 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 72 | RemoveQuotaManagedDataForeverOnlyTemporary); |
| 73 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 74 | RemoveQuotaManagedDataForeverOnlyPersistent); |
| 75 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 76 | RemoveQuotaManagedDataForeverNeither); |
| 77 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 78 | RemoveQuotaManagedDataForeverSpecificOrigin); |
| 79 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 80 | RemoveQuotaManagedDataForLastHour); |
| 81 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 82 | RemoveQuotaManagedDataForLastWeek); |
| 83 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 84 | RemoveQuotaManagedUnprotectedOrigins); |
| 85 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 86 | RemoveQuotaManagedProtectedSpecificOrigin); |
| 87 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 88 | RemoveQuotaManagedProtectedOrigins); |
| 89 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 90 | RemoveQuotaManagedIgnoreDevTools); |
| 91 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, RemoveCookieForever); |
| 92 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, RemoveCookieLastHour); |
| 93 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 94 | RemoveUnprotectedLocalStorageForever); |
| 95 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 96 | RemoveProtectedLocalStorageForever); |
| 97 | FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplTest, |
| 98 | RemoveLocalStorageForLastWeek); |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 99 | |
[email protected] | b471cf4 | 2012-11-13 09:11:30 | [diff] [blame] | 100 | // The |partition_path| is the absolute path to the root of this |
| 101 | // StoragePartition's on-disk storage. |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 102 | // |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 103 | // If |in_memory| is true, the |partition_path| is (ab)used as a way of |
[email protected] | b471cf4 | 2012-11-13 09:11:30 | [diff] [blame] | 104 | // distinguishing different in-memory partitions, but nothing is persisted |
| 105 | // on to disk. |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 106 | static StoragePartitionImpl* Create(BrowserContext* context, |
| 107 | bool in_memory, |
| 108 | const base::FilePath& profile_path); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 109 | |
[email protected] | 877e261 | 2013-04-05 05:58:18 | [diff] [blame] | 110 | CONTENT_EXPORT StoragePartitionImpl( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 111 | const base::FilePath& partition_path, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 112 | storage::QuotaManager* quota_manager, |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 113 | ChromeAppCacheService* appcache_service, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 114 | storage::FileSystemContext* filesystem_context, |
| 115 | storage::DatabaseTracker* database_tracker, |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 116 | DOMStorageContextWrapper* dom_storage_context, |
[email protected] | d322066 | 2013-07-01 21:21:46 | [diff] [blame] | 117 | IndexedDBContextImpl* indexed_db_context, |
[email protected] | 1f1e856 | 2013-11-13 05:05:16 | [diff] [blame] | 118 | ServiceWorkerContextWrapper* service_worker_context, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 119 | WebRTCIdentityStore* webrtc_identity_store, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 120 | storage::SpecialStoragePolicy* special_storage_policy); |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 121 | |
[email protected] | fdf3e13c | 2013-07-31 06:23:46 | [diff] [blame] | 122 | void ClearDataImpl(uint32 remove_mask, |
| 123 | uint32 quota_storage_remove_mask, |
[email protected] | 5ff8b2a | 2013-12-28 06:51:42 | [diff] [blame] | 124 | const GURL& remove_origin, |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 125 | const OriginMatcherFunction& origin_matcher, |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 126 | net::URLRequestContextGetter* rq_context, |
[email protected] | fdf3e13c | 2013-07-31 06:23:46 | [diff] [blame] | 127 | const base::Time begin, |
| 128 | const base::Time end, |
| 129 | const base::Closure& callback); |
| 130 | |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 131 | // Used by StoragePartitionImplMap. |
| 132 | // |
| 133 | // TODO(ajwong): These should be taken in the constructor and in Create() but |
| 134 | // because the URLRequestContextGetter still lives in Profile with a tangled |
| 135 | // initialization, if we try to retrieve the URLRequestContextGetter() |
| 136 | // before the default StoragePartition is created, we end up reentering the |
| 137 | // construction and double-initializing. For now, we retain the legacy |
| 138 | // behavior while allowing StoragePartitionImpl to expose these accessors by |
| 139 | // letting StoragePartitionImplMap call these two private settings at the |
| 140 | // appropriate time. These should move back into the constructor once |
| 141 | // URLRequestContextGetter's lifetime is sorted out. We should also move the |
| 142 | // PostCreateInitialization() out of StoragePartitionImplMap. |
[email protected] | 88562b51 | 2013-11-06 21:10:44 | [diff] [blame] | 143 | CONTENT_EXPORT void SetURLRequestContext( |
| 144 | net::URLRequestContextGetter* url_request_context); |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 145 | void SetMediaURLRequestContext( |
| 146 | net::URLRequestContextGetter* media_url_request_context); |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 147 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 148 | base::FilePath partition_path_; |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 149 | scoped_refptr<net::URLRequestContextGetter> url_request_context_; |
| 150 | scoped_refptr<net::URLRequestContextGetter> media_url_request_context_; |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 151 | scoped_refptr<storage::QuotaManager> quota_manager_; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 152 | scoped_refptr<ChromeAppCacheService> appcache_service_; |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 153 | scoped_refptr<storage::FileSystemContext> filesystem_context_; |
| 154 | scoped_refptr<storage::DatabaseTracker> database_tracker_; |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 155 | scoped_refptr<DOMStorageContextWrapper> dom_storage_context_; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 156 | scoped_refptr<IndexedDBContextImpl> indexed_db_context_; |
[email protected] | 1f1e856 | 2013-11-13 05:05:16 | [diff] [blame] | 157 | scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
[email protected] | ec346e0 | 2013-08-08 22:03:53 | [diff] [blame] | 158 | scoped_refptr<WebRTCIdentityStore> webrtc_identity_store_; |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 159 | scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 160 | |
| 161 | DISALLOW_COPY_AND_ASSIGN(StoragePartitionImpl); |
| 162 | }; |
| 163 | |
| 164 | } // namespace content |
| 165 | |
| 166 | #endif // CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_ |