| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 10 |
| 9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 13 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h" | 15 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h" |
| 14 #include "chrome/browser/chromeos/fileapi/file_system_backend_delegate.h" | 16 #include "chrome/browser/chromeos/fileapi/file_system_backend_delegate.h" |
| 15 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 17 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
| 16 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 17 #include "chromeos/chromeos_switches.h" | 19 #include "chromeos/chromeos_switches.h" |
| 18 #include "chromeos/dbus/cros_disks_client.h" | 20 #include "chromeos/dbus/cros_disks_client.h" |
| 19 #include "storage/browser/fileapi/async_file_util.h" | 21 #include "storage/browser/fileapi/async_file_util.h" |
| 20 #include "storage/browser/fileapi/external_mount_points.h" | 22 #include "storage/browser/fileapi/external_mount_points.h" |
| 21 #include "storage/browser/fileapi/file_stream_reader.h" | 23 #include "storage/browser/fileapi/file_stream_reader.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 DCHECK(url.is_valid()); | 275 DCHECK(url.is_valid()); |
| 274 | 276 |
| 275 if (!IsAccessAllowed(url)) { | 277 if (!IsAccessAllowed(url)) { |
| 276 *error_code = base::File::FILE_ERROR_SECURITY; | 278 *error_code = base::File::FILE_ERROR_SECURITY; |
| 277 return NULL; | 279 return NULL; |
| 278 } | 280 } |
| 279 | 281 |
| 280 if (url.type() == storage::kFileSystemTypeDeviceMediaAsFileStorage) { | 282 if (url.type() == storage::kFileSystemTypeDeviceMediaAsFileStorage) { |
| 281 // MTP file operations run on MediaTaskRunner. | 283 // MTP file operations run on MediaTaskRunner. |
| 282 return storage::FileSystemOperation::Create( | 284 return storage::FileSystemOperation::Create( |
| 283 url, | 285 url, context, |
| 284 context, | 286 base::WrapUnique(new storage::FileSystemOperationContext( |
| 285 make_scoped_ptr(new storage::FileSystemOperationContext( | |
| 286 context, MediaFileSystemBackend::MediaTaskRunner().get()))); | 287 context, MediaFileSystemBackend::MediaTaskRunner().get()))); |
| 287 } | 288 } |
| 288 | 289 |
| 289 DCHECK(url.type() == storage::kFileSystemTypeNativeLocal || | 290 DCHECK(url.type() == storage::kFileSystemTypeNativeLocal || |
| 290 url.type() == storage::kFileSystemTypeRestrictedNativeLocal || | 291 url.type() == storage::kFileSystemTypeRestrictedNativeLocal || |
| 291 url.type() == storage::kFileSystemTypeDrive || | 292 url.type() == storage::kFileSystemTypeDrive || |
| 292 url.type() == storage::kFileSystemTypeProvided); | 293 url.type() == storage::kFileSystemTypeProvided); |
| 293 return storage::FileSystemOperation::Create( | 294 return storage::FileSystemOperation::Create( |
| 294 url, | 295 url, context, |
| 295 context, | 296 base::WrapUnique(new storage::FileSystemOperationContext(context))); |
| 296 make_scoped_ptr(new storage::FileSystemOperationContext(context))); | |
| 297 } | 297 } |
| 298 | 298 |
| 299 bool FileSystemBackend::SupportsStreaming( | 299 bool FileSystemBackend::SupportsStreaming( |
| 300 const storage::FileSystemURL& url) const { | 300 const storage::FileSystemURL& url) const { |
| 301 return url.type() == storage::kFileSystemTypeDrive || | 301 return url.type() == storage::kFileSystemTypeDrive || |
| 302 url.type() == storage::kFileSystemTypeProvided || | 302 url.type() == storage::kFileSystemTypeProvided || |
| 303 url.type() == storage::kFileSystemTypeDeviceMediaAsFileStorage; | 303 url.type() == storage::kFileSystemTypeDeviceMediaAsFileStorage; |
| 304 } | 304 } |
| 305 | 305 |
| 306 bool FileSystemBackend::HasInplaceCopyImplementation( | 306 bool FileSystemBackend::HasInplaceCopyImplementation( |
| 307 storage::FileSystemType type) const { | 307 storage::FileSystemType type) const { |
| 308 switch (type) { | 308 switch (type) { |
| 309 case storage::kFileSystemTypeDrive: | 309 case storage::kFileSystemTypeDrive: |
| 310 case storage::kFileSystemTypeProvided: | 310 case storage::kFileSystemTypeProvided: |
| 311 case storage::kFileSystemTypeDeviceMediaAsFileStorage: | 311 case storage::kFileSystemTypeDeviceMediaAsFileStorage: |
| 312 return true; | 312 return true; |
| 313 case storage::kFileSystemTypeNativeLocal: | 313 case storage::kFileSystemTypeNativeLocal: |
| 314 case storage::kFileSystemTypeRestrictedNativeLocal: | 314 case storage::kFileSystemTypeRestrictedNativeLocal: |
| 315 return false; | 315 return false; |
| 316 default: | 316 default: |
| 317 NOTREACHED(); | 317 NOTREACHED(); |
| 318 } | 318 } |
| 319 return true; | 319 return true; |
| 320 } | 320 } |
| 321 | 321 |
| 322 scoped_ptr<storage::FileStreamReader> FileSystemBackend::CreateFileStreamReader( | 322 std::unique_ptr<storage::FileStreamReader> |
| 323 FileSystemBackend::CreateFileStreamReader( |
| 323 const storage::FileSystemURL& url, | 324 const storage::FileSystemURL& url, |
| 324 int64_t offset, | 325 int64_t offset, |
| 325 int64_t max_bytes_to_read, | 326 int64_t max_bytes_to_read, |
| 326 const base::Time& expected_modification_time, | 327 const base::Time& expected_modification_time, |
| 327 storage::FileSystemContext* context) const { | 328 storage::FileSystemContext* context) const { |
| 328 DCHECK(url.is_valid()); | 329 DCHECK(url.is_valid()); |
| 329 | 330 |
| 330 if (!IsAccessAllowed(url)) | 331 if (!IsAccessAllowed(url)) |
| 331 return scoped_ptr<storage::FileStreamReader>(); | 332 return std::unique_ptr<storage::FileStreamReader>(); |
| 332 | 333 |
| 333 switch (url.type()) { | 334 switch (url.type()) { |
| 334 case storage::kFileSystemTypeDrive: | 335 case storage::kFileSystemTypeDrive: |
| 335 return drive_delegate_->CreateFileStreamReader( | 336 return drive_delegate_->CreateFileStreamReader( |
| 336 url, offset, max_bytes_to_read, expected_modification_time, context); | 337 url, offset, max_bytes_to_read, expected_modification_time, context); |
| 337 case storage::kFileSystemTypeProvided: | 338 case storage::kFileSystemTypeProvided: |
| 338 return file_system_provider_delegate_->CreateFileStreamReader( | 339 return file_system_provider_delegate_->CreateFileStreamReader( |
| 339 url, offset, max_bytes_to_read, expected_modification_time, context); | 340 url, offset, max_bytes_to_read, expected_modification_time, context); |
| 340 case storage::kFileSystemTypeNativeLocal: | 341 case storage::kFileSystemTypeNativeLocal: |
| 341 case storage::kFileSystemTypeRestrictedNativeLocal: | 342 case storage::kFileSystemTypeRestrictedNativeLocal: |
| 342 return scoped_ptr<storage::FileStreamReader>( | 343 return std::unique_ptr<storage::FileStreamReader>( |
| 343 storage::FileStreamReader::CreateForFileSystemFile( | 344 storage::FileStreamReader::CreateForFileSystemFile( |
| 344 context, url, offset, expected_modification_time)); | 345 context, url, offset, expected_modification_time)); |
| 345 case storage::kFileSystemTypeDeviceMediaAsFileStorage: | 346 case storage::kFileSystemTypeDeviceMediaAsFileStorage: |
| 346 return mtp_delegate_->CreateFileStreamReader( | 347 return mtp_delegate_->CreateFileStreamReader( |
| 347 url, offset, max_bytes_to_read, expected_modification_time, context); | 348 url, offset, max_bytes_to_read, expected_modification_time, context); |
| 348 default: | 349 default: |
| 349 NOTREACHED(); | 350 NOTREACHED(); |
| 350 } | 351 } |
| 351 return scoped_ptr<storage::FileStreamReader>(); | 352 return std::unique_ptr<storage::FileStreamReader>(); |
| 352 } | 353 } |
| 353 | 354 |
| 354 scoped_ptr<storage::FileStreamWriter> FileSystemBackend::CreateFileStreamWriter( | 355 std::unique_ptr<storage::FileStreamWriter> |
| 356 FileSystemBackend::CreateFileStreamWriter( |
| 355 const storage::FileSystemURL& url, | 357 const storage::FileSystemURL& url, |
| 356 int64_t offset, | 358 int64_t offset, |
| 357 storage::FileSystemContext* context) const { | 359 storage::FileSystemContext* context) const { |
| 358 DCHECK(url.is_valid()); | 360 DCHECK(url.is_valid()); |
| 359 | 361 |
| 360 if (!IsAccessAllowed(url)) | 362 if (!IsAccessAllowed(url)) |
| 361 return scoped_ptr<storage::FileStreamWriter>(); | 363 return std::unique_ptr<storage::FileStreamWriter>(); |
| 362 | 364 |
| 363 switch (url.type()) { | 365 switch (url.type()) { |
| 364 case storage::kFileSystemTypeDrive: | 366 case storage::kFileSystemTypeDrive: |
| 365 return drive_delegate_->CreateFileStreamWriter(url, offset, context); | 367 return drive_delegate_->CreateFileStreamWriter(url, offset, context); |
| 366 case storage::kFileSystemTypeProvided: | 368 case storage::kFileSystemTypeProvided: |
| 367 return file_system_provider_delegate_->CreateFileStreamWriter( | 369 return file_system_provider_delegate_->CreateFileStreamWriter( |
| 368 url, offset, context); | 370 url, offset, context); |
| 369 case storage::kFileSystemTypeNativeLocal: | 371 case storage::kFileSystemTypeNativeLocal: |
| 370 return scoped_ptr<storage::FileStreamWriter>( | 372 return std::unique_ptr<storage::FileStreamWriter>( |
| 371 storage::FileStreamWriter::CreateForLocalFile( | 373 storage::FileStreamWriter::CreateForLocalFile( |
| 372 context->default_file_task_runner(), | 374 context->default_file_task_runner(), url.path(), offset, |
| 373 url.path(), | |
| 374 offset, | |
| 375 storage::FileStreamWriter::OPEN_EXISTING_FILE)); | 375 storage::FileStreamWriter::OPEN_EXISTING_FILE)); |
| 376 case storage::kFileSystemTypeRestrictedNativeLocal: | 376 case storage::kFileSystemTypeRestrictedNativeLocal: |
| 377 // Restricted native local file system is read only. | 377 // Restricted native local file system is read only. |
| 378 return scoped_ptr<storage::FileStreamWriter>(); | 378 return std::unique_ptr<storage::FileStreamWriter>(); |
| 379 case storage::kFileSystemTypeDeviceMediaAsFileStorage: | 379 case storage::kFileSystemTypeDeviceMediaAsFileStorage: |
| 380 return mtp_delegate_->CreateFileStreamWriter(url, offset, context); | 380 return mtp_delegate_->CreateFileStreamWriter(url, offset, context); |
| 381 default: | 381 default: |
| 382 NOTREACHED(); | 382 NOTREACHED(); |
| 383 } | 383 } |
| 384 return scoped_ptr<storage::FileStreamWriter>(); | 384 return std::unique_ptr<storage::FileStreamWriter>(); |
| 385 } | 385 } |
| 386 | 386 |
| 387 bool FileSystemBackend::GetVirtualPath(const base::FilePath& filesystem_path, | 387 bool FileSystemBackend::GetVirtualPath(const base::FilePath& filesystem_path, |
| 388 base::FilePath* virtual_path) const { | 388 base::FilePath* virtual_path) const { |
| 389 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || | 389 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || |
| 390 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); | 390 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); |
| 391 } | 391 } |
| 392 | 392 |
| 393 void FileSystemBackend::GetRedirectURLForContents( | 393 void FileSystemBackend::GetRedirectURLForContents( |
| 394 const storage::FileSystemURL& url, | 394 const storage::FileSystemURL& url, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 424 const base::FilePath& entry_path) const { | 424 const base::FilePath& entry_path) const { |
| 425 base::FilePath virtual_path; | 425 base::FilePath virtual_path; |
| 426 if (!GetVirtualPath(entry_path, &virtual_path)) | 426 if (!GetVirtualPath(entry_path, &virtual_path)) |
| 427 return storage::FileSystemURL(); | 427 return storage::FileSystemURL(); |
| 428 | 428 |
| 429 return context->CreateCrackedFileSystemURL( | 429 return context->CreateCrackedFileSystemURL( |
| 430 GURL() /* origin */, storage::kFileSystemTypeExternal, virtual_path); | 430 GURL() /* origin */, storage::kFileSystemTypeExternal, virtual_path); |
| 431 } | 431 } |
| 432 | 432 |
| 433 } // namespace chromeos | 433 } // namespace chromeos |
| OLD | NEW |