| Index: content/browser/loader/async_resource_handler.cc
|
| diff --git a/content/browser/loader/async_resource_handler.cc b/content/browser/loader/async_resource_handler.cc
|
| index 3b3cb0c5b926d0db247ca97f2a391ecd9ec2dc0a..445616d4a3613bb2c7e67c2e2a6712b2bcb1d528 100644
|
| --- a/content/browser/loader/async_resource_handler.cc
|
| +++ b/content/browser/loader/async_resource_handler.cc
|
| @@ -191,9 +191,75 @@ class DependentIOBuffer : public net::WrappedIOBuffer {
|
| scoped_refptr<ResourceBuffer> backing_;
|
| };
|
|
|
| -AsyncResourceHandler::AsyncResourceHandler(
|
| - net::URLRequest* request,
|
| - ResourceDispatcherHostImpl* rdh)
|
| +class AsyncResourceHandler::MojoHelper final {
|
| + public:
|
| + explicit MojoHelper(AsyncResourceHandler* owner) : owner_(owner) {}
|
| +
|
| + void OnResponseStarted() {
|
| + MojoCreateDataPipeOptions options;
|
| + options.struct_size = sizeof(MojoCreateDataPipeOptions);
|
| + options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
|
| + options.element_num_bytes = 1;
|
| + options.capacity_num_bytes = kMaxAllocationSize;
|
| + mojo::DataPipe data_pipe(options);
|
| +
|
| + writer_ = std::move(data_pipe.producer_handle);
|
| + owner_->GetRequestInfo()->InstallBodyReader(
|
| + std::move(data_pipe.consumer_handle));
|
| + }
|
| +
|
| + bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
|
| + int* buf_size,
|
| + int min_size) {
|
| + void* buffer = nullptr;
|
| + uint32_t available = 0;
|
| + MojoResult result = mojo::BeginWriteDataRaw(
|
| + writer_.get(), &buffer, &available, MOJO_WRITE_DATA_FLAG_NONE);
|
| + // Note that we cannot handle SHOULD_WAIT here. It should be handled in
|
| + // OnReadCompleted.
|
| + if (result == MOJO_RESULT_OK) {
|
| + *buf = new net::WrappedIOBuffer(static_cast<const char*>(buffer));
|
| + *buf_size = available;
|
| + return true;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + bool OnReadCompleted(int bytes_read, bool* defer) {
|
| + MojoResult result = mojo::EndWriteDataRaw(writer_.get(), bytes_read);
|
| + if (result != MOJO_RESULT_OK)
|
| + return false;
|
| + void* buffer = nullptr;
|
| + uint32_t available = 0;
|
| + // To see if we can continue writing.
|
| + result = mojo::BeginWriteDataRaw(writer_.get(), &buffer, &available,
|
| + MOJO_WRITE_DATA_FLAG_NONE);
|
| + if (result == MOJO_RESULT_SHOULD_WAIT ||
|
| + (result == MOJO_RESULT_OK && available == 0)) {
|
| + *defer = owner_->did_defer_ = true;
|
| + owner_->OnDefer();
|
| + handle_watcher_.Start(
|
| + writer_.get(), MOJO_HANDLE_SIGNAL_WRITABLE, MOJO_DEADLINE_INDEFINITE,
|
| + base::Bind(&MojoHelper::OnWritable, base::Unretained(this)));
|
| + }
|
| + if (result == MOJO_RESULT_OK)
|
| + mojo::EndWriteDataRaw(writer_.get(), 0);
|
| + return true;
|
| + }
|
| +
|
| + private:
|
| + void OnWritable(MojoResult result) { owner_->ResumeIfDeferred(); }
|
| +
|
| + mojo::ScopedDataPipeProducerHandle writer_;
|
| + mojo::common::HandleWatcher handle_watcher_;
|
| + AsyncResourceHandler* owner_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(MojoHelper);
|
| +};
|
| +
|
| +AsyncResourceHandler::AsyncResourceHandler(net::URLRequest* request,
|
| + ResourceDispatcherHostImpl* rdh,
|
| + bool using_mojo_data_handle)
|
| : ResourceHandler(request),
|
| ResourceMessageDelegate(request),
|
| rdh_(rdh),
|
| @@ -206,7 +272,8 @@ AsyncResourceHandler::AsyncResourceHandler(
|
| inlining_helper_(new InliningHelper),
|
| last_upload_position_(0),
|
| waiting_for_upload_progress_ack_(false),
|
| - reported_transfer_size_(0) {
|
| + reported_transfer_size_(0),
|
| + mojo_helper_(using_mojo_data_handle ? new MojoHelper(this) : nullptr) {
|
| InitializeResourceBufferConstants();
|
| }
|
|
|
| @@ -355,6 +422,9 @@ bool AsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
|
|
|
| response->head.request_start = request()->creation_time();
|
| response->head.response_start = TimeTicks::Now();
|
| + if (mojo_helper_)
|
| + mojo_helper_->OnResponseStarted();
|
| +
|
| info->filter()->Send(new ResourceMsg_ReceivedResponse(GetRequestID(),
|
| response->head));
|
| sent_received_response_msg_ = true;
|
| @@ -396,6 +466,9 @@ bool AsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
|
| if (!CheckForSufficientResource())
|
| return false;
|
|
|
| + if (mojo_helper_)
|
| + return mojo_helper_->OnWillRead(buf, buf_size, min_size);
|
| +
|
| // Return early if InliningHelper allocates the buffer, so that we should
|
| // inline the data into the IPC message without allocating SharedMemory.
|
| if (inlining_helper_->PrepareInlineBufferIfApplicable(buf, buf_size))
|
| @@ -420,6 +493,9 @@ bool AsyncResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
|
| if (!bytes_read)
|
| return true;
|
|
|
| + if (mojo_helper_)
|
| + return mojo_helper_->OnReadCompleted(bytes_read, defer);
|
| +
|
| ResourceMessageFilter* filter = GetFilter();
|
| if (!filter)
|
| return false;
|
|
|