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 "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" | 5 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <utility> | 10 #include <utility> |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 base::RunLoop run_loop; | 82 base::RunLoop run_loop; |
83 task_runner->PostTaskAndReply(location, task, | 83 task_runner->PostTaskAndReply(location, task, |
84 base::BindOnce(base::IgnoreResult(base::Bind( | 84 base::BindOnce(base::IgnoreResult(base::Bind( |
85 &base::SingleThreadTaskRunner::PostTask, | 85 &base::SingleThreadTaskRunner::PostTask, |
86 base::ThreadTaskRunnerHandle::Get(), | 86 base::ThreadTaskRunnerHandle::Get(), |
87 FROM_HERE, run_loop.QuitClosure())))); | 87 FROM_HERE, run_loop.QuitClosure())))); |
88 run_loop.Run(); | 88 run_loop.Run(); |
89 } | 89 } |
90 | 90 |
91 void EnsureRunningOn(base::SingleThreadTaskRunner* runner) { | 91 void EnsureRunningOn(base::SingleThreadTaskRunner* runner) { |
92 EXPECT_TRUE(runner->RunsTasksOnCurrentThread()); | 92 EXPECT_TRUE(runner->RunsTasksInCurrentSequence()); |
93 } | 93 } |
94 | 94 |
95 void VerifySameTaskRunner( | 95 void VerifySameTaskRunner( |
96 base::SingleThreadTaskRunner* runner1, | 96 base::SingleThreadTaskRunner* runner1, |
97 base::SingleThreadTaskRunner* runner2) { | 97 base::SingleThreadTaskRunner* runner2) { |
98 ASSERT_TRUE(runner1 != nullptr); | 98 ASSERT_TRUE(runner1 != nullptr); |
99 ASSERT_TRUE(runner2 != nullptr); | 99 ASSERT_TRUE(runner2 != nullptr); |
100 runner1->PostTask( | 100 runner1->PostTask( |
101 FROM_HERE, base::BindOnce(&EnsureRunningOn, base::RetainedRef(runner2))); | 101 FROM_HERE, base::BindOnce(&EnsureRunningOn, base::RetainedRef(runner2))); |
102 } | 102 } |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 FROM_HERE, &LocalFileSyncStatus::Observer::OnSyncEnabled, url); | 552 FROM_HERE, &LocalFileSyncStatus::Observer::OnSyncEnabled, url); |
553 } | 553 } |
554 | 554 |
555 void CannedSyncableFileSystem::OnWriteEnabled(const FileSystemURL& url) { | 555 void CannedSyncableFileSystem::OnWriteEnabled(const FileSystemURL& url) { |
556 sync_status_observers_->Notify( | 556 sync_status_observers_->Notify( |
557 FROM_HERE, &LocalFileSyncStatus::Observer::OnWriteEnabled, url); | 557 FROM_HERE, &LocalFileSyncStatus::Observer::OnWriteEnabled, url); |
558 } | 558 } |
559 | 559 |
560 void CannedSyncableFileSystem::DoOpenFileSystem( | 560 void CannedSyncableFileSystem::DoOpenFileSystem( |
561 const OpenFileSystemCallback& callback) { | 561 const OpenFileSystemCallback& callback) { |
562 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 562 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
563 EXPECT_FALSE(is_filesystem_opened_); | 563 EXPECT_FALSE(is_filesystem_opened_); |
564 file_system_context_->OpenFileSystem( | 564 file_system_context_->OpenFileSystem( |
565 origin_, | 565 origin_, |
566 type_, | 566 type_, |
567 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 567 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
568 callback); | 568 callback); |
569 } | 569 } |
570 | 570 |
571 void CannedSyncableFileSystem::DoCreateDirectory( | 571 void CannedSyncableFileSystem::DoCreateDirectory( |
572 const FileSystemURL& url, | 572 const FileSystemURL& url, |
573 const StatusCallback& callback) { | 573 const StatusCallback& callback) { |
574 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 574 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
575 EXPECT_TRUE(is_filesystem_opened_); | 575 EXPECT_TRUE(is_filesystem_opened_); |
576 operation_runner()->CreateDirectory( | 576 operation_runner()->CreateDirectory( |
577 url, false /* exclusive */, false /* recursive */, callback); | 577 url, false /* exclusive */, false /* recursive */, callback); |
578 } | 578 } |
579 | 579 |
580 void CannedSyncableFileSystem::DoCreateFile( | 580 void CannedSyncableFileSystem::DoCreateFile( |
581 const FileSystemURL& url, | 581 const FileSystemURL& url, |
582 const StatusCallback& callback) { | 582 const StatusCallback& callback) { |
583 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 583 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
584 EXPECT_TRUE(is_filesystem_opened_); | 584 EXPECT_TRUE(is_filesystem_opened_); |
585 operation_runner()->CreateFile(url, false /* exclusive */, callback); | 585 operation_runner()->CreateFile(url, false /* exclusive */, callback); |
586 } | 586 } |
587 | 587 |
588 void CannedSyncableFileSystem::DoCopy( | 588 void CannedSyncableFileSystem::DoCopy( |
589 const FileSystemURL& src_url, | 589 const FileSystemURL& src_url, |
590 const FileSystemURL& dest_url, | 590 const FileSystemURL& dest_url, |
591 const StatusCallback& callback) { | 591 const StatusCallback& callback) { |
592 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 592 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
593 EXPECT_TRUE(is_filesystem_opened_); | 593 EXPECT_TRUE(is_filesystem_opened_); |
594 operation_runner()->Copy( | 594 operation_runner()->Copy( |
595 src_url, dest_url, storage::FileSystemOperation::OPTION_NONE, | 595 src_url, dest_url, storage::FileSystemOperation::OPTION_NONE, |
596 storage::FileSystemOperation::ERROR_BEHAVIOR_ABORT, | 596 storage::FileSystemOperation::ERROR_BEHAVIOR_ABORT, |
597 storage::FileSystemOperationRunner::CopyProgressCallback(), callback); | 597 storage::FileSystemOperationRunner::CopyProgressCallback(), callback); |
598 } | 598 } |
599 | 599 |
600 void CannedSyncableFileSystem::DoMove( | 600 void CannedSyncableFileSystem::DoMove( |
601 const FileSystemURL& src_url, | 601 const FileSystemURL& src_url, |
602 const FileSystemURL& dest_url, | 602 const FileSystemURL& dest_url, |
603 const StatusCallback& callback) { | 603 const StatusCallback& callback) { |
604 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 604 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
605 EXPECT_TRUE(is_filesystem_opened_); | 605 EXPECT_TRUE(is_filesystem_opened_); |
606 operation_runner()->Move( | 606 operation_runner()->Move( |
607 src_url, dest_url, storage::FileSystemOperation::OPTION_NONE, callback); | 607 src_url, dest_url, storage::FileSystemOperation::OPTION_NONE, callback); |
608 } | 608 } |
609 | 609 |
610 void CannedSyncableFileSystem::DoTruncateFile(const FileSystemURL& url, | 610 void CannedSyncableFileSystem::DoTruncateFile(const FileSystemURL& url, |
611 int64_t size, | 611 int64_t size, |
612 const StatusCallback& callback) { | 612 const StatusCallback& callback) { |
613 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 613 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
614 EXPECT_TRUE(is_filesystem_opened_); | 614 EXPECT_TRUE(is_filesystem_opened_); |
615 operation_runner()->Truncate(url, size, callback); | 615 operation_runner()->Truncate(url, size, callback); |
616 } | 616 } |
617 | 617 |
618 void CannedSyncableFileSystem::DoTouchFile( | 618 void CannedSyncableFileSystem::DoTouchFile( |
619 const FileSystemURL& url, | 619 const FileSystemURL& url, |
620 const base::Time& last_access_time, | 620 const base::Time& last_access_time, |
621 const base::Time& last_modified_time, | 621 const base::Time& last_modified_time, |
622 const StatusCallback& callback) { | 622 const StatusCallback& callback) { |
623 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 623 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
624 EXPECT_TRUE(is_filesystem_opened_); | 624 EXPECT_TRUE(is_filesystem_opened_); |
625 operation_runner()->TouchFile(url, last_access_time, | 625 operation_runner()->TouchFile(url, last_access_time, |
626 last_modified_time, callback); | 626 last_modified_time, callback); |
627 } | 627 } |
628 | 628 |
629 void CannedSyncableFileSystem::DoRemove( | 629 void CannedSyncableFileSystem::DoRemove( |
630 const FileSystemURL& url, bool recursive, | 630 const FileSystemURL& url, bool recursive, |
631 const StatusCallback& callback) { | 631 const StatusCallback& callback) { |
632 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 632 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
633 EXPECT_TRUE(is_filesystem_opened_); | 633 EXPECT_TRUE(is_filesystem_opened_); |
634 operation_runner()->Remove(url, recursive, callback); | 634 operation_runner()->Remove(url, recursive, callback); |
635 } | 635 } |
636 | 636 |
637 void CannedSyncableFileSystem::DoFileExists( | 637 void CannedSyncableFileSystem::DoFileExists( |
638 const FileSystemURL& url, const StatusCallback& callback) { | 638 const FileSystemURL& url, const StatusCallback& callback) { |
639 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 639 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
640 EXPECT_TRUE(is_filesystem_opened_); | 640 EXPECT_TRUE(is_filesystem_opened_); |
641 operation_runner()->FileExists(url, callback); | 641 operation_runner()->FileExists(url, callback); |
642 } | 642 } |
643 | 643 |
644 void CannedSyncableFileSystem::DoDirectoryExists( | 644 void CannedSyncableFileSystem::DoDirectoryExists( |
645 const FileSystemURL& url, const StatusCallback& callback) { | 645 const FileSystemURL& url, const StatusCallback& callback) { |
646 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 646 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
647 EXPECT_TRUE(is_filesystem_opened_); | 647 EXPECT_TRUE(is_filesystem_opened_); |
648 operation_runner()->DirectoryExists(url, callback); | 648 operation_runner()->DirectoryExists(url, callback); |
649 } | 649 } |
650 | 650 |
651 void CannedSyncableFileSystem::DoVerifyFile( | 651 void CannedSyncableFileSystem::DoVerifyFile( |
652 const FileSystemURL& url, | 652 const FileSystemURL& url, |
653 const std::string& expected_data, | 653 const std::string& expected_data, |
654 const StatusCallback& callback) { | 654 const StatusCallback& callback) { |
655 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 655 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
656 EXPECT_TRUE(is_filesystem_opened_); | 656 EXPECT_TRUE(is_filesystem_opened_); |
657 operation_runner()->CreateSnapshotFile( | 657 operation_runner()->CreateSnapshotFile( |
658 url, | 658 url, |
659 base::Bind(&OnCreateSnapshotFileAndVerifyData, expected_data, callback)); | 659 base::Bind(&OnCreateSnapshotFileAndVerifyData, expected_data, callback)); |
660 } | 660 } |
661 | 661 |
662 void CannedSyncableFileSystem::DoGetMetadataAndPlatformPath( | 662 void CannedSyncableFileSystem::DoGetMetadataAndPlatformPath( |
663 const FileSystemURL& url, | 663 const FileSystemURL& url, |
664 base::File::Info* info, | 664 base::File::Info* info, |
665 base::FilePath* platform_path, | 665 base::FilePath* platform_path, |
666 const StatusCallback& callback) { | 666 const StatusCallback& callback) { |
667 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 667 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
668 EXPECT_TRUE(is_filesystem_opened_); | 668 EXPECT_TRUE(is_filesystem_opened_); |
669 operation_runner()->CreateSnapshotFile( | 669 operation_runner()->CreateSnapshotFile( |
670 url, base::Bind(&OnCreateSnapshotFile, info, platform_path, callback)); | 670 url, base::Bind(&OnCreateSnapshotFile, info, platform_path, callback)); |
671 } | 671 } |
672 | 672 |
673 void CannedSyncableFileSystem::DoReadDirectory( | 673 void CannedSyncableFileSystem::DoReadDirectory( |
674 const FileSystemURL& url, | 674 const FileSystemURL& url, |
675 FileEntryList* entries, | 675 FileEntryList* entries, |
676 const StatusCallback& callback) { | 676 const StatusCallback& callback) { |
677 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 677 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
678 EXPECT_TRUE(is_filesystem_opened_); | 678 EXPECT_TRUE(is_filesystem_opened_); |
679 operation_runner()->ReadDirectory( | 679 operation_runner()->ReadDirectory( |
680 url, base::Bind(&OnReadDirectory, entries, callback)); | 680 url, base::Bind(&OnReadDirectory, entries, callback)); |
681 } | 681 } |
682 | 682 |
683 void CannedSyncableFileSystem::DoWrite( | 683 void CannedSyncableFileSystem::DoWrite( |
684 net::URLRequestContext* url_request_context, | 684 net::URLRequestContext* url_request_context, |
685 const FileSystemURL& url, | 685 const FileSystemURL& url, |
686 std::unique_ptr<storage::BlobDataHandle> blob_data_handle, | 686 std::unique_ptr<storage::BlobDataHandle> blob_data_handle, |
687 const WriteCallback& callback) { | 687 const WriteCallback& callback) { |
688 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 688 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
689 EXPECT_TRUE(is_filesystem_opened_); | 689 EXPECT_TRUE(is_filesystem_opened_); |
690 WriteHelper* helper = new WriteHelper; | 690 WriteHelper* helper = new WriteHelper; |
691 operation_runner()->Write( | 691 operation_runner()->Write( |
692 url_request_context, url, std::move(blob_data_handle), 0, | 692 url_request_context, url, std::move(blob_data_handle), 0, |
693 base::Bind(&WriteHelper::DidWrite, base::Owned(helper), callback)); | 693 base::Bind(&WriteHelper::DidWrite, base::Owned(helper), callback)); |
694 } | 694 } |
695 | 695 |
696 void CannedSyncableFileSystem::DoWriteString( | 696 void CannedSyncableFileSystem::DoWriteString( |
697 const FileSystemURL& url, | 697 const FileSystemURL& url, |
698 const std::string& data, | 698 const std::string& data, |
699 const WriteCallback& callback) { | 699 const WriteCallback& callback) { |
700 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 700 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
701 EXPECT_TRUE(is_filesystem_opened_); | 701 EXPECT_TRUE(is_filesystem_opened_); |
702 MockBlobURLRequestContext* url_request_context( | 702 MockBlobURLRequestContext* url_request_context( |
703 new MockBlobURLRequestContext(file_system_context_.get())); | 703 new MockBlobURLRequestContext(file_system_context_.get())); |
704 WriteHelper* helper = new WriteHelper(url_request_context, data); | 704 WriteHelper* helper = new WriteHelper(url_request_context, data); |
705 operation_runner()->Write(url_request_context, url, | 705 operation_runner()->Write(url_request_context, url, |
706 helper->scoped_text_blob()->GetBlobDataHandle(), 0, | 706 helper->scoped_text_blob()->GetBlobDataHandle(), 0, |
707 base::Bind(&WriteHelper::DidWrite, | 707 base::Bind(&WriteHelper::DidWrite, |
708 base::Owned(helper), callback)); | 708 base::Owned(helper), callback)); |
709 } | 709 } |
710 | 710 |
711 void CannedSyncableFileSystem::DoGetUsageAndQuota( | 711 void CannedSyncableFileSystem::DoGetUsageAndQuota( |
712 int64_t* usage, | 712 int64_t* usage, |
713 int64_t* quota, | 713 int64_t* quota, |
714 const storage::StatusCallback& callback) { | 714 const storage::StatusCallback& callback) { |
715 // crbug.com/349708 | 715 // crbug.com/349708 |
716 TRACE_EVENT0("io", "CannedSyncableFileSystem::DoGetUsageAndQuota"); | 716 TRACE_EVENT0("io", "CannedSyncableFileSystem::DoGetUsageAndQuota"); |
717 | 717 |
718 EXPECT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 718 EXPECT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
719 EXPECT_TRUE(is_filesystem_opened_); | 719 EXPECT_TRUE(is_filesystem_opened_); |
720 DCHECK(quota_manager_.get()); | 720 DCHECK(quota_manager_.get()); |
721 quota_manager_->GetUsageAndQuota( | 721 quota_manager_->GetUsageAndQuota( |
722 origin_, storage_type(), | 722 origin_, storage_type(), |
723 base::Bind(&DidGetUsageAndQuota, callback, usage, quota)); | 723 base::Bind(&DidGetUsageAndQuota, callback, usage, quota)); |
724 } | 724 } |
725 | 725 |
726 void CannedSyncableFileSystem::DidOpenFileSystem( | 726 void CannedSyncableFileSystem::DidOpenFileSystem( |
727 base::SingleThreadTaskRunner* original_task_runner, | 727 base::SingleThreadTaskRunner* original_task_runner, |
728 const base::Closure& quit_closure, | 728 const base::Closure& quit_closure, |
729 const GURL& root, | 729 const GURL& root, |
730 const std::string& name, | 730 const std::string& name, |
731 File::Error result) { | 731 File::Error result) { |
732 if (io_task_runner_->RunsTasksOnCurrentThread()) { | 732 if (io_task_runner_->RunsTasksInCurrentSequence()) { |
733 EXPECT_FALSE(is_filesystem_opened_); | 733 EXPECT_FALSE(is_filesystem_opened_); |
734 is_filesystem_opened_ = true; | 734 is_filesystem_opened_ = true; |
735 } | 735 } |
736 if (!original_task_runner->RunsTasksOnCurrentThread()) { | 736 if (!original_task_runner->RunsTasksInCurrentSequence()) { |
737 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 737 DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
738 original_task_runner->PostTask( | 738 original_task_runner->PostTask( |
739 FROM_HERE, base::BindOnce(&CannedSyncableFileSystem::DidOpenFileSystem, | 739 FROM_HERE, base::BindOnce(&CannedSyncableFileSystem::DidOpenFileSystem, |
740 base::Unretained(this), | 740 base::Unretained(this), |
741 base::RetainedRef(original_task_runner), | 741 base::RetainedRef(original_task_runner), |
742 quit_closure, root, name, result)); | 742 quit_closure, root, name, result)); |
743 return; | 743 return; |
744 } | 744 } |
745 result_ = result; | 745 result_ = result; |
746 root_url_ = root; | 746 root_url_ = root; |
747 quit_closure.Run(); | 747 quit_closure.Run(); |
748 } | 748 } |
749 | 749 |
750 void CannedSyncableFileSystem::DidInitializeFileSystemContext( | 750 void CannedSyncableFileSystem::DidInitializeFileSystemContext( |
751 const base::Closure& quit_closure, | 751 const base::Closure& quit_closure, |
752 SyncStatusCode status) { | 752 SyncStatusCode status) { |
753 sync_status_ = status; | 753 sync_status_ = status; |
754 quit_closure.Run(); | 754 quit_closure.Run(); |
755 } | 755 } |
756 | 756 |
757 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { | 757 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { |
758 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 758 ASSERT_TRUE(io_task_runner_->RunsTasksInCurrentSequence()); |
759 backend()->sync_context()->sync_status()->AddObserver(this); | 759 backend()->sync_context()->sync_status()->AddObserver(this); |
760 } | 760 } |
761 | 761 |
762 } // namespace sync_file_system | 762 } // namespace sync_file_system |
OLD | NEW |