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