| 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/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h" | 10 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h" |
| 11 #include "chrome/browser/chromeos/fileapi/file_system_backend_delegate.h" | 11 #include "chrome/browser/chromeos/fileapi/file_system_backend_delegate.h" |
| 12 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
| 12 #include "chromeos/dbus/cros_disks_client.h" | 13 #include "chromeos/dbus/cros_disks_client.h" |
| 13 #include "webkit/browser/blob/file_stream_reader.h" | 14 #include "webkit/browser/blob/file_stream_reader.h" |
| 14 #include "webkit/browser/fileapi/async_file_util.h" | 15 #include "webkit/browser/fileapi/async_file_util.h" |
| 15 #include "webkit/browser/fileapi/external_mount_points.h" | 16 #include "webkit/browser/fileapi/external_mount_points.h" |
| 16 #include "webkit/browser/fileapi/file_stream_writer.h" | 17 #include "webkit/browser/fileapi/file_stream_writer.h" |
| 17 #include "webkit/browser/fileapi/file_system_context.h" | 18 #include "webkit/browser/fileapi/file_system_context.h" |
| 18 #include "webkit/browser/fileapi/file_system_operation.h" | 19 #include "webkit/browser/fileapi/file_system_operation.h" |
| 19 #include "webkit/browser/fileapi/file_system_operation_context.h" | 20 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 20 #include "webkit/browser/fileapi/file_system_url.h" | 21 #include "webkit/browser/fileapi/file_system_url.h" |
| 21 | 22 |
| 22 namespace chromeos { | 23 namespace chromeos { |
| 23 | 24 |
| 24 // static | 25 // static |
| 25 bool FileSystemBackend::CanHandleURL(const fileapi::FileSystemURL& url) { | 26 bool FileSystemBackend::CanHandleURL(const fileapi::FileSystemURL& url) { |
| 26 if (!url.is_valid()) | 27 if (!url.is_valid()) |
| 27 return false; | 28 return false; |
| 28 return url.type() == fileapi::kFileSystemTypeNativeLocal || | 29 return url.type() == fileapi::kFileSystemTypeNativeLocal || |
| 29 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || | 30 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || |
| 30 url.type() == fileapi::kFileSystemTypeDrive || | 31 url.type() == fileapi::kFileSystemTypeDrive || |
| 31 url.type() == fileapi::kFileSystemTypeProvided; | 32 url.type() == fileapi::kFileSystemTypeProvided || |
| 33 url.type() == fileapi::kFileSystemTypeDeviceMediaAsFileStorage; |
| 32 } | 34 } |
| 33 | 35 |
| 34 FileSystemBackend::FileSystemBackend( | 36 FileSystemBackend::FileSystemBackend( |
| 35 FileSystemBackendDelegate* drive_delegate, | 37 FileSystemBackendDelegate* drive_delegate, |
| 36 FileSystemBackendDelegate* file_system_provider_delegate, | 38 FileSystemBackendDelegate* file_system_provider_delegate, |
| 39 FileSystemBackendDelegate* mtp_delegate, |
| 37 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | 40 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
| 38 scoped_refptr<fileapi::ExternalMountPoints> mount_points, | 41 scoped_refptr<fileapi::ExternalMountPoints> mount_points, |
| 39 fileapi::ExternalMountPoints* system_mount_points) | 42 fileapi::ExternalMountPoints* system_mount_points) |
| 40 : special_storage_policy_(special_storage_policy), | 43 : special_storage_policy_(special_storage_policy), |
| 41 file_access_permissions_(new FileAccessPermissions()), | 44 file_access_permissions_(new FileAccessPermissions()), |
| 42 local_file_util_(fileapi::AsyncFileUtil::CreateForLocalFileSystem()), | 45 local_file_util_(fileapi::AsyncFileUtil::CreateForLocalFileSystem()), |
| 43 drive_delegate_(drive_delegate), | 46 drive_delegate_(drive_delegate), |
| 44 file_system_provider_delegate_(file_system_provider_delegate), | 47 file_system_provider_delegate_(file_system_provider_delegate), |
| 48 mtp_delegate_(mtp_delegate), |
| 45 mount_points_(mount_points), | 49 mount_points_(mount_points), |
| 46 system_mount_points_(system_mount_points) {} | 50 system_mount_points_(system_mount_points) {} |
| 47 | 51 |
| 48 FileSystemBackend::~FileSystemBackend() { | 52 FileSystemBackend::~FileSystemBackend() { |
| 49 } | 53 } |
| 50 | 54 |
| 51 void FileSystemBackend::AddSystemMountPoints() { | 55 void FileSystemBackend::AddSystemMountPoints() { |
| 52 // RegisterFileSystem() is no-op if the mount point with the same name | 56 // RegisterFileSystem() is no-op if the mount point with the same name |
| 53 // already exists, hence it's safe to call without checking if a mount | 57 // already exists, hence it's safe to call without checking if a mount |
| 54 // point already exists or not. | 58 // point already exists or not. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 69 base::FilePath(FILE_PATH_LITERAL("/usr/share/oem"))); | 73 base::FilePath(FILE_PATH_LITERAL("/usr/share/oem"))); |
| 70 } | 74 } |
| 71 | 75 |
| 72 bool FileSystemBackend::CanHandleType(fileapi::FileSystemType type) const { | 76 bool FileSystemBackend::CanHandleType(fileapi::FileSystemType type) const { |
| 73 switch (type) { | 77 switch (type) { |
| 74 case fileapi::kFileSystemTypeExternal: | 78 case fileapi::kFileSystemTypeExternal: |
| 75 case fileapi::kFileSystemTypeDrive: | 79 case fileapi::kFileSystemTypeDrive: |
| 76 case fileapi::kFileSystemTypeRestrictedNativeLocal: | 80 case fileapi::kFileSystemTypeRestrictedNativeLocal: |
| 77 case fileapi::kFileSystemTypeNativeLocal: | 81 case fileapi::kFileSystemTypeNativeLocal: |
| 78 case fileapi::kFileSystemTypeNativeForPlatformApp: | 82 case fileapi::kFileSystemTypeNativeForPlatformApp: |
| 83 case fileapi::kFileSystemTypeDeviceMediaAsFileStorage: |
| 79 return true; | 84 return true; |
| 80 default: | 85 default: |
| 81 return false; | 86 return false; |
| 82 } | 87 } |
| 83 } | 88 } |
| 84 | 89 |
| 85 void FileSystemBackend::Initialize(fileapi::FileSystemContext* context) { | 90 void FileSystemBackend::Initialize(fileapi::FileSystemContext* context) { |
| 86 } | 91 } |
| 87 | 92 |
| 88 void FileSystemBackend::ResolveURL(const fileapi::FileSystemURL& url, | 93 void FileSystemBackend::ResolveURL(const fileapi::FileSystemURL& url, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 fileapi::AsyncFileUtil* FileSystemBackend::GetAsyncFileUtil( | 223 fileapi::AsyncFileUtil* FileSystemBackend::GetAsyncFileUtil( |
| 219 fileapi::FileSystemType type) { | 224 fileapi::FileSystemType type) { |
| 220 switch (type) { | 225 switch (type) { |
| 221 case fileapi::kFileSystemTypeDrive: | 226 case fileapi::kFileSystemTypeDrive: |
| 222 return drive_delegate_->GetAsyncFileUtil(type); | 227 return drive_delegate_->GetAsyncFileUtil(type); |
| 223 case fileapi::kFileSystemTypeProvided: | 228 case fileapi::kFileSystemTypeProvided: |
| 224 return file_system_provider_delegate_->GetAsyncFileUtil(type); | 229 return file_system_provider_delegate_->GetAsyncFileUtil(type); |
| 225 case fileapi::kFileSystemTypeNativeLocal: | 230 case fileapi::kFileSystemTypeNativeLocal: |
| 226 case fileapi::kFileSystemTypeRestrictedNativeLocal: | 231 case fileapi::kFileSystemTypeRestrictedNativeLocal: |
| 227 return local_file_util_.get(); | 232 return local_file_util_.get(); |
| 233 case fileapi::kFileSystemTypeDeviceMediaAsFileStorage: |
| 234 return mtp_delegate_->GetAsyncFileUtil(type); |
| 228 default: | 235 default: |
| 229 NOTREACHED(); | 236 NOTREACHED(); |
| 230 } | 237 } |
| 231 return NULL; | 238 return NULL; |
| 232 } | 239 } |
| 233 | 240 |
| 234 fileapi::CopyOrMoveFileValidatorFactory* | 241 fileapi::CopyOrMoveFileValidatorFactory* |
| 235 FileSystemBackend::GetCopyOrMoveFileValidatorFactory( | 242 FileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
| 236 fileapi::FileSystemType type, base::File::Error* error_code) { | 243 fileapi::FileSystemType type, base::File::Error* error_code) { |
| 237 DCHECK(error_code); | 244 DCHECK(error_code); |
| 238 *error_code = base::File::FILE_OK; | 245 *error_code = base::File::FILE_OK; |
| 239 return NULL; | 246 return NULL; |
| 240 } | 247 } |
| 241 | 248 |
| 242 fileapi::FileSystemOperation* FileSystemBackend::CreateFileSystemOperation( | 249 fileapi::FileSystemOperation* FileSystemBackend::CreateFileSystemOperation( |
| 243 const fileapi::FileSystemURL& url, | 250 const fileapi::FileSystemURL& url, |
| 244 fileapi::FileSystemContext* context, | 251 fileapi::FileSystemContext* context, |
| 245 base::File::Error* error_code) const { | 252 base::File::Error* error_code) const { |
| 246 DCHECK(url.is_valid()); | 253 DCHECK(url.is_valid()); |
| 247 | 254 |
| 248 if (!IsAccessAllowed(url)) { | 255 if (!IsAccessAllowed(url)) { |
| 249 *error_code = base::File::FILE_ERROR_SECURITY; | 256 *error_code = base::File::FILE_ERROR_SECURITY; |
| 250 return NULL; | 257 return NULL; |
| 251 } | 258 } |
| 252 | 259 |
| 260 if (url.type() == fileapi::kFileSystemTypeDeviceMediaAsFileStorage) { |
| 261 // MTP file operations run on MediaTaskRunner. |
| 262 return fileapi::FileSystemOperation::Create( |
| 263 url, context, |
| 264 make_scoped_ptr(new fileapi::FileSystemOperationContext( |
| 265 context, MediaFileSystemBackend::MediaTaskRunner()))); |
| 266 } |
| 267 |
| 253 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || | 268 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || |
| 254 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || | 269 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || |
| 255 url.type() == fileapi::kFileSystemTypeDrive); | 270 url.type() == fileapi::kFileSystemTypeDrive); |
| 256 return fileapi::FileSystemOperation::Create( | 271 return fileapi::FileSystemOperation::Create( |
| 257 url, context, | 272 url, context, |
| 258 make_scoped_ptr(new fileapi::FileSystemOperationContext(context))); | 273 make_scoped_ptr(new fileapi::FileSystemOperationContext(context))); |
| 259 } | 274 } |
| 260 | 275 |
| 261 bool FileSystemBackend::SupportsStreaming( | 276 bool FileSystemBackend::SupportsStreaming( |
| 262 const fileapi::FileSystemURL& url) const { | 277 const fileapi::FileSystemURL& url) const { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 279 return drive_delegate_->CreateFileStreamReader( | 294 return drive_delegate_->CreateFileStreamReader( |
| 280 url, offset, expected_modification_time, context); | 295 url, offset, expected_modification_time, context); |
| 281 case fileapi::kFileSystemTypeProvided: | 296 case fileapi::kFileSystemTypeProvided: |
| 282 return file_system_provider_delegate_->CreateFileStreamReader( | 297 return file_system_provider_delegate_->CreateFileStreamReader( |
| 283 url, offset, expected_modification_time, context); | 298 url, offset, expected_modification_time, context); |
| 284 case fileapi::kFileSystemTypeNativeLocal: | 299 case fileapi::kFileSystemTypeNativeLocal: |
| 285 case fileapi::kFileSystemTypeRestrictedNativeLocal: | 300 case fileapi::kFileSystemTypeRestrictedNativeLocal: |
| 286 return scoped_ptr<webkit_blob::FileStreamReader>( | 301 return scoped_ptr<webkit_blob::FileStreamReader>( |
| 287 webkit_blob::FileStreamReader::CreateForFileSystemFile( | 302 webkit_blob::FileStreamReader::CreateForFileSystemFile( |
| 288 context, url, offset, expected_modification_time)); | 303 context, url, offset, expected_modification_time)); |
| 304 case fileapi::kFileSystemTypeDeviceMediaAsFileStorage: |
| 305 return mtp_delegate_->CreateFileStreamReader( |
| 306 url, offset, expected_modification_time, context); |
| 289 default: | 307 default: |
| 290 NOTREACHED(); | 308 NOTREACHED(); |
| 291 } | 309 } |
| 292 return scoped_ptr<webkit_blob::FileStreamReader>(); | 310 return scoped_ptr<webkit_blob::FileStreamReader>(); |
| 293 } | 311 } |
| 294 | 312 |
| 295 scoped_ptr<fileapi::FileStreamWriter> | 313 scoped_ptr<fileapi::FileStreamWriter> |
| 296 FileSystemBackend::CreateFileStreamWriter( | 314 FileSystemBackend::CreateFileStreamWriter( |
| 297 const fileapi::FileSystemURL& url, | 315 const fileapi::FileSystemURL& url, |
| 298 int64 offset, | 316 int64 offset, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 309 return file_system_provider_delegate_->CreateFileStreamWriter( | 327 return file_system_provider_delegate_->CreateFileStreamWriter( |
| 310 url, offset, context); | 328 url, offset, context); |
| 311 case fileapi::kFileSystemTypeNativeLocal: | 329 case fileapi::kFileSystemTypeNativeLocal: |
| 312 return scoped_ptr<fileapi::FileStreamWriter>( | 330 return scoped_ptr<fileapi::FileStreamWriter>( |
| 313 fileapi::FileStreamWriter::CreateForLocalFile( | 331 fileapi::FileStreamWriter::CreateForLocalFile( |
| 314 context->default_file_task_runner(), url.path(), offset, | 332 context->default_file_task_runner(), url.path(), offset, |
| 315 fileapi::FileStreamWriter::OPEN_EXISTING_FILE)); | 333 fileapi::FileStreamWriter::OPEN_EXISTING_FILE)); |
| 316 case fileapi::kFileSystemTypeRestrictedNativeLocal: | 334 case fileapi::kFileSystemTypeRestrictedNativeLocal: |
| 317 // Restricted native local file system is read only. | 335 // Restricted native local file system is read only. |
| 318 return scoped_ptr<fileapi::FileStreamWriter>(); | 336 return scoped_ptr<fileapi::FileStreamWriter>(); |
| 337 case fileapi::kFileSystemTypeDeviceMediaAsFileStorage: |
| 338 return mtp_delegate_->CreateFileStreamWriter(url, offset, context); |
| 319 default: | 339 default: |
| 320 NOTREACHED(); | 340 NOTREACHED(); |
| 321 } | 341 } |
| 322 return scoped_ptr<fileapi::FileStreamWriter>(); | 342 return scoped_ptr<fileapi::FileStreamWriter>(); |
| 323 } | 343 } |
| 324 | 344 |
| 325 bool FileSystemBackend::GetVirtualPath( | 345 bool FileSystemBackend::GetVirtualPath( |
| 326 const base::FilePath& filesystem_path, | 346 const base::FilePath& filesystem_path, |
| 327 base::FilePath* virtual_path) { | 347 base::FilePath* virtual_path) { |
| 328 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || | 348 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || |
| 329 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); | 349 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); |
| 330 } | 350 } |
| 331 | 351 |
| 332 } // namespace chromeos | 352 } // namespace chromeos |
| OLD | NEW |