| Index: content/browser/loader/mojo_async_resource_handler.cc
|
| diff --git a/content/browser/loader/mojo_async_resource_handler.cc b/content/browser/loader/mojo_async_resource_handler.cc
|
| index 48b668609b260afeae549dac87a897cab4c4e37d..d8b4bc89a5a9dbc88899f84448491f2e7a1f1ce9 100644
|
| --- a/content/browser/loader/mojo_async_resource_handler.cc
|
| +++ b/content/browser/loader/mojo_async_resource_handler.cc
|
| @@ -28,7 +28,6 @@
|
| #include "content/public/common/resource_response.h"
|
| #include "mojo/public/c/system/data_pipe.h"
|
| #include "mojo/public/cpp/bindings/message.h"
|
| -#include "net/base/mime_sniffer.h"
|
| #include "net/base/net_errors.h"
|
| #include "net/url_request/redirect_info.h"
|
|
|
| @@ -37,11 +36,6 @@ namespace {
|
|
|
| int g_allocation_size = MojoAsyncResourceHandler::kDefaultAllocationSize;
|
|
|
| -// MimeTypeResourceHandler *implicitly* requires that the buffer size
|
| -// returned from OnWillRead should be larger than certain size.
|
| -// TODO(yhirano): Fix MimeTypeResourceHandler.
|
| -constexpr size_t kMinAllocationSize = 2 * net::kMaxBytesToSniff;
|
| -
|
| constexpr size_t kMaxChunkSize = 32 * 1024;
|
|
|
| void GetNumericArg(const std::string& name, int* result) {
|
| @@ -238,9 +232,7 @@ void MojoAsyncResourceHandler::OnWillRead(
|
| return;
|
| }
|
|
|
| - bool first_call = false;
|
| if (!shared_writer_) {
|
| - first_call = true;
|
| MojoCreateDataPipeOptions options;
|
| options.struct_size = sizeof(MojoCreateDataPipeOptions);
|
| options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
|
| @@ -275,20 +267,6 @@ void MojoAsyncResourceHandler::OnWillRead(
|
| return;
|
| }
|
|
|
| - // The first call to OnWillRead must return a buffer of at least
|
| - // kMinAllocationSize. If the Mojo buffer is too small, need to allocate an
|
| - // intermediary buffer.
|
| - if (first_call && static_cast<size_t>(buffer_->size()) < kMinAllocationSize) {
|
| - // The allocated buffer is too small, so need to create an intermediary one.
|
| - if (EndWrite(0) != MOJO_RESULT_OK) {
|
| - controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
|
| - return;
|
| - }
|
| - DCHECK(!is_using_io_buffer_not_from_writer_);
|
| - is_using_io_buffer_not_from_writer_ = true;
|
| - buffer_ = new net::IOBufferWithSize(kMinAllocationSize);
|
| - }
|
| -
|
| *buf = buffer_;
|
| *buf_size = buffer_->size();
|
| controller->Resume();
|
| @@ -322,25 +300,6 @@ void MojoAsyncResourceHandler::OnReadCompleted(
|
| response_body_consumer_handle_.reset();
|
| }
|
|
|
| - if (is_using_io_buffer_not_from_writer_) {
|
| - // Couldn't allocate a large enough buffer on the data pipe in OnWillRead.
|
| - DCHECK_EQ(0u, buffer_bytes_read_);
|
| - buffer_bytes_read_ = bytes_read;
|
| - bool defer = false;
|
| - if (!CopyReadDataToDataPipe(&defer)) {
|
| - controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
|
| - return;
|
| - }
|
| - if (defer) {
|
| - request()->LogBlockedBy("MojoAsyncResourceHandler");
|
| - did_defer_on_writing_ = true;
|
| - HoldController(std::move(controller));
|
| - return;
|
| - }
|
| - controller->Resume();
|
| - return;
|
| - }
|
| -
|
| if (EndWrite(bytes_read) != MOJO_RESULT_OK) {
|
| controller->Cancel();
|
| return;
|
| @@ -367,7 +326,6 @@ void MojoAsyncResourceHandler::FollowRedirect() {
|
| }
|
|
|
| DCHECK(!did_defer_on_will_read_);
|
| - DCHECK(!did_defer_on_writing_);
|
| did_defer_on_redirect_ = false;
|
| request()->LogUnblocked();
|
| Resume();
|
| @@ -457,30 +415,6 @@ void MojoAsyncResourceHandler::OnResponseCompleted(
|
| controller->Resume();
|
| }
|
|
|
| -bool MojoAsyncResourceHandler::CopyReadDataToDataPipe(bool* defer) {
|
| - while (buffer_bytes_read_ > 0) {
|
| - scoped_refptr<net::IOBufferWithSize> dest;
|
| - if (!AllocateWriterIOBuffer(&dest, defer))
|
| - return false;
|
| - if (*defer)
|
| - return true;
|
| -
|
| - size_t copied_size =
|
| - std::min(buffer_bytes_read_, static_cast<size_t>(dest->size()));
|
| - memcpy(dest->data(), buffer_->data() + buffer_offset_, copied_size);
|
| - buffer_offset_ += copied_size;
|
| - buffer_bytes_read_ -= copied_size;
|
| - if (EndWrite(copied_size) != MOJO_RESULT_OK)
|
| - return false;
|
| - }
|
| -
|
| - // All bytes are copied.
|
| - buffer_ = nullptr;
|
| - buffer_offset_ = 0;
|
| - is_using_io_buffer_not_from_writer_ = false;
|
| - return true;
|
| -}
|
| -
|
| bool MojoAsyncResourceHandler::AllocateWriterIOBuffer(
|
| scoped_refptr<net::IOBufferWithSize>* buf,
|
| bool* defer) {
|
| @@ -510,44 +444,21 @@ bool MojoAsyncResourceHandler::CheckForSufficientResource() {
|
| }
|
|
|
| void MojoAsyncResourceHandler::OnWritable(MojoResult result) {
|
| - if (did_defer_on_will_read_) {
|
| - DCHECK(has_controller());
|
| - DCHECK(!did_defer_on_writing_);
|
| - DCHECK(!did_defer_on_redirect_);
|
| -
|
| - did_defer_on_will_read_ = false;
|
| -
|
| - scoped_refptr<net::IOBuffer>* parent_buffer = parent_buffer_;
|
| - parent_buffer_ = nullptr;
|
| - int* parent_buffer_size = parent_buffer_size_;
|
| - parent_buffer_size_ = nullptr;
|
| -
|
| - request()->LogUnblocked();
|
| - OnWillRead(parent_buffer, parent_buffer_size, ReleaseController());
|
| + if (!did_defer_on_will_read_)
|
| return;
|
| - }
|
|
|
| - if (!did_defer_on_writing_)
|
| - return;
|
| DCHECK(has_controller());
|
| DCHECK(!did_defer_on_redirect_);
|
| - did_defer_on_writing_ = false;
|
| -
|
| - DCHECK(is_using_io_buffer_not_from_writer_);
|
| - // |buffer_| is set to a net::IOBufferWithSize. Write the buffer contents
|
| - // to the data pipe.
|
| - DCHECK_GT(buffer_bytes_read_, 0u);
|
| - if (!CopyReadDataToDataPipe(&did_defer_on_writing_)) {
|
| - CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
|
| - return;
|
| - }
|
|
|
| - if (did_defer_on_writing_) {
|
| - // Continue waiting.
|
| - return;
|
| - }
|
| + did_defer_on_will_read_ = false;
|
| +
|
| + scoped_refptr<net::IOBuffer>* parent_buffer = parent_buffer_;
|
| + parent_buffer_ = nullptr;
|
| + int* parent_buffer_size = parent_buffer_size_;
|
| + parent_buffer_size_ = nullptr;
|
| +
|
| request()->LogUnblocked();
|
| - Resume();
|
| + OnWillRead(parent_buffer, parent_buffer_size, ReleaseController());
|
| }
|
|
|
| void MojoAsyncResourceHandler::Cancel() {
|
|
|