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 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
926 src_file_path, | 926 src_file_path, |
927 dest_file_path, | 927 dest_file_path, |
928 CreateRelayCallback(callback))); | 928 CreateRelayCallback(callback))); |
929 } | 929 } |
930 | 930 |
931 void GDataFileSystem::CopyOnUIThread(const FilePath& src_file_path, | 931 void GDataFileSystem::CopyOnUIThread(const FilePath& src_file_path, |
932 const FilePath& dest_file_path, | 932 const FilePath& dest_file_path, |
933 const FileOperationCallback& callback) { | 933 const FileOperationCallback& callback) { |
934 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 934 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
935 | 935 |
936 directory_service_->GetEntryInfoPairByPaths( | |
937 src_file_path, | |
938 dest_file_path.DirName(), | |
939 base::Bind(&GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair, | |
940 ui_weak_ptr_, | |
941 src_file_path, | |
942 dest_file_path, | |
943 callback)); | |
944 } | |
945 | |
946 void GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair( | |
947 const FilePath& src_file_path, | |
948 const FilePath& dest_file_path, | |
949 const FileOperationCallback& callback, | |
950 scoped_ptr<EntryInfoPairResult> result) { | |
951 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
952 DCHECK(result.get()); | |
953 | |
936 GDataFileError error = GDATA_FILE_OK; | 954 GDataFileError error = GDATA_FILE_OK; |
937 FilePath dest_parent_path = dest_file_path.DirName(); | 955 bool src_file_is_hosted_document = false; |
achuithb
2012/08/09 00:29:28
These auto vars seem unnecessary to me. I think it
satorux1
2012/08/09 08:33:03
I'm all for minimized scope, but these cannot be m
achuithb
2012/08/09 11:16:46
Hmm, what am I missing? It looks to me like these
satorux1
2012/08/09 16:51:50
Now I see your point. It seems to me that the awkw
| |
956 std::string src_file_resource_id; | |
938 | 957 |
939 std::string src_file_resource_id; | 958 if (result->first.error != GDATA_FILE_OK) { |
940 bool src_file_is_hosted_document = false; | 959 error = result->first.error; |
960 } else if (result->second.error != GDATA_FILE_OK) { | |
961 error = result->second.error; | |
962 } else { | |
963 scoped_ptr<GDataEntryProto> src_file_proto = result->first.proto.Pass(); | |
achuithb
2012/08/09 11:16:46
This seems rather weird to me. We are destroying t
satorux1
2012/08/09 16:51:50
That's a good point. With the new code, this weird
| |
964 scoped_ptr<GDataEntryProto> dest_parent_proto = | |
965 result->second.proto.Pass(); | |
941 | 966 |
942 GDataEntry* src_entry = directory_service_->FindEntryByPathSync( | 967 if (!dest_parent_proto->file_info().is_directory()) { |
943 src_file_path); | 968 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; |
944 GDataEntry* dest_parent = directory_service_->FindEntryByPathSync( | 969 } else if (src_file_proto->file_info().is_directory()) { |
945 dest_parent_path); | 970 // TODO(benchan): Implement copy for directories. In the interim, |
achuithb
2012/08/09 00:29:28
Can we update this TODO with an engineer current o
satorux1
2012/08/09 08:33:03
Done.
| |
946 if (!src_entry || !dest_parent) { | 971 // we handle recursive directory copy in the file manager. |
947 error = GDATA_FILE_ERROR_NOT_FOUND; | 972 error = GDATA_FILE_ERROR_INVALID_OPERATION; |
948 } else if (!dest_parent->AsGDataDirectory()) { | 973 } else { |
949 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 974 src_file_resource_id = src_file_proto->resource_id(); |
950 } else if (!src_entry->AsGDataFile()) { | 975 src_file_is_hosted_document = |
951 // TODO(benchan): Implement copy for directories. In the interim, | 976 src_file_proto->file_specific_info().is_hosted_document(); |
952 // we handle recursive directory copy in the file manager. | 977 } |
953 error = GDATA_FILE_ERROR_INVALID_OPERATION; | |
954 } else { | |
955 src_file_resource_id = src_entry->resource_id(); | |
956 src_file_is_hosted_document = | |
957 src_entry->AsGDataFile()->is_hosted_document(); | |
958 } | 978 } |
959 | 979 |
960 if (error != GDATA_FILE_OK) { | 980 if (error != GDATA_FILE_OK) { |
961 if (!callback.is_null()) | 981 if (!callback.is_null()) |
962 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, error)); | 982 callback.Run(error); |
963 | |
964 return; | 983 return; |
965 } | 984 } |
966 | 985 |
967 if (src_file_is_hosted_document) { | 986 if (src_file_is_hosted_document) { |
968 CopyDocumentToDirectory(dest_parent_path, | 987 CopyDocumentToDirectory(dest_file_path.DirName(), |
969 src_file_resource_id, | 988 src_file_resource_id, |
970 // Drop the document extension, which should not be | 989 // Drop the document extension, which should not be |
971 // in the document title. | 990 // in the document title. |
972 dest_file_path.BaseName().RemoveExtension().value(), | 991 dest_file_path.BaseName().RemoveExtension().value(), |
973 callback); | 992 callback); |
974 return; | 993 return; |
975 } | 994 } |
976 | 995 |
977 // TODO(benchan): Reimplement this once the server API supports | 996 // TODO(benchan): Reimplement this once the server API supports |
achuithb
2012/08/09 00:29:28
Maybe also update this TODO?
| |
978 // copying of regular files directly on the server side. | 997 // copying of regular files directly on the server side. |
979 GetFileByPath(src_file_path, | 998 GetFileByPath(src_file_path, |
980 base::Bind(&GDataFileSystem::OnGetFileCompleteForCopy, | 999 base::Bind(&GDataFileSystem::OnGetFileCompleteForCopy, |
981 ui_weak_ptr_, | 1000 ui_weak_ptr_, |
982 dest_file_path, | 1001 dest_file_path, |
983 callback), | 1002 callback), |
984 GetDownloadDataCallback()); | 1003 GetDownloadDataCallback()); |
985 } | 1004 } |
986 | 1005 |
987 void GDataFileSystem::OnGetFileCompleteForCopy( | 1006 void GDataFileSystem::OnGetFileCompleteForCopy( |
(...skipping 2425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3413 } | 3432 } |
3414 | 3433 |
3415 PlatformFileInfoProto entry_file_info; | 3434 PlatformFileInfoProto entry_file_info; |
3416 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3435 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3417 *entry_proto->mutable_file_info() = entry_file_info; | 3436 *entry_proto->mutable_file_info() = entry_file_info; |
3418 if (!callback.is_null()) | 3437 if (!callback.is_null()) |
3419 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3438 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
3420 } | 3439 } |
3421 | 3440 |
3422 } // namespace gdata | 3441 } // namespace gdata |
OLD | NEW |