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

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 1788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 1799
1800 // Note that we don't remove the security bits here. This will be done 1800 // Note that we don't remove the security bits here. This will be done
1801 // when all file refs are deleted (see RegisterDownloadedTempFile). 1801 // when all file refs are deleted (see RegisterDownloadedTempFile).
1802 } 1802 }
1803 1803
1804 bool ResourceDispatcherHostImpl::Send(IPC::Message* message) { 1804 bool ResourceDispatcherHostImpl::Send(IPC::Message* message) {
1805 delete message; 1805 delete message;
1806 return false; 1806 return false;
1807 } 1807 }
1808 1808
1809 // Note that this cancel is subtly different from the other
1810 // CancelRequest methods in this file, which also tear down the loader.
1811 void ResourceDispatcherHostImpl::OnCancelRequest(int request_id) { 1809 void ResourceDispatcherHostImpl::OnCancelRequest(int request_id) {
1812 int child_id = filter_->child_id(); 1810 CancelRequestFromRenderer(GlobalRequestID(filter_->child_id(), request_id));
1813
1814 // When the old renderer dies, it sends a message to us to cancel its
1815 // requests.
1816 if (IsTransferredNavigation(GlobalRequestID(child_id, request_id)))
1817 return;
1818
1819 ResourceLoader* loader = GetLoader(child_id, request_id);
1820
1821 // It is possible that the request has been completed and removed from the
1822 // loader queue but the client has not processed the request completed message
1823 // before issuing a cancel. This happens frequently for beacons which are
1824 // canceled in the response received handler.
1825 if (!loader)
1826 return;
1827
1828 loader->CancelRequest(true);
1829 } 1811 }
1830 1812
1831 ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo( 1813 ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo(
1832 int child_id, 1814 int child_id,
1833 int render_view_route_id, 1815 int render_view_route_id,
1834 int render_frame_route_id, 1816 int render_frame_route_id,
1835 bool download, 1817 bool download,
1836 ResourceContext* context) { 1818 ResourceContext* context) {
1837 return new ResourceRequestInfoImpl( 1819 return new ResourceRequestInfoImpl(
1838 PROCESS_TYPE_RENDERER, child_id, render_view_route_id, 1820 PROCESS_TYPE_RENDERER, child_id, render_view_route_id,
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
2447 true /* force_download */, true /* is_new_request */); 2429 true /* force_download */, true /* is_new_request */);
2448 } 2430 }
2449 BeginRequestInternal(std::move(request), std::move(handler)); 2431 BeginRequestInternal(std::move(request), std::move(handler));
2450 } 2432 }
2451 2433
2452 int ResourceDispatcherHostImpl::MakeRequestID() { 2434 int ResourceDispatcherHostImpl::MakeRequestID() {
2453 DCHECK_CURRENTLY_ON(BrowserThread::IO); 2435 DCHECK_CURRENTLY_ON(BrowserThread::IO);
2454 return --request_id_; 2436 return --request_id_;
2455 } 2437 }
2456 2438
2439 void ResourceDispatcherHostImpl::CancelRequestFromRenderer(
2440 GlobalRequestID request_id) {
2441 // When the old renderer dies, it sends a message to us to cancel its
2442 // requests.
2443 if (IsTransferredNavigation(request_id))
2444 return;
2445
2446 ResourceLoader* loader = GetLoader(request_id);
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
2457 void ResourceDispatcherHostImpl::StartLoading( 2458 void ResourceDispatcherHostImpl::StartLoading(
2458 ResourceRequestInfoImpl* info, 2459 ResourceRequestInfoImpl* info,
2459 std::unique_ptr<ResourceLoader> loader) { 2460 std::unique_ptr<ResourceLoader> loader) {
2460 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. 2461 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed.
2461 tracked_objects::ScopedTracker tracking_profile( 2462 tracked_objects::ScopedTracker tracking_profile(
2462 FROM_HERE_WITH_EXPLICIT_FUNCTION( 2463 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2463 "456331 ResourceDispatcherHostImpl::StartLoading")); 2464 "456331 ResourceDispatcherHostImpl::StartLoading"));
2464 2465
2465 ResourceLoader* loader_ptr = loader.get(); 2466 ResourceLoader* loader_ptr = loader.get();
2466 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
2791 &throttles); 2792 &throttles);
2792 if (!throttles.empty()) { 2793 if (!throttles.empty()) {
2793 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, 2794 handler.reset(new ThrottlingResourceHandler(std::move(handler), request,
2794 std::move(throttles))); 2795 std::move(throttles)));
2795 } 2796 }
2796 } 2797 }
2797 return handler; 2798 return handler;
2798 } 2799 }
2799 2800
2800 } // namespace content 2801 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | content/browser/loader/url_loader_factory_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698