OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_ |
6 #define CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_ | 6 #define CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/gtest_prod_util.h" |
10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
11 #include "content/browser/appcache/chrome_appcache_service.h" | 12 #include "content/browser/appcache/chrome_appcache_service.h" |
12 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 13 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
13 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" | 14 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" |
14 #include "content/public/browser/storage_partition.h" | 15 #include "content/public/browser/storage_partition.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 class StoragePartitionImpl : public StoragePartition { | 19 class StoragePartitionImpl : public StoragePartition { |
19 public: | 20 public: |
20 virtual ~StoragePartitionImpl(); | 21 virtual ~StoragePartitionImpl(); |
21 | 22 |
22 // TODO(ajwong): Break the direct dependency on |context|. We only | |
23 // need 3 pieces of info from it. | |
24 static StoragePartitionImpl* Create(BrowserContext* context, | |
25 const std::string& partition_id, | |
26 const FilePath& profile_path); | |
27 | |
28 // StoragePartition interface. | 23 // StoragePartition interface. |
29 virtual FilePath GetPath() OVERRIDE; | 24 virtual FilePath GetPath() OVERRIDE; |
30 virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE; | 25 virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE; |
31 virtual net::URLRequestContextGetter* GetMediaURLRequestContext() OVERRIDE; | 26 virtual net::URLRequestContextGetter* GetMediaURLRequestContext() OVERRIDE; |
32 virtual quota::QuotaManager* GetQuotaManager() OVERRIDE; | 27 virtual quota::QuotaManager* GetQuotaManager() OVERRIDE; |
33 virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE; | 28 virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE; |
34 virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE; | 29 virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE; |
35 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE; | 30 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE; |
36 virtual DOMStorageContextImpl* GetDOMStorageContext() OVERRIDE; | 31 virtual DOMStorageContextImpl* GetDOMStorageContext() OVERRIDE; |
37 virtual IndexedDBContextImpl* GetIndexedDBContext() OVERRIDE; | 32 virtual IndexedDBContextImpl* GetIndexedDBContext() OVERRIDE; |
38 | 33 |
39 private: | 34 private: |
| 35 FRIEND_TEST_ALL_PREFIXES(StoragePartitionConfigTest, OperatorLess); |
40 friend class StoragePartitionImplMap; | 36 friend class StoragePartitionImplMap; |
41 | 37 |
| 38 // 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 |
42 StoragePartitionImpl( | 92 StoragePartitionImpl( |
43 const FilePath& partition_path, | 93 const FilePath& partition_path, |
44 quota::QuotaManager* quota_manager, | 94 quota::QuotaManager* quota_manager, |
45 ChromeAppCacheService* appcache_service, | 95 ChromeAppCacheService* appcache_service, |
46 fileapi::FileSystemContext* filesystem_context, | 96 fileapi::FileSystemContext* filesystem_context, |
47 webkit_database::DatabaseTracker* database_tracker, | 97 webkit_database::DatabaseTracker* database_tracker, |
48 DOMStorageContextImpl* dom_storage_context, | 98 DOMStorageContextImpl* dom_storage_context, |
49 IndexedDBContextImpl* indexed_db_context); | 99 IndexedDBContextImpl* indexed_db_context); |
50 | 100 |
51 // Used by StoragePartitionImplMap. | 101 // Used by StoragePartitionImplMap. |
(...skipping 21 matching lines...) Expand all Loading... |
73 scoped_refptr<webkit_database::DatabaseTracker> database_tracker_; | 123 scoped_refptr<webkit_database::DatabaseTracker> database_tracker_; |
74 scoped_refptr<DOMStorageContextImpl> dom_storage_context_; | 124 scoped_refptr<DOMStorageContextImpl> dom_storage_context_; |
75 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; | 125 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; |
76 | 126 |
77 DISALLOW_COPY_AND_ASSIGN(StoragePartitionImpl); | 127 DISALLOW_COPY_AND_ASSIGN(StoragePartitionImpl); |
78 }; | 128 }; |
79 | 129 |
80 } // namespace content | 130 } // namespace content |
81 | 131 |
82 #endif // CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_ | 132 #endif // CONTENT_BROWSER_STORAGE_PARTITION_IMPL_H_ |
OLD | NEW |