Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10854072: gdata: Remove use of FindEntryByPathSync() fromMoveOnUIThread() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update a comment Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 base::Bind(&GDataFileSystem::OnCopyDocumentCompleted, 1074 base::Bind(&GDataFileSystem::OnCopyDocumentCompleted,
1075 ui_weak_ptr_, 1075 ui_weak_ptr_,
1076 dir_path, 1076 dir_path,
1077 callback)); 1077 callback));
1078 } 1078 }
1079 1079
1080 void GDataFileSystem::Rename(const FilePath& file_path, 1080 void GDataFileSystem::Rename(const FilePath& file_path,
1081 const FilePath::StringType& new_name, 1081 const FilePath::StringType& new_name,
1082 const FileMoveCallback& callback) { 1082 const FileMoveCallback& callback) {
1083 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1083 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1084 DCHECK(!callback.is_null());
1084 1085
1085 // It is a no-op if the file is renamed to the same name. 1086 // It is a no-op if the file is renamed to the same name.
1086 if (file_path.BaseName().value() == new_name) { 1087 if (file_path.BaseName().value() == new_name) {
1087 if (!callback.is_null()) { 1088 callback.Run(GDATA_FILE_OK, file_path);
1088 MessageLoop::current()->PostTask(
1089 FROM_HERE, base::Bind(callback, GDATA_FILE_OK, file_path));
1090 }
1091 return; 1089 return;
1092 } 1090 }
1093 1091
1094 // Get the edit URL of an entry at |file_path|. 1092 // Get the edit URL of an entry at |file_path|.
1095 directory_service_->GetEntryInfoByPath( 1093 directory_service_->GetEntryInfoByPath(
1096 file_path, 1094 file_path,
1097 base::Bind( 1095 base::Bind(
1098 &GDataFileSystem::RenameAfterGetEntryInfo, 1096 &GDataFileSystem::RenameAfterGetEntryInfo,
1099 ui_weak_ptr_, 1097 ui_weak_ptr_,
1100 file_path, 1098 file_path,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 file_path, 1136 file_path,
1139 file_name, 1137 file_name,
1140 callback)); 1138 callback));
1141 } 1139 }
1142 1140
1143 void GDataFileSystem::Move(const FilePath& src_file_path, 1141 void GDataFileSystem::Move(const FilePath& src_file_path,
1144 const FilePath& dest_file_path, 1142 const FilePath& dest_file_path,
1145 const FileOperationCallback& callback) { 1143 const FileOperationCallback& callback) {
1146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1147 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1145 BrowserThread::CurrentlyOn(BrowserThread::IO));
1146 DCHECK(!callback.is_null());
1147
1148 RunTaskOnUIThread(base::Bind(&GDataFileSystem::MoveOnUIThread, 1148 RunTaskOnUIThread(base::Bind(&GDataFileSystem::MoveOnUIThread,
1149 ui_weak_ptr_, 1149 ui_weak_ptr_,
1150 src_file_path, 1150 src_file_path,
1151 dest_file_path, 1151 dest_file_path,
1152 CreateRelayCallback(callback))); 1152 CreateRelayCallback(callback)));
1153 } 1153 }
1154 1154
1155 void GDataFileSystem::MoveOnUIThread(const FilePath& src_file_path, 1155 void GDataFileSystem::MoveOnUIThread(const FilePath& src_file_path,
1156 const FilePath& dest_file_path, 1156 const FilePath& dest_file_path,
1157 const FileOperationCallback& callback) { 1157 const FileOperationCallback& callback) {
1158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1159 DCHECK(!callback.is_null());
1159 1160
1160 GDataFileError error = GDATA_FILE_OK; 1161 directory_service_->GetEntryInfoPairByPaths(
1161 FilePath dest_parent_path = dest_file_path.DirName(); 1162 src_file_path,
1163 dest_file_path.DirName(),
1164 base::Bind(&GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair,
1165 ui_weak_ptr_,
1166 dest_file_path,
1167 callback));
1168 }
1162 1169
1163 GDataEntry* src_entry = directory_service_->FindEntryByPathSync( 1170 void GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair(
1164 src_file_path); 1171 const FilePath& dest_file_path,
1165 GDataEntry* dest_parent = directory_service_->FindEntryByPathSync( 1172 const FileOperationCallback& callback,
1166 dest_parent_path); 1173 scoped_ptr<EntryInfoPairResult> result) {
1167 if (!src_entry || !dest_parent) { 1174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1168 error = GDATA_FILE_ERROR_NOT_FOUND; 1175 DCHECK(!callback.is_null());
1169 } else if (!dest_parent->AsGDataDirectory()) { 1176 DCHECK(result.get());
1170 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; 1177
1178 if (result->first.error != GDATA_FILE_OK) {
1179 callback.Run(result->first.error);
1180 return;
1181 } else if (result->second.error != GDATA_FILE_OK) {
1182 callback.Run(result->second.error);
1183 return;
1171 } 1184 }
1172 1185
1173 if (error != GDATA_FILE_OK) { 1186 scoped_ptr<GDataEntryProto> dest_parent_proto = result->second.proto.Pass();
1174 if (!callback.is_null()) { 1187 if (!dest_parent_proto->file_info().is_directory()) {
1175 MessageLoop::current()->PostTask(FROM_HERE, 1188 callback.Run(GDATA_FILE_ERROR_NOT_A_DIRECTORY);
1176 base::Bind(callback, error));
1177 }
1178 return; 1189 return;
1179 } 1190 }
1180 1191
1181 // If the file/directory is moved to the same directory, just rename it. 1192 // If the file/directory is moved to the same directory, just rename it.
1193 const FilePath& src_file_path = result->first.path;
1194 const FilePath& dest_parent_path = result->second.path;
1182 if (src_file_path.DirName() == dest_parent_path) { 1195 if (src_file_path.DirName() == dest_parent_path) {
1183 FileMoveCallback final_file_path_update_callback = 1196 FileMoveCallback final_file_path_update_callback =
1184 base::Bind(&GDataFileSystem::OnFilePathUpdated, 1197 base::Bind(&GDataFileSystem::OnFilePathUpdated,
1185 ui_weak_ptr_, 1198 ui_weak_ptr_,
1186 callback); 1199 callback);
1187 1200
1188 Rename(src_file_path, dest_file_path.BaseName().value(), 1201 Rename(src_file_path, dest_file_path.BaseName().value(),
1189 final_file_path_update_callback); 1202 final_file_path_update_callback);
1190 return; 1203 return;
1191 } 1204 }
(...skipping 2247 matching lines...) Expand 10 before | Expand all | Expand 10 after
3439 } 3452 }
3440 3453
3441 PlatformFileInfoProto entry_file_info; 3454 PlatformFileInfoProto entry_file_info;
3442 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 3455 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
3443 *entry_proto->mutable_file_info() = entry_file_info; 3456 *entry_proto->mutable_file_info() = entry_file_info;
3444 if (!callback.is_null()) 3457 if (!callback.is_null())
3445 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 3458 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3446 } 3459 }
3447 3460
3448 } // namespace gdata 3461 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698