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

Side by Side Diff: chrome/common/resource_dispatcher.cc

Issue 1703017: When cancelling a pending request, release any outstanding SharedIOBuffer objects (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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 | « chrome/common/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) 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://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 "chrome/common/resource_dispatcher.h" 7 #include "chrome/common/resource_dispatcher.h"
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 pending_requests_[id] = 477 pending_requests_[id] =
478 PendingRequestInfo(callback, resource_type, request_url); 478 PendingRequestInfo(callback, resource_type, request_url);
479 return id; 479 return id;
480 } 480 }
481 481
482 bool ResourceDispatcher::RemovePendingRequest(int request_id) { 482 bool ResourceDispatcher::RemovePendingRequest(int request_id) {
483 PendingRequestList::iterator it = pending_requests_.find(request_id); 483 PendingRequestList::iterator it = pending_requests_.find(request_id);
484 if (it == pending_requests_.end()) 484 if (it == pending_requests_.end())
485 return false; 485 return false;
486 486
487 // Iterate through the deferred message queue and clean up the messages.
488 PendingRequestInfo& request_info = it->second; 487 PendingRequestInfo& request_info = it->second;
489 MessageQueue& q = request_info.deferred_message_queue; 488 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue);
490 while (!q.empty()) { 489 pending_requests_.erase(it);
491 IPC::Message* m = q.front();
492 ReleaseResourcesInDataMessage(*m);
493 q.pop_front();
494 delete m;
495 }
496 490
497 pending_requests_.erase(it);
498 return true; 491 return true;
499 } 492 }
500 493
501 void ResourceDispatcher::CancelPendingRequest(int routing_id, 494 void ResourceDispatcher::CancelPendingRequest(int routing_id,
502 int request_id) { 495 int request_id) {
503 PendingRequestList::iterator it = pending_requests_.find(request_id); 496 PendingRequestList::iterator it = pending_requests_.find(request_id);
504 if (it == pending_requests_.end()) { 497 if (it == pending_requests_.end()) {
505 DLOG(ERROR) << "unknown request"; 498 DLOG(WARNING) << "unknown request";
506 return; 499 return;
507 } 500 }
501
508 PendingRequestInfo& request_info = it->second; 502 PendingRequestInfo& request_info = it->second;
509 // Avoid spamming the host with cancel messages. 503 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue);
510 if (request_info.is_cancelled) 504 pending_requests_.erase(it);
511 return; 505
512 request_info.is_cancelled = true;
513 message_sender()->Send( 506 message_sender()->Send(
514 new ViewHostMsg_CancelRequest(routing_id, request_id)); 507 new ViewHostMsg_CancelRequest(routing_id, request_id));
515 } 508 }
516 509
517 void ResourceDispatcher::SetDefersLoading(int request_id, bool value) { 510 void ResourceDispatcher::SetDefersLoading(int request_id, bool value) {
518 PendingRequestList::iterator it = pending_requests_.find(request_id); 511 PendingRequestList::iterator it = pending_requests_.find(request_id);
519 if (it == pending_requests_.end()) { 512 if (it == pending_requests_.end()) {
520 DLOG(ERROR) << "unknown request"; 513 DLOG(ERROR) << "unknown request";
521 return; 514 return;
522 } 515 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 case ViewMsg_Resource_RequestComplete::ID: 584 case ViewMsg_Resource_RequestComplete::ID:
592 return true; 585 return true;
593 586
594 default: 587 default:
595 break; 588 break;
596 } 589 }
597 590
598 return false; 591 return false;
599 } 592 }
600 593
594 // static
601 void ResourceDispatcher::ReleaseResourcesInDataMessage( 595 void ResourceDispatcher::ReleaseResourcesInDataMessage(
602 const IPC::Message& message) { 596 const IPC::Message& message) {
603 void* iter = NULL; 597 void* iter = NULL;
604 int request_id; 598 int request_id;
605 if (!message.ReadInt(&iter, &request_id)) { 599 if (!message.ReadInt(&iter, &request_id)) {
606 NOTREACHED() << "malformed resource message"; 600 NOTREACHED() << "malformed resource message";
607 return; 601 return;
608 } 602 }
609 603
610 // If the message contains a shared memory handle, we should close the 604 // If the message contains a shared memory handle, we should close the
611 // handle or there will be a memory leak. 605 // handle or there will be a memory leak.
612 if (message.type() == ViewMsg_Resource_DataReceived::ID) { 606 if (message.type() == ViewMsg_Resource_DataReceived::ID) {
613 base::SharedMemoryHandle shm_handle; 607 base::SharedMemoryHandle shm_handle;
614 if (IPC::ParamTraits<base::SharedMemoryHandle>::Read(&message, 608 if (IPC::ParamTraits<base::SharedMemoryHandle>::Read(&message,
615 &iter, 609 &iter,
616 &shm_handle)) { 610 &shm_handle)) {
617 base::SharedMemory::CloseHandle(shm_handle); 611 base::SharedMemory::CloseHandle(shm_handle);
618 } 612 }
619 } 613 }
620 } 614 }
615
616 // static
617 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) {
618 while (!queue->empty()) {
619 IPC::Message* message = queue->front();
620 ReleaseResourcesInDataMessage(*message);
621 queue->pop_front();
622 delete message;
623 }
624 }
OLDNEW
« no previous file with comments | « chrome/common/resource_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698