blob: 97128378fdf180d010ea9602221a91384e10da39 [file] [log] [blame]
[email protected]4c3a23582012-08-18 08:54:341// 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"
9#include "base/file_path.h"
[email protected]1bc28312012-11-08 08:31:5310#include "base/gtest_prod_util.h"
[email protected]4c3a23582012-08-18 08:54:3411#include "base/memory/ref_counted.h"
12#include "content/browser/appcache/chrome_appcache_service.h"
13#include "content/browser/dom_storage/dom_storage_context_impl.h"
14#include "content/browser/in_process_webkit/indexed_db_context_impl.h"
15#include "content/public/browser/storage_partition.h"
16
17namespace content {
18
19class StoragePartitionImpl : public StoragePartition {
20 public:
21 virtual ~StoragePartitionImpl();
22
[email protected]4c3a23582012-08-18 08:54:3423 // StoragePartition interface.
[email protected]71ace012012-09-16 04:01:0824 virtual FilePath GetPath() OVERRIDE;
[email protected]10eb28162012-09-18 03:04:0925 virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE;
26 virtual net::URLRequestContextGetter* GetMediaURLRequestContext() OVERRIDE;
[email protected]4c3a23582012-08-18 08:54:3427 virtual quota::QuotaManager* GetQuotaManager() OVERRIDE;
28 virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE;
29 virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE;
30 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE;
31 virtual DOMStorageContextImpl* GetDOMStorageContext() OVERRIDE;
32 virtual IndexedDBContextImpl* GetIndexedDBContext() OVERRIDE;
33
34 private:
[email protected]1bc28312012-11-08 08:31:5335 FRIEND_TEST_ALL_PREFIXES(StoragePartitionConfigTest, OperatorLess);
[email protected]10eb28162012-09-18 03:04:0936 friend class StoragePartitionImplMap;
37
[email protected]1bc28312012-11-08 08:31:5338 // Each StoragePartition is uniquely identified by which partition domain
39 // it belongs to (such as an app or the browser itself), the user supplied
40 // partition name and the bit indicating whether it should be persisted on
41 // disk or not. This structure contains those elements and is used as
42 // uniqueness key to lookup StoragePartition objects in the global map.
43 //
44 // TODO(nasko): It is equivalent, though not identical to the same structure
45 // that lives in chrome profiles. The difference is that this one has
46 // partition_domain and partition_name separate, while the latter one has
47 // the path produced by combining the two pieces together.
48 // The fix for http://crbug.com/159193 will remove the chrome version.
49 struct StoragePartitionConfig {
50 const std::string partition_domain;
51 const std::string partition_name;
52 const bool in_memory;
53
54 StoragePartitionConfig(const std::string& domain,
55 const std::string& partition,
56 const bool& in_memory_only)
57 : partition_domain(domain),
58 partition_name(partition),
59 in_memory(in_memory_only) {}
60 };
61
62 // Functor for operator <.
63 struct StoragePartitionConfigLess {
64 bool operator()(const StoragePartitionConfig& lhs,
65 const StoragePartitionConfig& rhs) const {
66 if (lhs.partition_domain != rhs.partition_domain)
67 return lhs.partition_domain < rhs.partition_domain;
68 else if (lhs.partition_name != rhs.partition_name)
69 return lhs.partition_name < rhs.partition_name;
70 else if (lhs.in_memory != rhs.in_memory)
71 return lhs.in_memory < rhs.in_memory;
72 else
73 return false;
74 }
75 };
76
77 // TODO(ajwong): Break the direct dependency on |context|. We only
78 // need 3 pieces of info from it.
79 static StoragePartitionImpl* Create(
80 BrowserContext* context,
81 const StoragePartitionConfig& partition_id,
82 const FilePath& profile_path);
83
84 // Returns the relative path from the profile's base directory, to the
85 // directory that holds all the state for storage contexts in
86 // |partition_config|. If any of the strings in |partition_config| contain
87 // embedded nuls, the values will be truncated and only the portion prior to
88 // the nul will be used.
89 static FilePath GetStoragePartitionPath(
90 const StoragePartitionConfig& partition_config);
91
[email protected]10eb28162012-09-18 03:04:0992 StoragePartitionImpl(
93 const FilePath& partition_path,
94 quota::QuotaManager* quota_manager,
95 ChromeAppCacheService* appcache_service,
96 fileapi::FileSystemContext* filesystem_context,
97 webkit_database::DatabaseTracker* database_tracker,
98 DOMStorageContextImpl* dom_storage_context,
99 IndexedDBContextImpl* indexed_db_context);
100
101 // Used by StoragePartitionImplMap.
102 //
103 // TODO(ajwong): These should be taken in the constructor and in Create() but
104 // because the URLRequestContextGetter still lives in Profile with a tangled
105 // initialization, if we try to retrieve the URLRequestContextGetter()
106 // before the default StoragePartition is created, we end up reentering the
107 // construction and double-initializing. For now, we retain the legacy
108 // behavior while allowing StoragePartitionImpl to expose these accessors by
109 // letting StoragePartitionImplMap call these two private settings at the
110 // appropriate time. These should move back into the constructor once
111 // URLRequestContextGetter's lifetime is sorted out. We should also move the
112 // PostCreateInitialization() out of StoragePartitionImplMap.
113 void SetURLRequestContext(net::URLRequestContextGetter* url_request_context);
114 void SetMediaURLRequestContext(
115 net::URLRequestContextGetter* media_url_request_context);
[email protected]4c3a23582012-08-18 08:54:34116
117 FilePath partition_path_;
[email protected]10eb28162012-09-18 03:04:09118 scoped_refptr<net::URLRequestContextGetter> url_request_context_;
119 scoped_refptr<net::URLRequestContextGetter> media_url_request_context_;
[email protected]4c3a23582012-08-18 08:54:34120 scoped_refptr<quota::QuotaManager> quota_manager_;
121 scoped_refptr<ChromeAppCacheService> appcache_service_;
122 scoped_refptr<fileapi::FileSystemContext> filesystem_context_;
123 scoped_refptr<webkit_database::DatabaseTracker> database_tracker_;
124 scoped_refptr<DOMStorageContextImpl> dom_storage_context_;
125 scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
126
127 DISALLOW_COPY_AND_ASSIGN(StoragePartitionImpl);
128};
129
130} // namespace content
131
132#endif // CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_