OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "storage/browser/fileapi/file_system_operation_runner.h" | 5 #include "storage/browser/fileapi/file_system_operation_runner.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop_proxy.h" | |
9 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/thread_task_runner_handle.h" |
10 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
11 #include "storage/browser/blob/blob_url_request_job_factory.h" | 11 #include "storage/browser/blob/blob_url_request_job_factory.h" |
12 #include "storage/browser/blob/shareable_file_reference.h" | 12 #include "storage/browser/blob/shareable_file_reference.h" |
13 #include "storage/browser/fileapi/file_observers.h" | 13 #include "storage/browser/fileapi/file_observers.h" |
14 #include "storage/browser/fileapi/file_stream_writer.h" | 14 #include "storage/browser/fileapi/file_stream_writer.h" |
15 #include "storage/browser/fileapi/file_system_context.h" | 15 #include "storage/browser/fileapi/file_system_context.h" |
16 #include "storage/browser/fileapi/file_system_operation.h" | 16 #include "storage/browser/fileapi/file_system_operation.h" |
17 #include "storage/browser/fileapi/file_writer_delegate.h" | 17 #include "storage/browser/fileapi/file_writer_delegate.h" |
18 | 18 |
19 namespace storage { | 19 namespace storage { |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 FileSystemOperationRunner::FileSystemOperationRunner( | 507 FileSystemOperationRunner::FileSystemOperationRunner( |
508 FileSystemContext* file_system_context) | 508 FileSystemContext* file_system_context) |
509 : file_system_context_(file_system_context) {} | 509 : file_system_context_(file_system_context) {} |
510 | 510 |
511 void FileSystemOperationRunner::DidFinish( | 511 void FileSystemOperationRunner::DidFinish( |
512 const OperationHandle& handle, | 512 const OperationHandle& handle, |
513 const StatusCallback& callback, | 513 const StatusCallback& callback, |
514 base::File::Error rv) { | 514 base::File::Error rv) { |
515 if (handle.scope) { | 515 if (handle.scope) { |
516 finished_operations_.insert(handle.id); | 516 finished_operations_.insert(handle.id); |
517 base::MessageLoopProxy::current()->PostTask( | 517 base::ThreadTaskRunnerHandle::Get()->PostTask( |
518 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidFinish, | 518 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidFinish, |
519 AsWeakPtr(), handle, callback, rv)); | 519 AsWeakPtr(), handle, callback, rv)); |
520 return; | 520 return; |
521 } | 521 } |
522 callback.Run(rv); | 522 callback.Run(rv); |
523 FinishOperation(handle.id); | 523 FinishOperation(handle.id); |
524 } | 524 } |
525 | 525 |
526 void FileSystemOperationRunner::DidGetMetadata( | 526 void FileSystemOperationRunner::DidGetMetadata( |
527 const OperationHandle& handle, | 527 const OperationHandle& handle, |
528 const GetMetadataCallback& callback, | 528 const GetMetadataCallback& callback, |
529 base::File::Error rv, | 529 base::File::Error rv, |
530 const base::File::Info& file_info) { | 530 const base::File::Info& file_info) { |
531 if (handle.scope) { | 531 if (handle.scope) { |
532 finished_operations_.insert(handle.id); | 532 finished_operations_.insert(handle.id); |
533 base::MessageLoopProxy::current()->PostTask( | 533 base::ThreadTaskRunnerHandle::Get()->PostTask( |
534 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidGetMetadata, | 534 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidGetMetadata, |
535 AsWeakPtr(), handle, callback, rv, file_info)); | 535 AsWeakPtr(), handle, callback, rv, file_info)); |
536 return; | 536 return; |
537 } | 537 } |
538 callback.Run(rv, file_info); | 538 callback.Run(rv, file_info); |
539 FinishOperation(handle.id); | 539 FinishOperation(handle.id); |
540 } | 540 } |
541 | 541 |
542 void FileSystemOperationRunner::DidReadDirectory( | 542 void FileSystemOperationRunner::DidReadDirectory( |
543 const OperationHandle& handle, | 543 const OperationHandle& handle, |
544 const ReadDirectoryCallback& callback, | 544 const ReadDirectoryCallback& callback, |
545 base::File::Error rv, | 545 base::File::Error rv, |
546 const std::vector<DirectoryEntry>& entries, | 546 const std::vector<DirectoryEntry>& entries, |
547 bool has_more) { | 547 bool has_more) { |
548 if (handle.scope) { | 548 if (handle.scope) { |
549 finished_operations_.insert(handle.id); | 549 finished_operations_.insert(handle.id); |
550 base::MessageLoopProxy::current()->PostTask( | 550 base::ThreadTaskRunnerHandle::Get()->PostTask( |
551 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidReadDirectory, | 551 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidReadDirectory, |
552 AsWeakPtr(), handle, callback, rv, | 552 AsWeakPtr(), handle, callback, rv, |
553 entries, has_more)); | 553 entries, has_more)); |
554 return; | 554 return; |
555 } | 555 } |
556 callback.Run(rv, entries, has_more); | 556 callback.Run(rv, entries, has_more); |
557 if (rv != base::File::FILE_OK || !has_more) | 557 if (rv != base::File::FILE_OK || !has_more) |
558 FinishOperation(handle.id); | 558 FinishOperation(handle.id); |
559 } | 559 } |
560 | 560 |
561 void FileSystemOperationRunner::DidWrite( | 561 void FileSystemOperationRunner::DidWrite( |
562 const OperationHandle& handle, | 562 const OperationHandle& handle, |
563 const WriteCallback& callback, | 563 const WriteCallback& callback, |
564 base::File::Error rv, | 564 base::File::Error rv, |
565 int64 bytes, | 565 int64 bytes, |
566 bool complete) { | 566 bool complete) { |
567 if (handle.scope) { | 567 if (handle.scope) { |
568 finished_operations_.insert(handle.id); | 568 finished_operations_.insert(handle.id); |
569 base::MessageLoopProxy::current()->PostTask( | 569 base::ThreadTaskRunnerHandle::Get()->PostTask( |
570 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidWrite, AsWeakPtr(), | 570 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidWrite, AsWeakPtr(), |
571 handle, callback, rv, bytes, complete)); | 571 handle, callback, rv, bytes, complete)); |
572 return; | 572 return; |
573 } | 573 } |
574 callback.Run(rv, bytes, complete); | 574 callback.Run(rv, bytes, complete); |
575 if (rv != base::File::FILE_OK || complete) | 575 if (rv != base::File::FILE_OK || complete) |
576 FinishOperation(handle.id); | 576 FinishOperation(handle.id); |
577 } | 577 } |
578 | 578 |
579 void FileSystemOperationRunner::DidOpenFile( | 579 void FileSystemOperationRunner::DidOpenFile( |
580 const OperationHandle& handle, | 580 const OperationHandle& handle, |
581 const OpenFileCallback& callback, | 581 const OpenFileCallback& callback, |
582 base::File file, | 582 base::File file, |
583 const base::Closure& on_close_callback) { | 583 const base::Closure& on_close_callback) { |
584 if (handle.scope) { | 584 if (handle.scope) { |
585 finished_operations_.insert(handle.id); | 585 finished_operations_.insert(handle.id); |
586 base::MessageLoopProxy::current()->PostTask( | 586 base::ThreadTaskRunnerHandle::Get()->PostTask( |
587 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidOpenFile, | 587 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidOpenFile, |
588 AsWeakPtr(), handle, callback, Passed(&file), | 588 AsWeakPtr(), handle, callback, Passed(&file), |
589 on_close_callback)); | 589 on_close_callback)); |
590 return; | 590 return; |
591 } | 591 } |
592 callback.Run(file.Pass(), on_close_callback); | 592 callback.Run(file.Pass(), on_close_callback); |
593 FinishOperation(handle.id); | 593 FinishOperation(handle.id); |
594 } | 594 } |
595 | 595 |
596 void FileSystemOperationRunner::DidCreateSnapshot( | 596 void FileSystemOperationRunner::DidCreateSnapshot( |
597 const OperationHandle& handle, | 597 const OperationHandle& handle, |
598 const SnapshotFileCallback& callback, | 598 const SnapshotFileCallback& callback, |
599 base::File::Error rv, | 599 base::File::Error rv, |
600 const base::File::Info& file_info, | 600 const base::File::Info& file_info, |
601 const base::FilePath& platform_path, | 601 const base::FilePath& platform_path, |
602 const scoped_refptr<storage::ShareableFileReference>& file_ref) { | 602 const scoped_refptr<storage::ShareableFileReference>& file_ref) { |
603 if (handle.scope) { | 603 if (handle.scope) { |
604 finished_operations_.insert(handle.id); | 604 finished_operations_.insert(handle.id); |
605 base::MessageLoopProxy::current()->PostTask( | 605 base::ThreadTaskRunnerHandle::Get()->PostTask( |
606 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidCreateSnapshot, | 606 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidCreateSnapshot, |
607 AsWeakPtr(), handle, callback, rv, file_info, | 607 AsWeakPtr(), handle, callback, rv, file_info, |
608 platform_path, file_ref)); | 608 platform_path, file_ref)); |
609 return; | 609 return; |
610 } | 610 } |
611 callback.Run(rv, file_info, platform_path, file_ref); | 611 callback.Run(rv, file_info, platform_path, file_ref); |
612 FinishOperation(handle.id); | 612 FinishOperation(handle.id); |
613 } | 613 } |
614 | 614 |
615 void FileSystemOperationRunner::OnCopyProgress( | 615 void FileSystemOperationRunner::OnCopyProgress( |
616 const OperationHandle& handle, | 616 const OperationHandle& handle, |
617 const CopyProgressCallback& callback, | 617 const CopyProgressCallback& callback, |
618 FileSystemOperation::CopyProgressType type, | 618 FileSystemOperation::CopyProgressType type, |
619 const FileSystemURL& source_url, | 619 const FileSystemURL& source_url, |
620 const FileSystemURL& dest_url, | 620 const FileSystemURL& dest_url, |
621 int64 size) { | 621 int64 size) { |
622 if (handle.scope) { | 622 if (handle.scope) { |
623 base::MessageLoopProxy::current()->PostTask( | 623 base::ThreadTaskRunnerHandle::Get()->PostTask( |
624 FROM_HERE, base::Bind( | 624 FROM_HERE, base::Bind( |
625 &FileSystemOperationRunner::OnCopyProgress, | 625 &FileSystemOperationRunner::OnCopyProgress, |
626 AsWeakPtr(), handle, callback, type, source_url, dest_url, size)); | 626 AsWeakPtr(), handle, callback, type, source_url, dest_url, size)); |
627 return; | 627 return; |
628 } | 628 } |
629 callback.Run(type, source_url, dest_url, size); | 629 callback.Run(type, source_url, dest_url, size); |
630 } | 630 } |
631 | 631 |
632 void FileSystemOperationRunner::PrepareForWrite(OperationID id, | 632 void FileSystemOperationRunner::PrepareForWrite(OperationID id, |
633 const FileSystemURL& url) { | 633 const FileSystemURL& url) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 stray_cancel_callbacks_.find(id); | 681 stray_cancel_callbacks_.find(id); |
682 if (found_cancel != stray_cancel_callbacks_.end()) { | 682 if (found_cancel != stray_cancel_callbacks_.end()) { |
683 // This cancel has been requested after the operation has finished, | 683 // This cancel has been requested after the operation has finished, |
684 // so report that we failed to stop it. | 684 // so report that we failed to stop it. |
685 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 685 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
686 stray_cancel_callbacks_.erase(found_cancel); | 686 stray_cancel_callbacks_.erase(found_cancel); |
687 } | 687 } |
688 } | 688 } |
689 | 689 |
690 } // namespace storage | 690 } // namespace storage |
OLD | NEW |