Chromium Code Reviews| 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 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 915 } else if (!callback.is_null()) { | 915 } else if (!callback.is_null()) { |
| 916 callback.Run(error); | 916 callback.Run(error); |
| 917 } | 917 } |
| 918 } | 918 } |
| 919 | 919 |
| 920 void GDataFileSystem::Copy(const FilePath& src_file_path, | 920 void GDataFileSystem::Copy(const FilePath& src_file_path, |
| 921 const FilePath& dest_file_path, | 921 const FilePath& dest_file_path, |
| 922 const FileOperationCallback& callback) { | 922 const FileOperationCallback& callback) { |
| 923 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 923 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 924 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 924 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 925 DCHECK(!callback.is_null()); | |
| 926 | |
| 925 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread, | 927 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread, |
| 926 ui_weak_ptr_, | 928 ui_weak_ptr_, |
| 927 src_file_path, | 929 src_file_path, |
| 928 dest_file_path, | 930 dest_file_path, |
| 929 CreateRelayCallback(callback))); | 931 CreateRelayCallback(callback))); |
| 930 } | 932 } |
| 931 | 933 |
| 932 void GDataFileSystem::CopyOnUIThread(const FilePath& src_file_path, | 934 void GDataFileSystem::CopyOnUIThread(const FilePath& src_file_path, |
| 933 const FilePath& dest_file_path, | 935 const FilePath& dest_file_path, |
| 934 const FileOperationCallback& callback) { | 936 const FileOperationCallback& callback) { |
| 935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 937 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 938 DCHECK(!callback.is_null()); | |
| 936 | 939 |
| 937 GDataFileError error = GDATA_FILE_OK; | 940 directory_service_->GetEntryInfoPairByPaths( |
| 938 FilePath dest_parent_path = dest_file_path.DirName(); | 941 src_file_path, |
| 942 dest_file_path.DirName(), | |
| 943 base::Bind(&GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair, | |
| 944 ui_weak_ptr_, | |
| 945 dest_file_path, | |
| 946 callback)); | |
| 947 } | |
| 939 | 948 |
| 940 std::string src_file_resource_id; | 949 void GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair( |
| 941 bool src_file_is_hosted_document = false; | 950 const FilePath& dest_file_path, |
| 951 const FileOperationCallback& callback, | |
| 952 scoped_ptr<EntryInfoPairResult> result) { | |
| 953 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 954 DCHECK(!callback.is_null()); | |
| 955 DCHECK(result.get()); | |
| 942 | 956 |
| 943 GDataEntry* src_entry = directory_service_->FindEntryByPathSync( | 957 if (result->first.error != GDATA_FILE_OK) { |
| 944 src_file_path); | 958 callback.Run(result->first.error); |
| 945 GDataEntry* dest_parent = directory_service_->FindEntryByPathSync( | 959 return; |
| 946 dest_parent_path); | 960 } else if (result->second.error != GDATA_FILE_OK) { |
| 947 if (!src_entry || !dest_parent) { | 961 callback.Run(result->second.error); |
| 948 error = GDATA_FILE_ERROR_NOT_FOUND; | |
| 949 } else if (!dest_parent->AsGDataDirectory()) { | |
| 950 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; | |
| 951 } else if (!src_entry->AsGDataFile()) { | |
| 952 // TODO(benchan): Implement copy for directories. In the interim, | |
| 953 // we handle recursive directory copy in the file manager. | |
| 954 error = GDATA_FILE_ERROR_INVALID_OPERATION; | |
| 955 } else { | |
| 956 src_file_resource_id = src_entry->resource_id(); | |
| 957 src_file_is_hosted_document = | |
| 958 src_entry->AsGDataFile()->is_hosted_document(); | |
| 959 } | |
| 960 | |
| 961 if (error != GDATA_FILE_OK) { | |
| 962 if (!callback.is_null()) | |
| 963 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, error)); | |
| 964 | |
| 965 return; | 962 return; |
| 966 } | 963 } |
| 967 | 964 |
| 968 if (src_file_is_hosted_document) { | 965 scoped_ptr<GDataEntryProto> src_file_proto = result->first.proto.Pass(); |
| 969 CopyDocumentToDirectory(dest_parent_path, | 966 scoped_ptr<GDataEntryProto> dest_parent_proto = result->second.proto.Pass(); |
| 970 src_file_resource_id, | 967 |
| 968 if (!dest_parent_proto->file_info().is_directory()) { | |
| 969 callback.Run(GDATA_FILE_ERROR_NOT_A_DIRECTORY); | |
| 970 return; | |
| 971 } else if (src_file_proto->file_info().is_directory()) { | |
| 972 // TODO(kochi): Implement copy for directories. In the interim, | |
| 973 // we handle recursive directory copy in the file manager. | |
| 974 // crbug.com/141596 | |
| 975 callback.Run(GDATA_FILE_ERROR_INVALID_OPERATION); | |
| 976 return; | |
| 977 } | |
| 978 | |
| 979 if (src_file_proto->file_specific_info().is_hosted_document()) { | |
| 980 CopyDocumentToDirectory(dest_file_path.DirName(), | |
| 981 src_file_proto->resource_id(), | |
| 971 // Drop the document extension, which should not be | 982 // Drop the document extension, which should not be |
| 972 // in the document title. | 983 // in the document title. |
| 973 dest_file_path.BaseName().RemoveExtension().value(), | 984 dest_file_path.BaseName().RemoveExtension().value(), |
| 974 callback); | 985 callback); |
| 975 return; | 986 return; |
| 976 } | 987 } |
| 977 | 988 |
| 978 // TODO(benchan): Reimplement this once the server API supports | 989 // TODO(kochi): Reimplement this once the server API supports |
| 979 // copying of regular files directly on the server side. | 990 // copying of regular files directly on the server side. crbug.com/138273 |
| 991 const FilePath& src_file_path = result->first.path; | |
| 980 GetFileByPath(src_file_path, | 992 GetFileByPath(src_file_path, |
| 981 base::Bind(&GDataFileSystem::OnGetFileCompleteForCopy, | 993 base::Bind(&GDataFileSystem::OnGetFileCompleteForCopy, |
| 982 ui_weak_ptr_, | 994 ui_weak_ptr_, |
| 983 dest_file_path, | 995 dest_file_path, |
| 984 callback), | 996 callback), |
| 985 GetDownloadDataCallback()); | 997 GetDownloadDataCallback()); |
| 986 } | 998 } |
| 987 | 999 |
| 988 void GDataFileSystem::OnGetFileCompleteForCopy( | 1000 void GDataFileSystem::OnGetFileCompleteForCopy( |
| 989 const FilePath& remote_dest_file_path, | 1001 const FilePath& remote_dest_file_path, |
| 990 const FileOperationCallback& callback, | 1002 const FileOperationCallback& callback, |
| 991 GDataFileError error, | 1003 GDataFileError error, |
| 992 const FilePath& local_file_path, | 1004 const FilePath& local_file_path, |
| 993 const std::string& unused_mime_type, | 1005 const std::string& unused_mime_type, |
| 994 GDataFileType file_type) { | 1006 GDataFileType file_type) { |
| 995 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1008 if (!callback.is_null()) | |
|
satorux1
2012/08/09 17:07:29
this was wrong! fixed.
| |
| 996 | 1009 |
| 997 if (error != GDATA_FILE_OK) { | 1010 if (error != GDATA_FILE_OK) { |
| 998 if (!callback.is_null()) | 1011 callback.Run(error); |
| 999 callback.Run(error); | |
| 1000 | |
| 1001 return; | 1012 return; |
| 1002 } | 1013 } |
| 1003 | 1014 |
| 1004 // This callback is only triggered for a regular file via Copy() and runs | 1015 // This callback is only triggered for a regular file via Copy() and runs |
| 1005 // on the same thread as Copy (IO thread). As TransferRegularFile must run | 1016 // on the same thread as Copy (IO thread). As TransferRegularFile must run |
| 1006 // on the UI thread, we thus need to post a task to the UI thread. | 1017 // on the UI thread, we thus need to post a task to the UI thread. |
| 1007 // Also, upon the completion of TransferRegularFile, we need to run |callback| | 1018 // Also, upon the completion of TransferRegularFile, we need to run |callback| |
| 1008 // on the same thread as Copy (IO thread), and the transition from UI thread | 1019 // on the same thread as Copy (IO thread), and the transition from UI thread |
| 1009 // to IO thread is handled by OnTransferRegularFileCompleteForCopy. | 1020 // to IO thread is handled by OnTransferRegularFileCompleteForCopy. |
| 1010 DCHECK_EQ(REGULAR_FILE, file_type); | 1021 DCHECK_EQ(REGULAR_FILE, file_type); |
| (...skipping 2417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3428 } | 3439 } |
| 3429 | 3440 |
| 3430 PlatformFileInfoProto entry_file_info; | 3441 PlatformFileInfoProto entry_file_info; |
| 3431 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3442 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
| 3432 *entry_proto->mutable_file_info() = entry_file_info; | 3443 *entry_proto->mutable_file_info() = entry_file_info; |
| 3433 if (!callback.is_null()) | 3444 if (!callback.is_null()) |
| 3434 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3445 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
| 3435 } | 3446 } |
| 3436 | 3447 |
| 3437 } // namespace gdata | 3448 } // namespace gdata |
| OLD | NEW |