| 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 "webkit/browser/fileapi/file_system_context.h" | 5 #include "webkit/browser/fileapi/file_system_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| 11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 12 #include "webkit/browser/blob/file_stream_reader.h" | 12 #include "webkit/browser/blob/file_stream_reader.h" |
| 13 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" | 13 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" |
| 14 #include "webkit/browser/fileapi/external_mount_points.h" | 14 #include "webkit/browser/fileapi/external_mount_points.h" |
| 15 #include "webkit/browser/fileapi/file_permission_policy.h" | 15 #include "webkit/browser/fileapi/file_permission_policy.h" |
| 16 #include "webkit/browser/fileapi/file_stream_writer.h" | 16 #include "webkit/browser/fileapi/file_stream_writer.h" |
| 17 #include "webkit/browser/fileapi/file_system_file_util.h" | 17 #include "webkit/browser/fileapi/file_system_file_util.h" |
| 18 #include "webkit/browser/fileapi/file_system_operation.h" | 18 #include "webkit/browser/fileapi/file_system_operation.h" |
| 19 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 19 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 20 #include "webkit/browser/fileapi/file_system_options.h" | 20 #include "webkit/browser/fileapi/file_system_options.h" |
| 21 #include "webkit/browser/fileapi/file_system_quota_client.h" | 21 #include "webkit/browser/fileapi/file_system_quota_client.h" |
| 22 #include "webkit/browser/fileapi/file_system_task_runners.h" | 22 #include "webkit/browser/fileapi/file_system_task_runners.h" |
| 23 #include "webkit/browser/fileapi/file_system_url.h" | 23 #include "webkit/browser/fileapi/file_system_url.h" |
| 24 #include "webkit/browser/fileapi/isolated_context.h" | 24 #include "webkit/browser/fileapi/isolated_context.h" |
| 25 #include "webkit/browser/fileapi/isolated_mount_point_provider.h" | 25 #include "webkit/browser/fileapi/isolated_file_system_backend.h" |
| 26 #include "webkit/browser/fileapi/mount_points.h" | 26 #include "webkit/browser/fileapi/mount_points.h" |
| 27 #include "webkit/browser/fileapi/sandbox_mount_point_provider.h" | 27 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" |
| 28 #include "webkit/browser/fileapi/syncable/local_file_change_tracker.h" | 28 #include "webkit/browser/fileapi/syncable/local_file_change_tracker.h" |
| 29 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h" | 29 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h" |
| 30 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" | 30 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" |
| 31 #include "webkit/browser/fileapi/test_mount_point_provider.h" | 31 #include "webkit/browser/fileapi/test_file_system_backend.h" |
| 32 #include "webkit/browser/quota/quota_manager.h" | 32 #include "webkit/browser/quota/quota_manager.h" |
| 33 #include "webkit/browser/quota/special_storage_policy.h" | 33 #include "webkit/browser/quota/special_storage_policy.h" |
| 34 #include "webkit/common/fileapi/file_system_util.h" | 34 #include "webkit/common/fileapi/file_system_util.h" |
| 35 | 35 |
| 36 using quota::QuotaClient; | 36 using quota::QuotaClient; |
| 37 | 37 |
| 38 namespace fileapi { | 38 namespace fileapi { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 98 } |
| 99 NOTREACHED(); | 99 NOTREACHED(); |
| 100 return FILE_PERMISSION_ALWAYS_DENY; | 100 return FILE_PERMISSION_ALWAYS_DENY; |
| 101 } | 101 } |
| 102 | 102 |
| 103 FileSystemContext::FileSystemContext( | 103 FileSystemContext::FileSystemContext( |
| 104 scoped_ptr<FileSystemTaskRunners> task_runners, | 104 scoped_ptr<FileSystemTaskRunners> task_runners, |
| 105 ExternalMountPoints* external_mount_points, | 105 ExternalMountPoints* external_mount_points, |
| 106 quota::SpecialStoragePolicy* special_storage_policy, | 106 quota::SpecialStoragePolicy* special_storage_policy, |
| 107 quota::QuotaManagerProxy* quota_manager_proxy, | 107 quota::QuotaManagerProxy* quota_manager_proxy, |
| 108 ScopedVector<FileSystemMountPointProvider> additional_providers, | 108 ScopedVector<FileSystemBackend> additional_backends, |
| 109 const base::FilePath& partition_path, | 109 const base::FilePath& partition_path, |
| 110 const FileSystemOptions& options) | 110 const FileSystemOptions& options) |
| 111 : task_runners_(task_runners.Pass()), | 111 : task_runners_(task_runners.Pass()), |
| 112 quota_manager_proxy_(quota_manager_proxy), | 112 quota_manager_proxy_(quota_manager_proxy), |
| 113 sandbox_provider_( | 113 sandbox_backend_( |
| 114 new SandboxMountPointProvider( | 114 new SandboxFileSystemBackend( |
| 115 quota_manager_proxy, | 115 quota_manager_proxy, |
| 116 task_runners_->file_task_runner(), | 116 task_runners_->file_task_runner(), |
| 117 partition_path, | 117 partition_path, |
| 118 options, | 118 options, |
| 119 special_storage_policy)), | 119 special_storage_policy)), |
| 120 isolated_provider_(new IsolatedMountPointProvider()), | 120 isolated_backend_(new IsolatedFileSystemBackend()), |
| 121 additional_providers_(additional_providers.Pass()), | 121 additional_backends_(additional_backends.Pass()), |
| 122 external_mount_points_(external_mount_points), | 122 external_mount_points_(external_mount_points), |
| 123 partition_path_(partition_path), | 123 partition_path_(partition_path), |
| 124 operation_runner_(new FileSystemOperationRunner(this)) { | 124 operation_runner_(new FileSystemOperationRunner(this)) { |
| 125 DCHECK(task_runners_.get()); | 125 DCHECK(task_runners_.get()); |
| 126 | 126 |
| 127 if (quota_manager_proxy) { | 127 if (quota_manager_proxy) { |
| 128 quota_manager_proxy->RegisterClient(CreateQuotaClient( | 128 quota_manager_proxy->RegisterClient(CreateQuotaClient( |
| 129 this, options.is_incognito())); | 129 this, options.is_incognito())); |
| 130 } | 130 } |
| 131 | 131 |
| 132 RegisterMountPointProvider(sandbox_provider_.get()); | 132 RegisterBackend(sandbox_backend_.get()); |
| 133 RegisterMountPointProvider(isolated_provider_.get()); | 133 RegisterBackend(isolated_backend_.get()); |
| 134 | 134 |
| 135 for (ScopedVector<FileSystemMountPointProvider>::const_iterator iter = | 135 for (ScopedVector<FileSystemBackend>::const_iterator iter = |
| 136 additional_providers_.begin(); | 136 additional_backends_.begin(); |
| 137 iter != additional_providers_.end(); ++iter) { | 137 iter != additional_backends_.end(); ++iter) { |
| 138 RegisterMountPointProvider(*iter); | 138 RegisterBackend(*iter); |
| 139 } | 139 } |
| 140 | 140 |
| 141 // Additional mount points must be added before regular system-wide | 141 // Additional mount points must be added before regular system-wide |
| 142 // mount points. | 142 // mount points. |
| 143 if (external_mount_points) | 143 if (external_mount_points) |
| 144 url_crackers_.push_back(external_mount_points); | 144 url_crackers_.push_back(external_mount_points); |
| 145 url_crackers_.push_back(ExternalMountPoints::GetSystemInstance()); | 145 url_crackers_.push_back(ExternalMountPoints::GetSystemInstance()); |
| 146 url_crackers_.push_back(IsolatedContext::GetInstance()); | 146 url_crackers_.push_back(IsolatedContext::GetInstance()); |
| 147 } | 147 } |
| 148 | 148 |
| 149 bool FileSystemContext::DeleteDataForOriginOnFileThread( | 149 bool FileSystemContext::DeleteDataForOriginOnFileThread( |
| 150 const GURL& origin_url) { | 150 const GURL& origin_url) { |
| 151 DCHECK(task_runners_->file_task_runner()->RunsTasksOnCurrentThread()); | 151 DCHECK(task_runners_->file_task_runner()->RunsTasksOnCurrentThread()); |
| 152 DCHECK(origin_url == origin_url.GetOrigin()); | 152 DCHECK(origin_url == origin_url.GetOrigin()); |
| 153 | 153 |
| 154 bool success = true; | 154 bool success = true; |
| 155 for (MountPointProviderMap::iterator iter = provider_map_.begin(); | 155 for (FileSystemBackendMap::iterator iter = backend_map_.begin(); |
| 156 iter != provider_map_.end(); | 156 iter != backend_map_.end(); |
| 157 ++iter) { | 157 ++iter) { |
| 158 FileSystemMountPointProvider* provider = iter->second; | 158 FileSystemBackend* backend = iter->second; |
| 159 if (!provider->GetQuotaUtil()) | 159 if (!backend->GetQuotaUtil()) |
| 160 continue; | 160 continue; |
| 161 if (provider->GetQuotaUtil()->DeleteOriginDataOnFileThread( | 161 if (backend->GetQuotaUtil()->DeleteOriginDataOnFileThread( |
| 162 this, quota_manager_proxy(), origin_url, iter->first) | 162 this, quota_manager_proxy(), origin_url, iter->first) |
| 163 != base::PLATFORM_FILE_OK) { | 163 != base::PLATFORM_FILE_OK) { |
| 164 // Continue the loop, but record the failure. | 164 // Continue the loop, but record the failure. |
| 165 success = false; | 165 success = false; |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 return success; | 169 return success; |
| 170 } | 170 } |
| 171 | 171 |
| 172 FileSystemQuotaUtil* | 172 FileSystemQuotaUtil* |
| 173 FileSystemContext::GetQuotaUtil(FileSystemType type) const { | 173 FileSystemContext::GetQuotaUtil(FileSystemType type) const { |
| 174 FileSystemMountPointProvider* mount_point_provider = | 174 FileSystemBackend* backend = GetFileSystemBackend(type); |
| 175 GetMountPointProvider(type); | 175 if (!backend) |
| 176 if (!mount_point_provider) | |
| 177 return NULL; | 176 return NULL; |
| 178 return mount_point_provider->GetQuotaUtil(); | 177 return backend->GetQuotaUtil(); |
| 179 } | 178 } |
| 180 | 179 |
| 181 AsyncFileUtil* FileSystemContext::GetAsyncFileUtil( | 180 AsyncFileUtil* FileSystemContext::GetAsyncFileUtil( |
| 182 FileSystemType type) const { | 181 FileSystemType type) const { |
| 183 FileSystemMountPointProvider* mount_point_provider = | 182 FileSystemBackend* backend = GetFileSystemBackend(type); |
| 184 GetMountPointProvider(type); | 183 if (!backend) |
| 185 if (!mount_point_provider) | |
| 186 return NULL; | 184 return NULL; |
| 187 return mount_point_provider->GetAsyncFileUtil(type); | 185 return backend->GetAsyncFileUtil(type); |
| 188 } | 186 } |
| 189 | 187 |
| 190 FileSystemFileUtil* FileSystemContext::GetFileUtil( | 188 FileSystemFileUtil* FileSystemContext::GetFileUtil( |
| 191 FileSystemType type) const { | 189 FileSystemType type) const { |
| 192 FileSystemMountPointProvider* mount_point_provider = | 190 FileSystemBackend* backend = GetFileSystemBackend(type); |
| 193 GetMountPointProvider(type); | 191 if (!backend) |
| 194 if (!mount_point_provider) | |
| 195 return NULL; | 192 return NULL; |
| 196 return mount_point_provider->GetFileUtil(type); | 193 return backend->GetFileUtil(type); |
| 197 } | 194 } |
| 198 | 195 |
| 199 CopyOrMoveFileValidatorFactory* | 196 CopyOrMoveFileValidatorFactory* |
| 200 FileSystemContext::GetCopyOrMoveFileValidatorFactory( | 197 FileSystemContext::GetCopyOrMoveFileValidatorFactory( |
| 201 FileSystemType type, base::PlatformFileError* error_code) const { | 198 FileSystemType type, base::PlatformFileError* error_code) const { |
| 202 DCHECK(error_code); | 199 DCHECK(error_code); |
| 203 *error_code = base::PLATFORM_FILE_OK; | 200 *error_code = base::PLATFORM_FILE_OK; |
| 204 FileSystemMountPointProvider* mount_point_provider = | 201 FileSystemBackend* backend = GetFileSystemBackend(type); |
| 205 GetMountPointProvider(type); | 202 if (!backend) |
| 206 if (!mount_point_provider) | |
| 207 return NULL; | 203 return NULL; |
| 208 return mount_point_provider->GetCopyOrMoveFileValidatorFactory( | 204 return backend->GetCopyOrMoveFileValidatorFactory( |
| 209 type, error_code); | 205 type, error_code); |
| 210 } | 206 } |
| 211 | 207 |
| 212 FileSystemMountPointProvider* FileSystemContext::GetMountPointProvider( | 208 FileSystemBackend* FileSystemContext::GetFileSystemBackend( |
| 213 FileSystemType type) const { | 209 FileSystemType type) const { |
| 214 MountPointProviderMap::const_iterator found = provider_map_.find(type); | 210 FileSystemBackendMap::const_iterator found = backend_map_.find(type); |
| 215 if (found != provider_map_.end()) | 211 if (found != backend_map_.end()) |
| 216 return found->second; | 212 return found->second; |
| 217 NOTREACHED() << "Unknown filesystem type: " << type; | 213 NOTREACHED() << "Unknown filesystem type: " << type; |
| 218 return NULL; | 214 return NULL; |
| 219 } | 215 } |
| 220 | 216 |
| 221 bool FileSystemContext::IsSandboxFileSystem(FileSystemType type) const { | 217 bool FileSystemContext::IsSandboxFileSystem(FileSystemType type) const { |
| 222 return GetQuotaUtil(type) != NULL; | 218 return GetQuotaUtil(type) != NULL; |
| 223 } | 219 } |
| 224 | 220 |
| 225 const UpdateObserverList* FileSystemContext::GetUpdateObservers( | 221 const UpdateObserverList* FileSystemContext::GetUpdateObservers( |
| 226 FileSystemType type) const { | 222 FileSystemType type) const { |
| 227 // Currently update observer is only available in SandboxMountPointProvider | 223 // Currently update observer is only available in SandboxFileSystemBackend |
| 228 // and TestMountPointProvider. | 224 // and TestFileSystemBackend. |
| 229 // TODO(kinuko): Probably GetUpdateObservers() virtual method should be | 225 // TODO(kinuko): Probably GetUpdateObservers() virtual method should be |
| 230 // added to FileSystemMountPointProvider interface and be called like | 226 // added to FileSystemBackend interface and be called like |
| 231 // other GetFoo() methods do. | 227 // other GetFoo() methods do. |
| 232 if (sandbox_provider_->CanHandleType(type)) | 228 if (sandbox_backend_->CanHandleType(type)) |
| 233 return sandbox_provider_->GetUpdateObservers(type); | 229 return sandbox_backend_->GetUpdateObservers(type); |
| 234 if (type != kFileSystemTypeTest) | 230 if (type != kFileSystemTypeTest) |
| 235 return NULL; | 231 return NULL; |
| 236 FileSystemMountPointProvider* mount_point_provider = | 232 FileSystemBackend* backend = GetFileSystemBackend(type); |
| 237 GetMountPointProvider(type); | 233 return static_cast<TestFileSystemBackend*>( |
| 238 return static_cast<TestMountPointProvider*>( | 234 backend)->GetUpdateObservers(type); |
| 239 mount_point_provider)->GetUpdateObservers(type); | |
| 240 } | 235 } |
| 241 | 236 |
| 242 const AccessObserverList* FileSystemContext::GetAccessObservers( | 237 const AccessObserverList* FileSystemContext::GetAccessObservers( |
| 243 FileSystemType type) const { | 238 FileSystemType type) const { |
| 244 // Currently access observer is only available in SandboxMountPointProvider. | 239 // Currently access observer is only available in SandboxFileSystemBackend. |
| 245 if (sandbox_provider_->CanHandleType(type)) | 240 if (sandbox_backend_->CanHandleType(type)) |
| 246 return sandbox_provider_->GetAccessObservers(type); | 241 return sandbox_backend_->GetAccessObservers(type); |
| 247 return NULL; | 242 return NULL; |
| 248 } | 243 } |
| 249 | 244 |
| 250 void FileSystemContext::GetFileSystemTypes( | 245 void FileSystemContext::GetFileSystemTypes( |
| 251 std::vector<FileSystemType>* types) const { | 246 std::vector<FileSystemType>* types) const { |
| 252 types->clear(); | 247 types->clear(); |
| 253 for (MountPointProviderMap::const_iterator iter = provider_map_.begin(); | 248 for (FileSystemBackendMap::const_iterator iter = backend_map_.begin(); |
| 254 iter != provider_map_.end(); ++iter) | 249 iter != backend_map_.end(); ++iter) |
| 255 types->push_back(iter->first); | 250 types->push_back(iter->first); |
| 256 } | 251 } |
| 257 | 252 |
| 258 ExternalFileSystemMountPointProvider* | 253 ExternalFileSystemBackend* |
| 259 FileSystemContext::external_provider() const { | 254 FileSystemContext::external_backend() const { |
| 260 return static_cast<ExternalFileSystemMountPointProvider*>( | 255 return static_cast<ExternalFileSystemBackend*>( |
| 261 GetMountPointProvider(kFileSystemTypeExternal)); | 256 GetFileSystemBackend(kFileSystemTypeExternal)); |
| 262 } | 257 } |
| 263 | 258 |
| 264 void FileSystemContext::OpenFileSystem( | 259 void FileSystemContext::OpenFileSystem( |
| 265 const GURL& origin_url, | 260 const GURL& origin_url, |
| 266 FileSystemType type, | 261 FileSystemType type, |
| 267 OpenFileSystemMode mode, | 262 OpenFileSystemMode mode, |
| 268 const OpenFileSystemCallback& callback) { | 263 const OpenFileSystemCallback& callback) { |
| 269 DCHECK(!callback.is_null()); | 264 DCHECK(!callback.is_null()); |
| 270 | 265 |
| 271 FileSystemMountPointProvider* mount_point_provider = | 266 FileSystemBackend* backend = GetFileSystemBackend(type); |
| 272 GetMountPointProvider(type); | 267 if (!backend) { |
| 273 if (!mount_point_provider) { | |
| 274 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, std::string(), GURL()); | 268 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, std::string(), GURL()); |
| 275 return; | 269 return; |
| 276 } | 270 } |
| 277 | 271 |
| 278 GURL root_url; | 272 GURL root_url; |
| 279 if (type == kFileSystemTypeSyncable) | 273 if (type == kFileSystemTypeSyncable) |
| 280 root_url = sync_file_system::GetSyncableFileSystemRootURI(origin_url); | 274 root_url = sync_file_system::GetSyncableFileSystemRootURI(origin_url); |
| 281 else | 275 else |
| 282 root_url = GetFileSystemRootURI(origin_url, type); | 276 root_url = GetFileSystemRootURI(origin_url, type); |
| 283 std::string name = GetFileSystemName(origin_url, type); | 277 std::string name = GetFileSystemName(origin_url, type); |
| 284 | 278 |
| 285 mount_point_provider->OpenFileSystem( | 279 backend->OpenFileSystem( |
| 286 origin_url, type, mode, | 280 origin_url, type, mode, |
| 287 base::Bind(&DidOpenFileSystem, callback, root_url, name)); | 281 base::Bind(&DidOpenFileSystem, callback, root_url, name)); |
| 288 } | 282 } |
| 289 | 283 |
| 290 void FileSystemContext::DeleteFileSystem( | 284 void FileSystemContext::DeleteFileSystem( |
| 291 const GURL& origin_url, | 285 const GURL& origin_url, |
| 292 FileSystemType type, | 286 FileSystemType type, |
| 293 const DeleteFileSystemCallback& callback) { | 287 const DeleteFileSystemCallback& callback) { |
| 294 DCHECK(origin_url == origin_url.GetOrigin()); | 288 DCHECK(origin_url == origin_url.GetOrigin()); |
| 295 FileSystemMountPointProvider* mount_point_provider = | 289 FileSystemBackend* backend = GetFileSystemBackend(type); |
| 296 GetMountPointProvider(type); | 290 if (!backend) { |
| 297 if (!mount_point_provider) { | |
| 298 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 291 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
| 299 return; | 292 return; |
| 300 } | 293 } |
| 301 if (!mount_point_provider->GetQuotaUtil()) { | 294 if (!backend->GetQuotaUtil()) { |
| 302 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 295 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
| 303 return; | 296 return; |
| 304 } | 297 } |
| 305 | 298 |
| 306 base::PostTaskAndReplyWithResult( | 299 base::PostTaskAndReplyWithResult( |
| 307 task_runners()->file_task_runner(), | 300 task_runners()->file_task_runner(), |
| 308 FROM_HERE, | 301 FROM_HERE, |
| 309 // It is safe to pass Unretained(quota_util) since context owns it. | 302 // It is safe to pass Unretained(quota_util) since context owns it. |
| 310 base::Bind(&FileSystemQuotaUtil::DeleteOriginDataOnFileThread, | 303 base::Bind(&FileSystemQuotaUtil::DeleteOriginDataOnFileThread, |
| 311 base::Unretained(mount_point_provider->GetQuotaUtil()), | 304 base::Unretained(backend->GetQuotaUtil()), |
| 312 make_scoped_refptr(this), | 305 make_scoped_refptr(this), |
| 313 base::Unretained(quota_manager_proxy()), | 306 base::Unretained(quota_manager_proxy()), |
| 314 origin_url, | 307 origin_url, |
| 315 type), | 308 type), |
| 316 callback); | 309 callback); |
| 317 } | 310 } |
| 318 | 311 |
| 319 scoped_ptr<webkit_blob::FileStreamReader> | 312 scoped_ptr<webkit_blob::FileStreamReader> |
| 320 FileSystemContext::CreateFileStreamReader( | 313 FileSystemContext::CreateFileStreamReader( |
| 321 const FileSystemURL& url, | 314 const FileSystemURL& url, |
| 322 int64 offset, | 315 int64 offset, |
| 323 const base::Time& expected_modification_time) { | 316 const base::Time& expected_modification_time) { |
| 324 if (!url.is_valid()) | 317 if (!url.is_valid()) |
| 325 return scoped_ptr<webkit_blob::FileStreamReader>(); | 318 return scoped_ptr<webkit_blob::FileStreamReader>(); |
| 326 FileSystemMountPointProvider* mount_point_provider = | 319 FileSystemBackend* backend = GetFileSystemBackend(url.type()); |
| 327 GetMountPointProvider(url.type()); | 320 if (!backend) |
| 328 if (!mount_point_provider) | |
| 329 return scoped_ptr<webkit_blob::FileStreamReader>(); | 321 return scoped_ptr<webkit_blob::FileStreamReader>(); |
| 330 return mount_point_provider->CreateFileStreamReader( | 322 return backend->CreateFileStreamReader( |
| 331 url, offset, expected_modification_time, this); | 323 url, offset, expected_modification_time, this); |
| 332 } | 324 } |
| 333 | 325 |
| 334 scoped_ptr<FileStreamWriter> FileSystemContext::CreateFileStreamWriter( | 326 scoped_ptr<FileStreamWriter> FileSystemContext::CreateFileStreamWriter( |
| 335 const FileSystemURL& url, | 327 const FileSystemURL& url, |
| 336 int64 offset) { | 328 int64 offset) { |
| 337 if (!url.is_valid()) | 329 if (!url.is_valid()) |
| 338 return scoped_ptr<FileStreamWriter>(); | 330 return scoped_ptr<FileStreamWriter>(); |
| 339 FileSystemMountPointProvider* mount_point_provider = | 331 FileSystemBackend* backend = GetFileSystemBackend(url.type()); |
| 340 GetMountPointProvider(url.type()); | 332 if (!backend) |
| 341 if (!mount_point_provider) | |
| 342 return scoped_ptr<FileStreamWriter>(); | 333 return scoped_ptr<FileStreamWriter>(); |
| 343 return mount_point_provider->CreateFileStreamWriter(url, offset, this); | 334 return backend->CreateFileStreamWriter(url, offset, this); |
| 344 } | 335 } |
| 345 | 336 |
| 346 void FileSystemContext::SetLocalFileChangeTracker( | 337 void FileSystemContext::SetLocalFileChangeTracker( |
| 347 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { | 338 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { |
| 348 DCHECK(!change_tracker_.get()); | 339 DCHECK(!change_tracker_.get()); |
| 349 DCHECK(tracker.get()); | 340 DCHECK(tracker.get()); |
| 350 change_tracker_ = tracker.Pass(); | 341 change_tracker_ = tracker.Pass(); |
| 351 sandbox_provider_->AddFileUpdateObserver( | 342 sandbox_backend_->AddFileUpdateObserver( |
| 352 kFileSystemTypeSyncable, | 343 kFileSystemTypeSyncable, |
| 353 change_tracker_.get(), | 344 change_tracker_.get(), |
| 354 task_runners_->file_task_runner()); | 345 task_runners_->file_task_runner()); |
| 355 sandbox_provider_->AddFileChangeObserver( | 346 sandbox_backend_->AddFileChangeObserver( |
| 356 kFileSystemTypeSyncable, | 347 kFileSystemTypeSyncable, |
| 357 change_tracker_.get(), | 348 change_tracker_.get(), |
| 358 task_runners_->file_task_runner()); | 349 task_runners_->file_task_runner()); |
| 359 } | 350 } |
| 360 | 351 |
| 361 void FileSystemContext::set_sync_context( | 352 void FileSystemContext::set_sync_context( |
| 362 sync_file_system::LocalFileSyncContext* sync_context) { | 353 sync_file_system::LocalFileSyncContext* sync_context) { |
| 363 sync_context_ = sync_context; | 354 sync_context_ = sync_context; |
| 364 } | 355 } |
| 365 | 356 |
| 366 FileSystemURL FileSystemContext::CrackURL(const GURL& url) const { | 357 FileSystemURL FileSystemContext::CrackURL(const GURL& url) const { |
| 367 return CrackFileSystemURL(FileSystemURL(url)); | 358 return CrackFileSystemURL(FileSystemURL(url)); |
| 368 } | 359 } |
| 369 | 360 |
| 370 FileSystemURL FileSystemContext::CreateCrackedFileSystemURL( | 361 FileSystemURL FileSystemContext::CreateCrackedFileSystemURL( |
| 371 const GURL& origin, | 362 const GURL& origin, |
| 372 FileSystemType type, | 363 FileSystemType type, |
| 373 const base::FilePath& path) const { | 364 const base::FilePath& path) const { |
| 374 return CrackFileSystemURL(FileSystemURL(origin, type, path)); | 365 return CrackFileSystemURL(FileSystemURL(origin, type, path)); |
| 375 } | 366 } |
| 376 | 367 |
| 377 #if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD) | 368 #if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD) |
| 378 void FileSystemContext::EnableTemporaryFileSystemInIncognito() { | 369 void FileSystemContext::EnableTemporaryFileSystemInIncognito() { |
| 379 sandbox_provider_->set_enable_temporary_file_system_in_incognito(true); | 370 sandbox_backend_->set_enable_temporary_file_system_in_incognito(true); |
| 380 } | 371 } |
| 381 #endif | 372 #endif |
| 382 | 373 |
| 383 FileSystemContext::~FileSystemContext() { | 374 FileSystemContext::~FileSystemContext() { |
| 384 task_runners_->file_task_runner()->DeleteSoon( | 375 task_runners_->file_task_runner()->DeleteSoon( |
| 385 FROM_HERE, change_tracker_.release()); | 376 FROM_HERE, change_tracker_.release()); |
| 386 } | 377 } |
| 387 | 378 |
| 388 void FileSystemContext::DeleteOnCorrectThread() const { | 379 void FileSystemContext::DeleteOnCorrectThread() const { |
| 389 if (!task_runners_->io_task_runner()->RunsTasksOnCurrentThread() && | 380 if (!task_runners_->io_task_runner()->RunsTasksOnCurrentThread() && |
| 390 task_runners_->io_task_runner()->DeleteSoon(FROM_HERE, this)) { | 381 task_runners_->io_task_runner()->DeleteSoon(FROM_HERE, this)) { |
| 391 return; | 382 return; |
| 392 } | 383 } |
| 393 delete this; | 384 delete this; |
| 394 } | 385 } |
| 395 | 386 |
| 396 FileSystemOperation* FileSystemContext::CreateFileSystemOperation( | 387 FileSystemOperation* FileSystemContext::CreateFileSystemOperation( |
| 397 const FileSystemURL& url, base::PlatformFileError* error_code) { | 388 const FileSystemURL& url, base::PlatformFileError* error_code) { |
| 398 if (!url.is_valid()) { | 389 if (!url.is_valid()) { |
| 399 if (error_code) | 390 if (error_code) |
| 400 *error_code = base::PLATFORM_FILE_ERROR_INVALID_URL; | 391 *error_code = base::PLATFORM_FILE_ERROR_INVALID_URL; |
| 401 return NULL; | 392 return NULL; |
| 402 } | 393 } |
| 403 | 394 |
| 404 FileSystemMountPointProvider* mount_point_provider = | 395 FileSystemBackend* backend = GetFileSystemBackend(url.type()); |
| 405 GetMountPointProvider(url.type()); | 396 if (!backend) { |
| 406 if (!mount_point_provider) { | |
| 407 if (error_code) | 397 if (error_code) |
| 408 *error_code = base::PLATFORM_FILE_ERROR_FAILED; | 398 *error_code = base::PLATFORM_FILE_ERROR_FAILED; |
| 409 return NULL; | 399 return NULL; |
| 410 } | 400 } |
| 411 | 401 |
| 412 base::PlatformFileError fs_error = base::PLATFORM_FILE_OK; | 402 base::PlatformFileError fs_error = base::PLATFORM_FILE_OK; |
| 413 FileSystemOperation* operation = | 403 FileSystemOperation* operation = |
| 414 mount_point_provider->CreateFileSystemOperation(url, this, &fs_error); | 404 backend->CreateFileSystemOperation(url, this, &fs_error); |
| 415 | 405 |
| 416 if (error_code) | 406 if (error_code) |
| 417 *error_code = fs_error; | 407 *error_code = fs_error; |
| 418 return operation; | 408 return operation; |
| 419 } | 409 } |
| 420 | 410 |
| 421 | 411 |
| 422 FileSystemURL FileSystemContext::CrackFileSystemURL( | 412 FileSystemURL FileSystemContext::CrackFileSystemURL( |
| 423 const FileSystemURL& url) const { | 413 const FileSystemURL& url) const { |
| 424 if (!url.is_valid()) | 414 if (!url.is_valid()) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 439 if (cracked.is_valid()) | 429 if (cracked.is_valid()) |
| 440 break; | 430 break; |
| 441 } | 431 } |
| 442 if (cracked == current) | 432 if (cracked == current) |
| 443 break; | 433 break; |
| 444 current = cracked; | 434 current = cracked; |
| 445 } | 435 } |
| 446 return current; | 436 return current; |
| 447 } | 437 } |
| 448 | 438 |
| 449 void FileSystemContext::RegisterMountPointProvider( | 439 void FileSystemContext::RegisterBackend( |
| 450 FileSystemMountPointProvider* provider) { | 440 FileSystemBackend* backend) { |
| 451 const FileSystemType mount_types[] = { | 441 const FileSystemType mount_types[] = { |
| 452 kFileSystemTypeTemporary, | 442 kFileSystemTypeTemporary, |
| 453 kFileSystemTypePersistent, | 443 kFileSystemTypePersistent, |
| 454 kFileSystemTypeIsolated, | 444 kFileSystemTypeIsolated, |
| 455 kFileSystemTypeExternal, | 445 kFileSystemTypeExternal, |
| 456 }; | 446 }; |
| 457 // Register mount point providers for public mount types. | 447 // Register file system backends for public mount types. |
| 458 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(mount_types); ++j) { | 448 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(mount_types); ++j) { |
| 459 if (provider->CanHandleType(mount_types[j])) { | 449 if (backend->CanHandleType(mount_types[j])) { |
| 460 const bool inserted = provider_map_.insert( | 450 const bool inserted = backend_map_.insert( |
| 461 std::make_pair(mount_types[j], provider)).second; | 451 std::make_pair(mount_types[j], backend)).second; |
| 462 DCHECK(inserted); | 452 DCHECK(inserted); |
| 463 } | 453 } |
| 464 } | 454 } |
| 465 // Register mount point providers for internal types. | 455 // Register file system backends for internal types. |
| 466 for (int t = kFileSystemInternalTypeEnumStart + 1; | 456 for (int t = kFileSystemInternalTypeEnumStart + 1; |
| 467 t < kFileSystemInternalTypeEnumEnd; ++t) { | 457 t < kFileSystemInternalTypeEnumEnd; ++t) { |
| 468 FileSystemType type = static_cast<FileSystemType>(t); | 458 FileSystemType type = static_cast<FileSystemType>(t); |
| 469 if (provider->CanHandleType(type)) { | 459 if (backend->CanHandleType(type)) { |
| 470 const bool inserted = provider_map_.insert( | 460 const bool inserted = backend_map_.insert( |
| 471 std::make_pair(type, provider)).second; | 461 std::make_pair(type, backend)).second; |
| 472 DCHECK(inserted); | 462 DCHECK(inserted); |
| 473 } | 463 } |
| 474 } | 464 } |
| 475 } | 465 } |
| 476 | 466 |
| 477 } // namespace fileapi | 467 } // namespace fileapi |
| OLD | NEW |