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

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

Issue 2476163003: Refactor ResourceHandler API. (Closed)
Patch Set: Minor cleanups, one real fix Created 4 years, 1 month 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 1288fe45136fb67142fa4ca4383a058c83eb14e9..9114570ff2652da150e380878e3d3af411c942aa 100644
--- a/content/browser/loader/mojo_async_resource_handler.cc
+++ b/content/browser/loader/mojo_async_resource_handler.cc
@@ -125,15 +125,15 @@ MojoAsyncResourceHandler::~MojoAsyncResourceHandler() {
rdh_->FinishedWithResourcesForRequest(request());
}
-bool MojoAsyncResourceHandler::OnRequestRedirected(
+void MojoAsyncResourceHandler::OnRequestRedirected(
const net::RedirectInfo& redirect_info,
ResourceResponse* response,
- bool* defer) {
+ bool* defer_or_cancel) {
// Unlike OnResponseStarted, OnRequestRedirected will NOT be preceded by
// OnWillRead.
DCHECK(!shared_writer_);
- *defer = true;
+ *defer_or_cancel = true;
request()->LogBlockedBy("MojoAsyncResourceHandler");
did_defer_on_redirect_ = true;
@@ -146,11 +146,10 @@ bool MojoAsyncResourceHandler::OnRequestRedirected(
// and hopefully those will eventually all be owned by the browser. It's
// possible this is still needed while renderer-owned ones exist.
url_loader_client_->OnReceiveRedirect(redirect_info, response->head);
- return true;
}
-bool MojoAsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
- bool* defer) {
+void MojoAsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
+ bool* defer_or_cancel) {
const ResourceRequestInfoImpl* info = GetRequestInfo();
if (rdh_->delegate()) {
@@ -164,13 +163,15 @@ bool MojoAsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
response->head.response_start = base::TimeTicks::Now();
sent_received_response_message_ = true;
url_loader_client_->OnReceiveResponse(response->head);
- return true;
}
-bool MojoAsyncResourceHandler::OnWillStart(const GURL& url, bool* defer) {
- return true;
+void MojoAsyncResourceHandler::OnWillStart(const GURL& url,
+ bool* defer_or_cancel) {
+ return;
}
+// TODO(mmenke): The implementation of this method and OnReadComplete is very
+// unwieldy. Allow OnWillRead to complete asynchronously and clean things up.
bool MojoAsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
int* buf_size,
int min_size) {
@@ -223,37 +224,46 @@ bool MojoAsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
return true;
}
-bool MojoAsyncResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
+void MojoAsyncResourceHandler::OnReadCompleted(int bytes_read,
+ bool* defer_or_cancel) {
DCHECK_GE(bytes_read, 0);
DCHECK(buffer_);
if (!bytes_read)
- return true;
+ return;
if (is_using_io_buffer_not_from_writer_) {
// Couldn't allocate a buffer on the data pipe in OnWillRead.
DCHECK_EQ(0u, buffer_bytes_read_);
buffer_bytes_read_ = bytes_read;
- if (!CopyReadDataToDataPipe(defer))
- return false;
- if (*defer) {
+ if (!CopyReadDataToDataPipe(defer_or_cancel)) {
+ controller()->Cancel();
+ *defer_or_cancel = true;
+ return;
+ }
+ if (*defer_or_cancel) {
request()->LogBlockedBy("MojoAsyncResourceHandler");
did_defer_on_writing_ = true;
}
- return true;
+ return;
}
- if (EndWrite(bytes_read) != MOJO_RESULT_OK)
- return false;
+ if (EndWrite(bytes_read) != MOJO_RESULT_OK) {
+ controller()->Cancel();
+ *defer_or_cancel = true;
+ return;
+ }
// Allocate a buffer for the next OnWillRead call here, because OnWillRead
// doesn't have |defer| parameter.
- if (!AllocateWriterIOBuffer(&buffer_, defer))
- return false;
- if (*defer) {
+ if (!AllocateWriterIOBuffer(&buffer_, defer_or_cancel)) {
+ controller()->Cancel();
+ *defer_or_cancel = true;
+ return;
+ }
+ if (*defer_or_cancel) {
request()->LogBlockedBy("MojoAsyncResourceHandler");
did_defer_on_writing_ = true;
}
- return true;
}
void MojoAsyncResourceHandler::OnDataDownloaded(int bytes_downloaded) {
« 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