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

Side by Side Diff: content/child/resource_dispatcher.cc

Issue 268423002: Fix WebURLLoaderImpl::Context leak if a pending request is canceled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new CL Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/child/resource_dispatcher.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) 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/child/resource_dispatcher.h" 7 #include "content/child/resource_dispatcher.h"
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 return true; 290 return true;
291 } 291 }
292 292
293 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); 293 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
294 if (!request_info) { 294 if (!request_info) {
295 // Release resources in the message if it is a data message. 295 // Release resources in the message if it is a data message.
296 ReleaseResourcesInDataMessage(message); 296 ReleaseResourcesInDataMessage(message);
297 return true; 297 return true;
298 } 298 }
299 299
300 // If the request has been canceled, only dispatch
301 // ResourceMsg_RequestComplete (otherwise resource leaks) and drop other
302 // messages.
303 if (request_info->is_canceled) {
304 if (message.type() == ResourceMsg_RequestComplete::ID) {
305 DispatchMessage(message);
306 } else {
307 ReleaseResourcesInDataMessage(message);
308 }
309 return true;
310 }
311
300 if (request_info->is_deferred) { 312 if (request_info->is_deferred) {
301 request_info->deferred_message_queue.push_back(new IPC::Message(message)); 313 request_info->deferred_message_queue.push_back(new IPC::Message(message));
302 return true; 314 return true;
303 } 315 }
304 // Make sure any deferred messages are dispatched before we dispatch more. 316 // Make sure any deferred messages are dispatched before we dispatch more.
305 if (!request_info->deferred_message_queue.empty()) { 317 if (!request_info->deferred_message_queue.empty()) {
306 FlushDeferredMessages(request_id); 318 FlushDeferredMessages(request_id);
307 // The request could have been deferred now. If yes then the current 319 // The request could have been deferred now. If yes then the current
308 // message has to be queued up. The request_info instance should remain 320 // message has to be queued up. The request_info instance should remain
309 // valid here as there are pending messages for it. 321 // valid here as there are pending messages for it.
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 return true; 593 return true;
582 } 594 }
583 595
584 void ResourceDispatcher::CancelPendingRequest(int request_id) { 596 void ResourceDispatcher::CancelPendingRequest(int request_id) {
585 PendingRequestList::iterator it = pending_requests_.find(request_id); 597 PendingRequestList::iterator it = pending_requests_.find(request_id);
586 if (it == pending_requests_.end()) { 598 if (it == pending_requests_.end()) {
587 DVLOG(1) << "unknown request"; 599 DVLOG(1) << "unknown request";
588 return; 600 return;
589 } 601 }
590 602
603 PendingRequestInfo& request_info = it->second;
604 request_info.is_canceled = true;
605
606 // Because message handlers could result in request_info being destroyed,
607 // we need to work with a stack reference to the deferred queue.
608 MessageQueue queue;
609 queue.swap(request_info.deferred_message_queue);
610 // Removes pending requests. If ResourceMsg_RequestComplete was queued,
611 // dispatch it.
612 bool first_message = true;
613 while (!queue.empty()) {
614 IPC::Message* message = queue.front();
615 if (message->type() == ResourceMsg_RequestComplete::ID) {
616 if (first_message) {
617 // Dispatch as-is.
618 DispatchMessage(*message);
619 } else {
620 // There are some messages not dispatched before
621 // ResourceMsg_RequestComplete, so replace the data with failure
622 // error_code.
623 ResourceMsg_RequestCompleteData request_complete_data;
624 request_complete_data.error_code = net::ERR_ABORTED;
625 request_complete_data.was_ignored_by_handler = false;
626 request_complete_data.exists_in_cache = false;
627 request_complete_data.completion_time = base::TimeTicks();
628 request_complete_data.encoded_data_length = 0;
629
630 ResourceMsg_RequestComplete error_message(request_id,
631 request_complete_data);
632 DispatchMessage(error_message);
jam 2014/05/08 16:22:13 i don't understand this change. why are you dispat
kcwu1 2014/05/08 17:00:49 What do you mean "over and over"? If we skip some
jam 2014/05/08 17:03:52 ah, I missed that we're only doing this for the Re
kcwu1 2014/05/08 17:14:53 Done. Replaced the comment
633 }
634 } else {
635 ReleaseResourcesInDataMessage(*message);
636 }
637 first_message = false;
638 queue.pop_front();
639 delete message;
640 }
641
591 // |request_id| will be removed from |pending_requests_| when 642 // |request_id| will be removed from |pending_requests_| when
592 // OnRequestComplete returns with ERR_ABORTED. 643 // OnRequestComplete returns with ERR_ABORTED.
593 message_sender()->Send(new ResourceHostMsg_CancelRequest(request_id)); 644 message_sender()->Send(new ResourceHostMsg_CancelRequest(request_id));
594 } 645 }
595 646
596 void ResourceDispatcher::SetDefersLoading(int request_id, bool value) { 647 void ResourceDispatcher::SetDefersLoading(int request_id, bool value) {
597 PendingRequestList::iterator it = pending_requests_.find(request_id); 648 PendingRequestList::iterator it = pending_requests_.find(request_id);
598 if (it == pending_requests_.end()) { 649 if (it == pending_requests_.end()) {
599 DLOG(ERROR) << "unknown request"; 650 DLOG(ERROR) << "unknown request";
600 return; 651 return;
(...skipping 19 matching lines...) Expand all
620 int intra_priority_value) { 671 int intra_priority_value) {
621 DCHECK(ContainsKey(pending_requests_, request_id)); 672 DCHECK(ContainsKey(pending_requests_, request_id));
622 message_sender()->Send(new ResourceHostMsg_DidChangePriority( 673 message_sender()->Send(new ResourceHostMsg_DidChangePriority(
623 request_id, new_priority, intra_priority_value)); 674 request_id, new_priority, intra_priority_value));
624 } 675 }
625 676
626 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo() 677 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo()
627 : peer(NULL), 678 : peer(NULL),
628 resource_type(ResourceType::SUB_RESOURCE), 679 resource_type(ResourceType::SUB_RESOURCE),
629 is_deferred(false), 680 is_deferred(false),
681 is_canceled(false),
630 blocked_response(false), 682 blocked_response(false),
631 buffer_size(0) { 683 buffer_size(0) {
632 } 684 }
633 685
634 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo( 686 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo(
635 RequestPeer* peer, 687 RequestPeer* peer,
636 ResourceType::Type resource_type, 688 ResourceType::Type resource_type,
637 int origin_pid, 689 int origin_pid,
638 const GURL& frame_origin, 690 const GURL& frame_origin,
639 const GURL& request_url) 691 const GURL& request_url)
640 : peer(peer), 692 : peer(peer),
641 resource_type(resource_type), 693 resource_type(resource_type),
642 origin_pid(origin_pid), 694 origin_pid(origin_pid),
643 is_deferred(false), 695 is_deferred(false),
696 is_canceled(false),
644 url(request_url), 697 url(request_url),
645 frame_origin(frame_origin), 698 frame_origin(frame_origin),
646 response_url(request_url), 699 response_url(request_url),
647 request_start(base::TimeTicks::Now()), 700 request_start(base::TimeTicks::Now()),
648 blocked_response(false) {} 701 blocked_response(false) {}
649 702
650 ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {} 703 ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {}
651 704
652 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { 705 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) {
653 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) 706 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message)
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { 858 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) {
806 while (!queue->empty()) { 859 while (!queue->empty()) {
807 IPC::Message* message = queue->front(); 860 IPC::Message* message = queue->front();
808 ReleaseResourcesInDataMessage(*message); 861 ReleaseResourcesInDataMessage(*message);
809 queue->pop_front(); 862 queue->pop_front();
810 delete message; 863 delete message;
811 } 864 }
812 } 865 }
813 866
814 } // namespace content 867 } // namespace content
OLDNEW
« no previous file with comments | « content/child/resource_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698