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 af1f98a38d42e81db9364a85b62c98f7b51ffb4a..8f14d599510dd16a63e7ae5a2f2b187dcd21c217 100644 |
--- a/content/browser/loader/mojo_async_resource_handler.cc |
+++ b/content/browser/loader/mojo_async_resource_handler.cc |
@@ -229,11 +229,14 @@ void MojoAsyncResourceHandler::OnWillStart( |
controller->Resume(); |
} |
-bool MojoAsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
- int* buf_size) { |
- // TODO(mmenke): Cancel with net::ERR_INSUFFICIENT_RESOURCES instead. |
- if (!CheckForSufficientResource()) |
- return false; |
+void MojoAsyncResourceHandler::OnWillRead( |
+ scoped_refptr<net::IOBuffer>* buf, |
+ int* buf_size, |
+ std::unique_ptr<ResourceController> controller) { |
+ if (!CheckForSufficientResource()) { |
+ controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); |
+ return; |
+ } |
if (!shared_writer_) { |
MojoCreateDataPipeOptions options; |
@@ -254,18 +257,23 @@ bool MojoAsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
bool defer = false; |
scoped_refptr<net::IOBufferWithSize> buffer; |
- if (!AllocateWriterIOBuffer(&buffer, &defer)) |
- return false; |
+ if (!AllocateWriterIOBuffer(&buffer, &defer)) { |
+ controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); |
+ return; |
+ } |
if (!defer) { |
if (static_cast<size_t>(buffer->size()) >= kMinAllocationSize) { |
*buf = buffer_ = buffer; |
*buf_size = buffer_->size(); |
- return true; |
+ controller->Resume(); |
+ return; |
} |
// The allocated buffer is too small. |
- if (EndWrite(0) != MOJO_RESULT_OK) |
- return false; |
+ 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; |
@@ -275,7 +283,7 @@ bool MojoAsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
DCHECK_EQ(0u, buffer_offset_); |
*buf = buffer_; |
*buf_size = buffer_->size(); |
- return true; |
+ controller->Resume(); |
} |
void MojoAsyncResourceHandler::OnReadCompleted( |