Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(740)

Unified Diff: content/browser/loader/mojo_async_resource_handler.cc

Issue 2668603003: Make ResourceHandler::OnWillRead able to complete asynchronously. (Closed)
Patch Set: Response to comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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(
« no previous file with comments | « content/browser/loader/mojo_async_resource_handler.h ('k') | content/browser/loader/mojo_async_resource_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698