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 GetPartitionPath() constructs these path names. |
Charlie Reis
2012/11/07 18:38:36
nit: GetStoragePartitionPath()
Please also add a
nasko
2012/11/07 18:48:05
Done.
| |
32 const FilePath::CharType kStoragePartitionDirname[] = | 33 const FilePath::CharType kStoragePartitionDirname[] = |
33 FILE_PATH_LITERAL("Storage"); | 34 FILE_PATH_LITERAL("Storage"); |
34 const FilePath::CharType kExtensionsDirname[] = | 35 const FilePath::CharType kExtensionsDirname[] = |
35 FILE_PATH_LITERAL("ext"); | 36 FILE_PATH_LITERAL("ext"); |
36 const FilePath::CharType kDefaultPartitionDirname[] = | 37 const FilePath::CharType kDefaultPartitionDirname[] = |
37 FILE_PATH_LITERAL("def"); | 38 FILE_PATH_LITERAL("def"); |
38 | 39 |
39 } // namespace | 40 } // namespace |
40 | 41 |
41 // static | 42 // static |
42 FilePath StoragePartition::GetPartitionPath(const std::string& partition_id) { | 43 FilePath StoragePartitionImpl::GetStoragePartitionPath( |
43 if (partition_id.empty()) { | 44 const StoragePartitionConfig& config) { |
44 // The default profile just sits inside the top-level profile directory. | 45 if (config.partition_domain.empty()) |
45 return FilePath(); | 46 return FilePath(); |
46 } | |
47 | 47 |
48 // TODO(ajwong): This should check that we create a valid path name. | 48 CHECK(IsStringUTF8(config.partition_domain)); |
49 CHECK(IsStringASCII(partition_id)); | 49 |
50 return FilePath(kStoragePartitionDirname) | 50 FilePath path = FilePath(kStoragePartitionDirname).Append(kExtensionsDirname) |
51 .Append(kExtensionsDirname) | 51 .Append(config.partition_domain); |
52 .AppendASCII(partition_id) | 52 |
53 .Append(kDefaultPartitionDirname); | 53 if (!config.partition_name.empty()) |
54 return path.Append(FilePath::FromUTF8Unsafe(config.partition_name)); | |
55 | |
56 return path.Append(kDefaultPartitionDirname); | |
54 } | 57 } |
55 | 58 |
56 StoragePartitionImpl::StoragePartitionImpl( | 59 StoragePartitionImpl::StoragePartitionImpl( |
57 const FilePath& partition_path, | 60 const FilePath& partition_path, |
58 quota::QuotaManager* quota_manager, | 61 quota::QuotaManager* quota_manager, |
59 ChromeAppCacheService* appcache_service, | 62 ChromeAppCacheService* appcache_service, |
60 fileapi::FileSystemContext* filesystem_context, | 63 fileapi::FileSystemContext* filesystem_context, |
61 webkit_database::DatabaseTracker* database_tracker, | 64 webkit_database::DatabaseTracker* database_tracker, |
62 DOMStorageContextImpl* dom_storage_context, | 65 DOMStorageContextImpl* dom_storage_context, |
63 IndexedDBContextImpl* indexed_db_context) | 66 IndexedDBContextImpl* indexed_db_context) |
(...skipping 17 matching lines...) Expand all Loading... | |
81 } | 84 } |
82 | 85 |
83 if (GetDOMStorageContext()) | 86 if (GetDOMStorageContext()) |
84 GetDOMStorageContext()->Shutdown(); | 87 GetDOMStorageContext()->Shutdown(); |
85 } | 88 } |
86 | 89 |
87 // TODO(ajwong): Break the direct dependency on |context|. We only | 90 // TODO(ajwong): Break the direct dependency on |context|. We only |
88 // need 3 pieces of info from it. | 91 // need 3 pieces of info from it. |
89 StoragePartitionImpl* StoragePartitionImpl::Create( | 92 StoragePartitionImpl* StoragePartitionImpl::Create( |
90 BrowserContext* context, | 93 BrowserContext* context, |
91 const std::string& partition_id, | 94 const StoragePartitionConfig& partition_config, |
92 const FilePath& profile_path) { | 95 const FilePath& profile_path) { |
93 // Ensure that these methods are called on the UI thread, except for | 96 // Ensure that these methods are called on the UI thread, except for |
94 // unittests where a UI thread might not have been created. | 97 // unittests where a UI thread might not have been created. |
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
96 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); | 99 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); |
97 | 100 |
98 FilePath partition_path = | 101 FilePath partition_path = |
99 profile_path.Append(GetPartitionPath(partition_id)); | 102 profile_path.Append(GetStoragePartitionPath(partition_config)); |
100 | 103 |
101 // All of the clients have to be created and registered with the | 104 // All of the clients have to be created and registered with the |
102 // QuotaManager prior to the QuotaManger being used. We do them | 105 // QuotaManager prior to the QuotaManger being used. We do them |
103 // all together here prior to handing out a reference to anything | 106 // all together here prior to handing out a reference to anything |
104 // that utilizes the QuotaManager. | 107 // that utilizes the QuotaManager. |
105 scoped_refptr<quota::QuotaManager> quota_manager = | 108 scoped_refptr<quota::QuotaManager> quota_manager = |
106 new quota::QuotaManager( | 109 new quota::QuotaManager( |
107 context->IsOffTheRecord(), partition_path, | 110 partition_config.in_memory, partition_path, |
108 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 111 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
109 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 112 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
110 context->GetSpecialStoragePolicy()); | 113 context->GetSpecialStoragePolicy()); |
111 | 114 |
112 // Each consumer is responsible for registering its QuotaClient during | 115 // Each consumer is responsible for registering its QuotaClient during |
113 // its construction. | 116 // its construction. |
114 scoped_refptr<fileapi::FileSystemContext> filesystem_context = | 117 scoped_refptr<fileapi::FileSystemContext> filesystem_context = |
115 CreateFileSystemContext(partition_path, context->IsOffTheRecord(), | 118 CreateFileSystemContext(partition_path, partition_config.in_memory, |
116 context->GetSpecialStoragePolicy(), | 119 context->GetSpecialStoragePolicy(), |
117 quota_manager->proxy()); | 120 quota_manager->proxy()); |
118 | 121 |
119 scoped_refptr<webkit_database::DatabaseTracker> database_tracker = | 122 scoped_refptr<webkit_database::DatabaseTracker> database_tracker = |
120 new webkit_database::DatabaseTracker( | 123 new webkit_database::DatabaseTracker( |
121 partition_path, context->IsOffTheRecord(), | 124 partition_path, partition_config.in_memory, |
122 context->GetSpecialStoragePolicy(), quota_manager->proxy(), | 125 context->GetSpecialStoragePolicy(), quota_manager->proxy(), |
123 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 126 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
124 | 127 |
125 FilePath path = context->IsOffTheRecord() ? FilePath() : partition_path; | 128 FilePath path = partition_config.in_memory ? FilePath() : partition_path; |
126 scoped_refptr<DOMStorageContextImpl> dom_storage_context = | 129 scoped_refptr<DOMStorageContextImpl> dom_storage_context = |
127 new DOMStorageContextImpl(path, context->GetSpecialStoragePolicy()); | 130 new DOMStorageContextImpl(path, context->GetSpecialStoragePolicy()); |
128 | 131 |
129 scoped_refptr<IndexedDBContextImpl> indexed_db_context = | 132 scoped_refptr<IndexedDBContextImpl> indexed_db_context = |
130 new IndexedDBContextImpl(path, context->GetSpecialStoragePolicy(), | 133 new IndexedDBContextImpl(path, context->GetSpecialStoragePolicy(), |
131 quota_manager->proxy(), | 134 quota_manager->proxy(), |
132 BrowserThread::GetMessageLoopProxyForThread( | 135 BrowserThread::GetMessageLoopProxyForThread( |
133 BrowserThread::WEBKIT_DEPRECATED)); | 136 BrowserThread::WEBKIT_DEPRECATED)); |
134 | 137 |
135 scoped_refptr<ChromeAppCacheService> appcache_service = | 138 scoped_refptr<ChromeAppCacheService> appcache_service = |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 net::URLRequestContextGetter* url_request_context) { | 188 net::URLRequestContextGetter* url_request_context) { |
186 url_request_context_ = url_request_context; | 189 url_request_context_ = url_request_context; |
187 } | 190 } |
188 | 191 |
189 void StoragePartitionImpl::SetMediaURLRequestContext( | 192 void StoragePartitionImpl::SetMediaURLRequestContext( |
190 net::URLRequestContextGetter* media_url_request_context) { | 193 net::URLRequestContextGetter* media_url_request_context) { |
191 media_url_request_context_ = media_url_request_context; | 194 media_url_request_context_ = media_url_request_context; |
192 } | 195 } |
193 | 196 |
194 } // namespace content | 197 } // namespace content |
OLD | NEW |