Chromium Code Reviews| 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 "content/browser/fileapi/browser_file_system_helper.h" | 7 #include "content/browser/fileapi/browser_file_system_helper.h" |
| 8 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "webkit/database/database_tracker.h" | 10 #include "webkit/database/database_tracker.h" |
| 11 #include "webkit/quota/quota_manager.h" | 11 #include "webkit/quota/quota_manager.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 namespace { | |
| 16 | |
| 17 // These constants are used to create the directory structure under the profile | |
| 18 // where renderers with a non-default storage partition keep their persistent | |
| 19 // state. This will contain a set of directories that partially mirror the | |
| 20 // directory structure of BrowserContext::GetPath(). | |
| 21 // | |
| 22 // The kStoragePartitionDirname is contains an extensions directory which is | |
| 23 // further partitioned by extension id, followed by another level of directories | |
| 24 // for the "default" extension storage partition and one directory for each | |
| 25 // browser tag with persistent storage. Example: | |
|
Charlie Reis
2012/09/14 22:37:31
nit: This still isn't quite right, since you can h
awong
2012/09/14 23:01:22
reworded.
| |
| 26 // | |
| 27 // {kStoragePartitionDirname}/extensions/ABCDEF/default | |
| 28 // {kStoragePartitionDirname}/extensions/ABCDEF/{hash(guest partition)} | |
| 29 // | |
| 30 // The code in GetPartitionPath() constructs these path names. | |
| 31 const FilePath::CharType kStoragePartitionDirname[] = | |
| 32 FILE_PATH_LITERAL("Storage Partitions"); | |
| 33 const char kExtensionsDirname[] = "extensions"; | |
| 34 const char kDefaultPartitionDirname[] = "default"; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 FilePath StoragePartition::GetPartitionPath(const FilePath& profile_path, | |
|
Charlie Reis
2012/09/14 22:37:31
nit: // static
awong
2012/09/14 23:01:22
Done.
| |
| 39 const std::string& partition_id) { | |
| 40 if (partition_id.empty()) { | |
| 41 // The default profile just sits inside the top-level profile directory. | |
| 42 return profile_path; | |
| 43 } | |
| 44 | |
| 45 // TODO(ajwong): This should check we create a valid path name. | |
| 46 CHECK(IsStringASCII(partition_id)); | |
| 47 return profile_path.Append(kStoragePartitionDirname) | |
| 48 .AppendASCII(kExtensionsDirname) | |
| 49 .AppendASCII(partition_id) | |
| 50 .AppendASCII(kDefaultPartitionDirname); | |
| 51 } | |
| 52 | |
| 15 StoragePartitionImpl::StoragePartitionImpl( | 53 StoragePartitionImpl::StoragePartitionImpl( |
| 16 const FilePath& partition_path, | 54 const FilePath& partition_path, |
| 17 quota::QuotaManager* quota_manager, | 55 quota::QuotaManager* quota_manager, |
| 18 ChromeAppCacheService* appcache_service, | 56 ChromeAppCacheService* appcache_service, |
| 19 fileapi::FileSystemContext* filesystem_context, | 57 fileapi::FileSystemContext* filesystem_context, |
| 20 webkit_database::DatabaseTracker* database_tracker, | 58 webkit_database::DatabaseTracker* database_tracker, |
| 21 DOMStorageContextImpl* dom_storage_context, | 59 DOMStorageContextImpl* dom_storage_context, |
| 22 IndexedDBContextImpl* indexed_db_context) | 60 IndexedDBContextImpl* indexed_db_context) |
| 23 : partition_path_(partition_path), | 61 : partition_path_(partition_path), |
| 24 quota_manager_(quota_manager), | 62 quota_manager_(quota_manager), |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 40 } | 78 } |
| 41 | 79 |
| 42 if (GetDOMStorageContext()) | 80 if (GetDOMStorageContext()) |
| 43 GetDOMStorageContext()->Shutdown(); | 81 GetDOMStorageContext()->Shutdown(); |
| 44 } | 82 } |
| 45 | 83 |
| 46 // TODO(ajwong): Break the direct dependency on |context|. We only | 84 // TODO(ajwong): Break the direct dependency on |context|. We only |
| 47 // need 3 pieces of info from it. | 85 // need 3 pieces of info from it. |
| 48 StoragePartitionImpl* StoragePartitionImpl::Create( | 86 StoragePartitionImpl* StoragePartitionImpl::Create( |
| 49 BrowserContext* context, | 87 BrowserContext* context, |
| 50 const FilePath& partition_path) { | 88 const std::string& partition_id, |
| 89 const FilePath& profile_path) { | |
| 51 // Ensure that these methods are called on the UI thread, except for | 90 // Ensure that these methods are called on the UI thread, except for |
| 52 // unittests where a UI thread might not have been created. | 91 // unittests where a UI thread might not have been created. |
| 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 54 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); | 93 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); |
| 55 | 94 |
| 95 FilePath partition_path = | |
| 96 StoragePartition::GetPartitionPath(context->GetPath(), | |
| 97 partition_id); | |
| 98 | |
| 56 // All of the clients have to be created and registered with the | 99 // All of the clients have to be created and registered with the |
| 57 // QuotaManager prior to the QuotaManger being used. We do them | 100 // QuotaManager prior to the QuotaManger being used. We do them |
| 58 // all together here prior to handing out a reference to anything | 101 // all together here prior to handing out a reference to anything |
| 59 // that utilizes the QuotaManager. | 102 // that utilizes the QuotaManager. |
| 60 scoped_refptr<quota::QuotaManager> quota_manager = | 103 scoped_refptr<quota::QuotaManager> quota_manager = |
| 61 new quota::QuotaManager( | 104 new quota::QuotaManager( |
| 62 context->IsOffTheRecord(), partition_path, | 105 context->IsOffTheRecord(), partition_path, |
| 63 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 106 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 64 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 107 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
| 65 context->GetSpecialStoragePolicy()); | 108 context->GetSpecialStoragePolicy()); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 92 | 135 |
| 93 return new StoragePartitionImpl(partition_path, | 136 return new StoragePartitionImpl(partition_path, |
| 94 quota_manager, | 137 quota_manager, |
| 95 appcache_service, | 138 appcache_service, |
| 96 filesystem_context, | 139 filesystem_context, |
| 97 database_tracker, | 140 database_tracker, |
| 98 dom_storage_context, | 141 dom_storage_context, |
| 99 indexed_db_context); | 142 indexed_db_context); |
| 100 } | 143 } |
| 101 | 144 |
| 145 FilePath StoragePartitionImpl::GetPath() { | |
| 146 return partition_path_; | |
| 147 } | |
| 148 | |
| 102 quota::QuotaManager* StoragePartitionImpl::GetQuotaManager() { | 149 quota::QuotaManager* StoragePartitionImpl::GetQuotaManager() { |
| 103 return quota_manager_; | 150 return quota_manager_; |
| 104 } | 151 } |
| 105 | 152 |
| 106 ChromeAppCacheService* StoragePartitionImpl::GetAppCacheService() { | 153 ChromeAppCacheService* StoragePartitionImpl::GetAppCacheService() { |
| 107 return appcache_service_; | 154 return appcache_service_; |
| 108 } | 155 } |
| 109 | 156 |
| 110 fileapi::FileSystemContext* StoragePartitionImpl::GetFileSystemContext() { | 157 fileapi::FileSystemContext* StoragePartitionImpl::GetFileSystemContext() { |
| 111 return filesystem_context_; | 158 return filesystem_context_; |
| 112 } | 159 } |
| 113 | 160 |
| 114 webkit_database::DatabaseTracker* StoragePartitionImpl::GetDatabaseTracker() { | 161 webkit_database::DatabaseTracker* StoragePartitionImpl::GetDatabaseTracker() { |
| 115 return database_tracker_; | 162 return database_tracker_; |
| 116 } | 163 } |
| 117 | 164 |
| 118 DOMStorageContextImpl* StoragePartitionImpl::GetDOMStorageContext() { | 165 DOMStorageContextImpl* StoragePartitionImpl::GetDOMStorageContext() { |
| 119 return dom_storage_context_; | 166 return dom_storage_context_; |
| 120 } | 167 } |
| 121 | 168 |
| 122 IndexedDBContextImpl* StoragePartitionImpl::GetIndexedDBContext() { | 169 IndexedDBContextImpl* StoragePartitionImpl::GetIndexedDBContext() { |
| 123 return indexed_db_context_; | 170 return indexed_db_context_; |
| 124 } | 171 } |
| 125 | 172 |
| 126 } // namespace content | 173 } // namespace content |
| OLD | NEW |