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

Side by Side Diff: webkit/browser/fileapi/copy_or_move_operation_delegate.cc

Issue 536453007: Add truncation to StreamCopyOrMoveImpl and test case. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "webkit/browser/fileapi/copy_or_move_operation_delegate.h" 5 #include "webkit/browser/fileapi/copy_or_move_operation_delegate.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 416 }
417 417
418 if (file_info.is_directory) { 418 if (file_info.is_directory) {
419 // If not a directory, failed with appropriate error code. 419 // If not a directory, failed with appropriate error code.
420 callback.Run(base::File::FILE_ERROR_NOT_A_FILE); 420 callback.Run(base::File::FILE_ERROR_NOT_A_FILE);
421 return; 421 return;
422 } 422 }
423 423
424 // To use FileStreamWriter, we need to ensure the destination file exists. 424 // To use FileStreamWriter, we need to ensure the destination file exists.
425 operation_runner_->CreateFile( 425 operation_runner_->CreateFile(
426 dest_url_, false /* exclusive */, 426 dest_url_,
427 true /* exclusive */,
427 base::Bind(&StreamCopyOrMoveImpl::RunAfterCreateFileForDestination, 428 base::Bind(&StreamCopyOrMoveImpl::RunAfterCreateFileForDestination,
428 weak_factory_.GetWeakPtr(), 429 weak_factory_.GetWeakPtr(),
429 callback, file_info.last_modified)); 430 callback,
431 file_info.last_modified));
430 } 432 }
431 433
432 void RunAfterCreateFileForDestination( 434 void RunAfterCreateFileForDestination(
433 const CopyOrMoveOperationDelegate::StatusCallback& callback, 435 const CopyOrMoveOperationDelegate::StatusCallback& callback,
434 const base::Time& last_modified, 436 const base::Time& last_modified,
435 base::File::Error error) { 437 base::File::Error error) {
436 if (cancel_requested_) 438 if (cancel_requested_)
437 error = base::File::FILE_ERROR_ABORT; 439 error = base::File::FILE_ERROR_ABORT;
438 440
441 if (error != base::File::FILE_OK &&
442 error != base::File::FILE_ERROR_EXISTS) {
443 callback.Run(error);
444 return;
445 }
446
447 if (error == base::File::FILE_ERROR_EXISTS) {
448 operation_runner_->Truncate(
449 dest_url_,
450 0 /* length */,
451 base::Bind(&StreamCopyOrMoveImpl::RunAfterTruncateForDestination,
452 weak_factory_.GetWeakPtr(),
453 callback,
454 last_modified));
455 return;
456 }
tzik 2014/09/03 02:07:43 error == FILE_OK case handling?
iseki 2014/09/03 03:28:21 Done.
457 }
458
459 void RunAfterTruncateForDestination(
460 const CopyOrMoveOperationDelegate::StatusCallback& callback,
461 const base::Time& last_modified,
462 base::File::Error error) {
463 if (cancel_requested_)
464 error = base::File::FILE_ERROR_ABORT;
465
439 if (error != base::File::FILE_OK) { 466 if (error != base::File::FILE_OK) {
440 callback.Run(error); 467 callback.Run(error);
441 return; 468 return;
442 } 469 }
443 470
444 const bool need_flush = dest_url_.mount_option().copy_sync_option() == 471 const bool need_flush = dest_url_.mount_option().copy_sync_option() ==
445 storage::COPY_SYNC_OPTION_SYNC; 472 storage::COPY_SYNC_OPTION_SYNC;
446 473
447 DCHECK(!copy_helper_); 474 DCHECK(!copy_helper_);
448 copy_helper_.reset( 475 copy_helper_.reset(
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 base::FilePath relative = dest_root_.virtual_path(); 984 base::FilePath relative = dest_root_.virtual_path();
958 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), 985 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(),
959 &relative); 986 &relative);
960 return file_system_context()->CreateCrackedFileSystemURL( 987 return file_system_context()->CreateCrackedFileSystemURL(
961 dest_root_.origin(), 988 dest_root_.origin(),
962 dest_root_.mount_type(), 989 dest_root_.mount_type(),
963 relative); 990 relative);
964 } 991 }
965 992
966 } // namespace storage 993 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698