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 15 matching lines...) Expand all Loading... |
26 using base::MessageLoopProxy; | 26 using base::MessageLoopProxy; |
27 using content::BrowserThread; | 27 using content::BrowserThread; |
28 using fileapi::FileSystemURL; | 28 using fileapi::FileSystemURL; |
29 using fileapi::FileSystemOperation; | 29 using fileapi::FileSystemOperation; |
30 using webkit_blob::ShareableFileReference; | 30 using webkit_blob::ShareableFileReference; |
31 | 31 |
32 namespace drive { | 32 namespace drive { |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
| 36 typedef fileapi::RemoteFileSystemProxyInterface::OpenFileCallback |
| 37 OpenFileCallback; |
| 38 |
36 const char kFeedField[] = "feed"; | 39 const char kFeedField[] = "feed"; |
37 | 40 |
38 // Helper function to run reply on results of base::CreatePlatformFile() on | 41 // Helper function to run reply on results of base::CreatePlatformFile() on |
39 // IO thread. | 42 // IO thread. |
40 void OnPlatformFileOpened( | 43 void OnPlatformFileOpened( |
41 const FileSystemOperation::OpenFileCallback& callback, | 44 const OpenFileCallback& callback, |
42 base::ProcessHandle peer_handle, | 45 base::ProcessHandle peer_handle, |
43 base::PlatformFileError* open_error, | 46 base::PlatformFileError* open_error, |
44 base::PlatformFile platform_file) { | 47 base::PlatformFile platform_file) { |
45 callback.Run(*open_error, platform_file, peer_handle); | 48 callback.Run(*open_error, platform_file, peer_handle); |
46 } | 49 } |
47 | 50 |
48 // Helper function to run OpenFileCallback from | 51 // Helper function to run OpenFileCallback from |
49 // FileSystemProxy::OpenFile(). | 52 // FileSystemProxy::OpenFile(). |
50 void OnGetFileByPathForOpen( | 53 void OnGetFileByPathForOpen( |
51 const FileSystemOperation::OpenFileCallback& callback, | 54 const OpenFileCallback& callback, |
52 int file_flags, | 55 int file_flags, |
53 base::ProcessHandle peer_handle, | 56 base::ProcessHandle peer_handle, |
54 FileError file_error, | 57 FileError file_error, |
55 const base::FilePath& local_path, | 58 const base::FilePath& local_path, |
56 const std::string& unused_mime_type, | 59 const std::string& unused_mime_type, |
57 DriveFileType file_type) { | 60 DriveFileType file_type) { |
58 base::PlatformFileError error = | 61 base::PlatformFileError error = |
59 FileErrorToPlatformError(file_error); | 62 FileErrorToPlatformError(file_error); |
60 if (error != base::PLATFORM_FILE_OK) { | 63 if (error != base::PLATFORM_FILE_OK) { |
61 callback.Run(error, base::kInvalidPlatformFileValue, peer_handle); | 64 callback.Run(error, base::kInvalidPlatformFileValue, peer_handle); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 base::Bind(&FileSystemProxy::OnFileOpenedForTruncate, | 391 base::Bind(&FileSystemProxy::OnFileOpenedForTruncate, |
389 this, | 392 this, |
390 file_path, | 393 file_path, |
391 length, | 394 length, |
392 callback)))); | 395 callback)))); |
393 } | 396 } |
394 | 397 |
395 void FileSystemProxy::OnOpenFileForWriting( | 398 void FileSystemProxy::OnOpenFileForWriting( |
396 int file_flags, | 399 int file_flags, |
397 base::ProcessHandle peer_handle, | 400 base::ProcessHandle peer_handle, |
398 const FileSystemOperation::OpenFileCallback& callback, | 401 const OpenFileCallback& callback, |
399 FileError file_error, | 402 FileError file_error, |
400 const base::FilePath& local_cache_path) { | 403 const base::FilePath& local_cache_path) { |
401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
402 | 405 |
403 base::PlatformFileError error = | 406 base::PlatformFileError error = |
404 FileErrorToPlatformError(file_error); | 407 FileErrorToPlatformError(file_error); |
405 | 408 |
406 if (error != base::PLATFORM_FILE_OK) { | 409 if (error != base::PLATFORM_FILE_OK) { |
407 callback.Run(error, base::kInvalidPlatformFileValue, peer_handle); | 410 callback.Run(error, base::kInvalidPlatformFileValue, peer_handle); |
408 return; | 411 return; |
(...skipping 13 matching lines...) Expand all Loading... |
422 callback, | 425 callback, |
423 peer_handle, | 426 peer_handle, |
424 base::Owned(result))); | 427 base::Owned(result))); |
425 DCHECK(posted); | 428 DCHECK(posted); |
426 } | 429 } |
427 | 430 |
428 void FileSystemProxy::OnCreateFileForOpen( | 431 void FileSystemProxy::OnCreateFileForOpen( |
429 const base::FilePath& file_path, | 432 const base::FilePath& file_path, |
430 int file_flags, | 433 int file_flags, |
431 base::ProcessHandle peer_handle, | 434 base::ProcessHandle peer_handle, |
432 const FileSystemOperation::OpenFileCallback& callback, | 435 const OpenFileCallback& callback, |
433 FileError file_error) { | 436 FileError file_error) { |
434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
435 base::PlatformFileError create_result = | 438 base::PlatformFileError create_result = |
436 FileErrorToPlatformError(file_error); | 439 FileErrorToPlatformError(file_error); |
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. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 google_apis::CreateRelayCallback( | 506 google_apis::CreateRelayCallback( |
504 base::Bind(&DidCloseFileForTruncate, | 507 base::Bind(&DidCloseFileForTruncate, |
505 callback, | 508 callback, |
506 truncate_result)))); | 509 truncate_result)))); |
507 } | 510 } |
508 | 511 |
509 void FileSystemProxy::OpenFile( | 512 void FileSystemProxy::OpenFile( |
510 const FileSystemURL& file_url, | 513 const FileSystemURL& file_url, |
511 int file_flags, | 514 int file_flags, |
512 base::ProcessHandle peer_handle, | 515 base::ProcessHandle peer_handle, |
513 const FileSystemOperation::OpenFileCallback& callback) { | 516 const OpenFileCallback& callback) { |
514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 517 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
515 | 518 |
516 base::FilePath file_path; | 519 base::FilePath file_path; |
517 if (!ValidateUrl(file_url, &file_path)) { | 520 if (!ValidateUrl(file_url, &file_path)) { |
518 MessageLoopProxy::current()->PostTask( | 521 MessageLoopProxy::current()->PostTask( |
519 FROM_HERE, | 522 FROM_HERE, |
520 base::Bind(callback, | 523 base::Bind(callback, |
521 base::PLATFORM_FILE_ERROR_NOT_FOUND, | 524 base::PLATFORM_FILE_ERROR_NOT_FOUND, |
522 base::kInvalidPlatformFileValue, | 525 base::kInvalidPlatformFileValue, |
523 peer_handle)); | 526 peer_handle)); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 CallDriveFileSystemMethodOnUIThread( | 829 CallDriveFileSystemMethodOnUIThread( |
827 base::Bind(&DriveFileSystemInterface::CloseFile, | 830 base::Bind(&DriveFileSystemInterface::CloseFile, |
828 base::Unretained(file_system_), | 831 base::Unretained(file_system_), |
829 virtual_path, | 832 virtual_path, |
830 google_apis::CreateRelayCallback( | 833 google_apis::CreateRelayCallback( |
831 base::Bind(&EmitDebugLogForCloseFile, | 834 base::Bind(&EmitDebugLogForCloseFile, |
832 virtual_path)))); | 835 virtual_path)))); |
833 } | 836 } |
834 | 837 |
835 } // namespace drive | 838 } // namespace drive |
OLD | NEW |