Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/chromeos/fileapi/file_system_backend.h" | 5 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 namespace chromeos { | 32 namespace chromeos { |
| 33 | 33 |
| 34 // static | 34 // static |
| 35 bool FileSystemBackend::CanHandleURL(const fileapi::FileSystemURL& url) { | 35 bool FileSystemBackend::CanHandleURL(const fileapi::FileSystemURL& url) { |
| 36 if (!url.is_valid()) | 36 if (!url.is_valid()) |
| 37 return false; | 37 return false; |
| 38 return url.type() == fileapi::kFileSystemTypeNativeLocal || | 38 return url.type() == fileapi::kFileSystemTypeNativeLocal || |
| 39 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || | 39 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || |
| 40 url.type() == fileapi::kFileSystemTypeDrive; | 40 url.type() == fileapi::kFileSystemTypeDrive || |
| 41 url.type() == fileapi::kFileSystemTypeProvided; | |
| 41 } | 42 } |
| 42 | 43 |
| 43 FileSystemBackend::FileSystemBackend( | 44 FileSystemBackend::FileSystemBackend( |
| 44 FileSystemBackendDelegate* drive_delegate, | 45 FileSystemBackendDelegate* drive_delegate, |
| 46 FileSystemBackendDelegate* file_system_provider_delegate, | |
| 45 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | 47 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
| 46 scoped_refptr<fileapi::ExternalMountPoints> mount_points, | 48 scoped_refptr<fileapi::ExternalMountPoints> mount_points, |
| 47 fileapi::ExternalMountPoints* system_mount_points) | 49 fileapi::ExternalMountPoints* system_mount_points) |
| 48 : special_storage_policy_(special_storage_policy), | 50 : special_storage_policy_(special_storage_policy), |
| 49 file_access_permissions_(new FileAccessPermissions()), | 51 file_access_permissions_(new FileAccessPermissions()), |
| 50 local_file_util_(fileapi::AsyncFileUtil::CreateForLocalFileSystem()), | 52 local_file_util_(fileapi::AsyncFileUtil::CreateForLocalFileSystem()), |
| 51 drive_delegate_(drive_delegate), | 53 drive_delegate_(drive_delegate), |
| 54 file_system_provider_delegate_(file_system_provider_delegate), | |
|
mtomasz
2014/04/21 01:09:35
@kinaba: This was missing, causing a leak of the p
| |
| 52 mount_points_(mount_points), | 55 mount_points_(mount_points), |
| 53 system_mount_points_(system_mount_points) { | 56 system_mount_points_(system_mount_points) {} |
| 54 } | |
| 55 | 57 |
| 56 FileSystemBackend::~FileSystemBackend() { | 58 FileSystemBackend::~FileSystemBackend() { |
| 57 } | 59 } |
| 58 | 60 |
| 59 void FileSystemBackend::AddSystemMountPoints() { | 61 void FileSystemBackend::AddSystemMountPoints() { |
| 60 // RegisterFileSystem() is no-op if the mount point with the same name | 62 // RegisterFileSystem() is no-op if the mount point with the same name |
| 61 // already exists, hence it's safe to call without checking if a mount | 63 // already exists, hence it's safe to call without checking if a mount |
| 62 // point already exists or not. | 64 // point already exists or not. |
| 63 system_mount_points_->RegisterFileSystem( | 65 system_mount_points_->RegisterFileSystem( |
| 64 "archive", | 66 "archive", |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 std::vector<base::FilePath> root_dirs; | 227 std::vector<base::FilePath> root_dirs; |
| 226 for (size_t i = 0; i < mount_points.size(); ++i) | 228 for (size_t i = 0; i < mount_points.size(); ++i) |
| 227 root_dirs.push_back(mount_points[i].path); | 229 root_dirs.push_back(mount_points[i].path); |
| 228 return root_dirs; | 230 return root_dirs; |
| 229 } | 231 } |
| 230 | 232 |
| 231 fileapi::AsyncFileUtil* FileSystemBackend::GetAsyncFileUtil( | 233 fileapi::AsyncFileUtil* FileSystemBackend::GetAsyncFileUtil( |
| 232 fileapi::FileSystemType type) { | 234 fileapi::FileSystemType type) { |
| 233 if (type == fileapi::kFileSystemTypeDrive) | 235 if (type == fileapi::kFileSystemTypeDrive) |
| 234 return drive_delegate_->GetAsyncFileUtil(type); | 236 return drive_delegate_->GetAsyncFileUtil(type); |
| 237 if (type == fileapi::kFileSystemTypeProvided) | |
| 238 return file_system_provider_delegate_->GetAsyncFileUtil(type); | |
| 235 | 239 |
| 236 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || | 240 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || |
| 237 type == fileapi::kFileSystemTypeRestrictedNativeLocal); | 241 type == fileapi::kFileSystemTypeRestrictedNativeLocal); |
| 238 return local_file_util_.get(); | 242 return local_file_util_.get(); |
| 239 } | 243 } |
| 240 | 244 |
| 241 fileapi::CopyOrMoveFileValidatorFactory* | 245 fileapi::CopyOrMoveFileValidatorFactory* |
| 242 FileSystemBackend::GetCopyOrMoveFileValidatorFactory( | 246 FileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
| 243 fileapi::FileSystemType type, base::File::Error* error_code) { | 247 fileapi::FileSystemType type, base::File::Error* error_code) { |
| 244 DCHECK(error_code); | 248 DCHECK(error_code); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 DCHECK(url.is_valid()); | 283 DCHECK(url.is_valid()); |
| 280 | 284 |
| 281 if (!IsAccessAllowed(url)) | 285 if (!IsAccessAllowed(url)) |
| 282 return scoped_ptr<webkit_blob::FileStreamReader>(); | 286 return scoped_ptr<webkit_blob::FileStreamReader>(); |
| 283 | 287 |
| 284 if (url.type() == fileapi::kFileSystemTypeDrive) { | 288 if (url.type() == fileapi::kFileSystemTypeDrive) { |
| 285 return drive_delegate_->CreateFileStreamReader( | 289 return drive_delegate_->CreateFileStreamReader( |
| 286 url, offset, expected_modification_time, context); | 290 url, offset, expected_modification_time, context); |
| 287 } | 291 } |
| 288 | 292 |
| 293 if (url.type() == fileapi::kFileSystemTypeProvided) { | |
| 294 return file_system_provider_delegate_->CreateFileStreamReader( | |
| 295 url, offset, expected_modification_time, context); | |
| 296 } | |
| 297 | |
| 289 return scoped_ptr<webkit_blob::FileStreamReader>( | 298 return scoped_ptr<webkit_blob::FileStreamReader>( |
| 290 webkit_blob::FileStreamReader::CreateForFileSystemFile( | 299 webkit_blob::FileStreamReader::CreateForFileSystemFile( |
| 291 context, url, offset, expected_modification_time)); | 300 context, url, offset, expected_modification_time)); |
| 292 } | 301 } |
| 293 | 302 |
| 294 scoped_ptr<fileapi::FileStreamWriter> | 303 scoped_ptr<fileapi::FileStreamWriter> |
| 295 FileSystemBackend::CreateFileStreamWriter( | 304 FileSystemBackend::CreateFileStreamWriter( |
| 296 const fileapi::FileSystemURL& url, | 305 const fileapi::FileSystemURL& url, |
| 297 int64 offset, | 306 int64 offset, |
| 298 fileapi::FileSystemContext* context) const { | 307 fileapi::FileSystemContext* context) const { |
| 299 DCHECK(url.is_valid()); | 308 DCHECK(url.is_valid()); |
| 300 | 309 |
| 301 if (!IsAccessAllowed(url)) | 310 if (!IsAccessAllowed(url)) |
| 302 return scoped_ptr<fileapi::FileStreamWriter>(); | 311 return scoped_ptr<fileapi::FileStreamWriter>(); |
| 303 | 312 |
| 304 if (url.type() == fileapi::kFileSystemTypeDrive) | 313 if (url.type() == fileapi::kFileSystemTypeDrive) |
| 305 return drive_delegate_->CreateFileStreamWriter(url, offset, context); | 314 return drive_delegate_->CreateFileStreamWriter(url, offset, context); |
| 306 | 315 |
| 307 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) | 316 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) |
| 308 return scoped_ptr<fileapi::FileStreamWriter>(); | 317 return scoped_ptr<fileapi::FileStreamWriter>(); |
| 309 | 318 |
| 319 if (url.type() == fileapi::kFileSystemTypeProvided) { | |
| 320 return file_system_provider_delegate_->CreateFileStreamWriter( | |
| 321 url, offset, context); | |
| 322 } | |
| 323 | |
| 310 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); | 324 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); |
| 311 return scoped_ptr<fileapi::FileStreamWriter>( | 325 return scoped_ptr<fileapi::FileStreamWriter>( |
| 312 fileapi::FileStreamWriter::CreateForLocalFile( | 326 fileapi::FileStreamWriter::CreateForLocalFile( |
| 313 context->default_file_task_runner(), url.path(), offset, | 327 context->default_file_task_runner(), url.path(), offset, |
| 314 fileapi::FileStreamWriter::OPEN_EXISTING_FILE)); | 328 fileapi::FileStreamWriter::OPEN_EXISTING_FILE)); |
| 315 } | 329 } |
| 316 | 330 |
| 317 bool FileSystemBackend::GetVirtualPath( | 331 bool FileSystemBackend::GetVirtualPath( |
| 318 const base::FilePath& filesystem_path, | 332 const base::FilePath& filesystem_path, |
| 319 base::FilePath* virtual_path) { | 333 base::FilePath* virtual_path) { |
| 320 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || | 334 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || |
| 321 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); | 335 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); |
| 322 } | 336 } |
| 323 | 337 |
| 324 } // namespace chromeos | 338 } // namespace chromeos |
| OLD | NEW |