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

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

Issue 2668603003: Make ResourceHandler::OnWillRead able to complete asynchronously. (Closed)
Patch Set: One bot doesn't like 256 day timers. :( Created 3 years, 11 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/async_resource_handler.cc
diff --git a/content/browser/loader/async_resource_handler.cc b/content/browser/loader/async_resource_handler.cc
index 8168f1083a21946220a6fe746383aa9269146f91..facde3fb24f50dc9ee4cdfba78296eaa85b0dc12 100644
--- a/content/browser/loader/async_resource_handler.cc
+++ b/content/browser/loader/async_resource_handler.cc
@@ -367,21 +367,28 @@ void AsyncResourceHandler::OnWillStart(
controller->Resume();
}
-bool AsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
- int* buf_size) {
+void AsyncResourceHandler::OnWillRead(
+ scoped_refptr<net::IOBuffer>* buf,
+ int* buf_size,
+ std::unique_ptr<ResourceController> controller) {
DCHECK(!has_controller());
- // TODO(mmenke): Should fail with ERR_INSUFFICIENT_RESOURCES here.
- if (!CheckForSufficientResource())
- return false;
+ if (!CheckForSufficientResource()) {
+ controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
Charlie Harrison 2017/02/16 21:25:04 w00t!
+ return;
+ }
// 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))
- return true;
+ if (inlining_helper_->PrepareInlineBufferIfApplicable(buf, buf_size)) {
+ controller->Resume();
+ return;
+ }
- if (!EnsureResourceBufferIsInitialized())
- return false;
+ if (!EnsureResourceBufferIsInitialized()) {
+ controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
+ return;
+ }
DCHECK(buffer_->CanAllocate());
char* memory = buffer_->Allocate(&allocation_size_);
@@ -390,7 +397,7 @@ bool AsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
*buf = new DependentIOBuffer(buffer_.get(), memory);
*buf_size = allocation_size_;
- return true;
+ controller->Resume();
}
void AsyncResourceHandler::OnReadCompleted(

Powered by Google App Engine
This is Rietveld 408576698