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/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_util.h" | 9 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
| 10 #include "chrome/browser/chromeos/drive/drive_scheduler.h" | 10 #include "chrome/browser/chromeos/drive/drive_scheduler.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 Rename(src_file_path, dest_file_path.BaseName().value(), | 81 Rename(src_file_path, dest_file_path.BaseName().value(), |
| 82 final_file_path_update_callback); | 82 final_file_path_update_callback); |
| 83 return; | 83 return; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Otherwise, the move operation involves three steps: | 86 // Otherwise, the move operation involves three steps: |
| 87 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|) | 87 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|) |
| 88 // within the same directory. The rename operation is a no-op if | 88 // within the same directory. The rename operation is a no-op if |
| 89 // basename(|src_file_path|) equals to basename(|dest_file_path|). | 89 // basename(|src_file_path|) equals to basename(|dest_file_path|). |
| 90 // 2. Removes the file from its parent directory (the file is not deleted), | 90 // 2. Removes the file from its parent directory (the file is not deleted), |
| 91 // which effectively moves the file to the root directory. | 91 // which effectively moves the file to the root directory. |
|
kinaba
2013/01/21 08:24:29
A note:
Strictly speaking, this is false. Removing
satorux1
2013/01/22 06:51:50
Could you update the comment?
kinaba
2013/01/22 07:09:10
Done.
| |
| 92 // 3. Adds the file to the parent directory of |dest_file_path|, which | 92 // 3. Adds the file to the parent directory of |dest_file_path|, which |
| 93 // effectively moves the file from the root directory to the parent | 93 // effectively moves the file from the root directory to the parent |
| 94 // directory of |dest_file_path|. | 94 // directory of |dest_file_path|. |
| 95 const FileMoveCallback add_file_to_directory_callback = | 95 const FileMoveCallback add_file_to_directory_callback = |
| 96 base::Bind(&MoveOperation::MoveEntryFromRootDirectory, | 96 base::Bind(&MoveOperation::AddEntryToDirectory, |
| 97 weak_ptr_factory_.GetWeakPtr(), | 97 weak_ptr_factory_.GetWeakPtr(), |
| 98 dest_parent_path, | 98 dest_parent_path, |
| 99 callback); | 99 callback); |
| 100 | 100 |
| 101 const FileMoveCallback remove_file_from_directory_callback = | 101 const FileMoveCallback remove_file_from_directory_callback = |
| 102 base::Bind(&MoveOperation::RemoveEntryFromNonRootDirectory, | 102 base::Bind(&MoveOperation::RemoveEntryFromDirectory, |
| 103 weak_ptr_factory_.GetWeakPtr(), | 103 weak_ptr_factory_.GetWeakPtr(), |
| 104 add_file_to_directory_callback); | 104 add_file_to_directory_callback); |
| 105 | 105 |
| 106 Rename(src_file_path, dest_file_path.BaseName().value(), | 106 Rename(src_file_path, dest_file_path.BaseName().value(), |
| 107 remove_file_from_directory_callback); | 107 remove_file_from_directory_callback); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void MoveOperation::OnFilePathUpdated(const FileOperationCallback& callback, | 110 void MoveOperation::OnFilePathUpdated(const FileOperationCallback& callback, |
| 111 DriveFileError error, | 111 DriveFileError error, |
| 112 const FilePath& /* file_path */) { | 112 const FilePath& /* file_path */) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 } | 199 } |
| 200 | 200 |
| 201 metadata_->RenameEntry( | 201 metadata_->RenameEntry( |
| 202 file_path, | 202 file_path, |
| 203 new_name, | 203 new_name, |
| 204 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback, | 204 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback, |
| 205 weak_ptr_factory_.GetWeakPtr(), | 205 weak_ptr_factory_.GetWeakPtr(), |
| 206 callback)); | 206 callback)); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void MoveOperation::RemoveEntryFromNonRootDirectory( | 209 void MoveOperation::RemoveEntryFromDirectory( |
| 210 const FileMoveCallback& callback, | 210 const FileMoveCallback& callback, |
| 211 DriveFileError error, | 211 DriveFileError error, |
| 212 const FilePath& file_path) { | 212 const FilePath& file_path) { |
| 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 214 DCHECK(!callback.is_null()); | 214 DCHECK(!callback.is_null()); |
| 215 | 215 |
| 216 const FilePath dir_path = file_path.DirName(); | |
| 217 // Return if there is an error or |dir_path| is the root directory. | |
| 218 if (error != DRIVE_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) { | |
| 219 callback.Run(error, file_path); | |
| 220 return; | |
| 221 } | |
| 222 | |
| 223 metadata_->GetEntryInfoPairByPaths( | 216 metadata_->GetEntryInfoPairByPaths( |
| 224 file_path, | 217 file_path, |
| 225 dir_path, | 218 file_path.DirName(), |
| 226 base::Bind( | 219 base::Bind( |
| 227 &MoveOperation::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair, | 220 &MoveOperation::RemoveEntryFromDirectoryAfterEntryInfoPair, |
| 228 weak_ptr_factory_.GetWeakPtr(), | 221 weak_ptr_factory_.GetWeakPtr(), |
| 229 callback)); | 222 callback)); |
| 230 } | 223 } |
| 231 | 224 |
| 232 void MoveOperation::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair( | 225 void MoveOperation::RemoveEntryFromDirectoryAfterEntryInfoPair( |
| 233 const FileMoveCallback& callback, | 226 const FileMoveCallback& callback, |
| 234 scoped_ptr<EntryInfoPairResult> result) { | 227 scoped_ptr<EntryInfoPairResult> result) { |
| 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 236 DCHECK(!callback.is_null()); | 229 DCHECK(!callback.is_null()); |
| 237 DCHECK(result.get()); | 230 DCHECK(result.get()); |
| 238 | 231 |
| 239 const FilePath& file_path = result->first.path; | 232 const FilePath& file_path = result->first.path; |
| 240 if (result->first.error != DRIVE_FILE_OK) { | 233 if (result->first.error != DRIVE_FILE_OK) { |
| 241 callback.Run(result->first.error, file_path); | 234 callback.Run(result->first.error, file_path); |
| 242 return; | 235 return; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 261 weak_ptr_factory_.GetWeakPtr(), | 254 weak_ptr_factory_.GetWeakPtr(), |
| 262 file_path, | 255 file_path, |
| 263 FilePath(kDriveRootDirectory), | 256 FilePath(kDriveRootDirectory), |
| 264 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback, | 257 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback, |
| 265 weak_ptr_factory_.GetWeakPtr(), | 258 weak_ptr_factory_.GetWeakPtr(), |
| 266 callback))); | 259 callback))); |
| 267 } | 260 } |
| 268 | 261 |
| 269 // TODO(zork): Share with CopyOperation. | 262 // TODO(zork): Share with CopyOperation. |
| 270 // See: crbug.com/150050 | 263 // See: crbug.com/150050 |
| 271 void MoveOperation::MoveEntryFromRootDirectory( | 264 void MoveOperation::AddEntryToDirectory(const FilePath& directory_path, |
| 272 const FilePath& directory_path, | 265 const FileOperationCallback& callback, |
| 273 const FileOperationCallback& callback, | 266 DriveFileError error, |
| 274 DriveFileError error, | 267 const FilePath& file_path) { |
| 275 const FilePath& file_path) { | |
| 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 277 DCHECK(!callback.is_null()); | 269 DCHECK(!callback.is_null()); |
| 278 DCHECK_EQ(kDriveRootDirectory, file_path.DirName().value()); | |
| 279 | |
| 280 // Return if there is an error or |dir_path| is the root directory. | |
| 281 if (error != DRIVE_FILE_OK || | |
| 282 directory_path == FilePath(kDriveRootDirectory)) { | |
| 283 callback.Run(error); | |
| 284 return; | |
| 285 } | |
| 286 | 270 |
| 287 metadata_->GetEntryInfoPairByPaths( | 271 metadata_->GetEntryInfoPairByPaths( |
| 288 file_path, | 272 file_path, |
| 289 directory_path, | 273 directory_path, |
| 290 base::Bind( | 274 base::Bind( |
| 291 &MoveOperation::MoveEntryFromRootDirectoryAfterGetEntryInfoPair, | 275 &MoveOperation::AddEntryToDirectoryAfterGetEntryInfoPair, |
| 292 weak_ptr_factory_.GetWeakPtr(), | 276 weak_ptr_factory_.GetWeakPtr(), |
| 293 callback)); | 277 callback)); |
| 294 } | 278 } |
| 295 | 279 |
| 296 // TODO(zork): Share with CopyOperation. | 280 // TODO(zork): Share with CopyOperation. |
| 297 // See: crbug.com/150050 | 281 // See: crbug.com/150050 |
| 298 void MoveOperation::MoveEntryFromRootDirectoryAfterGetEntryInfoPair( | 282 void MoveOperation::AddEntryToDirectoryAfterGetEntryInfoPair( |
| 299 const FileOperationCallback& callback, | 283 const FileOperationCallback& callback, |
| 300 scoped_ptr<EntryInfoPairResult> result) { | 284 scoped_ptr<EntryInfoPairResult> result) { |
| 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 302 DCHECK(!callback.is_null()); | 286 DCHECK(!callback.is_null()); |
| 303 DCHECK(result.get()); | 287 DCHECK(result.get()); |
| 304 | 288 |
| 305 if (result->first.error != DRIVE_FILE_OK) { | 289 if (result->first.error != DRIVE_FILE_OK) { |
| 306 callback.Run(result->first.error); | 290 callback.Run(result->first.error); |
| 307 return; | 291 return; |
| 308 } else if (result->second.error != DRIVE_FILE_OK) { | 292 } else if (result->second.error != DRIVE_FILE_OK) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 DCHECK(!callback.is_null()); | 358 DCHECK(!callback.is_null()); |
| 375 | 359 |
| 376 if (error == DRIVE_FILE_OK) | 360 if (error == DRIVE_FILE_OK) |
| 377 observer_->OnDirectoryChangedByOperation(moved_file_path.DirName()); | 361 observer_->OnDirectoryChangedByOperation(moved_file_path.DirName()); |
| 378 | 362 |
| 379 callback.Run(error, moved_file_path); | 363 callback.Run(error, moved_file_path); |
| 380 } | 364 } |
| 381 | 365 |
| 382 } // namespace file_system | 366 } // namespace file_system |
| 383 } // namespace drive | 367 } // namespace drive |
| OLD | NEW |