| 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/move_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/drive/drive.pb.h" | 7 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 8 #include "chrome/browser/chromeos/drive/drive_cache.h" | 8 #include "chrome/browser/chromeos/drive/drive_cache.h" |
| 9 #include "chrome/browser/chromeos/drive/drive_file_system.h" | 9 #include "chrome/browser/chromeos/drive/drive_file_system.h" |
| 10 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 10 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 MoveOperation::~MoveOperation() { | 29 MoveOperation::~MoveOperation() { |
| 30 } | 30 } |
| 31 | 31 |
| 32 void MoveOperation::Move(const FilePath& src_file_path, | 32 void MoveOperation::Move(const FilePath& src_file_path, |
| 33 const FilePath& dest_file_path, | 33 const FilePath& dest_file_path, |
| 34 const FileOperationCallback& callback) { | 34 const FileOperationCallback& callback) { |
| 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 36 DCHECK(!callback.is_null()); | 36 DCHECK(!callback.is_null()); |
| 37 | 37 |
| 38 file_system_->ResourceMetadata()->GetEntryInfoPairByPaths( | 38 file_system_->GetResourceMetadata()->GetEntryInfoPairByPaths( |
| 39 src_file_path, | 39 src_file_path, |
| 40 dest_file_path.DirName(), | 40 dest_file_path.DirName(), |
| 41 base::Bind(&MoveOperation::MoveAfterGetEntryInfoPair, | 41 base::Bind(&MoveOperation::MoveAfterGetEntryInfoPair, |
| 42 weak_ptr_factory_.GetWeakPtr(), | 42 weak_ptr_factory_.GetWeakPtr(), |
| 43 dest_file_path, | 43 dest_file_path, |
| 44 callback)); | 44 callback)); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void MoveOperation::MoveAfterGetEntryInfoPair( | 47 void MoveOperation::MoveAfterGetEntryInfoPair( |
| 48 const FilePath& dest_file_path, | 48 const FilePath& dest_file_path, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 120 DCHECK(!callback.is_null()); | 120 DCHECK(!callback.is_null()); |
| 121 | 121 |
| 122 // It is a no-op if the file is renamed to the same name. | 122 // It is a no-op if the file is renamed to the same name. |
| 123 if (file_path.BaseName().value() == new_name) { | 123 if (file_path.BaseName().value() == new_name) { |
| 124 callback.Run(DRIVE_FILE_OK, file_path); | 124 callback.Run(DRIVE_FILE_OK, file_path); |
| 125 return; | 125 return; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Get the edit URL of an entry at |file_path|. | 128 // Get the edit URL of an entry at |file_path|. |
| 129 file_system_->ResourceMetadata()->GetEntryInfoByPath( | 129 file_system_->GetResourceMetadata()->GetEntryInfoByPath( |
| 130 file_path, | 130 file_path, |
| 131 base::Bind( | 131 base::Bind( |
| 132 &MoveOperation::RenameAfterGetEntryInfo, | 132 &MoveOperation::RenameAfterGetEntryInfo, |
| 133 weak_ptr_factory_.GetWeakPtr(), | 133 weak_ptr_factory_.GetWeakPtr(), |
| 134 file_path, | 134 file_path, |
| 135 new_name, | 135 new_name, |
| 136 callback)); | 136 callback)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void MoveOperation::RenameAfterGetEntryInfo( | 139 void MoveOperation::RenameAfterGetEntryInfo( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 const GURL& /* document_url */) { | 182 const GURL& /* document_url */) { |
| 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 184 DCHECK(!callback.is_null()); | 184 DCHECK(!callback.is_null()); |
| 185 | 185 |
| 186 const DriveFileError error = util::GDataToDriveFileError(status); | 186 const DriveFileError error = util::GDataToDriveFileError(status); |
| 187 if (error != DRIVE_FILE_OK) { | 187 if (error != DRIVE_FILE_OK) { |
| 188 callback.Run(error, FilePath()); | 188 callback.Run(error, FilePath()); |
| 189 return; | 189 return; |
| 190 } | 190 } |
| 191 | 191 |
| 192 file_system_->ResourceMetadata()->RenameEntry( | 192 file_system_->GetResourceMetadata()->RenameEntry( |
| 193 file_path, | 193 file_path, |
| 194 new_name, | 194 new_name, |
| 195 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback, | 195 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback, |
| 196 weak_ptr_factory_.GetWeakPtr(), | 196 weak_ptr_factory_.GetWeakPtr(), |
| 197 callback)); | 197 callback)); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void MoveOperation::RemoveEntryFromNonRootDirectory( | 200 void MoveOperation::RemoveEntryFromNonRootDirectory( |
| 201 const FileMoveCallback& callback, | 201 const FileMoveCallback& callback, |
| 202 DriveFileError error, | 202 DriveFileError error, |
| 203 const FilePath& file_path) { | 203 const FilePath& file_path) { |
| 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 205 DCHECK(!callback.is_null()); | 205 DCHECK(!callback.is_null()); |
| 206 | 206 |
| 207 const FilePath dir_path = file_path.DirName(); | 207 const FilePath dir_path = file_path.DirName(); |
| 208 // Return if there is an error or |dir_path| is the root directory. | 208 // Return if there is an error or |dir_path| is the root directory. |
| 209 if (error != DRIVE_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) { | 209 if (error != DRIVE_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) { |
| 210 callback.Run(error, file_path); | 210 callback.Run(error, file_path); |
| 211 return; | 211 return; |
| 212 } | 212 } |
| 213 | 213 |
| 214 file_system_->ResourceMetadata()->GetEntryInfoPairByPaths( | 214 file_system_->GetResourceMetadata()->GetEntryInfoPairByPaths( |
| 215 file_path, | 215 file_path, |
| 216 dir_path, | 216 dir_path, |
| 217 base::Bind( | 217 base::Bind( |
| 218 &MoveOperation::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair, | 218 &MoveOperation::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair, |
| 219 weak_ptr_factory_.GetWeakPtr(), | 219 weak_ptr_factory_.GetWeakPtr(), |
| 220 callback)); | 220 callback)); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void MoveOperation::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair( | 223 void MoveOperation::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair( |
| 224 const FileMoveCallback& callback, | 224 const FileMoveCallback& callback, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 245 } | 245 } |
| 246 | 246 |
| 247 // The entry is moved to the root directory. | 247 // The entry is moved to the root directory. |
| 248 drive_service_->RemoveResourceFromDirectory( | 248 drive_service_->RemoveResourceFromDirectory( |
| 249 GURL(dir_proto->content_url()), | 249 GURL(dir_proto->content_url()), |
| 250 GURL(entry_proto->edit_url()), | 250 GURL(entry_proto->edit_url()), |
| 251 entry_proto->resource_id(), | 251 entry_proto->resource_id(), |
| 252 base::Bind(&MoveOperation::MoveEntryToDirectory, | 252 base::Bind(&MoveOperation::MoveEntryToDirectory, |
| 253 weak_ptr_factory_.GetWeakPtr(), | 253 weak_ptr_factory_.GetWeakPtr(), |
| 254 file_path, | 254 file_path, |
| 255 file_system_->ResourceMetadata()->root()->GetFilePath(), | 255 file_system_->GetResourceMetadata()->root()->GetFilePath(), |
| 256 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback, | 256 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback, |
| 257 weak_ptr_factory_.GetWeakPtr(), | 257 weak_ptr_factory_.GetWeakPtr(), |
| 258 callback))); | 258 callback))); |
| 259 } | 259 } |
| 260 | 260 |
| 261 // TODO(zork): Share with CopyOperation. | 261 // TODO(zork): Share with CopyOperation. |
| 262 // See: crbug.com/150050 | 262 // See: crbug.com/150050 |
| 263 void MoveOperation::MoveEntryFromRootDirectory( | 263 void MoveOperation::MoveEntryFromRootDirectory( |
| 264 const FilePath& directory_path, | 264 const FilePath& directory_path, |
| 265 const FileOperationCallback& callback, | 265 const FileOperationCallback& callback, |
| 266 DriveFileError error, | 266 DriveFileError error, |
| 267 const FilePath& file_path) { | 267 const FilePath& file_path) { |
| 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 269 DCHECK(!callback.is_null()); | 269 DCHECK(!callback.is_null()); |
| 270 DCHECK_EQ(kDriveRootDirectory, file_path.DirName().value()); | 270 DCHECK_EQ(kDriveRootDirectory, file_path.DirName().value()); |
| 271 | 271 |
| 272 // Return if there is an error or |dir_path| is the root directory. | 272 // Return if there is an error or |dir_path| is the root directory. |
| 273 if (error != DRIVE_FILE_OK || | 273 if (error != DRIVE_FILE_OK || |
| 274 directory_path == FilePath(kDriveRootDirectory)) { | 274 directory_path == FilePath(kDriveRootDirectory)) { |
| 275 callback.Run(error); | 275 callback.Run(error); |
| 276 return; | 276 return; |
| 277 } | 277 } |
| 278 | 278 |
| 279 file_system_->ResourceMetadata()->GetEntryInfoPairByPaths( | 279 file_system_->GetResourceMetadata()->GetEntryInfoPairByPaths( |
| 280 file_path, | 280 file_path, |
| 281 directory_path, | 281 directory_path, |
| 282 base::Bind( | 282 base::Bind( |
| 283 &MoveOperation::MoveEntryFromRootDirectoryAfterGetEntryInfoPair, | 283 &MoveOperation::MoveEntryFromRootDirectoryAfterGetEntryInfoPair, |
| 284 weak_ptr_factory_.GetWeakPtr(), | 284 weak_ptr_factory_.GetWeakPtr(), |
| 285 callback)); | 285 callback)); |
| 286 } | 286 } |
| 287 | 287 |
| 288 // TODO(zork): Share with CopyOperation. | 288 // TODO(zork): Share with CopyOperation. |
| 289 // See: crbug.com/150050 | 289 // See: crbug.com/150050 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 const GURL& /* document_url */) { | 334 const GURL& /* document_url */) { |
| 335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 336 DCHECK(!callback.is_null()); | 336 DCHECK(!callback.is_null()); |
| 337 | 337 |
| 338 const DriveFileError error = util::GDataToDriveFileError(status); | 338 const DriveFileError error = util::GDataToDriveFileError(status); |
| 339 if (error != DRIVE_FILE_OK) { | 339 if (error != DRIVE_FILE_OK) { |
| 340 callback.Run(error, FilePath()); | 340 callback.Run(error, FilePath()); |
| 341 return; | 341 return; |
| 342 } | 342 } |
| 343 | 343 |
| 344 file_system_->ResourceMetadata()->MoveEntryToDirectory( | 344 file_system_->GetResourceMetadata()->MoveEntryToDirectory( |
| 345 file_path, directory_path, callback); | 345 file_path, directory_path, callback); |
| 346 } | 346 } |
| 347 | 347 |
| 348 // TODO(zork): Share with CopyOperation. | 348 // TODO(zork): Share with CopyOperation. |
| 349 // See: crbug.com/150050 | 349 // See: crbug.com/150050 |
| 350 void MoveOperation::NotifyAndRunFileOperationCallback( | 350 void MoveOperation::NotifyAndRunFileOperationCallback( |
| 351 const FileOperationCallback& callback, | 351 const FileOperationCallback& callback, |
| 352 DriveFileError error, | 352 DriveFileError error, |
| 353 const FilePath& moved_file_path) { | 353 const FilePath& moved_file_path) { |
| 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 368 DCHECK(!callback.is_null()); | 368 DCHECK(!callback.is_null()); |
| 369 | 369 |
| 370 if (error == DRIVE_FILE_OK) | 370 if (error == DRIVE_FILE_OK) |
| 371 file_system_->OnDirectoryChanged(moved_file_path.DirName()); | 371 file_system_->OnDirectoryChanged(moved_file_path.DirName()); |
| 372 | 372 |
| 373 callback.Run(error, moved_file_path); | 373 callback.Run(error, moved_file_path); |
| 374 } | 374 } |
| 375 | 375 |
| 376 } // namespace file_system | 376 } // namespace file_system |
| 377 } // namespace drive | 377 } // namespace drive |
| OLD | NEW |