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/gdata/gdata_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
704 | 704 |
705 directory_service_->FindEntryByPathAndRunSync(search_file_path, callback); | 705 directory_service_->FindEntryByPathAndRunSync(search_file_path, callback); |
706 } | 706 } |
707 | 707 |
708 void GDataFileSystem::TransferFileFromRemoteToLocal( | 708 void GDataFileSystem::TransferFileFromRemoteToLocal( |
709 const FilePath& remote_src_file_path, | 709 const FilePath& remote_src_file_path, |
710 const FilePath& local_dest_file_path, | 710 const FilePath& local_dest_file_path, |
711 const FileOperationCallback& callback) { | 711 const FileOperationCallback& callback) { |
712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 713 DCHECK(!callback.is_null()); |
713 | 714 |
714 GetFileByPath(remote_src_file_path, | 715 GetFileByPath(remote_src_file_path, |
715 base::Bind(&GDataFileSystem::OnGetFileCompleteForTransferFile, | 716 base::Bind(&GDataFileSystem::OnGetFileCompleteForTransferFile, |
716 ui_weak_ptr_, | 717 ui_weak_ptr_, |
717 local_dest_file_path, | 718 local_dest_file_path, |
718 callback), | 719 callback), |
719 GetDownloadDataCallback()); | 720 GetDownloadDataCallback()); |
720 } | 721 } |
721 | 722 |
722 void GDataFileSystem::TransferFileFromLocalToRemote( | 723 void GDataFileSystem::TransferFileFromLocalToRemote( |
723 const FilePath& local_src_file_path, | 724 const FilePath& local_src_file_path, |
724 const FilePath& remote_dest_file_path, | 725 const FilePath& remote_dest_file_path, |
725 const FileOperationCallback& callback) { | 726 const FileOperationCallback& callback) { |
726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 727 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 728 DCHECK(!callback.is_null()); |
727 | 729 |
728 // Make sure the destination directory exists. | 730 // Make sure the destination directory exists. |
729 directory_service_->GetEntryInfoByPath( | 731 directory_service_->GetEntryInfoByPath( |
730 remote_dest_file_path.DirName(), | 732 remote_dest_file_path.DirName(), |
731 base::Bind( | 733 base::Bind( |
732 &GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo, | 734 &GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo, |
733 ui_weak_ptr_, | 735 ui_weak_ptr_, |
734 local_src_file_path, | 736 local_src_file_path, |
735 remote_dest_file_path, | 737 remote_dest_file_path, |
736 callback)); | 738 callback)); |
737 } | 739 } |
738 | 740 |
739 void GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo( | 741 void GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo( |
740 const FilePath& local_src_file_path, | 742 const FilePath& local_src_file_path, |
741 const FilePath& remote_dest_file_path, | 743 const FilePath& remote_dest_file_path, |
742 const FileOperationCallback& callback, | 744 const FileOperationCallback& callback, |
743 GDataFileError error, | 745 GDataFileError error, |
744 scoped_ptr<GDataEntryProto> entry_proto) { | 746 scoped_ptr<GDataEntryProto> entry_proto) { |
745 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 747 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 748 DCHECK(!callback.is_null()); |
746 | 749 |
747 if (error != GDATA_FILE_OK) { | 750 if (error != GDATA_FILE_OK) { |
748 if (!callback.is_null()) { | 751 callback.Run(error); |
749 base::MessageLoopProxy::current()->PostTask( | |
750 FROM_HERE, base::Bind(callback, error)); | |
751 } | |
752 return; | 752 return; |
753 } | 753 } |
754 | 754 |
755 DCHECK(entry_proto.get()); | 755 DCHECK(entry_proto.get()); |
756 if (!entry_proto->file_info().is_directory()) { | 756 if (!entry_proto->file_info().is_directory()) { |
757 // The parent of |remote_dest_file_path| is not a directory. | 757 // The parent of |remote_dest_file_path| is not a directory. |
758 if (!callback.is_null()) { | 758 callback.Run(GDATA_FILE_ERROR_NOT_A_DIRECTORY); |
759 base::MessageLoopProxy::current()->PostTask( | |
760 FROM_HERE, base::Bind(callback, GDATA_FILE_ERROR_NOT_A_DIRECTORY)); | |
761 } | |
762 return; | 759 return; |
763 } | 760 } |
764 | 761 |
765 std::string* resource_id = new std::string; | 762 std::string* resource_id = new std::string; |
766 util::PostBlockingPoolSequencedTaskAndReply( | 763 util::PostBlockingPoolSequencedTaskAndReply( |
767 FROM_HERE, | 764 FROM_HERE, |
768 blocking_task_runner_, | 765 blocking_task_runner_, |
769 base::Bind(&GetDocumentResourceIdOnBlockingPool, | 766 base::Bind(&GetDocumentResourceIdOnBlockingPool, |
770 local_src_file_path, | 767 local_src_file_path, |
771 resource_id), | 768 resource_id), |
772 base::Bind(&GDataFileSystem::TransferFileForResourceId, | 769 base::Bind(&GDataFileSystem::TransferFileForResourceId, |
773 ui_weak_ptr_, | 770 ui_weak_ptr_, |
774 local_src_file_path, | 771 local_src_file_path, |
775 remote_dest_file_path, | 772 remote_dest_file_path, |
776 callback, | 773 callback, |
777 base::Owned(resource_id))); | 774 base::Owned(resource_id))); |
778 } | 775 } |
779 | 776 |
780 void GDataFileSystem::TransferFileForResourceId( | 777 void GDataFileSystem::TransferFileForResourceId( |
781 const FilePath& local_file_path, | 778 const FilePath& local_file_path, |
782 const FilePath& remote_dest_file_path, | 779 const FilePath& remote_dest_file_path, |
783 const FileOperationCallback& callback, | 780 const FileOperationCallback& callback, |
784 std::string* resource_id) { | 781 std::string* resource_id) { |
785 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
786 DCHECK(resource_id); | 783 DCHECK(resource_id); |
| 784 DCHECK(!callback.is_null()); |
787 | 785 |
788 if (resource_id->empty()) { | 786 if (resource_id->empty()) { |
789 // If |resource_id| is empty, upload the local file as a regular file. | 787 // If |resource_id| is empty, upload the local file as a regular file. |
790 TransferRegularFile(local_file_path, remote_dest_file_path, callback); | 788 TransferRegularFile(local_file_path, remote_dest_file_path, callback); |
791 return; | 789 return; |
792 } | 790 } |
793 | 791 |
794 // Otherwise, copy the document on the server side and add the new copy | 792 // Otherwise, copy the document on the server side and add the new copy |
795 // to the destination directory (collection). | 793 // to the destination directory (collection). |
796 CopyDocumentToDirectory( | 794 CopyDocumentToDirectory( |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 } | 1029 } |
1032 | 1030 |
1033 void GDataFileSystem::OnGetFileCompleteForTransferFile( | 1031 void GDataFileSystem::OnGetFileCompleteForTransferFile( |
1034 const FilePath& local_dest_file_path, | 1032 const FilePath& local_dest_file_path, |
1035 const FileOperationCallback& callback, | 1033 const FileOperationCallback& callback, |
1036 GDataFileError error, | 1034 GDataFileError error, |
1037 const FilePath& local_file_path, | 1035 const FilePath& local_file_path, |
1038 const std::string& unused_mime_type, | 1036 const std::string& unused_mime_type, |
1039 GDataFileType file_type) { | 1037 GDataFileType file_type) { |
1040 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1038 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1039 DCHECK(!callback.is_null()); |
1041 | 1040 |
1042 if (error != GDATA_FILE_OK) { | 1041 if (error != GDATA_FILE_OK) { |
1043 if (!callback.is_null()) | 1042 callback.Run(error); |
1044 callback.Run(error); | |
1045 | |
1046 return; | 1043 return; |
1047 } | 1044 } |
1048 | 1045 |
1049 // GetFileByPath downloads the file from gdata to a local cache, which is then | 1046 // GetFileByPath downloads the file from gdata to a local cache, which is then |
1050 // copied to the actual destination path on the local file system using | 1047 // copied to the actual destination path on the local file system using |
1051 // CopyLocalFileOnBlockingPool. | 1048 // CopyLocalFileOnBlockingPool. |
1052 GDataFileError* copy_file_error = | 1049 GDataFileError* copy_file_error = |
1053 new GDataFileError(GDATA_FILE_OK); | 1050 new GDataFileError(GDATA_FILE_OK); |
1054 util::PostBlockingPoolSequencedTaskAndReply( | 1051 util::PostBlockingPoolSequencedTaskAndReply( |
1055 FROM_HERE, | 1052 FROM_HERE, |
1056 blocking_task_runner_, | 1053 blocking_task_runner_, |
1057 base::Bind(&CopyLocalFileOnBlockingPool, | 1054 base::Bind(&CopyLocalFileOnBlockingPool, |
1058 local_file_path, | 1055 local_file_path, |
1059 local_dest_file_path, | 1056 local_dest_file_path, |
1060 copy_file_error), | 1057 copy_file_error), |
1061 base::Bind(&RunFileOperationCallbackHelper, | 1058 base::Bind(&RunFileOperationCallbackHelper, |
1062 callback, | 1059 callback, |
1063 base::Owned(copy_file_error))); | 1060 base::Owned(copy_file_error))); |
1064 } | 1061 } |
1065 | 1062 |
1066 void GDataFileSystem::CopyDocumentToDirectory( | 1063 void GDataFileSystem::CopyDocumentToDirectory( |
1067 const FilePath& dir_path, | 1064 const FilePath& dir_path, |
1068 const std::string& resource_id, | 1065 const std::string& resource_id, |
1069 const FilePath::StringType& new_name, | 1066 const FilePath::StringType& new_name, |
1070 const FileOperationCallback& callback) { | 1067 const FileOperationCallback& callback) { |
1071 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1068 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1069 DCHECK(!callback.is_null()); |
1072 | 1070 |
1073 documents_service_->CopyDocument(resource_id, new_name, | 1071 documents_service_->CopyDocument(resource_id, new_name, |
1074 base::Bind(&GDataFileSystem::OnCopyDocumentCompleted, | 1072 base::Bind(&GDataFileSystem::OnCopyDocumentCompleted, |
1075 ui_weak_ptr_, | 1073 ui_weak_ptr_, |
1076 dir_path, | 1074 dir_path, |
1077 callback)); | 1075 callback)); |
1078 } | 1076 } |
1079 | 1077 |
1080 void GDataFileSystem::Rename(const FilePath& file_path, | 1078 void GDataFileSystem::Rename(const FilePath& file_path, |
1081 const FilePath::StringType& new_name, | 1079 const FilePath::StringType& new_name, |
(...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2448 if (!callback.is_null()) | 2446 if (!callback.is_null()) |
2449 callback.Run(error); | 2447 callback.Run(error); |
2450 } | 2448 } |
2451 | 2449 |
2452 void GDataFileSystem::OnCopyDocumentCompleted( | 2450 void GDataFileSystem::OnCopyDocumentCompleted( |
2453 const FilePath& dir_path, | 2451 const FilePath& dir_path, |
2454 const FileOperationCallback& callback, | 2452 const FileOperationCallback& callback, |
2455 GDataErrorCode status, | 2453 GDataErrorCode status, |
2456 scoped_ptr<base::Value> data) { | 2454 scoped_ptr<base::Value> data) { |
2457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2456 DCHECK(!callback.is_null()); |
2458 | 2457 |
2459 GDataFileError error = util::GDataToGDataFileError(status); | 2458 GDataFileError error = util::GDataToGDataFileError(status); |
2460 if (error != GDATA_FILE_OK) { | 2459 if (error != GDATA_FILE_OK) { |
2461 if (!callback.is_null()) | 2460 callback.Run(error); |
2462 callback.Run(error); | |
2463 | |
2464 return; | 2461 return; |
2465 } | 2462 } |
2466 | 2463 |
2467 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); | 2464 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); |
2468 if (!doc_entry.get()) { | 2465 if (!doc_entry.get()) { |
2469 if (!callback.is_null()) | 2466 callback.Run(GDATA_FILE_ERROR_FAILED); |
2470 callback.Run(GDATA_FILE_ERROR_FAILED); | |
2471 | |
2472 return; | 2467 return; |
2473 } | 2468 } |
2474 | 2469 |
2475 GDataEntry* entry = GDataEntry::FromDocumentEntry( | 2470 GDataEntry* entry = GDataEntry::FromDocumentEntry( |
2476 NULL, doc_entry.get(), directory_service_.get()); | 2471 NULL, doc_entry.get(), directory_service_.get()); |
2477 if (!entry) { | 2472 if (!entry) { |
2478 if (!callback.is_null()) | 2473 callback.Run(GDATA_FILE_ERROR_FAILED); |
2479 callback.Run(GDATA_FILE_ERROR_FAILED); | |
2480 | |
2481 return; | 2474 return; |
2482 } | 2475 } |
2483 | 2476 |
2484 // |entry| was added in the root directory on the server, so we should | 2477 // |entry| was added in the root directory on the server, so we should |
2485 // first add it to |root_| to mirror the state and then move it to the | 2478 // first add it to |root_| to mirror the state and then move it to the |
2486 // destination directory by AddEntryToDirectory(). | 2479 // destination directory by AddEntryToDirectory(). |
2487 directory_service_->root()->AddEntry(entry); | 2480 directory_service_->root()->AddEntry(entry); |
2488 AddEntryToDirectory(dir_path, callback, GDATA_FILE_OK, entry->GetFilePath()); | 2481 AddEntryToDirectory(dir_path, callback, GDATA_FILE_OK, entry->GetFilePath()); |
2489 } | 2482 } |
2490 | 2483 |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3439 } | 3432 } |
3440 | 3433 |
3441 PlatformFileInfoProto entry_file_info; | 3434 PlatformFileInfoProto entry_file_info; |
3442 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3435 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3443 *entry_proto->mutable_file_info() = entry_file_info; | 3436 *entry_proto->mutable_file_info() = entry_file_info; |
3444 if (!callback.is_null()) | 3437 if (!callback.is_null()) |
3445 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3438 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
3446 } | 3439 } |
3447 | 3440 |
3448 } // namespace gdata | 3441 } // namespace gdata |
OLD | NEW |