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

Side by Side Diff: chrome/browser/resource_dispatcher_host.cc

Issue 12602: Fix for 1498134, possible crash when cancelling a url request. The... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resource_dispatcher_host.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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://wiki.corp.google.com/twiki/bin/view/Main/ChromeMultiProcessResourc eLoading 5 // See http://wiki.corp.google.com/twiki/bin/view/Main/ChromeMultiProcessResourc eLoading
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "chrome/browser/resource_dispatcher_host.h" 9 #include "chrome/browser/resource_dispatcher_host.h"
10 10
(...skipping 1711 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 extra_info->allow_download = false; 1722 extra_info->allow_download = false;
1723 extra_info->is_download = false; 1723 extra_info->is_download = false;
1724 request->set_user_data(extra_info); // Takes pointer ownership. 1724 request->set_user_data(extra_info); // Takes pointer ownership.
1725 1725
1726 BeginRequestInternal(request, false); 1726 BeginRequestInternal(request, false);
1727 } 1727 }
1728 1728
1729 void ResourceDispatcherHost::CancelRequest(int render_process_host_id, 1729 void ResourceDispatcherHost::CancelRequest(int render_process_host_id,
1730 int request_id, 1730 int request_id,
1731 bool from_renderer) { 1731 bool from_renderer) {
1732 CancelRequest(render_process_host_id, request_id, from_renderer, true);
1733 }
1734
1735 void ResourceDispatcherHost::CancelRequest(int render_process_host_id,
1736 int request_id,
1737 bool from_renderer,
1738 bool allow_delete) {
1732 PendingRequestList::iterator i = pending_requests_.find( 1739 PendingRequestList::iterator i = pending_requests_.find(
1733 GlobalRequestID(render_process_host_id, request_id)); 1740 GlobalRequestID(render_process_host_id, request_id));
1734 if (i == pending_requests_.end()) { 1741 if (i == pending_requests_.end()) {
1735 // We probably want to remove this warning eventually, but I wanted to be 1742 // We probably want to remove this warning eventually, but I wanted to be
1736 // able to notice when this happens during initial development since it 1743 // able to notice when this happens during initial development since it
1737 // should be rare and may indicate a bug. 1744 // should be rare and may indicate a bug.
1738 DLOG(WARNING) << "Canceling a request that wasn't found"; 1745 DLOG(WARNING) << "Canceling a request that wasn't found";
1739 return; 1746 return;
1740 } 1747 }
1741 1748
1742 // WebKit will send us a cancel for downloads since it no longer handles them. 1749 // WebKit will send us a cancel for downloads since it no longer handles them.
1743 // In this case, ignore the cancel since we handle downloads in the browser. 1750 // In this case, ignore the cancel since we handle downloads in the browser.
1744 ExtraRequestInfo* info = ExtraInfoForRequest(i->second); 1751 ExtraRequestInfo* info = ExtraInfoForRequest(i->second);
1745 if (!from_renderer || !info->is_download) { 1752 if (!from_renderer || !info->is_download) {
1746 if (info->login_handler) { 1753 if (info->login_handler) {
1747 info->login_handler->OnRequestCancelled(); 1754 info->login_handler->OnRequestCancelled();
1748 info->login_handler = NULL; 1755 info->login_handler = NULL;
1749 } 1756 }
1750 i->second->Cancel(); 1757 if (!i->second->is_pending() && allow_delete) {
1758 // No io is pending, canceling the request won't notify us of anything,
1759 // so we explicitly remove it.
1760 // TODO: removing the request in this manner means we're not notifying
1761 // anyone. We need make sure the event handlers and others are notified
1762 // so that everything is cleaned up properly.
1763 RemovePendingRequest(info->render_process_host_id, info->request_id);
1764 } else {
1765 i->second->Cancel();
1766 }
1751 } 1767 }
1752 1768
1753 // Do not remove from the pending requests, as the request will still 1769 // Do not remove from the pending requests, as the request will still
1754 // call AllDataReceived, and may even have more data before it does 1770 // call AllDataReceived, and may even have more data before it does
1755 // that. 1771 // that.
1756 } 1772 }
1757 1773
1758 void ResourceDispatcherHost::OnDataReceivedACK(int render_process_host_id, 1774 void ResourceDispatcherHost::OnDataReceivedACK(int render_process_host_id,
1759 int request_id) { 1775 int request_id) {
1760 PendingRequestList::iterator i = pending_requests_.find( 1776 PendingRequestList::iterator i = pending_requests_.find(
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
2227 bool ResourceDispatcherHost::CompleteRead(URLRequest* request, 2243 bool ResourceDispatcherHost::CompleteRead(URLRequest* request,
2228 int* bytes_read) { 2244 int* bytes_read) {
2229 if (!request->status().is_success()) { 2245 if (!request->status().is_success()) {
2230 NOTREACHED(); 2246 NOTREACHED();
2231 return false; 2247 return false;
2232 } 2248 }
2233 2249
2234 ExtraRequestInfo* info = ExtraInfoForRequest(request); 2250 ExtraRequestInfo* info = ExtraInfoForRequest(request);
2235 2251
2236 if (!info->event_handler->OnReadCompleted(info->request_id, bytes_read)) { 2252 if (!info->event_handler->OnReadCompleted(info->request_id, bytes_read)) {
2237 CancelRequest(info->render_process_host_id, info->request_id, false); 2253 // Pass in false as the last arg to indicate we don't want |request|
2254 // deleted. We do this as callers of us assume |request| is valid after we
2255 // return.
2256 CancelRequest(info->render_process_host_id, info->request_id, false, false);
2238 return false; 2257 return false;
2239 } 2258 }
2240 2259
2241 return *bytes_read != 0; 2260 return *bytes_read != 0;
2242 } 2261 }
2243 2262
2244 void ResourceDispatcherHost::OnResponseCompleted(URLRequest* request) { 2263 void ResourceDispatcherHost::OnResponseCompleted(URLRequest* request) {
2245 RESOURCE_LOG("OnResponseCompleted: " << request->url().spec()); 2264 RESOURCE_LOG("OnResponseCompleted: " << request->url().spec());
2246 ExtraRequestInfo* info = ExtraInfoForRequest(request); 2265 ExtraRequestInfo* info = ExtraInfoForRequest(request);
2247 2266
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 bool enough_new_progress = (amt_since_last > (size / kHalfPercentIncrements)); 2510 bool enough_new_progress = (amt_since_last > (size / kHalfPercentIncrements));
2492 bool too_much_time_passed = time_since_last > kOneSecond; 2511 bool too_much_time_passed = time_since_last > kOneSecond;
2493 2512
2494 if (is_finished || enough_new_progress || too_much_time_passed) { 2513 if (is_finished || enough_new_progress || too_much_time_passed) {
2495 info->event_handler->OnUploadProgress(info->request_id, position, size); 2514 info->event_handler->OnUploadProgress(info->request_id, position, size);
2496 info->waiting_for_upload_progress_ack = true; 2515 info->waiting_for_upload_progress_ack = true;
2497 info->last_upload_ticks = TimeTicks::Now(); 2516 info->last_upload_ticks = TimeTicks::Now();
2498 info->last_upload_position = position; 2517 info->last_upload_position = position;
2499 } 2518 }
2500 } 2519 }
OLDNEW
« no previous file with comments | « chrome/browser/resource_dispatcher_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698