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