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/indexed_db/indexed_db_context_impl.h"
14 #include "content/browser/media/webrtc_identity_store.h"
15 #include "content/browser/service_worker/service_worker_context.h"
16 #include "content/common/content_export.h"
17 #include "content/public/browser/storage_partition.h"
21 class StoragePartitionImpl : public StoragePartition {
23 CONTENT_EXPORT virtual ~StoragePartitionImpl();
25 // StoragePartition interface.
26 virtual base::FilePath GetPath() OVERRIDE;
27 virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE;
28 virtual net::URLRequestContextGetter* GetMediaURLRequestContext() OVERRIDE;
29 virtual quota::QuotaManager* GetQuotaManager() OVERRIDE;
30 virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE;
31 virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE;
32 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE;
33 virtual DOMStorageContextWrapper* GetDOMStorageContext() OVERRIDE;
34 virtual IndexedDBContextImpl* GetIndexedDBContext() OVERRIDE;
36 virtual void ClearDataForOrigin(
38 uint32 quota_storage_remove_mask,
39 const GURL& storage_origin,
40 net::URLRequestContextGetter* request_context_getter) OVERRIDE;
41 virtual void ClearDataForUnboundedRange(
43 uint32 quota_storage_remove_mask) OVERRIDE;
44 virtual void ClearDataForRange(uint32 remove_mask,
45 uint32 quota_storage_remove_mask,
46 const base::Time& begin,
47 const base::Time& end,
48 const base::Closure& callback) OVERRIDE;
50 ServiceWorkerContext* GetServiceWorkerContext();
52 WebRTCIdentityStore* GetWebRTCIdentityStore();
54 struct DataDeletionHelper;
55 struct QuotaManagedDataDeletionHelper;
58 friend class StoragePartitionImplMap;
59 FRIEND_TEST_ALL_PREFIXES(StoragePartitionShaderClearTest, ClearShaderCache);
61 // The |partition_path| is the absolute path to the root of this
62 // StoragePartition's on-disk storage.
64 // If |in_memory| is true, the |partition_path| is (ab)used as a way of
65 // distinguishing different in-memory partitions, but nothing is persisted
67 static StoragePartitionImpl* Create(BrowserContext* context,
69 const base::FilePath& profile_path);
71 // Quota managed data uses a different bitmask for types than
72 // StoragePartition uses. This method generates that mask.
73 static int GenerateQuotaClientMask(uint32 remove_mask);
75 CONTENT_EXPORT StoragePartitionImpl(
76 const base::FilePath& partition_path,
77 quota::QuotaManager* quota_manager,
78 ChromeAppCacheService* appcache_service,
79 fileapi::FileSystemContext* filesystem_context,
80 webkit_database::DatabaseTracker* database_tracker,
81 DOMStorageContextWrapper* dom_storage_context,
82 IndexedDBContextImpl* indexed_db_context,
83 ServiceWorkerContext* service_worker_context,
84 WebRTCIdentityStore* webrtc_identity_store);
86 void ClearDataImpl(uint32 remove_mask,
87 uint32 quota_storage_remove_mask,
88 const GURL& remove_origin,
89 net::URLRequestContextGetter* rq_context,
90 const base::Time begin,
92 const base::Closure& callback);
94 // Used by StoragePartitionImplMap.
96 // TODO(ajwong): These should be taken in the constructor and in Create() but
97 // because the URLRequestContextGetter still lives in Profile with a tangled
98 // initialization, if we try to retrieve the URLRequestContextGetter()
99 // before the default StoragePartition is created, we end up reentering the
100 // construction and double-initializing. For now, we retain the legacy
101 // behavior while allowing StoragePartitionImpl to expose these accessors by
102 // letting StoragePartitionImplMap call these two private settings at the
103 // appropriate time. These should move back into the constructor once
104 // URLRequestContextGetter's lifetime is sorted out. We should also move the
105 // PostCreateInitialization() out of StoragePartitionImplMap.
106 void SetURLRequestContext(net::URLRequestContextGetter* url_request_context);
107 void SetMediaURLRequestContext(
108 net::URLRequestContextGetter* media_url_request_context);
110 base::FilePath partition_path_;
111 scoped_refptr<net::URLRequestContextGetter> url_request_context_;
112 scoped_refptr<net::URLRequestContextGetter> media_url_request_context_;
113 scoped_refptr<quota::QuotaManager> quota_manager_;
114 scoped_refptr<ChromeAppCacheService> appcache_service_;
115 scoped_refptr<fileapi::FileSystemContext> filesystem_context_;
116 scoped_refptr<webkit_database::DatabaseTracker> database_tracker_;
117 scoped_refptr<DOMStorageContextWrapper> dom_storage_context_;
118 scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
119 scoped_refptr<ServiceWorkerContext> service_worker_context_;
120 scoped_refptr<WebRTCIdentityStore> webrtc_identity_store_;
122 DISALLOW_COPY_AND_ASSIGN(StoragePartitionImpl);
125 } // namespace content
127 #endif // CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_