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/drive/file_system/copy_operation.cc

Issue 372713004: Wait for parent directory sync before performing server-side copy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add operation_observer.cc Created 6 years, 5 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/copy_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 FileChange::FILE_TYPE_FILE, 344 FileChange::FILE_TYPE_FILE,
345 FileChange::ADD_OR_UPDATE); 345 FileChange::ADD_OR_UPDATE);
346 observer_->OnFileChangedByOperation(changed_file); 346 observer_->OnFileChangedByOperation(changed_file);
347 } 347 }
348 348
349 if (error != FILE_ERROR_OK || !*should_copy_on_server) { 349 if (error != FILE_ERROR_OK || !*should_copy_on_server) {
350 params->callback.Run(error); 350 params->callback.Run(error);
351 return; 351 return;
352 } 352 }
353 353
354 base::FilePath new_title = params->dest_file_path.BaseName(); 354 if (params->parent_entry.resource_id().empty()) {
355 if (params->src_entry.file_specific_info().is_hosted_document()) { 355 // Parent entry may be being synced.
356 const bool waiting = observer_->WaitForSyncComplete(
357 params->parent_entry.local_id(),
358 base::Bind(&CopyOperation::CopyAfterParentSync,
359 weak_ptr_factory_.GetWeakPtr(), *params));
360 if (!waiting)
361 params->callback.Run(FILE_ERROR_NOT_FOUND);
362 } else {
363 CopyAfterGetParentResourceId(*params, &params->parent_entry, FILE_ERROR_OK);
364 }
365 }
366
367 void CopyOperation::CopyAfterParentSync(const CopyParams& params,
368 FileError error) {
369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
370 DCHECK(!params.callback.is_null());
371
372 if (error != FILE_ERROR_OK) {
373 params.callback.Run(error);
374 return;
375 }
376
377 ResourceEntry* parent = new ResourceEntry;
378 base::PostTaskAndReplyWithResult(
379 blocking_task_runner_,
380 FROM_HERE,
381 base::Bind(&internal::ResourceMetadata::GetResourceEntryById,
382 base::Unretained(metadata_),
383 params.parent_entry.local_id(), parent),
384 base::Bind(&CopyOperation::CopyAfterGetParentResourceId,
385 weak_ptr_factory_.GetWeakPtr(), params, base::Owned(parent)));
386 }
387
388 void CopyOperation::CopyAfterGetParentResourceId(const CopyParams& params,
389 const ResourceEntry* parent,
390 FileError error) {
391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
392 DCHECK(!params.callback.is_null());
393
394 if (error != FILE_ERROR_OK) {
395 params.callback.Run(error);
396 return;
397 }
398
399 base::FilePath new_title = params.dest_file_path.BaseName();
400 if (params.src_entry.file_specific_info().is_hosted_document()) {
356 // Drop the document extension, which should not be in the title. 401 // Drop the document extension, which should not be in the title.
357 // TODO(yoshiki): Remove this code with crbug.com/223304. 402 // TODO(yoshiki): Remove this code with crbug.com/223304.
358 new_title = new_title.RemoveExtension(); 403 new_title = new_title.RemoveExtension();
359 } 404 }
360 405
361 base::Time last_modified = 406 base::Time last_modified =
362 params->preserve_last_modified ? 407 params.preserve_last_modified ?
363 base::Time::FromInternalValue( 408 base::Time::FromInternalValue(
364 params->src_entry.file_info().last_modified()) : base::Time(); 409 params.src_entry.file_info().last_modified()) : base::Time();
365 410
366 CopyResourceOnServer( 411 CopyResourceOnServer(
367 params->src_entry.resource_id(), params->parent_entry.resource_id(), 412 params.src_entry.resource_id(), parent->resource_id(),
368 new_title.AsUTF8Unsafe(), last_modified, params->callback); 413 new_title.AsUTF8Unsafe(), last_modified, params.callback);
369 } 414 }
370 415
371 void CopyOperation::TransferFileFromLocalToRemote( 416 void CopyOperation::TransferFileFromLocalToRemote(
372 const base::FilePath& local_src_path, 417 const base::FilePath& local_src_path,
373 const base::FilePath& remote_dest_path, 418 const base::FilePath& remote_dest_path,
374 const FileOperationCallback& callback) { 419 const FileOperationCallback& callback) {
375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
376 DCHECK(!callback.is_null()); 421 DCHECK(!callback.is_null());
377 422
378 std::string* gdoc_resource_id = new std::string; 423 std::string* gdoc_resource_id = new std::string;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 FileChange changed_file; 661 FileChange changed_file;
617 changed_file.Update(remote_dest_path, *entry, FileChange::ADD_OR_UPDATE); 662 changed_file.Update(remote_dest_path, *entry, FileChange::ADD_OR_UPDATE);
618 observer_->OnFileChangedByOperation(changed_file); 663 observer_->OnFileChangedByOperation(changed_file);
619 observer_->OnEntryUpdatedByOperation(*local_id); 664 observer_->OnEntryUpdatedByOperation(*local_id);
620 } 665 }
621 callback.Run(error); 666 callback.Run(error);
622 } 667 }
623 668
624 } // namespace file_system 669 } // namespace file_system
625 } // namespace drive 670 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698