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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/move_operation.cc

Issue 12049062: Merge 177997 (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1364/src/
Patch Set: Created 7 years, 11 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
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/move_operation.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/file_system/operation_observer.h" 10 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 Rename(src_file_path, dest_file_path.BaseName().value(), 79 Rename(src_file_path, dest_file_path.BaseName().value(),
80 final_file_path_update_callback); 80 final_file_path_update_callback);
81 return; 81 return;
82 } 82 }
83 83
84 // Otherwise, the move operation involves three steps: 84 // Otherwise, the move operation involves three steps:
85 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|) 85 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|)
86 // within the same directory. The rename operation is a no-op if 86 // within the same directory. The rename operation is a no-op if
87 // basename(|src_file_path|) equals to basename(|dest_file_path|). 87 // basename(|src_file_path|) equals to basename(|dest_file_path|).
88 // 2. Removes the file from its parent directory (the file is not deleted), 88 // 2. Removes the file from its parent directory (the file is not deleted, but
89 // which effectively moves the file to the root directory. 89 // just becomes orphaned).
90 // 3. Adds the file to the parent directory of |dest_file_path|, which 90 // 3. Adds the file to the parent directory of |dest_file_path|.
91 // effectively moves the file from the root directory to the parent 91 //
92 // directory of |dest_file_path|. 92 // TODO(kinaba): After the step 2, the file gets into the state with no parent
93 // node. Our current implementation regards the state as belonging to the root
94 // directory, so below the file is dealt as such. In fact, this is not the
95 // case on the server side. No-parent and in-root is a different concept. We
96 // need to make our implementation consistent to the server: crbug.com/171207.
93 const FileMoveCallback add_file_to_directory_callback = 97 const FileMoveCallback add_file_to_directory_callback =
94 base::Bind(&MoveOperation::MoveEntryFromRootDirectory, 98 base::Bind(&MoveOperation::AddEntryToDirectory,
95 weak_ptr_factory_.GetWeakPtr(), 99 weak_ptr_factory_.GetWeakPtr(),
96 dest_parent_path, 100 dest_parent_path,
97 callback); 101 callback);
98 102
99 const FileMoveCallback remove_file_from_directory_callback = 103 const FileMoveCallback remove_file_from_directory_callback =
100 base::Bind(&MoveOperation::RemoveEntryFromNonRootDirectory, 104 base::Bind(&MoveOperation::RemoveEntryFromDirectory,
101 weak_ptr_factory_.GetWeakPtr(), 105 weak_ptr_factory_.GetWeakPtr(),
102 add_file_to_directory_callback); 106 add_file_to_directory_callback);
103 107
104 Rename(src_file_path, dest_file_path.BaseName().value(), 108 Rename(src_file_path, dest_file_path.BaseName().value(),
105 remove_file_from_directory_callback); 109 remove_file_from_directory_callback);
106 } 110 }
107 111
108 void MoveOperation::OnFilePathUpdated(const FileOperationCallback& callback, 112 void MoveOperation::OnFilePathUpdated(const FileOperationCallback& callback,
109 DriveFileError error, 113 DriveFileError error,
110 const FilePath& /* file_path */) { 114 const FilePath& /* file_path */) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 201 }
198 202
199 metadata_->RenameEntry( 203 metadata_->RenameEntry(
200 file_path, 204 file_path,
201 new_name, 205 new_name,
202 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback, 206 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback,
203 weak_ptr_factory_.GetWeakPtr(), 207 weak_ptr_factory_.GetWeakPtr(),
204 callback)); 208 callback));
205 } 209 }
206 210
207 void MoveOperation::RemoveEntryFromNonRootDirectory( 211 void MoveOperation::RemoveEntryFromDirectory(
208 const FileMoveCallback& callback, 212 const FileMoveCallback& callback,
209 DriveFileError error, 213 DriveFileError error,
210 const FilePath& file_path) { 214 const FilePath& file_path) {
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
212 DCHECK(!callback.is_null()); 216 DCHECK(!callback.is_null());
213 217
214 const FilePath dir_path = file_path.DirName();
215 // Return if there is an error or |dir_path| is the root directory.
216 if (error != DRIVE_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) {
217 callback.Run(error, file_path);
218 return;
219 }
220
221 metadata_->GetEntryInfoPairByPaths( 218 metadata_->GetEntryInfoPairByPaths(
222 file_path, 219 file_path,
223 dir_path, 220 file_path.DirName(),
224 base::Bind( 221 base::Bind(
225 &MoveOperation::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair, 222 &MoveOperation::RemoveEntryFromDirectoryAfterEntryInfoPair,
226 weak_ptr_factory_.GetWeakPtr(), 223 weak_ptr_factory_.GetWeakPtr(),
227 callback)); 224 callback));
228 } 225 }
229 226
230 void MoveOperation::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair( 227 void MoveOperation::RemoveEntryFromDirectoryAfterEntryInfoPair(
231 const FileMoveCallback& callback, 228 const FileMoveCallback& callback,
232 scoped_ptr<EntryInfoPairResult> result) { 229 scoped_ptr<EntryInfoPairResult> result) {
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
234 DCHECK(!callback.is_null()); 231 DCHECK(!callback.is_null());
235 DCHECK(result.get()); 232 DCHECK(result.get());
236 233
237 const FilePath& file_path = result->first.path; 234 const FilePath& file_path = result->first.path;
238 if (result->first.error != DRIVE_FILE_OK) { 235 if (result->first.error != DRIVE_FILE_OK) {
239 callback.Run(result->first.error, file_path); 236 callback.Run(result->first.error, file_path);
240 return; 237 return;
(...skipping 18 matching lines...) Expand all
259 weak_ptr_factory_.GetWeakPtr(), 256 weak_ptr_factory_.GetWeakPtr(),
260 file_path, 257 file_path,
261 FilePath(kDriveRootDirectory), 258 FilePath(kDriveRootDirectory),
262 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback, 259 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback,
263 weak_ptr_factory_.GetWeakPtr(), 260 weak_ptr_factory_.GetWeakPtr(),
264 callback))); 261 callback)));
265 } 262 }
266 263
267 // TODO(zork): Share with CopyOperation. 264 // TODO(zork): Share with CopyOperation.
268 // See: crbug.com/150050 265 // See: crbug.com/150050
269 void MoveOperation::MoveEntryFromRootDirectory( 266 void MoveOperation::AddEntryToDirectory(const FilePath& directory_path,
270 const FilePath& directory_path, 267 const FileOperationCallback& callback,
271 const FileOperationCallback& callback, 268 DriveFileError error,
272 DriveFileError error, 269 const FilePath& file_path) {
273 const FilePath& file_path) {
274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
275 DCHECK(!callback.is_null()); 271 DCHECK(!callback.is_null());
276 DCHECK_EQ(kDriveRootDirectory, file_path.DirName().value());
277
278 // Return if there is an error or |dir_path| is the root directory.
279 if (error != DRIVE_FILE_OK ||
280 directory_path == FilePath(kDriveRootDirectory)) {
281 callback.Run(error);
282 return;
283 }
284 272
285 metadata_->GetEntryInfoPairByPaths( 273 metadata_->GetEntryInfoPairByPaths(
286 file_path, 274 file_path,
287 directory_path, 275 directory_path,
288 base::Bind( 276 base::Bind(
289 &MoveOperation::MoveEntryFromRootDirectoryAfterGetEntryInfoPair, 277 &MoveOperation::AddEntryToDirectoryAfterGetEntryInfoPair,
290 weak_ptr_factory_.GetWeakPtr(), 278 weak_ptr_factory_.GetWeakPtr(),
291 callback)); 279 callback));
292 } 280 }
293 281
294 // TODO(zork): Share with CopyOperation. 282 // TODO(zork): Share with CopyOperation.
295 // See: crbug.com/150050 283 // See: crbug.com/150050
296 void MoveOperation::MoveEntryFromRootDirectoryAfterGetEntryInfoPair( 284 void MoveOperation::AddEntryToDirectoryAfterGetEntryInfoPair(
297 const FileOperationCallback& callback, 285 const FileOperationCallback& callback,
298 scoped_ptr<EntryInfoPairResult> result) { 286 scoped_ptr<EntryInfoPairResult> result) {
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
300 DCHECK(!callback.is_null()); 288 DCHECK(!callback.is_null());
301 DCHECK(result.get()); 289 DCHECK(result.get());
302 290
303 if (result->first.error != DRIVE_FILE_OK) { 291 if (result->first.error != DRIVE_FILE_OK) {
304 callback.Run(result->first.error); 292 callback.Run(result->first.error);
305 return; 293 return;
306 } else if (result->second.error != DRIVE_FILE_OK) { 294 } else if (result->second.error != DRIVE_FILE_OK) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 DCHECK(!callback.is_null()); 360 DCHECK(!callback.is_null());
373 361
374 if (error == DRIVE_FILE_OK) 362 if (error == DRIVE_FILE_OK)
375 observer_->OnDirectoryChangedByOperation(moved_file_path.DirName()); 363 observer_->OnDirectoryChangedByOperation(moved_file_path.DirName());
376 364
377 callback.Run(error, moved_file_path); 365 callback.Run(error, moved_file_path);
378 } 366 }
379 367
380 } // namespace file_system 368 } // namespace file_system
381 } // namespace drive 369 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/move_operation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698