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

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

Issue 1616943003: Teach navigation throttles how to cancel requests in WillProcessResponse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 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/navigation_resource_throttle.cc
diff --git a/content/browser/loader/navigation_resource_throttle.cc b/content/browser/loader/navigation_resource_throttle.cc
index 44fd0c131ff413fd0d90d0d4c07adae7dedc338b..63210620c9f3fb59a790033b72efd34d153183d6 100644
--- a/content/browser/loader/navigation_resource_throttle.cc
+++ b/content/browser/loader/navigation_resource_throttle.cc
@@ -4,9 +4,13 @@
#include "content/browser/loader/navigation_resource_throttle.h"
+#include "base/bind.h"
#include "base/callback.h"
+#include "base/location.h"
+#include "base/logging.h"
#include "content/browser/frame_host/navigation_handle_impl.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/resource_controller.h"
#include "content/public/browser/resource_request_info.h"
@@ -26,7 +30,7 @@ typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)>
void SendCheckResultToIOThread(UIChecksPerformedCallback callback,
NavigationThrottle::ThrottleCheckResult result) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- CHECK(result != NavigationThrottle::DEFER);
+ DCHECK_NE(result, NavigationThrottle::DEFER);
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(callback, result));
}
@@ -93,21 +97,28 @@ void CheckWillRedirectRequestOnUIThread(
}
void WillProcessResponseOnUIThread(
+ UIChecksPerformedCallback callback,
int render_process_id,
int render_frame_host_id,
scoped_refptr<net::HttpResponseHeaders> headers) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RenderFrameHostImpl* render_frame_host =
RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id);
- if (!render_frame_host)
+ if (!render_frame_host) {
+ SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED);
return;
+ }
NavigationHandleImpl* navigation_handle =
render_frame_host->navigation_handle();
- if (!navigation_handle)
+ if (!navigation_handle) {
+ SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED);
return;
+ }
- navigation_handle->ReadyToCommitNavigation(render_frame_host, headers);
+ navigation_handle->WillProcessResponse(
+ render_frame_host, headers,
+ base::Bind(&SendCheckResultToIOThread, callback));
}
} // namespace
@@ -204,10 +215,15 @@ void NavigationResourceThrottle::WillProcessResponse(bool* defer) {
request_->response_headers()->raw_headers());
}
+ UIChecksPerformedCallback callback =
+ base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed,
+ weak_ptr_factory_.GetWeakPtr());
+
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&WillProcessResponseOnUIThread, render_process_id,
+ base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id,
render_frame_id, response_headers));
+ *defer = true;
}
const char* NavigationResourceThrottle::GetNameForLogging() const {
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl_unittest.cc ('k') | content/public/browser/navigation_throttle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698