OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "chrome/common/render_messages.h" | |
16 #include "chrome/common/render_messages_params.h" | |
17 #include "chrome/common/resource_response.h" | |
18 #include "chrome/common/security_filter_peer.h" | 15 #include "chrome/common/security_filter_peer.h" |
| 16 #include "content/common/resource_response.h" |
| 17 #include "content/common/resource_messages.h" |
19 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
20 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
21 #include "net/base/upload_data.h" | 20 #include "net/base/upload_data.h" |
22 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
23 #include "webkit/glue/resource_type.h" | 22 #include "webkit/glue/resource_type.h" |
24 #include "webkit/glue/webkit_glue.h" | 23 #include "webkit/glue/webkit_glue.h" |
25 | 24 |
26 // Each resource request is assigned an ID scoped to this process. | 25 // Each resource request is assigned an ID scoped to this process. |
27 static int MakeRequestID() { | 26 static int MakeRequestID() { |
28 // NOTE: The resource_dispatcher_host also needs probably unique | 27 // NOTE: The resource_dispatcher_host also needs probably unique |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 59 |
61 private: | 60 private: |
62 ResourceLoaderBridge::Peer* peer_; | 61 ResourceLoaderBridge::Peer* peer_; |
63 | 62 |
64 // The resource dispatcher for this loader. The bridge doesn't own it, but | 63 // The resource dispatcher for this loader. The bridge doesn't own it, but |
65 // it's guaranteed to outlive the bridge. | 64 // it's guaranteed to outlive the bridge. |
66 ResourceDispatcher* dispatcher_; | 65 ResourceDispatcher* dispatcher_; |
67 | 66 |
68 // The request to send, created on initialization for modification and | 67 // The request to send, created on initialization for modification and |
69 // appending data. | 68 // appending data. |
70 ViewHostMsg_Resource_Request request_; | 69 ResourceHostMsg_Request request_; |
71 | 70 |
72 // ID for the request, valid once Start()ed, -1 if not valid yet. | 71 // ID for the request, valid once Start()ed, -1 if not valid yet. |
73 int request_id_; | 72 int request_id_; |
74 | 73 |
75 // The routing id used when sending IPC messages. | 74 // The routing id used when sending IPC messages. |
76 int routing_id_; | 75 int routing_id_; |
77 | 76 |
78 // The following two members are specified if the request is initiated by | 77 // The following two members are specified if the request is initiated by |
79 // a plugin like Gears. | 78 // a plugin like Gears. |
80 | 79 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 IPCResourceLoaderBridge::~IPCResourceLoaderBridge() { | 115 IPCResourceLoaderBridge::~IPCResourceLoaderBridge() { |
117 // we remove our hook for the resource dispatcher only when going away, since | 116 // we remove our hook for the resource dispatcher only when going away, since |
118 // it doesn't keep track of whether we've force terminated the request | 117 // it doesn't keep track of whether we've force terminated the request |
119 if (request_id_ >= 0) { | 118 if (request_id_ >= 0) { |
120 // this operation may fail, as the dispatcher will have preemptively | 119 // this operation may fail, as the dispatcher will have preemptively |
121 // removed us when the renderer sends the ReceivedAllData message. | 120 // removed us when the renderer sends the ReceivedAllData message. |
122 dispatcher_->RemovePendingRequest(request_id_); | 121 dispatcher_->RemovePendingRequest(request_id_); |
123 | 122 |
124 if (request_.download_to_file) { | 123 if (request_.download_to_file) { |
125 dispatcher_->message_sender()->Send( | 124 dispatcher_->message_sender()->Send( |
126 new ViewHostMsg_ReleaseDownloadedFile(request_id_)); | 125 new ResourceHostMsg_ReleaseDownloadedFile(request_id_)); |
127 } | 126 } |
128 } | 127 } |
129 } | 128 } |
130 | 129 |
131 void IPCResourceLoaderBridge::AppendDataToUpload(const char* data, | 130 void IPCResourceLoaderBridge::AppendDataToUpload(const char* data, |
132 int data_len) { | 131 int data_len) { |
133 DCHECK(request_id_ == -1) << "request already started"; | 132 DCHECK(request_id_ == -1) << "request already started"; |
134 | 133 |
135 // don't bother appending empty data segments | 134 // don't bother appending empty data segments |
136 if (data_len == 0) | 135 if (data_len == 0) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 return false; | 174 return false; |
176 } | 175 } |
177 | 176 |
178 peer_ = peer; | 177 peer_ = peer; |
179 | 178 |
180 // generate the request ID, and append it to the message | 179 // generate the request ID, and append it to the message |
181 request_id_ = dispatcher_->AddPendingRequest( | 180 request_id_ = dispatcher_->AddPendingRequest( |
182 peer_, request_.resource_type, request_.url); | 181 peer_, request_.resource_type, request_.url); |
183 | 182 |
184 return dispatcher_->message_sender()->Send( | 183 return dispatcher_->message_sender()->Send( |
185 new ViewHostMsg_RequestResource(routing_id_, request_id_, request_)); | 184 new ResourceHostMsg_RequestResource(routing_id_, request_id_, request_)); |
186 } | 185 } |
187 | 186 |
188 void IPCResourceLoaderBridge::Cancel() { | 187 void IPCResourceLoaderBridge::Cancel() { |
189 if (request_id_ < 0) { | 188 if (request_id_ < 0) { |
190 NOTREACHED() << "Trying to cancel an unstarted request"; | 189 NOTREACHED() << "Trying to cancel an unstarted request"; |
191 return; | 190 return; |
192 } | 191 } |
193 | 192 |
194 dispatcher_->CancelPendingRequest(routing_id_, request_id_); | 193 dispatcher_->CancelPendingRequest(routing_id_, request_id_); |
195 | 194 |
(...skipping 14 matching lines...) Expand all Loading... |
210 void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) { | 209 void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) { |
211 if (request_id_ != -1) { | 210 if (request_id_ != -1) { |
212 NOTREACHED() << "Starting a request twice"; | 211 NOTREACHED() << "Starting a request twice"; |
213 response->status.set_status(net::URLRequestStatus::FAILED); | 212 response->status.set_status(net::URLRequestStatus::FAILED); |
214 return; | 213 return; |
215 } | 214 } |
216 | 215 |
217 request_id_ = MakeRequestID(); | 216 request_id_ = MakeRequestID(); |
218 | 217 |
219 SyncLoadResult result; | 218 SyncLoadResult result; |
220 IPC::SyncMessage* msg = new ViewHostMsg_SyncLoad(routing_id_, request_id_, | 219 IPC::SyncMessage* msg = new ResourceHostMsg_SyncLoad(routing_id_, request_id_, |
221 request_, &result); | 220 request_, &result); |
222 // NOTE: This may pump events (see RenderThread::Send). | 221 // NOTE: This may pump events (see RenderThread::Send). |
223 if (!dispatcher_->message_sender()->Send(msg)) { | 222 if (!dispatcher_->message_sender()->Send(msg)) { |
224 response->status.set_status(net::URLRequestStatus::FAILED); | 223 response->status.set_status(net::URLRequestStatus::FAILED); |
225 return; | 224 return; |
226 } | 225 } |
227 | 226 |
228 response->status = result.status; | 227 response->status = result.status; |
229 response->url = result.final_url; | 228 response->url = result.final_url; |
230 response->headers = result.headers; | 229 response->headers = result.headers; |
231 response->mime_type = result.mime_type; | 230 response->mime_type = result.mime_type; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 void ResourceDispatcher::OnUploadProgress( | 309 void ResourceDispatcher::OnUploadProgress( |
311 const IPC::Message& message, int request_id, int64 position, int64 size) { | 310 const IPC::Message& message, int request_id, int64 position, int64 size) { |
312 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 311 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
313 if (!request_info) | 312 if (!request_info) |
314 return; | 313 return; |
315 | 314 |
316 request_info->peer->OnUploadProgress(position, size); | 315 request_info->peer->OnUploadProgress(position, size); |
317 | 316 |
318 // Acknowledge receipt | 317 // Acknowledge receipt |
319 message_sender()->Send( | 318 message_sender()->Send( |
320 new ViewHostMsg_UploadProgress_ACK(message.routing_id(), request_id)); | 319 new ResourceHostMsg_UploadProgress_ACK(message.routing_id(), request_id)); |
321 } | 320 } |
322 | 321 |
323 void ResourceDispatcher::OnReceivedResponse( | 322 void ResourceDispatcher::OnReceivedResponse( |
324 int request_id, const ResourceResponseHead& response_head) { | 323 int request_id, const ResourceResponseHead& response_head) { |
325 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 324 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
326 if (!request_info) | 325 if (!request_info) |
327 return; | 326 return; |
328 | 327 |
329 webkit_glue::ResourceLoaderBridge::Peer* new_peer = webkit_glue::ReplacePeer( | 328 webkit_glue::ResourceLoaderBridge::Peer* new_peer = webkit_glue::ReplacePeer( |
330 request_info->peer, response_head.mime_type, request_info->url); | 329 request_info->peer, response_head.mime_type, request_info->url); |
(...skipping 12 matching lines...) Expand all Loading... |
343 if (data.size()) | 342 if (data.size()) |
344 request_info->peer->OnReceivedCachedMetadata(&data.front(), data.size()); | 343 request_info->peer->OnReceivedCachedMetadata(&data.front(), data.size()); |
345 } | 344 } |
346 | 345 |
347 void ResourceDispatcher::OnReceivedData(const IPC::Message& message, | 346 void ResourceDispatcher::OnReceivedData(const IPC::Message& message, |
348 int request_id, | 347 int request_id, |
349 base::SharedMemoryHandle shm_handle, | 348 base::SharedMemoryHandle shm_handle, |
350 int data_len) { | 349 int data_len) { |
351 // Acknowledge the reception of this data. | 350 // Acknowledge the reception of this data. |
352 message_sender()->Send( | 351 message_sender()->Send( |
353 new ViewHostMsg_DataReceived_ACK(message.routing_id(), request_id)); | 352 new ResourceHostMsg_DataReceived_ACK(message.routing_id(), request_id)); |
354 | 353 |
355 const bool shm_valid = base::SharedMemory::IsHandleValid(shm_handle); | 354 const bool shm_valid = base::SharedMemory::IsHandleValid(shm_handle); |
356 DCHECK((shm_valid && data_len > 0) || (!shm_valid && !data_len)); | 355 DCHECK((shm_valid && data_len > 0) || (!shm_valid && !data_len)); |
357 base::SharedMemory shared_mem(shm_handle, true); // read only | 356 base::SharedMemory shared_mem(shm_handle, true); // read only |
358 | 357 |
359 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 358 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
360 if (!request_info) | 359 if (!request_info) |
361 return; | 360 return; |
362 | 361 |
363 if (data_len > 0 && shared_mem.Map(data_len)) { | 362 if (data_len > 0 && shared_mem.Map(data_len)) { |
364 const char* data = static_cast<char*>(shared_mem.memory()); | 363 const char* data = static_cast<char*>(shared_mem.memory()); |
365 request_info->peer->OnReceivedData(data, data_len); | 364 request_info->peer->OnReceivedData(data, data_len); |
366 } | 365 } |
367 } | 366 } |
368 | 367 |
369 void ResourceDispatcher::OnDownloadedData(const IPC::Message& message, | 368 void ResourceDispatcher::OnDownloadedData(const IPC::Message& message, |
370 int request_id, | 369 int request_id, |
371 int data_len) { | 370 int data_len) { |
372 // Acknowledge the reception of this message. | 371 // Acknowledge the reception of this message. |
373 message_sender()->Send( | 372 message_sender()->Send( |
374 new ViewHostMsg_DataDownloaded_ACK(message.routing_id(), request_id)); | 373 new ResourceHostMsg_DataDownloaded_ACK(message.routing_id(), request_id)); |
375 | 374 |
376 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 375 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
377 if (!request_info) | 376 if (!request_info) |
378 return; | 377 return; |
379 | 378 |
380 request_info->peer->OnDownloadedData(data_len); | 379 request_info->peer->OnDownloadedData(data_len); |
381 } | 380 } |
382 | 381 |
383 void ResourceDispatcher::OnReceivedRedirect( | 382 void ResourceDispatcher::OnReceivedRedirect( |
384 const IPC::Message& message, | 383 const IPC::Message& message, |
385 int request_id, | 384 int request_id, |
386 const GURL& new_url, | 385 const GURL& new_url, |
387 const webkit_glue::ResourceResponseInfo& info) { | 386 const webkit_glue::ResourceResponseInfo& info) { |
388 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 387 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
389 if (!request_info) | 388 if (!request_info) |
390 return; | 389 return; |
391 | 390 |
392 int32 routing_id = message.routing_id(); | 391 int32 routing_id = message.routing_id(); |
393 bool has_new_first_party_for_cookies = false; | 392 bool has_new_first_party_for_cookies = false; |
394 GURL new_first_party_for_cookies; | 393 GURL new_first_party_for_cookies; |
395 if (request_info->peer->OnReceivedRedirect(new_url, info, | 394 if (request_info->peer->OnReceivedRedirect(new_url, info, |
396 &has_new_first_party_for_cookies, | 395 &has_new_first_party_for_cookies, |
397 &new_first_party_for_cookies)) { | 396 &new_first_party_for_cookies)) { |
398 // Double-check if the request is still around. The call above could | 397 // Double-check if the request is still around. The call above could |
399 // potentially remove it. | 398 // potentially remove it. |
400 request_info = GetPendingRequestInfo(request_id); | 399 request_info = GetPendingRequestInfo(request_id); |
401 if (!request_info) | 400 if (!request_info) |
402 return; | 401 return; |
403 request_info->pending_redirect_message.reset( | 402 request_info->pending_redirect_message.reset( |
404 new ViewHostMsg_FollowRedirect(routing_id, request_id, | 403 new ResourceHostMsg_FollowRedirect(routing_id, request_id, |
405 has_new_first_party_for_cookies, | 404 has_new_first_party_for_cookies, |
406 new_first_party_for_cookies)); | 405 new_first_party_for_cookies)); |
407 if (!request_info->is_deferred) { | 406 if (!request_info->is_deferred) { |
408 FollowPendingRedirect(request_id, *request_info); | 407 FollowPendingRedirect(request_id, *request_info); |
409 } | 408 } |
410 } else { | 409 } else { |
411 CancelPendingRequest(routing_id, request_id); | 410 CancelPendingRequest(routing_id, request_id); |
412 } | 411 } |
413 } | 412 } |
414 | 413 |
415 void ResourceDispatcher::FollowPendingRedirect( | 414 void ResourceDispatcher::FollowPendingRedirect( |
416 int request_id, | 415 int request_id, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 if (it == pending_requests_.end()) { | 480 if (it == pending_requests_.end()) { |
482 DLOG(WARNING) << "unknown request"; | 481 DLOG(WARNING) << "unknown request"; |
483 return; | 482 return; |
484 } | 483 } |
485 | 484 |
486 PendingRequestInfo& request_info = it->second; | 485 PendingRequestInfo& request_info = it->second; |
487 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue); | 486 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue); |
488 pending_requests_.erase(it); | 487 pending_requests_.erase(it); |
489 | 488 |
490 message_sender()->Send( | 489 message_sender()->Send( |
491 new ViewHostMsg_CancelRequest(routing_id, request_id)); | 490 new ResourceHostMsg_CancelRequest(routing_id, request_id)); |
492 } | 491 } |
493 | 492 |
494 void ResourceDispatcher::SetDefersLoading(int request_id, bool value) { | 493 void ResourceDispatcher::SetDefersLoading(int request_id, bool value) { |
495 PendingRequestList::iterator it = pending_requests_.find(request_id); | 494 PendingRequestList::iterator it = pending_requests_.find(request_id); |
496 if (it == pending_requests_.end()) { | 495 if (it == pending_requests_.end()) { |
497 DLOG(ERROR) << "unknown request"; | 496 DLOG(ERROR) << "unknown request"; |
498 return; | 497 return; |
499 } | 498 } |
500 PendingRequestInfo& request_info = it->second; | 499 PendingRequestInfo& request_info = it->second; |
501 if (value) { | 500 if (value) { |
502 request_info.is_deferred = value; | 501 request_info.is_deferred = value; |
503 } else if (request_info.is_deferred) { | 502 } else if (request_info.is_deferred) { |
504 request_info.is_deferred = false; | 503 request_info.is_deferred = false; |
505 | 504 |
506 FollowPendingRedirect(request_id, request_info); | 505 FollowPendingRedirect(request_id, request_info); |
507 | 506 |
508 MessageLoop::current()->PostTask(FROM_HERE, | 507 MessageLoop::current()->PostTask(FROM_HERE, |
509 method_factory_.NewRunnableMethod( | 508 method_factory_.NewRunnableMethod( |
510 &ResourceDispatcher::FlushDeferredMessages, request_id)); | 509 &ResourceDispatcher::FlushDeferredMessages, request_id)); |
511 } | 510 } |
512 } | 511 } |
513 | 512 |
514 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { | 513 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { |
515 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) | 514 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) |
516 IPC_MESSAGE_HANDLER(ViewMsg_Resource_UploadProgress, OnUploadProgress) | 515 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress) |
517 IPC_MESSAGE_HANDLER(ViewMsg_Resource_ReceivedResponse, OnReceivedResponse) | 516 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse) |
518 IPC_MESSAGE_HANDLER( | 517 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata, |
519 ViewMsg_Resource_ReceivedCachedMetadata, OnReceivedCachedMetadata) | 518 OnReceivedCachedMetadata) |
520 IPC_MESSAGE_HANDLER(ViewMsg_Resource_ReceivedRedirect, OnReceivedRedirect) | 519 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedRedirect, OnReceivedRedirect) |
521 IPC_MESSAGE_HANDLER(ViewMsg_Resource_DataReceived, OnReceivedData) | 520 IPC_MESSAGE_HANDLER(ResourceMsg_DataReceived, OnReceivedData) |
522 IPC_MESSAGE_HANDLER(ViewMsg_Resource_DataDownloaded, OnDownloadedData) | 521 IPC_MESSAGE_HANDLER(ResourceMsg_DataDownloaded, OnDownloadedData) |
523 IPC_MESSAGE_HANDLER(ViewMsg_Resource_RequestComplete, OnRequestComplete) | 522 IPC_MESSAGE_HANDLER(ResourceMsg_RequestComplete, OnRequestComplete) |
524 IPC_END_MESSAGE_MAP() | 523 IPC_END_MESSAGE_MAP() |
525 } | 524 } |
526 | 525 |
527 void ResourceDispatcher::FlushDeferredMessages(int request_id) { | 526 void ResourceDispatcher::FlushDeferredMessages(int request_id) { |
528 PendingRequestList::iterator it = pending_requests_.find(request_id); | 527 PendingRequestList::iterator it = pending_requests_.find(request_id); |
529 if (it == pending_requests_.end()) // The request could have become invalid. | 528 if (it == pending_requests_.end()) // The request could have become invalid. |
530 return; | 529 return; |
531 PendingRequestInfo& request_info = it->second; | 530 PendingRequestInfo& request_info = it->second; |
532 if (request_info.is_deferred) | 531 if (request_info.is_deferred) |
533 return; | 532 return; |
(...skipping 26 matching lines...) Expand all Loading... |
560 int host_renderer_id, | 559 int host_renderer_id, |
561 int host_render_view_id) { | 560 int host_render_view_id) { |
562 return new webkit_glue::IPCResourceLoaderBridge(this, request_info, | 561 return new webkit_glue::IPCResourceLoaderBridge(this, request_info, |
563 host_renderer_id, | 562 host_renderer_id, |
564 host_render_view_id); | 563 host_render_view_id); |
565 } | 564 } |
566 | 565 |
567 bool ResourceDispatcher::IsResourceDispatcherMessage( | 566 bool ResourceDispatcher::IsResourceDispatcherMessage( |
568 const IPC::Message& message) { | 567 const IPC::Message& message) { |
569 switch (message.type()) { | 568 switch (message.type()) { |
570 case ViewMsg_Resource_UploadProgress::ID: | 569 case ResourceMsg_UploadProgress::ID: |
571 case ViewMsg_Resource_ReceivedResponse::ID: | 570 case ResourceMsg_ReceivedResponse::ID: |
572 case ViewMsg_Resource_ReceivedCachedMetadata::ID: | 571 case ResourceMsg_ReceivedCachedMetadata::ID: |
573 case ViewMsg_Resource_ReceivedRedirect::ID: | 572 case ResourceMsg_ReceivedRedirect::ID: |
574 case ViewMsg_Resource_DataReceived::ID: | 573 case ResourceMsg_DataReceived::ID: |
575 case ViewMsg_Resource_DataDownloaded::ID: | 574 case ResourceMsg_DataDownloaded::ID: |
576 case ViewMsg_Resource_RequestComplete::ID: | 575 case ResourceMsg_RequestComplete::ID: |
577 return true; | 576 return true; |
578 | 577 |
579 default: | 578 default: |
580 break; | 579 break; |
581 } | 580 } |
582 | 581 |
583 return false; | 582 return false; |
584 } | 583 } |
585 | 584 |
586 // static | 585 // static |
587 void ResourceDispatcher::ReleaseResourcesInDataMessage( | 586 void ResourceDispatcher::ReleaseResourcesInDataMessage( |
588 const IPC::Message& message) { | 587 const IPC::Message& message) { |
589 void* iter = NULL; | 588 void* iter = NULL; |
590 int request_id; | 589 int request_id; |
591 if (!message.ReadInt(&iter, &request_id)) { | 590 if (!message.ReadInt(&iter, &request_id)) { |
592 NOTREACHED() << "malformed resource message"; | 591 NOTREACHED() << "malformed resource message"; |
593 return; | 592 return; |
594 } | 593 } |
595 | 594 |
596 // If the message contains a shared memory handle, we should close the | 595 // If the message contains a shared memory handle, we should close the |
597 // handle or there will be a memory leak. | 596 // handle or there will be a memory leak. |
598 if (message.type() == ViewMsg_Resource_DataReceived::ID) { | 597 if (message.type() == ResourceMsg_DataReceived::ID) { |
599 base::SharedMemoryHandle shm_handle; | 598 base::SharedMemoryHandle shm_handle; |
600 if (IPC::ParamTraits<base::SharedMemoryHandle>::Read(&message, | 599 if (IPC::ParamTraits<base::SharedMemoryHandle>::Read(&message, |
601 &iter, | 600 &iter, |
602 &shm_handle)) { | 601 &shm_handle)) { |
603 base::SharedMemory::CloseHandle(shm_handle); | 602 base::SharedMemory::CloseHandle(shm_handle); |
604 } | 603 } |
605 } | 604 } |
606 } | 605 } |
607 | 606 |
608 // static | 607 // static |
609 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { | 608 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { |
610 while (!queue->empty()) { | 609 while (!queue->empty()) { |
611 IPC::Message* message = queue->front(); | 610 IPC::Message* message = queue->front(); |
612 ReleaseResourcesInDataMessage(*message); | 611 ReleaseResourcesInDataMessage(*message); |
613 queue->pop_front(); | 612 queue->pop_front(); |
614 delete message; | 613 delete message; |
615 } | 614 } |
616 } | 615 } |
OLD | NEW |