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
3 // found in the LICENSE file.
5 // See http://dev.chromium.org/developers/design-documents/multi-process-resource-loading
7 #include "content/common/resource_dispatcher.h"
9 #include "base/basictypes.h"
10 #include "base/bind.h"
11 #include "base/compiler_specific.h"
12 #include "base/file_path.h"
13 #include "base/message_loop.h"
14 #include "base/metrics/histogram.h"
15 #include "base/shared_memory.h"
16 #include "base/string_util.h"
17 #include "content/common/inter_process_time_ticks_converter.h"
18 #include "content/common/request_extra_data.h"
19 #include "content/common/resource_messages.h"
20 #include "content/public/common/resource_dispatcher_delegate.h"
21 #include "content/public/common/resource_response.h"
22 #include "net/base/net_errors.h"
23 #include "net/base/net_util.h"
24 #include "net/http/http_response_headers.h"
25 #include "webkit/glue/resource_request_body.h"
26 #include "webkit/glue/resource_type.h"
28 using webkit_glue::ResourceLoaderBridge
;
29 using webkit_glue::ResourceRequestBody
;
30 using webkit_glue::ResourceResponseInfo
;
34 // Each resource request is assigned an ID scoped to this process.
35 static int MakeRequestID() {
36 // NOTE: The resource_dispatcher_host also needs probably unique
37 // request_ids, so they count down from -2 (-1 is a special we're
38 // screwed value), while the renderer process counts up.
39 static int next_request_id
= 0;
40 return next_request_id
++;
43 // ResourceLoaderBridge implementation ----------------------------------------
45 class IPCResourceLoaderBridge
: public ResourceLoaderBridge
{
47 IPCResourceLoaderBridge(ResourceDispatcher
* dispatcher
,
48 const ResourceLoaderBridge::RequestInfo
& request_info
);
49 virtual ~IPCResourceLoaderBridge();
51 // ResourceLoaderBridge
52 virtual void SetRequestBody(ResourceRequestBody
* request_body
);
53 virtual bool Start(Peer
* peer
);
54 virtual void Cancel();
55 virtual void SetDefersLoading(bool value
);
56 virtual void SyncLoad(SyncLoadResponse
* response
);
59 ResourceLoaderBridge::Peer
* peer_
;
61 // The resource dispatcher for this loader. The bridge doesn't own it, but
62 // it's guaranteed to outlive the bridge.
63 ResourceDispatcher
* dispatcher_
;
65 // The request to send, created on initialization for modification and
67 ResourceHostMsg_Request request_
;
69 // ID for the request, valid once Start()ed, -1 if not valid yet.
72 // The routing id used when sending IPC messages.
75 bool is_synchronous_request_
;
78 IPCResourceLoaderBridge::IPCResourceLoaderBridge(
79 ResourceDispatcher
* dispatcher
,
80 const ResourceLoaderBridge::RequestInfo
& request_info
)
82 dispatcher_(dispatcher
),
84 routing_id_(request_info
.routing_id
),
85 is_synchronous_request_(false) {
86 DCHECK(dispatcher_
) << "no resource dispatcher";
87 request_
.method
= request_info
.method
;
88 request_
.url
= request_info
.url
;
89 request_
.first_party_for_cookies
= request_info
.first_party_for_cookies
;
90 request_
.referrer
= request_info
.referrer
;
91 request_
.referrer_policy
= request_info
.referrer_policy
;
92 request_
.headers
= request_info
.headers
;
93 request_
.load_flags
= request_info
.load_flags
;
94 request_
.origin_pid
= request_info
.requestor_pid
;
95 request_
.resource_type
= request_info
.request_type
;
96 request_
.request_context
= request_info
.request_context
;
97 request_
.appcache_host_id
= request_info
.appcache_host_id
;
98 request_
.download_to_file
= request_info
.download_to_file
;
99 request_
.has_user_gesture
= request_info
.has_user_gesture
;
100 if (request_info
.extra_data
) {
101 RequestExtraData
* extra_data
=
102 static_cast<RequestExtraData
*>(request_info
.extra_data
);
103 request_
.is_main_frame
= extra_data
->is_main_frame();
104 request_
.frame_id
= extra_data
->frame_id();
105 request_
.parent_is_main_frame
= extra_data
->parent_is_main_frame();
106 request_
.parent_frame_id
= extra_data
->parent_frame_id();
107 request_
.allow_download
= extra_data
->allow_download();
108 request_
.transition_type
= extra_data
->transition_type();
109 request_
.transferred_request_child_id
=
110 extra_data
->transferred_request_child_id();
111 request_
.transferred_request_request_id
=
112 extra_data
->transferred_request_request_id();
114 request_
.is_main_frame
= false;
115 request_
.frame_id
= -1;
116 request_
.parent_is_main_frame
= false;
117 request_
.parent_frame_id
= -1;
118 request_
.allow_download
= true;
119 request_
.transition_type
= PAGE_TRANSITION_LINK
;
120 request_
.transferred_request_child_id
= -1;
121 request_
.transferred_request_request_id
= -1;
125 IPCResourceLoaderBridge::~IPCResourceLoaderBridge() {
126 // we remove our hook for the resource dispatcher only when going away, since
127 // it doesn't keep track of whether we've force terminated the request
128 if (request_id_
>= 0) {
129 // this operation may fail, as the dispatcher will have preemptively
130 // removed us when the renderer sends the ReceivedAllData message.
131 dispatcher_
->RemovePendingRequest(request_id_
);
133 if (request_
.download_to_file
) {
134 dispatcher_
->message_sender()->Send(
135 new ResourceHostMsg_ReleaseDownloadedFile(request_id_
));
140 void IPCResourceLoaderBridge::SetRequestBody(
141 ResourceRequestBody
* request_body
) {
142 DCHECK(request_id_
== -1) << "request already started";
143 request_
.request_body
= request_body
;
146 // Writes a footer on the message and sends it
147 bool IPCResourceLoaderBridge::Start(Peer
* peer
) {
148 if (request_id_
!= -1) {
149 NOTREACHED() << "Starting a request twice";
155 // generate the request ID, and append it to the message
156 request_id_
= dispatcher_
->AddPendingRequest(
157 peer_
, request_
.resource_type
, request_
.url
);
159 return dispatcher_
->message_sender()->Send(
160 new ResourceHostMsg_RequestResource(routing_id_
, request_id_
, request_
));
163 void IPCResourceLoaderBridge::Cancel() {
164 if (request_id_
< 0) {
165 NOTREACHED() << "Trying to cancel an unstarted request";
169 if (!is_synchronous_request_
)
170 dispatcher_
->CancelPendingRequest(routing_id_
, request_id_
);
172 // We can't remove the request ID from the resource dispatcher because more
173 // data might be pending. Sending the cancel message may cause more data
174 // to be flushed, and will then cause a complete message to be sent.
177 void IPCResourceLoaderBridge::SetDefersLoading(bool value
) {
178 if (request_id_
< 0) {
179 NOTREACHED() << "Trying to (un)defer an unstarted request";
183 dispatcher_
->SetDefersLoading(request_id_
, value
);
186 void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse
* response
) {
187 if (request_id_
!= -1) {
188 NOTREACHED() << "Starting a request twice";
189 response
->error_code
= net::ERR_FAILED
;
193 request_id_
= MakeRequestID();
194 is_synchronous_request_
= true;
196 SyncLoadResult result
;
197 IPC::SyncMessage
* msg
= new ResourceHostMsg_SyncLoad(routing_id_
, request_id_
,
199 // NOTE: This may pump events (see RenderThread::Send).
200 if (!dispatcher_
->message_sender()->Send(msg
)) {
201 response
->error_code
= net::ERR_FAILED
;
205 response
->error_code
= result
.error_code
;
206 response
->url
= result
.final_url
;
207 response
->headers
= result
.headers
;
208 response
->mime_type
= result
.mime_type
;
209 response
->charset
= result
.charset
;
210 response
->request_time
= result
.request_time
;
211 response
->response_time
= result
.response_time
;
212 response
->encoded_data_length
= result
.encoded_data_length
;
213 response
->connection_id
= result
.connection_id
;
214 response
->connection_reused
= result
.connection_reused
;
215 response
->load_timing
= result
.load_timing
;
216 response
->devtools_info
= result
.devtools_info
;
217 response
->data
.swap(result
.data
);
218 response
->download_file_path
= result
.download_file_path
;
221 // ResourceDispatcher ---------------------------------------------------------
223 ResourceDispatcher::ResourceDispatcher(IPC::Sender
* sender
)
224 : message_sender_(sender
),
225 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
229 ResourceDispatcher::~ResourceDispatcher() {
232 // ResourceDispatcher implementation ------------------------------------------
234 bool ResourceDispatcher::OnMessageReceived(const IPC::Message
& message
) {
235 if (!IsResourceDispatcherMessage(message
)) {
241 PickleIterator
iter(message
);
242 if (!message
.ReadInt(&iter
, &request_id
)) {
243 NOTREACHED() << "malformed resource message";
247 PendingRequestInfo
* request_info
= GetPendingRequestInfo(request_id
);
249 // Release resources in the message if it is a data message.
250 ReleaseResourcesInDataMessage(message
);
254 if (request_info
->is_deferred
) {
255 request_info
->deferred_message_queue
.push_back(new IPC::Message(message
));
258 // Make sure any deferred messages are dispatched before we dispatch more.
259 if (!request_info
->deferred_message_queue
.empty()) {
260 FlushDeferredMessages(request_id
);
261 // The request could have been deferred now. If yes then the current
262 // message has to be queued up. The request_info instance should remain
263 // valid here as there are pending messages for it.
264 DCHECK(pending_requests_
.find(request_id
) != pending_requests_
.end());
265 if (request_info
->is_deferred
) {
266 request_info
->deferred_message_queue
.push_back(new IPC::Message(message
));
271 DispatchMessage(message
);
275 ResourceDispatcher::PendingRequestInfo
*
276 ResourceDispatcher::GetPendingRequestInfo(int request_id
) {
277 PendingRequestList::iterator it
= pending_requests_
.find(request_id
);
278 if (it
== pending_requests_
.end()) {
279 // This might happen for kill()ed requests on the webkit end.
282 return &(it
->second
);
285 void ResourceDispatcher::OnUploadProgress(
286 const IPC::Message
& message
, int request_id
, int64 position
, int64 size
) {
287 PendingRequestInfo
* request_info
= GetPendingRequestInfo(request_id
);
291 request_info
->peer
->OnUploadProgress(position
, size
);
293 // Acknowledge receipt
294 message_sender()->Send(
295 new ResourceHostMsg_UploadProgress_ACK(message
.routing_id(), request_id
));
298 void ResourceDispatcher::OnReceivedResponse(
299 int request_id
, const ResourceResponseHead
& response_head
) {
300 PendingRequestInfo
* request_info
= GetPendingRequestInfo(request_id
);
303 request_info
->response_start
= base::TimeTicks::Now();
306 ResourceLoaderBridge::Peer
* new_peer
=
307 delegate_
->OnReceivedResponse(
308 request_info
->peer
, response_head
.mime_type
, request_info
->url
);
310 request_info
->peer
= new_peer
;
313 ResourceResponseInfo renderer_response_info
;
314 ToResourceResponseInfo(*request_info
, response_head
, &renderer_response_info
);
315 request_info
->peer
->OnReceivedResponse(renderer_response_info
);
318 void ResourceDispatcher::OnReceivedCachedMetadata(
319 int request_id
, const std::vector
<char>& data
) {
320 PendingRequestInfo
* request_info
= GetPendingRequestInfo(request_id
);
325 request_info
->peer
->OnReceivedCachedMetadata(&data
.front(), data
.size());
328 void ResourceDispatcher::OnSetDataBuffer(const IPC::Message
& message
,
330 base::SharedMemoryHandle shm_handle
,
332 PendingRequestInfo
* request_info
= GetPendingRequestInfo(request_id
);
336 bool shm_valid
= base::SharedMemory::IsHandleValid(shm_handle
);
337 CHECK((shm_valid
&& shm_size
> 0) || (!shm_valid
&& !shm_size
));
339 request_info
->buffer
.reset(
340 new base::SharedMemory(shm_handle
, true)); // read only
342 bool ok
= request_info
->buffer
->Map(shm_size
);
345 request_info
->buffer_size
= shm_size
;
348 void ResourceDispatcher::OnReceivedData(const IPC::Message
& message
,
352 int encoded_data_length
) {
353 PendingRequestInfo
* request_info
= GetPendingRequestInfo(request_id
);
354 if (request_info
&& data_length
> 0) {
355 CHECK(base::SharedMemory::IsHandleValid(request_info
->buffer
->handle()));
356 CHECK_GE(request_info
->buffer_size
, data_offset
+ data_length
);
358 // Ensure that the SHM buffer remains valid for the duration of this scope.
359 // It is possible for CancelPendingRequest() to be called before we exit
361 linked_ptr
<base::SharedMemory
> retain_buffer(request_info
->buffer
);
363 base::TimeTicks time_start
= base::TimeTicks::Now();
365 const char* data_ptr
= static_cast<char*>(request_info
->buffer
->memory());
367 CHECK(data_ptr
+ data_offset
);
369 request_info
->peer
->OnReceivedData(
370 data_ptr
+ data_offset
,
372 encoded_data_length
);
374 UMA_HISTOGRAM_TIMES("ResourceDispatcher.OnReceivedDataTime",
375 base::TimeTicks::Now() - time_start
);
378 // Acknowledge the reception of this data.
379 message_sender()->Send(
380 new ResourceHostMsg_DataReceived_ACK(message
.routing_id(), request_id
));
383 void ResourceDispatcher::OnDownloadedData(const IPC::Message
& message
,
386 // Acknowledge the reception of this message.
387 message_sender()->Send(
388 new ResourceHostMsg_DataDownloaded_ACK(message
.routing_id(), request_id
));
390 PendingRequestInfo
* request_info
= GetPendingRequestInfo(request_id
);
394 request_info
->peer
->OnDownloadedData(data_len
);
397 void ResourceDispatcher::OnReceivedRedirect(
398 const IPC::Message
& message
,
401 const ResourceResponseHead
& response_head
) {
402 PendingRequestInfo
* request_info
= GetPendingRequestInfo(request_id
);
405 request_info
->response_start
= base::TimeTicks::Now();
407 int32 routing_id
= message
.routing_id();
408 bool has_new_first_party_for_cookies
= false;
409 GURL new_first_party_for_cookies
;
410 ResourceResponseInfo renderer_response_info
;
411 ToResourceResponseInfo(*request_info
, response_head
, &renderer_response_info
);
412 if (request_info
->peer
->OnReceivedRedirect(new_url
, renderer_response_info
,
413 &has_new_first_party_for_cookies
,
414 &new_first_party_for_cookies
)) {
415 // Double-check if the request is still around. The call above could
416 // potentially remove it.
417 request_info
= GetPendingRequestInfo(request_id
);
420 request_info
->pending_redirect_message
.reset(
421 new ResourceHostMsg_FollowRedirect(routing_id
, request_id
,
422 has_new_first_party_for_cookies
,
423 new_first_party_for_cookies
));
424 if (!request_info
->is_deferred
) {
425 FollowPendingRedirect(request_id
, *request_info
);
428 CancelPendingRequest(routing_id
, request_id
);
432 void ResourceDispatcher::FollowPendingRedirect(
434 PendingRequestInfo
& request_info
) {
435 IPC::Message
* msg
= request_info
.pending_redirect_message
.release();
437 message_sender()->Send(msg
);
440 void ResourceDispatcher::OnRequestComplete(
443 bool was_ignored_by_handler
,
444 const std::string
& security_info
,
445 const base::TimeTicks
& browser_completion_time
) {
446 PendingRequestInfo
* request_info
= GetPendingRequestInfo(request_id
);
449 request_info
->completion_time
= base::TimeTicks::Now();
450 request_info
->buffer
.reset();
451 request_info
->buffer_size
= 0;
453 ResourceLoaderBridge::Peer
* peer
= request_info
->peer
;
456 ResourceLoaderBridge::Peer
* new_peer
=
457 delegate_
->OnRequestComplete(
458 request_info
->peer
, request_info
->resource_type
, error_code
);
460 request_info
->peer
= new_peer
;
463 base::TimeTicks renderer_completion_time
= ToRendererCompletionTime(
464 *request_info
, browser_completion_time
);
465 // The request ID will be removed from our pending list in the destructor.
466 // Normally, dispatching this message causes the reference-counted request to
468 peer
->OnCompletedRequest(error_code
, was_ignored_by_handler
, security_info
,
469 renderer_completion_time
);
472 int ResourceDispatcher::AddPendingRequest(
473 ResourceLoaderBridge::Peer
* callback
,
474 ResourceType::Type resource_type
,
475 const GURL
& request_url
) {
476 // Compute a unique request_id for this renderer process.
477 int id
= MakeRequestID();
478 pending_requests_
[id
] =
479 PendingRequestInfo(callback
, resource_type
, request_url
);
483 bool ResourceDispatcher::RemovePendingRequest(int request_id
) {
484 PendingRequestList::iterator it
= pending_requests_
.find(request_id
);
485 if (it
== pending_requests_
.end())
488 PendingRequestInfo
& request_info
= it
->second
;
489 ReleaseResourcesInMessageQueue(&request_info
.deferred_message_queue
);
490 pending_requests_
.erase(it
);
495 void ResourceDispatcher::CancelPendingRequest(int routing_id
,
497 PendingRequestList::iterator it
= pending_requests_
.find(request_id
);
498 if (it
== pending_requests_
.end()) {
499 DVLOG(1) << "unknown request";
503 PendingRequestInfo
& request_info
= it
->second
;
504 ReleaseResourcesInMessageQueue(&request_info
.deferred_message_queue
);
505 pending_requests_
.erase(it
);
507 message_sender()->Send(
508 new ResourceHostMsg_CancelRequest(routing_id
, request_id
));
511 void ResourceDispatcher::SetDefersLoading(int request_id
, bool value
) {
512 PendingRequestList::iterator it
= pending_requests_
.find(request_id
);
513 if (it
== pending_requests_
.end()) {
514 DLOG(ERROR
) << "unknown request";
517 PendingRequestInfo
& request_info
= it
->second
;
519 request_info
.is_deferred
= value
;
520 } else if (request_info
.is_deferred
) {
521 request_info
.is_deferred
= false;
523 FollowPendingRedirect(request_id
, request_info
);
525 MessageLoop::current()->PostTask(FROM_HERE
,
526 base::Bind(&ResourceDispatcher::FlushDeferredMessages
,
527 weak_factory_
.GetWeakPtr(), request_id
));
531 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo()
533 resource_type(ResourceType::SUB_RESOURCE
),
538 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo(
539 webkit_glue::ResourceLoaderBridge::Peer
* peer
,
540 ResourceType::Type resource_type
,
541 const GURL
& request_url
)
543 resource_type(resource_type
),
546 request_start(base::TimeTicks::Now()) {
549 ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {}
551 void ResourceDispatcher::DispatchMessage(const IPC::Message
& message
) {
552 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher
, message
)
553 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress
, OnUploadProgress
)
554 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse
, OnReceivedResponse
)
555 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata
,
556 OnReceivedCachedMetadata
)
557 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedRedirect
, OnReceivedRedirect
)
558 IPC_MESSAGE_HANDLER(ResourceMsg_SetDataBuffer
, OnSetDataBuffer
)
559 IPC_MESSAGE_HANDLER(ResourceMsg_DataReceived
, OnReceivedData
)
560 IPC_MESSAGE_HANDLER(ResourceMsg_DataDownloaded
, OnDownloadedData
)
561 IPC_MESSAGE_HANDLER(ResourceMsg_RequestComplete
, OnRequestComplete
)
562 IPC_END_MESSAGE_MAP()
565 void ResourceDispatcher::FlushDeferredMessages(int request_id
) {
566 PendingRequestList::iterator it
= pending_requests_
.find(request_id
);
567 if (it
== pending_requests_
.end()) // The request could have become invalid.
569 PendingRequestInfo
& request_info
= it
->second
;
570 if (request_info
.is_deferred
)
572 // Because message handlers could result in request_info being destroyed,
573 // we need to work with a stack reference to the deferred queue.
575 q
.swap(request_info
.deferred_message_queue
);
577 IPC::Message
* m
= q
.front();
581 // If this request is deferred in the context of the above message, then
582 // we should honor the same and stop dispatching further messages.
583 // We need to find the request again in the list as it may have completed
584 // by now and the request_info instance above may be invalid.
585 PendingRequestList::iterator index
= pending_requests_
.find(request_id
);
586 if (index
!= pending_requests_
.end()) {
587 PendingRequestInfo
& pending_request
= index
->second
;
588 if (pending_request
.is_deferred
) {
589 pending_request
.deferred_message_queue
.swap(q
);
596 ResourceLoaderBridge
* ResourceDispatcher::CreateBridge(
597 const ResourceLoaderBridge::RequestInfo
& request_info
) {
598 return new IPCResourceLoaderBridge(this, request_info
);
601 void ResourceDispatcher::ToResourceResponseInfo(
602 const PendingRequestInfo
& request_info
,
603 const ResourceResponseHead
& browser_info
,
604 ResourceResponseInfo
* renderer_info
) const {
605 *renderer_info
= browser_info
;
606 if (request_info
.request_start
.is_null() ||
607 request_info
.response_start
.is_null() ||
608 browser_info
.request_start
.is_null() ||
609 browser_info
.response_start
.is_null() ||
610 browser_info
.load_timing
.base_ticks
.is_null()) {
613 InterProcessTimeTicksConverter
converter(
614 LocalTimeTicks::FromTimeTicks(request_info
.request_start
),
615 LocalTimeTicks::FromTimeTicks(request_info
.response_start
),
616 RemoteTimeTicks::FromTimeTicks(browser_info
.request_start
),
617 RemoteTimeTicks::FromTimeTicks(browser_info
.response_start
));
619 LocalTimeTicks renderer_base_ticks
= converter
.ToLocalTimeTicks(
620 RemoteTimeTicks::FromTimeTicks(browser_info
.load_timing
.base_ticks
));
621 renderer_info
->load_timing
.base_ticks
= renderer_base_ticks
.ToTimeTicks();
623 #define CONVERT(field) \
624 LocalTimeDelta renderer_##field = converter.ToLocalTimeDelta( \
625 RemoteTimeDelta::FromRawDelta(browser_info.load_timing.field)); \
626 renderer_info->load_timing.field = renderer_##field.ToInt32()
628 CONVERT(proxy_start
);
631 CONVERT(connect_start
);
632 CONVERT(connect_end
);
637 CONVERT(receive_headers_start
);
638 CONVERT(receive_headers_end
);
643 base::TimeTicks
ResourceDispatcher::ToRendererCompletionTime(
644 const PendingRequestInfo
& request_info
,
645 const base::TimeTicks
& browser_completion_time
) const {
646 if (request_info
.completion_time
.is_null()) {
647 return browser_completion_time
;
650 // TODO(simonjam): The optimal lower bound should be the most recent value of
651 // TimeTicks::Now() returned to WebKit. Is it worth trying to cache that?
652 // Until then, |response_start| is used as it is the most recent value
653 // returned for this request.
654 int64 result
= std::max(browser_completion_time
.ToInternalValue(),
655 request_info
.response_start
.ToInternalValue());
656 result
= std::min(result
, request_info
.completion_time
.ToInternalValue());
657 return base::TimeTicks::FromInternalValue(result
);
661 bool ResourceDispatcher::IsResourceDispatcherMessage(
662 const IPC::Message
& message
) {
663 switch (message
.type()) {
664 case ResourceMsg_UploadProgress::ID
:
665 case ResourceMsg_ReceivedResponse::ID
:
666 case ResourceMsg_ReceivedCachedMetadata::ID
:
667 case ResourceMsg_ReceivedRedirect::ID
:
668 case ResourceMsg_SetDataBuffer::ID
:
669 case ResourceMsg_DataReceived::ID
:
670 case ResourceMsg_DataDownloaded::ID
:
671 case ResourceMsg_RequestComplete::ID
:
682 void ResourceDispatcher::ReleaseResourcesInDataMessage(
683 const IPC::Message
& message
) {
684 PickleIterator
iter(message
);
686 if (!message
.ReadInt(&iter
, &request_id
)) {
687 NOTREACHED() << "malformed resource message";
691 // If the message contains a shared memory handle, we should close the handle
692 // or there will be a memory leak.
693 if (message
.type() == ResourceMsg_SetDataBuffer::ID
) {
694 base::SharedMemoryHandle shm_handle
;
695 if (IPC::ParamTraits
<base::SharedMemoryHandle
>::Read(&message
,
698 if (base::SharedMemory::IsHandleValid(shm_handle
))
699 base::SharedMemory::CloseHandle(shm_handle
);
705 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue
* queue
) {
706 while (!queue
->empty()) {
707 IPC::Message
* message
= queue
->front();
708 ReleaseResourcesInDataMessage(*message
);
714 } // namespace content