| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <limits> | 6 #include <limits> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.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/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
| 21 #include "net/base/request_priority.h" | 21 #include "net/base/request_priority.h" |
| 22 #include "net/http/http_response_headers.h" | 22 #include "net/http/http_response_headers.h" |
| 23 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 23 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
| 24 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
| 25 #include "net/url_request/url_request_job.h" | 26 #include "net/url_request/url_request_job.h" |
| 26 #include "net/url_request/url_request_job_factory.h" | 27 #include "net/url_request/url_request_job_factory.h" |
| 27 #include "net/url_request/url_request_status.h" | 28 #include "net/url_request/url_request_status.h" |
| 28 #include "storage/browser/fileapi/file_system_context.h" | 29 #include "storage/browser/fileapi/file_system_context.h" |
| 29 #include "storage/browser/fileapi/file_system_quota_util.h" | 30 #include "storage/browser/fileapi/file_system_quota_util.h" |
| 30 #include "storage/browser/fileapi/file_writer_delegate.h" | 31 #include "storage/browser/fileapi/file_writer_delegate.h" |
| 31 #include "storage/browser/fileapi/sandbox_file_stream_writer.h" | 32 #include "storage/browser/fileapi/sandbox_file_stream_writer.h" |
| 32 #include "storage/browser/test/async_file_test_helper.h" | 33 #include "storage/browser/test/async_file_test_helper.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 142 } |
| 142 | 143 |
| 143 // Creates and sets up a FileWriterDelegate for writing the given |blob_url|, | 144 // Creates and sets up a FileWriterDelegate for writing the given |blob_url|, |
| 144 // and creates a new FileWriterDelegate for the file. | 145 // and creates a new FileWriterDelegate for the file. |
| 145 void PrepareForWrite(const char* test_file_path, | 146 void PrepareForWrite(const char* test_file_path, |
| 146 const GURL& blob_url, | 147 const GURL& blob_url, |
| 147 int64_t offset, | 148 int64_t offset, |
| 148 int64_t allowed_growth) { | 149 int64_t allowed_growth) { |
| 149 file_writer_delegate_.reset( | 150 file_writer_delegate_.reset( |
| 150 CreateWriterDelegate(test_file_path, offset, allowed_growth)); | 151 CreateWriterDelegate(test_file_path, offset, allowed_growth)); |
| 151 request_ = empty_context_.CreateRequest( | 152 request_ = empty_context_.CreateRequest(blob_url, net::DEFAULT_PRIORITY, |
| 152 blob_url, net::DEFAULT_PRIORITY, file_writer_delegate_.get()); | 153 file_writer_delegate_.get(), |
| 154 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 153 } | 155 } |
| 154 | 156 |
| 155 // This should be alive until the very end of this instance. | 157 // This should be alive until the very end of this instance. |
| 156 base::MessageLoopForIO loop_; | 158 base::MessageLoopForIO loop_; |
| 157 | 159 |
| 158 scoped_refptr<storage::FileSystemContext> file_system_context_; | 160 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 159 | 161 |
| 160 net::URLRequestContext empty_context_; | 162 net::URLRequestContext empty_context_; |
| 161 std::unique_ptr<FileWriterDelegate> file_writer_delegate_; | 163 std::unique_ptr<FileWriterDelegate> file_writer_delegate_; |
| 162 std::unique_ptr<net::URLRequest> request_; | 164 std::unique_ptr<net::URLRequest> request_; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 374 |
| 373 const GURL kBlobURL("blob:nolimitconcurrent"); | 375 const GURL kBlobURL("blob:nolimitconcurrent"); |
| 374 const GURL kBlobURL2("blob:nolimitconcurrent2"); | 376 const GURL kBlobURL2("blob:nolimitconcurrent2"); |
| 375 content_ = kData; | 377 content_ = kData; |
| 376 | 378 |
| 377 PrepareForWrite("test", kBlobURL, 0, std::numeric_limits<int64_t>::max()); | 379 PrepareForWrite("test", kBlobURL, 0, std::numeric_limits<int64_t>::max()); |
| 378 | 380 |
| 379 // Credate another FileWriterDelegate for concurrent write. | 381 // Credate another FileWriterDelegate for concurrent write. |
| 380 file_writer_delegate2.reset( | 382 file_writer_delegate2.reset( |
| 381 CreateWriterDelegate("test2", 0, std::numeric_limits<int64_t>::max())); | 383 CreateWriterDelegate("test2", 0, std::numeric_limits<int64_t>::max())); |
| 382 request2 = empty_context_.CreateRequest( | 384 request2 = empty_context_.CreateRequest(kBlobURL2, net::DEFAULT_PRIORITY, |
| 383 kBlobURL2, net::DEFAULT_PRIORITY, file_writer_delegate2.get()); | 385 file_writer_delegate2.get(), |
| 386 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 384 | 387 |
| 385 Result result, result2; | 388 Result result, result2; |
| 386 ASSERT_EQ(0, usage()); | 389 ASSERT_EQ(0, usage()); |
| 387 file_writer_delegate_->Start(std::move(request_), GetWriteCallback(&result)); | 390 file_writer_delegate_->Start(std::move(request_), GetWriteCallback(&result)); |
| 388 file_writer_delegate2->Start(std::move(request2), GetWriteCallback(&result2)); | 391 file_writer_delegate2->Start(std::move(request2), GetWriteCallback(&result2)); |
| 389 base::RunLoop().Run(); | 392 base::RunLoop().Run(); |
| 390 if (result.write_status() == FileWriterDelegate::SUCCESS_IO_PENDING || | 393 if (result.write_status() == FileWriterDelegate::SUCCESS_IO_PENDING || |
| 391 result2.write_status() == FileWriterDelegate::SUCCESS_IO_PENDING) | 394 result2.write_status() == FileWriterDelegate::SUCCESS_IO_PENDING) |
| 392 base::RunLoop().Run(); | 395 base::RunLoop().Run(); |
| 393 | 396 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 file_writer_delegate_.reset(); | 506 file_writer_delegate_.reset(); |
| 504 | 507 |
| 505 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); | 508 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); |
| 506 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); | 509 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); |
| 507 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); | 510 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); |
| 508 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status()); | 511 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status()); |
| 509 } | 512 } |
| 510 } | 513 } |
| 511 | 514 |
| 512 } // namespace content | 515 } // namespace content |
| OLD | NEW |