| 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 "chrome/browser/chromeos/drive/file_system_proxy.h" | 5 #include "chrome/browser/chromeos/drive/file_system_proxy.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 const char kFeedField[] = "feed"; | 36 const char kFeedField[] = "feed"; |
| 37 | 37 |
| 38 // Helper function to run reply on results of base::CreatePlatformFile() on | 38 // Helper function to run reply on results of base::CreatePlatformFile() on |
| 39 // IO thread. | 39 // IO thread. |
| 40 void OnPlatformFileOpened( | 40 void OnPlatformFileOpened( |
| 41 const FileSystemOperation::OpenFileCallback& callback, | 41 const FileSystemOperation::OpenFileCallback& callback, |
| 42 base::ProcessHandle peer_handle, | 42 base::ProcessHandle peer_handle, |
| 43 base::PlatformFileError* open_error, | 43 base::PlatformFileError* open_error, |
| 44 base::PlatformFile platform_file) { | 44 base::PlatformFile platform_file) { |
| 45 callback.Run(*open_error, platform_file, peer_handle); | 45 callback.Run(*open_error, platform_file, peer_handle, |
| 46 quota::kQuotaLimitTypeLimited); |
| 46 } | 47 } |
| 47 | 48 |
| 48 // Helper function to run OpenFileCallback from | 49 // Helper function to run OpenFileCallback from |
| 49 // FileSystemProxy::OpenFile(). | 50 // FileSystemProxy::OpenFile(). |
| 50 void OnGetFileByPathForOpen( | 51 void OnGetFileByPathForOpen( |
| 51 const FileSystemOperation::OpenFileCallback& callback, | 52 const FileSystemOperation::OpenFileCallback& callback, |
| 52 int file_flags, | 53 int file_flags, |
| 53 base::ProcessHandle peer_handle, | 54 base::ProcessHandle peer_handle, |
| 54 FileError file_error, | 55 FileError file_error, |
| 55 const base::FilePath& local_path, | 56 const base::FilePath& local_path, |
| 56 const std::string& unused_mime_type, | 57 const std::string& unused_mime_type, |
| 57 DriveFileType file_type) { | 58 DriveFileType file_type) { |
| 58 base::PlatformFileError error = | 59 base::PlatformFileError error = |
| 59 FileErrorToPlatformError(file_error); | 60 FileErrorToPlatformError(file_error); |
| 60 if (error != base::PLATFORM_FILE_OK) { | 61 if (error != base::PLATFORM_FILE_OK) { |
| 61 callback.Run(error, base::kInvalidPlatformFileValue, peer_handle); | 62 callback.Run(error, base::kInvalidPlatformFileValue, peer_handle, |
| 63 quota::kQuotaLimitTypeLimited); |
| 62 return; | 64 return; |
| 63 } | 65 } |
| 64 | 66 |
| 65 base::PlatformFileError* open_error = | 67 base::PlatformFileError* open_error = |
| 66 new base::PlatformFileError(base::PLATFORM_FILE_ERROR_FAILED); | 68 new base::PlatformFileError(base::PLATFORM_FILE_ERROR_FAILED); |
| 67 base::PostTaskAndReplyWithResult( | 69 base::PostTaskAndReplyWithResult( |
| 68 BrowserThread::GetBlockingPool(), | 70 BrowserThread::GetBlockingPool(), |
| 69 FROM_HERE, | 71 FROM_HERE, |
| 70 base::Bind(&base::CreatePlatformFile, | 72 base::Bind(&base::CreatePlatformFile, |
| 71 local_path, | 73 local_path, |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 base::ProcessHandle peer_handle, | 399 base::ProcessHandle peer_handle, |
| 398 const FileSystemOperation::OpenFileCallback& callback, | 400 const FileSystemOperation::OpenFileCallback& callback, |
| 399 FileError file_error, | 401 FileError file_error, |
| 400 const base::FilePath& local_cache_path) { | 402 const base::FilePath& local_cache_path) { |
| 401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 402 | 404 |
| 403 base::PlatformFileError error = | 405 base::PlatformFileError error = |
| 404 FileErrorToPlatformError(file_error); | 406 FileErrorToPlatformError(file_error); |
| 405 | 407 |
| 406 if (error != base::PLATFORM_FILE_OK) { | 408 if (error != base::PLATFORM_FILE_OK) { |
| 407 callback.Run(error, base::kInvalidPlatformFileValue, peer_handle); | 409 callback.Run(error, base::kInvalidPlatformFileValue, peer_handle, |
| 410 quota::kQuotaLimitTypeLimited); |
| 408 return; | 411 return; |
| 409 } | 412 } |
| 410 | 413 |
| 411 // Cache file prepared for modification is available. Truncate it. | 414 // Cache file prepared for modification is available. Truncate it. |
| 412 base::PlatformFileError* result = | 415 base::PlatformFileError* result = |
| 413 new base::PlatformFileError(base::PLATFORM_FILE_ERROR_FAILED); | 416 new base::PlatformFileError(base::PLATFORM_FILE_ERROR_FAILED); |
| 414 bool posted = base::PostTaskAndReplyWithResult( | 417 bool posted = base::PostTaskAndReplyWithResult( |
| 415 BrowserThread::GetBlockingPool(), FROM_HERE, | 418 BrowserThread::GetBlockingPool(), FROM_HERE, |
| 416 base::Bind(&base::CreatePlatformFile, | 419 base::Bind(&base::CreatePlatformFile, |
| 417 local_cache_path, | 420 local_cache_path, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 437 | 440 |
| 438 if ((create_result == base::PLATFORM_FILE_OK) || | 441 if ((create_result == base::PLATFORM_FILE_OK) || |
| 439 ((create_result == base::PLATFORM_FILE_ERROR_EXISTS) && | 442 ((create_result == base::PLATFORM_FILE_ERROR_EXISTS) && |
| 440 (file_flags & base::PLATFORM_FILE_CREATE_ALWAYS))) { | 443 (file_flags & base::PLATFORM_FILE_CREATE_ALWAYS))) { |
| 441 // If we are trying to always create an existing file, then | 444 // If we are trying to always create an existing file, then |
| 442 // if it really exists open it as truncated. | 445 // if it really exists open it as truncated. |
| 443 file_flags &= ~base::PLATFORM_FILE_CREATE; | 446 file_flags &= ~base::PLATFORM_FILE_CREATE; |
| 444 file_flags &= ~base::PLATFORM_FILE_CREATE_ALWAYS; | 447 file_flags &= ~base::PLATFORM_FILE_CREATE_ALWAYS; |
| 445 file_flags |= base::PLATFORM_FILE_OPEN_TRUNCATED; | 448 file_flags |= base::PLATFORM_FILE_OPEN_TRUNCATED; |
| 446 } else { | 449 } else { |
| 447 callback.Run(create_result, base::kInvalidPlatformFileValue, peer_handle); | 450 callback.Run(create_result, base::kInvalidPlatformFileValue, peer_handle, |
| 451 quota::kQuotaLimitTypeLimited); |
| 448 return; | 452 return; |
| 449 } | 453 } |
| 450 | 454 |
| 451 // Open created (or existing) file for writing. | 455 // Open created (or existing) file for writing. |
| 452 CallDriveFileSystemMethodOnUIThread( | 456 CallDriveFileSystemMethodOnUIThread( |
| 453 base::Bind(&DriveFileSystemInterface::OpenFile, | 457 base::Bind(&DriveFileSystemInterface::OpenFile, |
| 454 base::Unretained(file_system_), | 458 base::Unretained(file_system_), |
| 455 file_path, | 459 file_path, |
| 456 google_apis::CreateRelayCallback( | 460 google_apis::CreateRelayCallback( |
| 457 base::Bind(&FileSystemProxy::OnOpenFileForWriting, | 461 base::Bind(&FileSystemProxy::OnOpenFileForWriting, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 const FileSystemOperation::OpenFileCallback& callback) { | 517 const FileSystemOperation::OpenFileCallback& callback) { |
| 514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 515 | 519 |
| 516 base::FilePath file_path; | 520 base::FilePath file_path; |
| 517 if (!ValidateUrl(file_url, &file_path)) { | 521 if (!ValidateUrl(file_url, &file_path)) { |
| 518 MessageLoopProxy::current()->PostTask( | 522 MessageLoopProxy::current()->PostTask( |
| 519 FROM_HERE, | 523 FROM_HERE, |
| 520 base::Bind(callback, | 524 base::Bind(callback, |
| 521 base::PLATFORM_FILE_ERROR_NOT_FOUND, | 525 base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 522 base::kInvalidPlatformFileValue, | 526 base::kInvalidPlatformFileValue, |
| 523 peer_handle)); | 527 peer_handle, |
| 528 quota::kQuotaLimitTypeLimited)); |
| 524 return; | 529 return; |
| 525 } | 530 } |
| 526 | 531 |
| 527 // TODO(zelidrag): Wire all other file open operations. | 532 // TODO(zelidrag): Wire all other file open operations. |
| 528 if ((file_flags & base::PLATFORM_FILE_DELETE_ON_CLOSE)) { | 533 if ((file_flags & base::PLATFORM_FILE_DELETE_ON_CLOSE)) { |
| 529 NOTIMPLEMENTED() << "File create/write operations not yet supported " | 534 NOTIMPLEMENTED() << "File create/write operations not yet supported " |
| 530 << file_path.value(); | 535 << file_path.value(); |
| 531 MessageLoopProxy::current()->PostTask( | 536 MessageLoopProxy::current()->PostTask( |
| 532 FROM_HERE, | 537 FROM_HERE, |
| 533 base::Bind(callback, | 538 base::Bind(callback, |
| 534 base::PLATFORM_FILE_ERROR_FAILED, | 539 base::PLATFORM_FILE_ERROR_FAILED, |
| 535 base::kInvalidPlatformFileValue, | 540 base::kInvalidPlatformFileValue, |
| 536 peer_handle)); | 541 peer_handle, |
| 542 quota::kQuotaLimitTypeLimited)); |
| 537 return; | 543 return; |
| 538 } | 544 } |
| 539 | 545 |
| 540 if ((file_flags & base::PLATFORM_FILE_OPEN) || | 546 if ((file_flags & base::PLATFORM_FILE_OPEN) || |
| 541 (file_flags & base::PLATFORM_FILE_OPEN_ALWAYS) || | 547 (file_flags & base::PLATFORM_FILE_OPEN_ALWAYS) || |
| 542 (file_flags & base::PLATFORM_FILE_OPEN_TRUNCATED)) { | 548 (file_flags & base::PLATFORM_FILE_OPEN_TRUNCATED)) { |
| 543 if ((file_flags & base::PLATFORM_FILE_OPEN_TRUNCATED) || | 549 if ((file_flags & base::PLATFORM_FILE_OPEN_TRUNCATED) || |
| 544 (file_flags & base::PLATFORM_FILE_OPEN_ALWAYS) || | 550 (file_flags & base::PLATFORM_FILE_OPEN_ALWAYS) || |
| 545 (file_flags & base::PLATFORM_FILE_WRITE) || | 551 (file_flags & base::PLATFORM_FILE_WRITE) || |
| 546 (file_flags & base::PLATFORM_FILE_EXCLUSIVE_WRITE)) { | 552 (file_flags & base::PLATFORM_FILE_EXCLUSIVE_WRITE)) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 file_flags, | 588 file_flags, |
| 583 peer_handle, | 589 peer_handle, |
| 584 callback)))); | 590 callback)))); |
| 585 } else { | 591 } else { |
| 586 NOTREACHED() << "Unhandled file flags combination " << file_flags; | 592 NOTREACHED() << "Unhandled file flags combination " << file_flags; |
| 587 MessageLoopProxy::current()->PostTask( | 593 MessageLoopProxy::current()->PostTask( |
| 588 FROM_HERE, | 594 FROM_HERE, |
| 589 base::Bind(callback, | 595 base::Bind(callback, |
| 590 base::PLATFORM_FILE_ERROR_FAILED, | 596 base::PLATFORM_FILE_ERROR_FAILED, |
| 591 base::kInvalidPlatformFileValue, | 597 base::kInvalidPlatformFileValue, |
| 592 peer_handle)); | 598 peer_handle, |
| 599 quota::kQuotaLimitTypeLimited)); |
| 593 } | 600 } |
| 594 } | 601 } |
| 595 | 602 |
| 596 void FileSystemProxy::NotifyCloseFile(const FileSystemURL& url) { | 603 void FileSystemProxy::NotifyCloseFile(const FileSystemURL& url) { |
| 597 base::FilePath file_path; | 604 base::FilePath file_path; |
| 598 if (!ValidateUrl(url, &file_path)) | 605 if (!ValidateUrl(url, &file_path)) |
| 599 return; | 606 return; |
| 600 | 607 |
| 601 CallDriveFileSystemMethodOnUIThread( | 608 CallDriveFileSystemMethodOnUIThread( |
| 602 base::Bind(&DriveFileSystemInterface::CloseFile, | 609 base::Bind(&DriveFileSystemInterface::CloseFile, |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 CallDriveFileSystemMethodOnUIThread( | 833 CallDriveFileSystemMethodOnUIThread( |
| 827 base::Bind(&DriveFileSystemInterface::CloseFile, | 834 base::Bind(&DriveFileSystemInterface::CloseFile, |
| 828 base::Unretained(file_system_), | 835 base::Unretained(file_system_), |
| 829 virtual_path, | 836 virtual_path, |
| 830 google_apis::CreateRelayCallback( | 837 google_apis::CreateRelayCallback( |
| 831 base::Bind(&EmitDebugLogForCloseFile, | 838 base::Bind(&EmitDebugLogForCloseFile, |
| 832 virtual_path)))); | 839 virtual_path)))); |
| 833 } | 840 } |
| 834 | 841 |
| 835 } // namespace drive | 842 } // namespace drive |
| OLD | NEW |