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

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

Issue 12039005: drive: Deal with the root directory in the same way as others in MoveOperation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix. 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
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/drive_scheduler.h" 10 #include "chrome/browser/chromeos/drive/drive_scheduler.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
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, but
91 // which effectively moves the file to the root directory. 91 // just becomes orphaned).
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|.
93 // effectively moves the file from the root directory to the parent 93 //
94 // directory of |dest_file_path|. 94 // TODO(kinaba): After the step 2, the file gets into the state with no parent
95 // node. Our current implementation regards the state as belonging to the root
96 // directory, so below the file is dealt as such. In fact, this is not the
97 // case on the server side. No-parent and in-root is a different concept. We
98 // need to make our implementation consistent to the server: crbug.com/171207.
95 const FileMoveCallback add_file_to_directory_callback = 99 const FileMoveCallback add_file_to_directory_callback =
96 base::Bind(&MoveOperation::MoveEntryFromRootDirectory, 100 base::Bind(&MoveOperation::AddEntryToDirectory,
97 weak_ptr_factory_.GetWeakPtr(), 101 weak_ptr_factory_.GetWeakPtr(),
98 dest_parent_path, 102 dest_parent_path,
99 callback); 103 callback);
100 104
101 const FileMoveCallback remove_file_from_directory_callback = 105 const FileMoveCallback remove_file_from_directory_callback =
102 base::Bind(&MoveOperation::RemoveEntryFromNonRootDirectory, 106 base::Bind(&MoveOperation::RemoveEntryFromDirectory,
103 weak_ptr_factory_.GetWeakPtr(), 107 weak_ptr_factory_.GetWeakPtr(),
104 add_file_to_directory_callback); 108 add_file_to_directory_callback);
105 109
106 Rename(src_file_path, dest_file_path.BaseName().value(), 110 Rename(src_file_path, dest_file_path.BaseName().value(),
107 remove_file_from_directory_callback); 111 remove_file_from_directory_callback);
108 } 112 }
109 113
110 void MoveOperation::OnFilePathUpdated(const FileOperationCallback& callback, 114 void MoveOperation::OnFilePathUpdated(const FileOperationCallback& callback,
111 DriveFileError error, 115 DriveFileError error,
112 const FilePath& /* file_path */) { 116 const FilePath& /* file_path */) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 203 }
200 204
201 metadata_->RenameEntry( 205 metadata_->RenameEntry(
202 file_path, 206 file_path,
203 new_name, 207 new_name,
204 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback, 208 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback,
205 weak_ptr_factory_.GetWeakPtr(), 209 weak_ptr_factory_.GetWeakPtr(),
206 callback)); 210 callback));
207 } 211 }
208 212
209 void MoveOperation::RemoveEntryFromNonRootDirectory( 213 void MoveOperation::RemoveEntryFromDirectory(
210 const FileMoveCallback& callback, 214 const FileMoveCallback& callback,
211 DriveFileError error, 215 DriveFileError error,
212 const FilePath& file_path) { 216 const FilePath& file_path) {
213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
214 DCHECK(!callback.is_null()); 218 DCHECK(!callback.is_null());
215 219
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( 220 metadata_->GetEntryInfoPairByPaths(
224 file_path, 221 file_path,
225 dir_path, 222 file_path.DirName(),
226 base::Bind( 223 base::Bind(
227 &MoveOperation::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair, 224 &MoveOperation::RemoveEntryFromDirectoryAfterEntryInfoPair,
228 weak_ptr_factory_.GetWeakPtr(), 225 weak_ptr_factory_.GetWeakPtr(),
229 callback)); 226 callback));
230 } 227 }
231 228
232 void MoveOperation::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair( 229 void MoveOperation::RemoveEntryFromDirectoryAfterEntryInfoPair(
233 const FileMoveCallback& callback, 230 const FileMoveCallback& callback,
234 scoped_ptr<EntryInfoPairResult> result) { 231 scoped_ptr<EntryInfoPairResult> result) {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
236 DCHECK(!callback.is_null()); 233 DCHECK(!callback.is_null());
237 DCHECK(result.get()); 234 DCHECK(result.get());
238 235
239 const FilePath& file_path = result->first.path; 236 const FilePath& file_path = result->first.path;
240 if (result->first.error != DRIVE_FILE_OK) { 237 if (result->first.error != DRIVE_FILE_OK) {
241 callback.Run(result->first.error, file_path); 238 callback.Run(result->first.error, file_path);
242 return; 239 return;
(...skipping 18 matching lines...) Expand all
261 weak_ptr_factory_.GetWeakPtr(), 258 weak_ptr_factory_.GetWeakPtr(),
262 file_path, 259 file_path,
263 FilePath(kDriveRootDirectory), 260 FilePath(kDriveRootDirectory),
264 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback, 261 base::Bind(&MoveOperation::NotifyAndRunFileMoveCallback,
265 weak_ptr_factory_.GetWeakPtr(), 262 weak_ptr_factory_.GetWeakPtr(),
266 callback))); 263 callback)));
267 } 264 }
268 265
269 // TODO(zork): Share with CopyOperation. 266 // TODO(zork): Share with CopyOperation.
270 // See: crbug.com/150050 267 // See: crbug.com/150050
271 void MoveOperation::MoveEntryFromRootDirectory( 268 void MoveOperation::AddEntryToDirectory(const FilePath& directory_path,
272 const FilePath& directory_path, 269 const FileOperationCallback& callback,
273 const FileOperationCallback& callback, 270 DriveFileError error,
274 DriveFileError error, 271 const FilePath& file_path) {
275 const FilePath& file_path) {
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
277 DCHECK(!callback.is_null()); 273 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 274
287 metadata_->GetEntryInfoPairByPaths( 275 metadata_->GetEntryInfoPairByPaths(
288 file_path, 276 file_path,
289 directory_path, 277 directory_path,
290 base::Bind( 278 base::Bind(
291 &MoveOperation::MoveEntryFromRootDirectoryAfterGetEntryInfoPair, 279 &MoveOperation::AddEntryToDirectoryAfterGetEntryInfoPair,
292 weak_ptr_factory_.GetWeakPtr(), 280 weak_ptr_factory_.GetWeakPtr(),
293 callback)); 281 callback));
294 } 282 }
295 283
296 // TODO(zork): Share with CopyOperation. 284 // TODO(zork): Share with CopyOperation.
297 // See: crbug.com/150050 285 // See: crbug.com/150050
298 void MoveOperation::MoveEntryFromRootDirectoryAfterGetEntryInfoPair( 286 void MoveOperation::AddEntryToDirectoryAfterGetEntryInfoPair(
299 const FileOperationCallback& callback, 287 const FileOperationCallback& callback,
300 scoped_ptr<EntryInfoPairResult> result) { 288 scoped_ptr<EntryInfoPairResult> result) {
301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
302 DCHECK(!callback.is_null()); 290 DCHECK(!callback.is_null());
303 DCHECK(result.get()); 291 DCHECK(result.get());
304 292
305 if (result->first.error != DRIVE_FILE_OK) { 293 if (result->first.error != DRIVE_FILE_OK) {
306 callback.Run(result->first.error); 294 callback.Run(result->first.error);
307 return; 295 return;
308 } else if (result->second.error != DRIVE_FILE_OK) { 296 } else if (result->second.error != DRIVE_FILE_OK) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 DCHECK(!callback.is_null()); 362 DCHECK(!callback.is_null());
375 363
376 if (error == DRIVE_FILE_OK) 364 if (error == DRIVE_FILE_OK)
377 observer_->OnDirectoryChangedByOperation(moved_file_path.DirName()); 365 observer_->OnDirectoryChangedByOperation(moved_file_path.DirName());
378 366
379 callback.Run(error, moved_file_path); 367 callback.Run(error, moved_file_path);
380 } 368 }
381 369
382 } // namespace file_system 370 } // namespace file_system
383 } // namespace drive 371 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/move_operation.h ('k') | chrome/browser/google_apis/fake_drive_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698