 Chromium Code Reviews
 Chromium Code Reviews Issue 1616943003:
  Teach navigation throttles how to cancel requests in WillProcessResponse.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1616943003:
  Teach navigation throttles how to cancel requests in WillProcessResponse.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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..62f0eae8c35a1c0a15f2c202d1e66783d3641366 100644 | 
| --- a/content/browser/loader/navigation_resource_throttle.cc | 
| +++ b/content/browser/loader/navigation_resource_throttle.cc | 
| @@ -5,8 +5,10 @@ | 
| #include "content/browser/loader/navigation_resource_throttle.h" | 
| #include "base/callback.h" | 
| +#include "base/logging.h" | 
| 
mmenke
2016/01/27 16:34:08
While you're here, should also include base/bind.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 +28,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 +95,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 +213,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 { |