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

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

Issue 2526983002: Refactor ResourceHandler API. (Closed)
Patch Set: Fix stuff 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/navigation_resource_handler.cc
diff --git a/content/browser/loader/navigation_resource_handler.cc b/content/browser/loader/navigation_resource_handler.cc
index dc73b854bea71788845ddf9f8114a42eb1427d92..d438fb8cb31b96a3e6f472abd87a1522eadbb93f 100644
--- a/content/browser/loader/navigation_resource_handler.cc
+++ b/content/browser/loader/navigation_resource_handler.cc
@@ -6,6 +6,7 @@
#include <memory>
+#include "base/bind.h"
#include "base/logging.h"
#include "content/browser/loader/navigation_url_loader_impl_core.h"
#include "content/browser/loader/netlog_observer.h"
@@ -53,44 +54,43 @@ NavigationResourceHandler::~NavigationResourceHandler() {
}
void NavigationResourceHandler::Cancel() {
- controller()->Cancel();
+ // TODO(mmenke): This is ugle and error prone. Can we do better?
+ ResourceHandler::Cancel();
core_ = nullptr;
}
void NavigationResourceHandler::FollowRedirect() {
- controller()->Resume();
+ Resume();
}
void NavigationResourceHandler::ProceedWithResponse() {
// Detach from the loader; at this point, the request is now owned by the
// StreamHandle sent in OnResponseStarted.
DetachFromCore();
- controller()->Resume();
+ Resume();
}
-void NavigationResourceHandler::SetController(ResourceController* controller) {
- writer_.set_controller(controller);
- ResourceHandler::SetController(controller);
-}
-
-bool NavigationResourceHandler::OnRequestRedirected(
+void NavigationResourceHandler::OnRequestRedirected(
const net::RedirectInfo& redirect_info,
ResourceResponse* response,
- bool* defer) {
+ std::unique_ptr<ResourceController> controller) {
DCHECK(core_);
+ DCHECK(!has_controller());
// TODO(davidben): Perform a CSP check here, and anything else that would have
// been done renderer-side.
NetLogObserver::PopulateResponseInfo(request(), response);
response->head.encoded_data_length = request()->GetTotalReceivedBytes();
core_->NotifyRequestRedirected(redirect_info, response);
- *defer = true;
- return true;
+
+ set_controller(std::move(controller));
}
-bool NavigationResourceHandler::OnResponseStarted(ResourceResponse* response,
- bool* defer) {
+void NavigationResourceHandler::OnResponseStarted(
+ ResourceResponse* response,
+ std::unique_ptr<ResourceController> controller) {
DCHECK(core_);
+ DCHECK(!has_controller());
ResourceRequestInfoImpl* info = GetRequestInfo();
@@ -101,13 +101,17 @@ bool NavigationResourceHandler::OnResponseStarted(ResourceResponse* response,
// TODO(davidben): Move the dispatch out of MimeTypeResourceHandler. Perhaps
// all the way to the UI thread. Downloads, user certificates, etc., should be
// dispatched at the navigation layer.
- if (info->IsDownload())
- return true;
+ if (info->IsDownload()) {
+ controller->Resume();
+ return;
+ }
StreamContext* stream_context =
GetStreamContextForResourceContext(info->GetContext());
- writer_.InitializeStream(stream_context->registry(),
- request()->url().GetOrigin());
+ writer_.InitializeStream(
+ stream_context->registry(), request()->url().GetOrigin(),
+ base::Bind(&NavigationResourceHandler::OutOfBandCancel,
+ base::Unretained(this)));
NetLogObserver::PopulateResponseInfo(request(), response);
@@ -136,33 +140,44 @@ bool NavigationResourceHandler::OnResponseStarted(ResourceResponse* response,
// Make sure that the requests go through the throttle checks. Currently this
// does not work as the InterceptingResourceHandler is above us and hence it
// does not expect the old handler to defer the request.
- if (!info->is_stream())
- *defer = true;
- return true;
+ if (!info->is_stream()) {
+ set_controller(std::move(controller));
+ } else {
+ controller->Resume();
+ }
}
-bool NavigationResourceHandler::OnWillStart(const GURL& url, bool* defer) {
- return true;
+void NavigationResourceHandler::OnWillStart(
+ const GURL& url,
+ std::unique_ptr<ResourceController> controller) {
+ DCHECK(!has_controller());
+ controller->Resume();
}
bool NavigationResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
int* buf_size,
int min_size) {
+ DCHECK(!has_controller());
writer_.OnWillRead(buf, buf_size, min_size);
return true;
}
-bool NavigationResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
- writer_.OnReadCompleted(bytes_read, defer);
- return true;
+void NavigationResourceHandler::OnReadCompleted(
+ int bytes_read,
+ std::unique_ptr<ResourceController> controller) {
+ DCHECK(!has_controller());
+ writer_.OnReadCompleted(bytes_read,
+ base::Bind(&ResourceController::Resume,
+ base::Passed(std::move(controller))));
}
void NavigationResourceHandler::OnResponseCompleted(
const net::URLRequestStatus& status,
- bool* defer) {
+ std::unique_ptr<ResourceController> controller) {
// If the request has already committed, close the stream and leave it as-is.
if (writer_.stream()) {
writer_.Finalize(status.error());
+ controller->Resume();
return;
}
@@ -172,6 +187,7 @@ void NavigationResourceHandler::OnResponseCompleted(
status.error());
DetachFromCore();
}
+ controller->Resume();
}
void NavigationResourceHandler::OnDataDownloaded(int bytes_downloaded) {

Powered by Google App Engine
This is Rietveld 408576698