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

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

Issue 10911297: Modify AsyncResourceHandler to use a single shared memory buffer (in ring (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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
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/common/resource_dispatcher.h" 7 #include "content/common/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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 void ResourceDispatcher::OnReceivedCachedMetadata( 317 void ResourceDispatcher::OnReceivedCachedMetadata(
318 int request_id, const std::vector<char>& data) { 318 int request_id, const std::vector<char>& data) {
319 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); 319 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
320 if (!request_info) 320 if (!request_info)
321 return; 321 return;
322 322
323 if (data.size()) 323 if (data.size())
324 request_info->peer->OnReceivedCachedMetadata(&data.front(), data.size()); 324 request_info->peer->OnReceivedCachedMetadata(&data.front(), data.size());
325 } 325 }
326 326
327 void ResourceDispatcher::OnSetDataBuffer(const IPC::Message& message,
328 int request_id,
329 base::SharedMemoryHandle shm_handle,
330 int shm_size) {
331 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
332 if (!request_info)
333 return;
334
335 bool shm_valid = base::SharedMemory::IsHandleValid(shm_handle);
336 DCHECK((shm_valid && shm_size > 0) || (!shm_valid && !shm_size));
337
338 request_info->buffer.reset(
339 new base::SharedMemory(shm_handle, true)); // read only
340 request_info->buffer->Map(shm_size);
341 }
342
327 void ResourceDispatcher::OnReceivedData(const IPC::Message& message, 343 void ResourceDispatcher::OnReceivedData(const IPC::Message& message,
328 int request_id, 344 int request_id,
329 base::SharedMemoryHandle shm_handle, 345 int data_offset,
330 int data_len, 346 int data_length,
331 int encoded_data_length) { 347 int encoded_data_length) {
348 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
349 if (request_info && data_length > 0) {
350 request_info->peer->OnReceivedData(
351 static_cast<char*>(request_info->buffer->memory()) + data_offset,
352 data_length,
353 encoded_data_length);
354 }
355
332 // Acknowledge the reception of this data. 356 // Acknowledge the reception of this data.
333 message_sender()->Send( 357 message_sender()->Send(
334 new ResourceHostMsg_DataReceived_ACK(message.routing_id(), request_id)); 358 new ResourceHostMsg_DataReceived_ACK(message.routing_id(), request_id));
335
336 const bool shm_valid = base::SharedMemory::IsHandleValid(shm_handle);
337 DCHECK((shm_valid && data_len > 0) || (!shm_valid && !data_len));
338 base::SharedMemory shared_mem(shm_handle, true); // read only
339
340 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
341 if (!request_info)
342 return;
343
344 if (data_len > 0 && shared_mem.Map(data_len)) {
345 const char* data = static_cast<char*>(shared_mem.memory());
346 request_info->peer->OnReceivedData(data, data_len, encoded_data_length);
347 }
348 } 359 }
349 360
350 void ResourceDispatcher::OnDownloadedData(const IPC::Message& message, 361 void ResourceDispatcher::OnDownloadedData(const IPC::Message& message,
351 int request_id, 362 int request_id,
352 int data_len) { 363 int data_len) {
353 // Acknowledge the reception of this message. 364 // Acknowledge the reception of this message.
354 message_sender()->Send( 365 message_sender()->Send(
355 new ResourceHostMsg_DataDownloaded_ACK(message.routing_id(), request_id)); 366 new ResourceHostMsg_DataDownloaded_ACK(message.routing_id(), request_id));
356 367
357 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); 368 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 void ResourceDispatcher::OnRequestComplete( 418 void ResourceDispatcher::OnRequestComplete(
408 int request_id, 419 int request_id,
409 int error_code, 420 int error_code,
410 bool was_ignored_by_handler, 421 bool was_ignored_by_handler,
411 const std::string& security_info, 422 const std::string& security_info,
412 const base::TimeTicks& browser_completion_time) { 423 const base::TimeTicks& browser_completion_time) {
413 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); 424 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
414 if (!request_info) 425 if (!request_info)
415 return; 426 return;
416 request_info->completion_time = base::TimeTicks::Now(); 427 request_info->completion_time = base::TimeTicks::Now();
428 request_info->buffer.reset();
417 429
418 ResourceLoaderBridge::Peer* peer = request_info->peer; 430 ResourceLoaderBridge::Peer* peer = request_info->peer;
419 431
420 if (delegate_) { 432 if (delegate_) {
421 ResourceLoaderBridge::Peer* new_peer = 433 ResourceLoaderBridge::Peer* new_peer =
422 delegate_->OnRequestComplete( 434 delegate_->OnRequestComplete(
423 request_info->peer, request_info->resource_type, error_code); 435 request_info->peer, request_info->resource_type, error_code);
424 if (new_peer) 436 if (new_peer)
425 request_info->peer = new_peer; 437 request_info->peer = new_peer;
426 } 438 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 524
513 ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {} 525 ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {}
514 526
515 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { 527 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) {
516 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) 528 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message)
517 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress) 529 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress)
518 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse) 530 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse)
519 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata, 531 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata,
520 OnReceivedCachedMetadata) 532 OnReceivedCachedMetadata)
521 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedRedirect, OnReceivedRedirect) 533 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedRedirect, OnReceivedRedirect)
534 IPC_MESSAGE_HANDLER(ResourceMsg_SetDataBuffer, OnSetDataBuffer)
522 IPC_MESSAGE_HANDLER(ResourceMsg_DataReceived, OnReceivedData) 535 IPC_MESSAGE_HANDLER(ResourceMsg_DataReceived, OnReceivedData)
523 IPC_MESSAGE_HANDLER(ResourceMsg_DataDownloaded, OnDownloadedData) 536 IPC_MESSAGE_HANDLER(ResourceMsg_DataDownloaded, OnDownloadedData)
524 IPC_MESSAGE_HANDLER(ResourceMsg_RequestComplete, OnRequestComplete) 537 IPC_MESSAGE_HANDLER(ResourceMsg_RequestComplete, OnRequestComplete)
525 IPC_END_MESSAGE_MAP() 538 IPC_END_MESSAGE_MAP()
526 } 539 }
527 540
528 void ResourceDispatcher::FlushDeferredMessages(int request_id) { 541 void ResourceDispatcher::FlushDeferredMessages(int request_id) {
529 PendingRequestList::iterator it = pending_requests_.find(request_id); 542 PendingRequestList::iterator it = pending_requests_.find(request_id);
530 if (it == pending_requests_.end()) // The request could have become invalid. 543 if (it == pending_requests_.end()) // The request could have become invalid.
531 return; 544 return;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 } 634 }
622 635
623 // static 636 // static
624 bool ResourceDispatcher::IsResourceDispatcherMessage( 637 bool ResourceDispatcher::IsResourceDispatcherMessage(
625 const IPC::Message& message) { 638 const IPC::Message& message) {
626 switch (message.type()) { 639 switch (message.type()) {
627 case ResourceMsg_UploadProgress::ID: 640 case ResourceMsg_UploadProgress::ID:
628 case ResourceMsg_ReceivedResponse::ID: 641 case ResourceMsg_ReceivedResponse::ID:
629 case ResourceMsg_ReceivedCachedMetadata::ID: 642 case ResourceMsg_ReceivedCachedMetadata::ID:
630 case ResourceMsg_ReceivedRedirect::ID: 643 case ResourceMsg_ReceivedRedirect::ID:
644 case ResourceMsg_SetDataBuffer::ID:
631 case ResourceMsg_DataReceived::ID: 645 case ResourceMsg_DataReceived::ID:
632 case ResourceMsg_DataDownloaded::ID: 646 case ResourceMsg_DataDownloaded::ID:
633 case ResourceMsg_RequestComplete::ID: 647 case ResourceMsg_RequestComplete::ID:
634 return true; 648 return true;
635 649
636 default: 650 default:
637 break; 651 break;
638 } 652 }
639 653
640 return false; 654 return false;
641 } 655 }
642 656
643 // static 657 // static
644 void ResourceDispatcher::ReleaseResourcesInDataMessage( 658 void ResourceDispatcher::ReleaseResourcesInDataMessage(
645 const IPC::Message& message) { 659 const IPC::Message& message) {
646 PickleIterator iter(message); 660 PickleIterator iter(message);
647 int request_id; 661 int request_id;
648 if (!message.ReadInt(&iter, &request_id)) { 662 if (!message.ReadInt(&iter, &request_id)) {
649 NOTREACHED() << "malformed resource message"; 663 NOTREACHED() << "malformed resource message";
650 return; 664 return;
651 } 665 }
652 666
653 // If the message contains a shared memory handle, we should close the 667 // If the message contains a shared memory handle, we should close the handle
654 // handle or there will be a memory leak. 668 // or there will be a memory leak.
655 if (message.type() == ResourceMsg_DataReceived::ID) { 669 if (message.type() == ResourceMsg_SetDataBuffer::ID) {
656 base::SharedMemoryHandle shm_handle; 670 base::SharedMemoryHandle shm_handle;
657 if (IPC::ParamTraits<base::SharedMemoryHandle>::Read(&message, 671 if (IPC::ParamTraits<base::SharedMemoryHandle>::Read(&message,
658 &iter, 672 &iter,
659 &shm_handle)) { 673 &shm_handle)) {
660 base::SharedMemory::CloseHandle(shm_handle); 674 if (base::SharedMemory::IsHandleValid(shm_handle))
675 base::SharedMemory::CloseHandle(shm_handle);
661 } 676 }
662 } 677 }
663 } 678 }
664 679
665 // static 680 // static
666 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { 681 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) {
667 while (!queue->empty()) { 682 while (!queue->empty()) {
668 IPC::Message* message = queue->front(); 683 IPC::Message* message = queue->front();
669 ReleaseResourcesInDataMessage(*message); 684 ReleaseResourcesInDataMessage(*message);
670 queue->pop_front(); 685 queue->pop_front();
671 delete message; 686 delete message;
672 } 687 }
673 } 688 }
674 689
675 } // namespace content 690 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698