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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 2466843002: Cancel the request when URLLoader is gone (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
6 6
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" 7 #include "content/browser/loader/resource_dispatcher_host_impl.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 1798
1799 // Note that we don't remove the security bits here. This will be done 1799 // Note that we don't remove the security bits here. This will be done
1800 // when all file refs are deleted (see RegisterDownloadedTempFile). 1800 // when all file refs are deleted (see RegisterDownloadedTempFile).
1801 } 1801 }
1802 1802
1803 bool ResourceDispatcherHostImpl::Send(IPC::Message* message) { 1803 bool ResourceDispatcherHostImpl::Send(IPC::Message* message) {
1804 delete message; 1804 delete message;
1805 return false; 1805 return false;
1806 } 1806 }
1807 1807
1808 // Note that this cancel is subtly different from the other
1809 // CancelRequest methods in this file, which also tear down the loader.
1810 void ResourceDispatcherHostImpl::OnCancelRequest(int request_id) { 1808 void ResourceDispatcherHostImpl::OnCancelRequest(int request_id) {
1811 int child_id = filter_->child_id(); 1809 CancelRequestFromRenderer(GlobalRequestID(filter_->child_id(), request_id));
1812
1813 // When the old renderer dies, it sends a message to us to cancel its
1814 // requests.
1815 if (IsTransferredNavigation(GlobalRequestID(child_id, request_id)))
1816 return;
1817
1818 ResourceLoader* loader = GetLoader(child_id, request_id);
1819
1820 // It is possible that the request has been completed and removed from the
1821 // loader queue but the client has not processed the request completed message
1822 // before issuing a cancel. This happens frequently for beacons which are
1823 // canceled in the response received handler.
1824 if (!loader)
1825 return;
1826
1827 loader->CancelRequest(true);
1828 } 1810 }
1829 1811
1830 ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo( 1812 ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo(
1831 int child_id, 1813 int child_id,
1832 int render_view_route_id, 1814 int render_view_route_id,
1833 int render_frame_route_id, 1815 int render_frame_route_id,
1834 bool download, 1816 bool download,
1835 ResourceContext* context) { 1817 ResourceContext* context) {
1836 return new ResourceRequestInfoImpl( 1818 return new ResourceRequestInfoImpl(
1837 PROCESS_TYPE_RENDERER, child_id, render_view_route_id, 1819 PROCESS_TYPE_RENDERER, child_id, render_view_route_id,
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
2446 true /* force_download */, true /* is_new_request */); 2428 true /* force_download */, true /* is_new_request */);
2447 } 2429 }
2448 BeginRequestInternal(std::move(request), std::move(handler)); 2430 BeginRequestInternal(std::move(request), std::move(handler));
2449 } 2431 }
2450 2432
2451 int ResourceDispatcherHostImpl::MakeRequestID() { 2433 int ResourceDispatcherHostImpl::MakeRequestID() {
2452 DCHECK_CURRENTLY_ON(BrowserThread::IO); 2434 DCHECK_CURRENTLY_ON(BrowserThread::IO);
2453 return --request_id_; 2435 return --request_id_;
2454 } 2436 }
2455 2437
2438 void ResourceDispatcherHostImpl::CancelRequestFromRenderer(
2439 GlobalRequestID request_id) {
2440 // When the old renderer dies, it sends a message to us to cancel its
2441 // requests.
2442 if (IsTransferredNavigation(request_id))
2443 return;
2444
2445 ResourceLoader* loader =
2446 GetLoader(request_id.child_id, request_id.request_id);
mmenke 2016/11/03 18:17:41 nit: GetLoader(request_id) (There's an overload t
yhirano 2016/11/08 11:52:23 Done.
2447
2448 // It is possible that the request has been completed and removed from the
2449 // loader queue but the client has not processed the request completed message
2450 // before issuing a cancel. This happens frequently for beacons which are
2451 // canceled in the response received handler.
2452 if (!loader)
2453 return;
2454
2455 loader->CancelRequest(true);
2456 }
2457
2456 void ResourceDispatcherHostImpl::StartLoading( 2458 void ResourceDispatcherHostImpl::StartLoading(
2457 ResourceRequestInfoImpl* info, 2459 ResourceRequestInfoImpl* info,
2458 std::unique_ptr<ResourceLoader> loader) { 2460 std::unique_ptr<ResourceLoader> loader) {
2459 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. 2461 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed.
2460 tracked_objects::ScopedTracker tracking_profile( 2462 tracked_objects::ScopedTracker tracking_profile(
2461 FROM_HERE_WITH_EXPLICIT_FUNCTION( 2463 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2462 "456331 ResourceDispatcherHostImpl::StartLoading")); 2464 "456331 ResourceDispatcherHostImpl::StartLoading"));
2463 2465
2464 ResourceLoader* loader_ptr = loader.get(); 2466 ResourceLoader* loader_ptr = loader.get();
2465 DCHECK(pending_loaders_[info->GetGlobalRequestID()] == nullptr); 2467 DCHECK(pending_loaders_[info->GetGlobalRequestID()] == nullptr);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
2790 &throttles); 2792 &throttles);
2791 if (!throttles.empty()) { 2793 if (!throttles.empty()) {
2792 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, 2794 handler.reset(new ThrottlingResourceHandler(std::move(handler), request,
2793 std::move(throttles))); 2795 std::move(throttles)));
2794 } 2796 }
2795 } 2797 }
2796 return handler; 2798 return handler;
2797 } 2799 }
2798 2800
2799 } // namespace content 2801 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698