| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | |
| 8 #include <map> | 7 #include <map> |
| 9 #include <queue> | 8 #include <queue> |
| 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 19 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 base::Bind(&ExpectOk)); | 214 base::Bind(&ExpectOk)); |
| 215 backend = file_system_context_->GetFileSystemBackend(dest_type_); | 215 backend = file_system_context_->GetFileSystemBackend(dest_type_); |
| 216 if (dest_type_ == storage::kFileSystemTypeTest) { | 216 if (dest_type_ == storage::kFileSystemTypeTest) { |
| 217 TestFileSystemBackend* test_backend = | 217 TestFileSystemBackend* test_backend = |
| 218 static_cast<TestFileSystemBackend*>(backend); | 218 static_cast<TestFileSystemBackend*>(backend); |
| 219 scoped_ptr<storage::CopyOrMoveFileValidatorFactory> factory( | 219 scoped_ptr<storage::CopyOrMoveFileValidatorFactory> factory( |
| 220 new TestValidatorFactory); | 220 new TestValidatorFactory); |
| 221 test_backend->set_require_copy_or_move_validator( | 221 test_backend->set_require_copy_or_move_validator( |
| 222 require_copy_or_move_validator); | 222 require_copy_or_move_validator); |
| 223 if (init_copy_or_move_validator) | 223 if (init_copy_or_move_validator) |
| 224 test_backend->InitializeCopyOrMoveFileValidatorFactory(factory.Pass()); | 224 test_backend->InitializeCopyOrMoveFileValidatorFactory( |
| 225 std::move(factory)); |
| 225 } | 226 } |
| 226 backend->ResolveURL( | 227 backend->ResolveURL( |
| 227 FileSystemURL::CreateForTest(origin_, dest_type_, base::FilePath()), | 228 FileSystemURL::CreateForTest(origin_, dest_type_, base::FilePath()), |
| 228 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 229 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 229 base::Bind(&ExpectOk)); | 230 base::Bind(&ExpectOk)); |
| 230 base::RunLoop().RunUntilIdle(); | 231 base::RunLoop().RunUntilIdle(); |
| 231 | 232 |
| 232 // Grant relatively big quota initially. | 233 // Grant relatively big quota initially. |
| 233 quota_manager_->SetQuota( | 234 quota_manager_->SetQuota( |
| 234 origin_, | 235 origin_, |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 | 738 |
| 738 scoped_ptr<storage::FileStreamReader> reader( | 739 scoped_ptr<storage::FileStreamReader> reader( |
| 739 storage::FileStreamReader::CreateForLocalFile( | 740 storage::FileStreamReader::CreateForLocalFile( |
| 740 task_runner.get(), source_path, 0, base::Time())); | 741 task_runner.get(), source_path, 0, base::Time())); |
| 741 | 742 |
| 742 scoped_ptr<FileStreamWriter> writer(FileStreamWriter::CreateForLocalFile( | 743 scoped_ptr<FileStreamWriter> writer(FileStreamWriter::CreateForLocalFile( |
| 743 task_runner.get(), dest_path, 0, FileStreamWriter::CREATE_NEW_FILE)); | 744 task_runner.get(), dest_path, 0, FileStreamWriter::CREATE_NEW_FILE)); |
| 744 | 745 |
| 745 std::vector<int64_t> progress; | 746 std::vector<int64_t> progress; |
| 746 CopyOrMoveOperationDelegate::StreamCopyHelper helper( | 747 CopyOrMoveOperationDelegate::StreamCopyHelper helper( |
| 747 reader.Pass(), writer.Pass(), | 748 std::move(reader), std::move(writer), |
| 748 storage::FlushPolicy::NO_FLUSH_ON_COMPLETION, | 749 storage::FlushPolicy::NO_FLUSH_ON_COMPLETION, |
| 749 10, // buffer size | 750 10, // buffer size |
| 750 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)), | 751 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)), |
| 751 base::TimeDelta()); // For testing, we need all the progress. | 752 base::TimeDelta()); // For testing, we need all the progress. |
| 752 | 753 |
| 753 base::File::Error error = base::File::FILE_ERROR_FAILED; | 754 base::File::Error error = base::File::FILE_ERROR_FAILED; |
| 754 base::RunLoop run_loop; | 755 base::RunLoop run_loop; |
| 755 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); | 756 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); |
| 756 run_loop.Run(); | 757 run_loop.Run(); |
| 757 | 758 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 | 794 |
| 794 scoped_ptr<storage::FileStreamReader> reader( | 795 scoped_ptr<storage::FileStreamReader> reader( |
| 795 storage::FileStreamReader::CreateForLocalFile( | 796 storage::FileStreamReader::CreateForLocalFile( |
| 796 task_runner.get(), source_path, 0, base::Time())); | 797 task_runner.get(), source_path, 0, base::Time())); |
| 797 | 798 |
| 798 scoped_ptr<FileStreamWriter> writer(FileStreamWriter::CreateForLocalFile( | 799 scoped_ptr<FileStreamWriter> writer(FileStreamWriter::CreateForLocalFile( |
| 799 task_runner.get(), dest_path, 0, FileStreamWriter::CREATE_NEW_FILE)); | 800 task_runner.get(), dest_path, 0, FileStreamWriter::CREATE_NEW_FILE)); |
| 800 | 801 |
| 801 std::vector<int64_t> progress; | 802 std::vector<int64_t> progress; |
| 802 CopyOrMoveOperationDelegate::StreamCopyHelper helper( | 803 CopyOrMoveOperationDelegate::StreamCopyHelper helper( |
| 803 reader.Pass(), writer.Pass(), | 804 std::move(reader), std::move(writer), |
| 804 storage::FlushPolicy::NO_FLUSH_ON_COMPLETION, | 805 storage::FlushPolicy::NO_FLUSH_ON_COMPLETION, |
| 805 10, // buffer size | 806 10, // buffer size |
| 806 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)), | 807 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)), |
| 807 base::TimeDelta()); // For testing, we need all the progress. | 808 base::TimeDelta()); // For testing, we need all the progress. |
| 808 | 809 |
| 809 base::File::Error error = base::File::FILE_ERROR_FAILED; | 810 base::File::Error error = base::File::FILE_ERROR_FAILED; |
| 810 base::RunLoop run_loop; | 811 base::RunLoop run_loop; |
| 811 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); | 812 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); |
| 812 run_loop.Run(); | 813 run_loop.Run(); |
| 813 | 814 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 844 | 845 |
| 845 scoped_ptr<storage::FileStreamReader> reader( | 846 scoped_ptr<storage::FileStreamReader> reader( |
| 846 storage::FileStreamReader::CreateForLocalFile( | 847 storage::FileStreamReader::CreateForLocalFile( |
| 847 task_runner.get(), source_path, 0, base::Time())); | 848 task_runner.get(), source_path, 0, base::Time())); |
| 848 | 849 |
| 849 scoped_ptr<FileStreamWriter> writer(FileStreamWriter::CreateForLocalFile( | 850 scoped_ptr<FileStreamWriter> writer(FileStreamWriter::CreateForLocalFile( |
| 850 task_runner.get(), dest_path, 0, FileStreamWriter::CREATE_NEW_FILE)); | 851 task_runner.get(), dest_path, 0, FileStreamWriter::CREATE_NEW_FILE)); |
| 851 | 852 |
| 852 std::vector<int64_t> progress; | 853 std::vector<int64_t> progress; |
| 853 CopyOrMoveOperationDelegate::StreamCopyHelper helper( | 854 CopyOrMoveOperationDelegate::StreamCopyHelper helper( |
| 854 reader.Pass(), writer.Pass(), | 855 std::move(reader), std::move(writer), |
| 855 storage::FlushPolicy::NO_FLUSH_ON_COMPLETION, | 856 storage::FlushPolicy::NO_FLUSH_ON_COMPLETION, |
| 856 10, // buffer size | 857 10, // buffer size |
| 857 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)), | 858 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)), |
| 858 base::TimeDelta()); // For testing, we need all the progress. | 859 base::TimeDelta()); // For testing, we need all the progress. |
| 859 | 860 |
| 860 // Call Cancel() later. | 861 // Call Cancel() later. |
| 861 base::ThreadTaskRunnerHandle::Get()->PostTask( | 862 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 862 FROM_HERE, | 863 FROM_HERE, |
| 863 base::Bind(&CopyOrMoveOperationDelegate::StreamCopyHelper::Cancel, | 864 base::Bind(&CopyOrMoveOperationDelegate::StreamCopyHelper::Cancel, |
| 864 base::Unretained(&helper))); | 865 base::Unretained(&helper))); |
| 865 | 866 |
| 866 base::File::Error error = base::File::FILE_ERROR_FAILED; | 867 base::File::Error error = base::File::FILE_ERROR_FAILED; |
| 867 base::RunLoop run_loop; | 868 base::RunLoop run_loop; |
| 868 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); | 869 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); |
| 869 run_loop.Run(); | 870 run_loop.Run(); |
| 870 | 871 |
| 871 EXPECT_EQ(base::File::FILE_ERROR_ABORT, error); | 872 EXPECT_EQ(base::File::FILE_ERROR_ABORT, error); |
| 872 } | 873 } |
| 873 | 874 |
| 874 } // namespace content | 875 } // namespace content |
| OLD | NEW |