| 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 GetPartitionPath() constructs these path names. | |
| 33 const FilePath::CharType kStoragePartitionDirname[] = | |
| 34 FILE_PATH_LITERAL("Storage"); | |
| 35 const FilePath::CharType kExtensionsDirname[] = | |
| 36 FILE_PATH_LITERAL("ext"); | |
| 37 const FilePath::CharType kDefaultPartitionDirname[] = | |
| 38 FILE_PATH_LITERAL("def"); | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 // static | |
| 43 FilePath StoragePartitionImpl::GetStoragePartitionPath( | |
| 44 const StoragePartitionDescriptor& descriptor) { | |
| 45 if (descriptor.partition_domain.empty()) | |
| 46 return FilePath(); | |
| 47 | |
| 48 FilePath path = FilePath(kStoragePartitionDirname).Append(kExtensionsDirname) | |
| 49 .AppendASCII(descriptor.partition_domain); | |
| 50 | |
| 51 if (!descriptor.partition_name.empty()) | |
| 52 return path.Append(FilePath::FromUTF8Unsafe(descriptor.partition_name)); | |
| 53 | |
| 54 return path.Append(kDefaultPartitionDirname); | |
| 55 } | |
| 56 | |
| 57 StoragePartitionImpl::StoragePartitionImpl( | 17 StoragePartitionImpl::StoragePartitionImpl( |
| 58 const FilePath& partition_path, | 18 const FilePath& partition_path, |
| 59 quota::QuotaManager* quota_manager, | 19 quota::QuotaManager* quota_manager, |
| 60 ChromeAppCacheService* appcache_service, | 20 ChromeAppCacheService* appcache_service, |
| 61 fileapi::FileSystemContext* filesystem_context, | 21 fileapi::FileSystemContext* filesystem_context, |
| 62 webkit_database::DatabaseTracker* database_tracker, | 22 webkit_database::DatabaseTracker* database_tracker, |
| 63 DOMStorageContextImpl* dom_storage_context, | 23 DOMStorageContextImpl* dom_storage_context, |
| 64 IndexedDBContextImpl* indexed_db_context) | 24 IndexedDBContextImpl* indexed_db_context) |
| 65 : partition_path_(partition_path), | 25 : partition_path_(partition_path), |
| 66 quota_manager_(quota_manager), | 26 quota_manager_(quota_manager), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 82 } | 42 } |
| 83 | 43 |
| 84 if (GetDOMStorageContext()) | 44 if (GetDOMStorageContext()) |
| 85 GetDOMStorageContext()->Shutdown(); | 45 GetDOMStorageContext()->Shutdown(); |
| 86 } | 46 } |
| 87 | 47 |
| 88 // TODO(ajwong): Break the direct dependency on |context|. We only | 48 // TODO(ajwong): Break the direct dependency on |context|. We only |
| 89 // need 3 pieces of info from it. | 49 // need 3 pieces of info from it. |
| 90 StoragePartitionImpl* StoragePartitionImpl::Create( | 50 StoragePartitionImpl* StoragePartitionImpl::Create( |
| 91 BrowserContext* context, | 51 BrowserContext* context, |
| 92 const StoragePartitionDescriptor& partition_descriptor, | 52 bool in_memory, |
| 93 const FilePath& profile_path) { | 53 const FilePath& partition_path) { |
| 94 // 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 |
| 95 // unittests where a UI thread might not have been created. | 55 // unittests where a UI thread might not have been created. |
| 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 97 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); | 57 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); |
| 98 | 58 |
| 99 FilePath partition_path = | |
| 100 profile_path.Append(GetStoragePartitionPath(partition_descriptor)); | |
| 101 | |
| 102 // 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 |
| 103 // QuotaManager prior to the QuotaManger being used. We do them | 60 // QuotaManager prior to the QuotaManger being used. We do them |
| 104 // all together here prior to handing out a reference to anything | 61 // all together here prior to handing out a reference to anything |
| 105 // that utilizes the QuotaManager. | 62 // that utilizes the QuotaManager. |
| 106 scoped_refptr<quota::QuotaManager> quota_manager = | 63 scoped_refptr<quota::QuotaManager> quota_manager = |
| 107 new quota::QuotaManager( | 64 new quota::QuotaManager( |
| 108 partition_descriptor.in_memory, partition_path, | 65 in_memory, partition_path, |
| 109 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 66 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 110 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 67 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
| 111 context->GetSpecialStoragePolicy()); | 68 context->GetSpecialStoragePolicy()); |
| 112 | 69 |
| 113 // Each consumer is responsible for registering its QuotaClient during | 70 // Each consumer is responsible for registering its QuotaClient during |
| 114 // its construction. | 71 // its construction. |
| 115 scoped_refptr<fileapi::FileSystemContext> filesystem_context = | 72 scoped_refptr<fileapi::FileSystemContext> filesystem_context = |
| 116 CreateFileSystemContext(partition_path, partition_descriptor.in_memory, | 73 CreateFileSystemContext(partition_path, in_memory, |
| 117 context->GetSpecialStoragePolicy(), | 74 context->GetSpecialStoragePolicy(), |
| 118 quota_manager->proxy()); | 75 quota_manager->proxy()); |
| 119 | 76 |
| 120 scoped_refptr<webkit_database::DatabaseTracker> database_tracker = | 77 scoped_refptr<webkit_database::DatabaseTracker> database_tracker = |
| 121 new webkit_database::DatabaseTracker( | 78 new webkit_database::DatabaseTracker( |
| 122 partition_path, partition_descriptor.in_memory, | 79 partition_path, in_memory, |
| 123 context->GetSpecialStoragePolicy(), quota_manager->proxy(), | 80 context->GetSpecialStoragePolicy(), quota_manager->proxy(), |
| 124 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 81 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
| 125 | 82 |
| 126 FilePath path = partition_descriptor.in_memory ? FilePath() : partition_path; | 83 FilePath path = in_memory ? FilePath() : partition_path; |
| 127 scoped_refptr<DOMStorageContextImpl> dom_storage_context = | 84 scoped_refptr<DOMStorageContextImpl> dom_storage_context = |
| 128 new DOMStorageContextImpl(path, context->GetSpecialStoragePolicy()); | 85 new DOMStorageContextImpl(path, context->GetSpecialStoragePolicy()); |
| 129 | 86 |
| 130 scoped_refptr<IndexedDBContextImpl> indexed_db_context = | 87 scoped_refptr<IndexedDBContextImpl> indexed_db_context = |
| 131 new IndexedDBContextImpl(path, context->GetSpecialStoragePolicy(), | 88 new IndexedDBContextImpl(path, context->GetSpecialStoragePolicy(), |
| 132 quota_manager->proxy(), | 89 quota_manager->proxy(), |
| 133 BrowserThread::GetMessageLoopProxyForThread( | 90 BrowserThread::GetMessageLoopProxyForThread( |
| 134 BrowserThread::WEBKIT_DEPRECATED)); | 91 BrowserThread::WEBKIT_DEPRECATED)); |
| 135 | 92 |
| 136 scoped_refptr<ChromeAppCacheService> appcache_service = | 93 scoped_refptr<ChromeAppCacheService> appcache_service = |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 net::URLRequestContextGetter* url_request_context) { | 143 net::URLRequestContextGetter* url_request_context) { |
| 187 url_request_context_ = url_request_context; | 144 url_request_context_ = url_request_context; |
| 188 } | 145 } |
| 189 | 146 |
| 190 void StoragePartitionImpl::SetMediaURLRequestContext( | 147 void StoragePartitionImpl::SetMediaURLRequestContext( |
| 191 net::URLRequestContextGetter* media_url_request_context) { | 148 net::URLRequestContextGetter* media_url_request_context) { |
| 192 media_url_request_context_ = media_url_request_context; | 149 media_url_request_context_ = media_url_request_context; |
| 193 } | 150 } |
| 194 | 151 |
| 195 } // namespace content | 152 } // namespace content |
| OLD | NEW |