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

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

Issue 522543002: Modify test case to support streaming operation in sandbox file system. (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"
11 #include "webkit/browser/blob/file_stream_reader.h" 11 #include "webkit/browser/blob/file_stream_reader.h"
12 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" 12 #include "webkit/browser/fileapi/copy_or_move_file_validator.h"
13 #include "webkit/browser/fileapi/file_observers.h"
13 #include "webkit/browser/fileapi/file_stream_writer.h" 14 #include "webkit/browser/fileapi/file_stream_writer.h"
14 #include "webkit/browser/fileapi/file_system_context.h" 15 #include "webkit/browser/fileapi/file_system_context.h"
15 #include "webkit/browser/fileapi/file_system_operation_runner.h" 16 #include "webkit/browser/fileapi/file_system_operation_runner.h"
16 #include "webkit/browser/fileapi/file_system_url.h" 17 #include "webkit/browser/fileapi/file_system_url.h"
17 #include "webkit/browser/fileapi/recursive_operation_delegate.h" 18 #include "webkit/browser/fileapi/recursive_operation_delegate.h"
18 #include "webkit/common/blob/shareable_file_reference.h" 19 #include "webkit/common/blob/shareable_file_reference.h"
19 #include "webkit/common/fileapi/file_system_util.h" 20 #include "webkit/common/fileapi/file_system_util.h"
20 21
21 namespace storage { 22 namespace storage {
22 23
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 const int kMinProgressCallbackInvocationSpanInMilliseconds = 50; 360 const int kMinProgressCallbackInvocationSpanInMilliseconds = 50;
360 361
361 // Specifically for cross file system copy/move operation, this class uses 362 // Specifically for cross file system copy/move operation, this class uses
362 // stream reader and writer for copying. Validator is not supported, so if 363 // stream reader and writer for copying. Validator is not supported, so if
363 // necessary SnapshotCopyOrMoveImpl should be used. 364 // necessary SnapshotCopyOrMoveImpl should be used.
364 class StreamCopyOrMoveImpl 365 class StreamCopyOrMoveImpl
365 : public CopyOrMoveOperationDelegate::CopyOrMoveImpl { 366 : public CopyOrMoveOperationDelegate::CopyOrMoveImpl {
366 public: 367 public:
367 StreamCopyOrMoveImpl( 368 StreamCopyOrMoveImpl(
368 FileSystemOperationRunner* operation_runner, 369 FileSystemOperationRunner* operation_runner,
370 FileSystemContext* file_system_context,
369 CopyOrMoveOperationDelegate::OperationType operation_type, 371 CopyOrMoveOperationDelegate::OperationType operation_type,
370 const FileSystemURL& src_url, 372 const FileSystemURL& src_url,
371 const FileSystemURL& dest_url, 373 const FileSystemURL& dest_url,
372 CopyOrMoveOperationDelegate::CopyOrMoveOption option, 374 CopyOrMoveOperationDelegate::CopyOrMoveOption option,
373 scoped_ptr<storage::FileStreamReader> reader, 375 scoped_ptr<storage::FileStreamReader> reader,
374 scoped_ptr<FileStreamWriter> writer, 376 scoped_ptr<FileStreamWriter> writer,
375 const FileSystemOperation::CopyFileProgressCallback& 377 const FileSystemOperation::CopyFileProgressCallback&
376 file_progress_callback) 378 file_progress_callback)
377 : operation_runner_(operation_runner), 379 : operation_runner_(operation_runner),
380 file_system_context_(file_system_context),
378 operation_type_(operation_type), 381 operation_type_(operation_type),
379 src_url_(src_url), 382 src_url_(src_url),
380 dest_url_(dest_url), 383 dest_url_(dest_url),
381 option_(option), 384 option_(option),
382 reader_(reader.Pass()), 385 reader_(reader.Pass()),
383 writer_(writer.Pass()), 386 writer_(writer.Pass()),
384 file_progress_callback_(file_progress_callback), 387 file_progress_callback_(file_progress_callback),
385 cancel_requested_(false), 388 cancel_requested_(false),
386 weak_factory_(this) {} 389 weak_factory_(this) {}
387 390
388 virtual void Run( 391 virtual void Run(
389 const CopyOrMoveOperationDelegate::StatusCallback& callback) OVERRIDE { 392 const CopyOrMoveOperationDelegate::StatusCallback& callback) OVERRIDE {
390 // Reader can be created even if the entry does not exist or the entry is 393 // Reader can be created even if the entry does not exist or the entry is
391 // a directory. To check errors before destination file creation, 394 // a directory. To check errors before destination file creation,
392 // check metadata first. 395 // check metadata first.
393 operation_runner_->GetMetadata( 396 operation_runner_->GetMetadata(
394 src_url_, 397 src_url_,
395 base::Bind(&StreamCopyOrMoveImpl::RunAfterGetMetadataForSource, 398 base::Bind(&StreamCopyOrMoveImpl::RunAfterGetMetadataForSource,
396 weak_factory_.GetWeakPtr(), callback)); 399 weak_factory_.GetWeakPtr(), callback));
397 } 400 }
398 401
399 virtual void Cancel() OVERRIDE { 402 virtual void Cancel() OVERRIDE {
400 cancel_requested_ = true; 403 cancel_requested_ = true;
401 if (copy_helper_) 404 if (copy_helper_)
402 copy_helper_->Cancel(); 405 copy_helper_->Cancel();
403 } 406 }
404 407
405 private: 408 private:
409 void NotifyOnStartUpdate(const FileSystemURL& url) {
410 if (file_system_context_->GetUpdateObservers(url.type())) {
411 file_system_context_->GetUpdateObservers(url.type())
412 ->Notify(&FileUpdateObserver::OnStartUpdate, MakeTuple(url));
413 }
414 }
415
416 void NotifyOnModifyFile(const FileSystemURL& url) {
417 if (file_system_context_->GetChangeObservers(url.type())) {
418 file_system_context_->GetChangeObservers(url.type())
419 ->Notify(&FileChangeObserver::OnModifyFile, MakeTuple(url));
420 }
421 }
422
423 void NotifyOnEndUpdate(const FileSystemURL& url) {
424 if (file_system_context_->GetUpdateObservers(url.type())) {
425 file_system_context_->GetUpdateObservers(url.type())
426 ->Notify(&FileUpdateObserver::OnEndUpdate, MakeTuple(url));
427 }
428 }
429
406 void RunAfterGetMetadataForSource( 430 void RunAfterGetMetadataForSource(
407 const CopyOrMoveOperationDelegate::StatusCallback& callback, 431 const CopyOrMoveOperationDelegate::StatusCallback& callback,
408 base::File::Error error, 432 base::File::Error error,
409 const base::File::Info& file_info) { 433 const base::File::Info& file_info) {
410 if (cancel_requested_) 434 if (cancel_requested_)
411 error = base::File::FILE_ERROR_ABORT; 435 error = base::File::FILE_ERROR_ABORT;
412 436
413 if (error != base::File::FILE_OK) { 437 if (error != base::File::FILE_OK) {
414 callback.Run(error); 438 callback.Run(error);
415 return; 439 return;
(...skipping 14 matching lines...) Expand all
430 callback, 454 callback,
431 file_info.last_modified)); 455 file_info.last_modified));
432 } 456 }
433 457
434 void RunAfterCreateFileForDestination( 458 void RunAfterCreateFileForDestination(
435 const CopyOrMoveOperationDelegate::StatusCallback& callback, 459 const CopyOrMoveOperationDelegate::StatusCallback& callback,
436 const base::Time& last_modified, 460 const base::Time& last_modified,
437 base::File::Error error) { 461 base::File::Error error) {
438 if (cancel_requested_) 462 if (cancel_requested_)
439 error = base::File::FILE_ERROR_ABORT; 463 error = base::File::FILE_ERROR_ABORT;
464 // This conversion it to avoid redundant creation and deletion.
tzik 2014/09/04 04:05:43 "is to return the consistent status code to FileSy
iseki 2014/09/04 04:12:17 Yes!
465 if (error == base::File::FILE_ERROR_NOT_A_FILE)
466 error = base::File::FILE_ERROR_INVALID_OPERATION;
440 467
441 if (error != base::File::FILE_OK && 468 if (error != base::File::FILE_OK &&
442 error != base::File::FILE_ERROR_EXISTS) { 469 error != base::File::FILE_ERROR_EXISTS) {
443 callback.Run(error); 470 callback.Run(error);
444 return; 471 return;
445 } 472 }
446 473
447 if (error == base::File::FILE_ERROR_EXISTS) { 474 if (error == base::File::FILE_ERROR_EXISTS) {
448 operation_runner_->Truncate( 475 operation_runner_->Truncate(
449 dest_url_, 476 dest_url_,
(...skipping 16 matching lines...) Expand all
466 error = base::File::FILE_ERROR_ABORT; 493 error = base::File::FILE_ERROR_ABORT;
467 494
468 if (error != base::File::FILE_OK) { 495 if (error != base::File::FILE_OK) {
469 callback.Run(error); 496 callback.Run(error);
470 return; 497 return;
471 } 498 }
472 499
473 const bool need_flush = dest_url_.mount_option().copy_sync_option() == 500 const bool need_flush = dest_url_.mount_option().copy_sync_option() ==
474 storage::COPY_SYNC_OPTION_SYNC; 501 storage::COPY_SYNC_OPTION_SYNC;
475 502
503 NotifyOnStartUpdate(src_url_);
tzik 2014/09/04 03:32:12 Could you remove this since the src is not updated
iseki 2014/09/04 04:12:17 Done.
504 NotifyOnStartUpdate(dest_url_);
476 DCHECK(!copy_helper_); 505 DCHECK(!copy_helper_);
477 copy_helper_.reset( 506 copy_helper_.reset(
478 new CopyOrMoveOperationDelegate::StreamCopyHelper( 507 new CopyOrMoveOperationDelegate::StreamCopyHelper(
479 reader_.Pass(), writer_.Pass(), 508 reader_.Pass(), writer_.Pass(),
480 need_flush, 509 need_flush,
481 kReadBufferSize, 510 kReadBufferSize,
482 file_progress_callback_, 511 file_progress_callback_,
483 base::TimeDelta::FromMilliseconds( 512 base::TimeDelta::FromMilliseconds(
484 kMinProgressCallbackInvocationSpanInMilliseconds))); 513 kMinProgressCallbackInvocationSpanInMilliseconds)));
485 copy_helper_->Run( 514 copy_helper_->Run(
486 base::Bind(&StreamCopyOrMoveImpl::RunAfterStreamCopy, 515 base::Bind(&StreamCopyOrMoveImpl::RunAfterStreamCopy,
487 weak_factory_.GetWeakPtr(), callback, last_modified)); 516 weak_factory_.GetWeakPtr(), callback, last_modified));
488 } 517 }
489 518
490 void RunAfterStreamCopy( 519 void RunAfterStreamCopy(
491 const CopyOrMoveOperationDelegate::StatusCallback& callback, 520 const CopyOrMoveOperationDelegate::StatusCallback& callback,
492 const base::Time& last_modified, 521 const base::Time& last_modified,
493 base::File::Error error) { 522 base::File::Error error) {
523 NotifyOnModifyFile(dest_url_);
524 NotifyOnEndUpdate(src_url_);
tzik 2014/09/04 03:32:12 ditto
iseki 2014/09/04 04:12:17 Done.
525 NotifyOnEndUpdate(dest_url_);
494 if (cancel_requested_) 526 if (cancel_requested_)
495 error = base::File::FILE_ERROR_ABORT; 527 error = base::File::FILE_ERROR_ABORT;
496 528
497 if (error != base::File::FILE_OK) { 529 if (error != base::File::FILE_OK) {
498 callback.Run(error); 530 callback.Run(error);
499 return; 531 return;
500 } 532 }
501 533
502 if (option_ == FileSystemOperation::OPTION_NONE) { 534 if (option_ == FileSystemOperation::OPTION_NONE) {
503 RunAfterTouchFile(callback, base::File::FILE_OK); 535 RunAfterTouchFile(callback, base::File::FILE_OK);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 const CopyOrMoveOperationDelegate::StatusCallback& callback, 569 const CopyOrMoveOperationDelegate::StatusCallback& callback,
538 base::File::Error error) { 570 base::File::Error error) {
539 if (cancel_requested_) 571 if (cancel_requested_)
540 error = base::File::FILE_ERROR_ABORT; 572 error = base::File::FILE_ERROR_ABORT;
541 if (error == base::File::FILE_ERROR_NOT_FOUND) 573 if (error == base::File::FILE_ERROR_NOT_FOUND)
542 error = base::File::FILE_OK; 574 error = base::File::FILE_OK;
543 callback.Run(error); 575 callback.Run(error);
544 } 576 }
545 577
546 FileSystemOperationRunner* operation_runner_; 578 FileSystemOperationRunner* operation_runner_;
579 FileSystemContext* file_system_context_;
tzik 2014/09/04 03:32:12 scoped_refptr?
iseki 2014/09/04 04:12:17 Done.
547 CopyOrMoveOperationDelegate::OperationType operation_type_; 580 CopyOrMoveOperationDelegate::OperationType operation_type_;
548 FileSystemURL src_url_; 581 FileSystemURL src_url_;
549 FileSystemURL dest_url_; 582 FileSystemURL dest_url_;
550 CopyOrMoveOperationDelegate::CopyOrMoveOption option_; 583 CopyOrMoveOperationDelegate::CopyOrMoveOption option_;
551 scoped_ptr<storage::FileStreamReader> reader_; 584 scoped_ptr<storage::FileStreamReader> reader_;
552 scoped_ptr<FileStreamWriter> writer_; 585 scoped_ptr<FileStreamWriter> writer_;
553 FileSystemOperation::CopyFileProgressCallback file_progress_callback_; 586 FileSystemOperation::CopyFileProgressCallback file_progress_callback_;
554 scoped_ptr<CopyOrMoveOperationDelegate::StreamCopyHelper> copy_helper_; 587 scoped_ptr<CopyOrMoveOperationDelegate::StreamCopyHelper> copy_helper_;
555 bool cancel_requested_; 588 bool cancel_requested_;
556 base::WeakPtrFactory<StreamCopyOrMoveImpl> weak_factory_; 589 base::WeakPtrFactory<StreamCopyOrMoveImpl> weak_factory_;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 } 817 }
785 818
786 if (!validator_factory) { 819 if (!validator_factory) {
787 scoped_ptr<storage::FileStreamReader> reader = 820 scoped_ptr<storage::FileStreamReader> reader =
788 file_system_context()->CreateFileStreamReader( 821 file_system_context()->CreateFileStreamReader(
789 src_url, 0, base::Time()); 822 src_url, 0, base::Time());
790 scoped_ptr<FileStreamWriter> writer = 823 scoped_ptr<FileStreamWriter> writer =
791 file_system_context()->CreateFileStreamWriter(dest_url, 0); 824 file_system_context()->CreateFileStreamWriter(dest_url, 0);
792 if (reader && writer) { 825 if (reader && writer) {
793 impl = new StreamCopyOrMoveImpl( 826 impl = new StreamCopyOrMoveImpl(
794 operation_runner(), operation_type_, src_url, dest_url, option_, 827 operation_runner(),
795 reader.Pass(), writer.Pass(), 828 file_system_context(),
829 operation_type_,
830 src_url,
831 dest_url,
832 option_,
833 reader.Pass(),
834 writer.Pass(),
796 base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress, 835 base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress,
797 weak_factory_.GetWeakPtr(), src_url)); 836 weak_factory_.GetWeakPtr(),
837 src_url));
798 } 838 }
799 } 839 }
800 840
801 if (!impl) { 841 if (!impl) {
802 impl = new SnapshotCopyOrMoveImpl( 842 impl = new SnapshotCopyOrMoveImpl(
803 operation_runner(), operation_type_, src_url, dest_url, option_, 843 operation_runner(), operation_type_, src_url, dest_url, option_,
804 validator_factory, 844 validator_factory,
805 base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress, 845 base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress,
806 weak_factory_.GetWeakPtr(), src_url)); 846 weak_factory_.GetWeakPtr(), src_url));
807 } 847 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 base::FilePath relative = dest_root_.virtual_path(); 1026 base::FilePath relative = dest_root_.virtual_path();
987 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), 1027 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(),
988 &relative); 1028 &relative);
989 return file_system_context()->CreateCrackedFileSystemURL( 1029 return file_system_context()->CreateCrackedFileSystemURL(
990 dest_root_.origin(), 1030 dest_root_.origin(),
991 dest_root_.mount_type(), 1031 dest_root_.mount_type(),
992 relative); 1032 relative);
993 } 1033 }
994 1034
995 } // namespace storage 1035 } // namespace storage
OLDNEW
« no previous file with comments | « content/browser/fileapi/obfuscated_file_util_unittest.cc ('k') | webkit/browser/fileapi/file_system_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698