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