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 #include "content/browser/storage_partition_impl.h" | 5 #include "content/browser/storage_partition_impl.h" |
6 | 6 |
| 7 #include "base/utf_string_conversions.h" |
7 #include "content/browser/fileapi/browser_file_system_helper.h" | 8 #include "content/browser/fileapi/browser_file_system_helper.h" |
8 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
10 #include "net/url_request/url_request_context_getter.h" | 11 #include "net/url_request/url_request_context_getter.h" |
11 #include "webkit/database/database_tracker.h" | 12 #include "webkit/database/database_tracker.h" |
12 #include "webkit/quota/quota_manager.h" | 13 #include "webkit/quota/quota_manager.h" |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // These constants are used to create the directory structure under the profile | 19 // These constants are used to create the directory structure under the profile |
19 // where renderers with a non-default storage partition keep their persistent | 20 // where renderers with a non-default storage partition keep their persistent |
20 // state. This will contain a set of directories that partially mirror the | 21 // state. This will contain a set of directories that partially mirror the |
21 // directory structure of BrowserContext::GetPath(). | 22 // directory structure of BrowserContext::GetPath(). |
22 // | 23 // |
23 // The kStoragePartitionDirname is contains an extensions directory which is | 24 // The kStoragePartitionDirname is contains an extensions directory which is |
24 // further partitioned by extension id, followed by another level of directories | 25 // further partitioned by extension id, followed by another level of directories |
25 // for the "default" extension storage partition and one directory for each | 26 // for the "default" extension storage partition and one directory for each |
26 // persistent partition used by an extension's browser tags. Example: | 27 // persistent partition used by an extension's browser tags. Example: |
27 // | 28 // |
28 // Storage/ext/ABCDEF/def | 29 // Storage/ext/ABCDEF/def |
29 // Storage/ext/ABCDEF/{hash(guest partition)} | 30 // Storage/ext/ABCDEF/{hash(guest partition)} |
30 // | 31 // |
31 // The code in GetPartitionPath() constructs these path names. | 32 // The code in GetStoragePartitionPath() constructs these path names. |
| 33 // |
| 34 // TODO(nasko): Move extension related path code out of content. |
32 const FilePath::CharType kStoragePartitionDirname[] = | 35 const FilePath::CharType kStoragePartitionDirname[] = |
33 FILE_PATH_LITERAL("Storage"); | 36 FILE_PATH_LITERAL("Storage"); |
34 const FilePath::CharType kExtensionsDirname[] = | 37 const FilePath::CharType kExtensionsDirname[] = |
35 FILE_PATH_LITERAL("ext"); | 38 FILE_PATH_LITERAL("ext"); |
36 const FilePath::CharType kDefaultPartitionDirname[] = | 39 const FilePath::CharType kDefaultPartitionDirname[] = |
37 FILE_PATH_LITERAL("def"); | 40 FILE_PATH_LITERAL("def"); |
38 | 41 |
39 } // namespace | 42 } // namespace |
40 | 43 |
41 // static | 44 // static |
42 FilePath StoragePartition::GetPartitionPath(const std::string& partition_id) { | 45 FilePath StoragePartitionImpl::GetStoragePartitionPath( |
43 if (partition_id.empty()) { | 46 const StoragePartitionConfig& config) { |
44 // The default profile just sits inside the top-level profile directory. | 47 if (config.partition_domain.empty()) |
45 return FilePath(); | 48 return FilePath(); |
46 } | |
47 | 49 |
48 // TODO(ajwong): This should check that we create a valid path name. | 50 CHECK(IsStringUTF8(config.partition_domain)); |
49 CHECK(IsStringASCII(partition_id)); | 51 |
50 return FilePath(kStoragePartitionDirname) | 52 FilePath path = FilePath(kStoragePartitionDirname).Append(kExtensionsDirname) |
51 .Append(kExtensionsDirname) | 53 .Append(FilePath::FromUTF8Unsafe(config.partition_domain)); |
52 .AppendASCII(partition_id) | 54 |
53 .Append(kDefaultPartitionDirname); | 55 if (!config.partition_name.empty()) |
| 56 return path.Append(FilePath::FromUTF8Unsafe(config.partition_name)); |
| 57 |
| 58 return path.Append(kDefaultPartitionDirname); |
54 } | 59 } |
55 | 60 |
56 StoragePartitionImpl::StoragePartitionImpl( | 61 StoragePartitionImpl::StoragePartitionImpl( |
57 const FilePath& partition_path, | 62 const FilePath& partition_path, |
58 quota::QuotaManager* quota_manager, | 63 quota::QuotaManager* quota_manager, |
59 ChromeAppCacheService* appcache_service, | 64 ChromeAppCacheService* appcache_service, |
60 fileapi::FileSystemContext* filesystem_context, | 65 fileapi::FileSystemContext* filesystem_context, |
61 webkit_database::DatabaseTracker* database_tracker, | 66 webkit_database::DatabaseTracker* database_tracker, |
62 DOMStorageContextImpl* dom_storage_context, | 67 DOMStorageContextImpl* dom_storage_context, |
63 IndexedDBContextImpl* indexed_db_context) | 68 IndexedDBContextImpl* indexed_db_context) |
(...skipping 17 matching lines...) Expand all Loading... |
81 } | 86 } |
82 | 87 |
83 if (GetDOMStorageContext()) | 88 if (GetDOMStorageContext()) |
84 GetDOMStorageContext()->Shutdown(); | 89 GetDOMStorageContext()->Shutdown(); |
85 } | 90 } |
86 | 91 |
87 // TODO(ajwong): Break the direct dependency on |context|. We only | 92 // TODO(ajwong): Break the direct dependency on |context|. We only |
88 // need 3 pieces of info from it. | 93 // need 3 pieces of info from it. |
89 StoragePartitionImpl* StoragePartitionImpl::Create( | 94 StoragePartitionImpl* StoragePartitionImpl::Create( |
90 BrowserContext* context, | 95 BrowserContext* context, |
91 const std::string& partition_id, | 96 const StoragePartitionConfig& partition_config, |
92 const FilePath& profile_path) { | 97 const FilePath& profile_path) { |
93 // Ensure that these methods are called on the UI thread, except for | 98 // Ensure that these methods are called on the UI thread, except for |
94 // unittests where a UI thread might not have been created. | 99 // unittests where a UI thread might not have been created. |
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
96 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); | 101 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); |
97 | 102 |
98 FilePath partition_path = | 103 FilePath partition_path = |
99 profile_path.Append(GetPartitionPath(partition_id)); | 104 profile_path.Append(GetStoragePartitionPath(partition_config)); |
100 | 105 |
101 // All of the clients have to be created and registered with the | 106 // All of the clients have to be created and registered with the |
102 // QuotaManager prior to the QuotaManger being used. We do them | 107 // QuotaManager prior to the QuotaManger being used. We do them |
103 // all together here prior to handing out a reference to anything | 108 // all together here prior to handing out a reference to anything |
104 // that utilizes the QuotaManager. | 109 // that utilizes the QuotaManager. |
105 scoped_refptr<quota::QuotaManager> quota_manager = | 110 scoped_refptr<quota::QuotaManager> quota_manager = |
106 new quota::QuotaManager( | 111 new quota::QuotaManager( |
107 context->IsOffTheRecord(), partition_path, | 112 partition_config.in_memory, partition_path, |
108 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 113 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
109 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 114 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
110 context->GetSpecialStoragePolicy()); | 115 context->GetSpecialStoragePolicy()); |
111 | 116 |
112 // Each consumer is responsible for registering its QuotaClient during | 117 // Each consumer is responsible for registering its QuotaClient during |
113 // its construction. | 118 // its construction. |
114 scoped_refptr<fileapi::FileSystemContext> filesystem_context = | 119 scoped_refptr<fileapi::FileSystemContext> filesystem_context = |
115 CreateFileSystemContext(partition_path, context->IsOffTheRecord(), | 120 CreateFileSystemContext(partition_path, partition_config.in_memory, |
116 context->GetSpecialStoragePolicy(), | 121 context->GetSpecialStoragePolicy(), |
117 quota_manager->proxy()); | 122 quota_manager->proxy()); |
118 | 123 |
119 scoped_refptr<webkit_database::DatabaseTracker> database_tracker = | 124 scoped_refptr<webkit_database::DatabaseTracker> database_tracker = |
120 new webkit_database::DatabaseTracker( | 125 new webkit_database::DatabaseTracker( |
121 partition_path, context->IsOffTheRecord(), | 126 partition_path, partition_config.in_memory, |
122 context->GetSpecialStoragePolicy(), quota_manager->proxy(), | 127 context->GetSpecialStoragePolicy(), quota_manager->proxy(), |
123 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 128 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
124 | 129 |
125 FilePath path = context->IsOffTheRecord() ? FilePath() : partition_path; | 130 FilePath path = partition_config.in_memory ? FilePath() : partition_path; |
126 scoped_refptr<DOMStorageContextImpl> dom_storage_context = | 131 scoped_refptr<DOMStorageContextImpl> dom_storage_context = |
127 new DOMStorageContextImpl(path, context->GetSpecialStoragePolicy()); | 132 new DOMStorageContextImpl(path, context->GetSpecialStoragePolicy()); |
128 | 133 |
129 scoped_refptr<IndexedDBContextImpl> indexed_db_context = | 134 scoped_refptr<IndexedDBContextImpl> indexed_db_context = |
130 new IndexedDBContextImpl(path, context->GetSpecialStoragePolicy(), | 135 new IndexedDBContextImpl(path, context->GetSpecialStoragePolicy(), |
131 quota_manager->proxy(), | 136 quota_manager->proxy(), |
132 BrowserThread::GetMessageLoopProxyForThread( | 137 BrowserThread::GetMessageLoopProxyForThread( |
133 BrowserThread::WEBKIT_DEPRECATED)); | 138 BrowserThread::WEBKIT_DEPRECATED)); |
134 | 139 |
135 scoped_refptr<ChromeAppCacheService> appcache_service = | 140 scoped_refptr<ChromeAppCacheService> appcache_service = |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 net::URLRequestContextGetter* url_request_context) { | 190 net::URLRequestContextGetter* url_request_context) { |
186 url_request_context_ = url_request_context; | 191 url_request_context_ = url_request_context; |
187 } | 192 } |
188 | 193 |
189 void StoragePartitionImpl::SetMediaURLRequestContext( | 194 void StoragePartitionImpl::SetMediaURLRequestContext( |
190 net::URLRequestContextGetter* media_url_request_context) { | 195 net::URLRequestContextGetter* media_url_request_context) { |
191 media_url_request_context_ = media_url_request_context; | 196 media_url_request_context_ = media_url_request_context; |
192 } | 197 } |
193 | 198 |
194 } // namespace content | 199 } // namespace content |
OLD | NEW |