OLD | NEW |
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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 response->devtools_info = result.devtools_info; | 250 response->devtools_info = result.devtools_info; |
251 response->data.swap(result.data); | 251 response->data.swap(result.data); |
252 response->download_file_path = result.download_file_path; | 252 response->download_file_path = result.download_file_path; |
253 } | 253 } |
254 | 254 |
255 // ResourceDispatcher --------------------------------------------------------- | 255 // ResourceDispatcher --------------------------------------------------------- |
256 | 256 |
257 ResourceDispatcher::ResourceDispatcher(IPC::Sender* sender) | 257 ResourceDispatcher::ResourceDispatcher(IPC::Sender* sender) |
258 : message_sender_(sender), | 258 : message_sender_(sender), |
259 weak_factory_(this), | 259 weak_factory_(this), |
260 delegate_(NULL) { | 260 delegate_(NULL), |
| 261 io_timestamp_(base::TimeTicks()) { |
261 } | 262 } |
262 | 263 |
263 ResourceDispatcher::~ResourceDispatcher() { | 264 ResourceDispatcher::~ResourceDispatcher() { |
264 } | 265 } |
265 | 266 |
266 // ResourceDispatcher implementation ------------------------------------------ | 267 // ResourceDispatcher implementation ------------------------------------------ |
267 | 268 |
268 bool ResourceDispatcher::OnMessageReceived(const IPC::Message& message) { | 269 bool ResourceDispatcher::OnMessageReceived(const IPC::Message& message) { |
269 if (!IsResourceDispatcherMessage(message)) { | 270 if (!IsResourceDispatcherMessage(message)) { |
270 return false; | 271 return false; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 // Acknowledge receipt | 328 // Acknowledge receipt |
328 message_sender()->Send( | 329 message_sender()->Send( |
329 new ResourceHostMsg_UploadProgress_ACK(message.routing_id(), request_id)); | 330 new ResourceHostMsg_UploadProgress_ACK(message.routing_id(), request_id)); |
330 } | 331 } |
331 | 332 |
332 void ResourceDispatcher::OnReceivedResponse( | 333 void ResourceDispatcher::OnReceivedResponse( |
333 int request_id, const ResourceResponseHead& response_head) { | 334 int request_id, const ResourceResponseHead& response_head) { |
334 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 335 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
335 if (!request_info) | 336 if (!request_info) |
336 return; | 337 return; |
337 request_info->response_start = base::TimeTicks::Now(); | 338 request_info->response_start = consume_io_timestamp(); |
338 | 339 |
339 if (delegate_) { | 340 if (delegate_) { |
340 ResourceLoaderBridge::Peer* new_peer = | 341 ResourceLoaderBridge::Peer* new_peer = |
341 delegate_->OnReceivedResponse( | 342 delegate_->OnReceivedResponse( |
342 request_info->peer, response_head.mime_type, request_info->url); | 343 request_info->peer, response_head.mime_type, request_info->url); |
343 if (new_peer) | 344 if (new_peer) |
344 request_info->peer = new_peer; | 345 request_info->peer = new_peer; |
345 } | 346 } |
346 | 347 |
347 ResourceResponseInfo renderer_response_info; | 348 ResourceResponseInfo renderer_response_info; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 } | 441 } |
441 | 442 |
442 void ResourceDispatcher::OnReceivedRedirect( | 443 void ResourceDispatcher::OnReceivedRedirect( |
443 const IPC::Message& message, | 444 const IPC::Message& message, |
444 int request_id, | 445 int request_id, |
445 const GURL& new_url, | 446 const GURL& new_url, |
446 const ResourceResponseHead& response_head) { | 447 const ResourceResponseHead& response_head) { |
447 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 448 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
448 if (!request_info) | 449 if (!request_info) |
449 return; | 450 return; |
450 request_info->response_start = base::TimeTicks::Now(); | 451 request_info->response_start = consume_io_timestamp(); |
451 | 452 |
452 int32 routing_id = message.routing_id(); | 453 int32 routing_id = message.routing_id(); |
453 bool has_new_first_party_for_cookies = false; | 454 bool has_new_first_party_for_cookies = false; |
454 GURL new_first_party_for_cookies; | 455 GURL new_first_party_for_cookies; |
455 ResourceResponseInfo renderer_response_info; | 456 ResourceResponseInfo renderer_response_info; |
456 ToResourceResponseInfo(*request_info, response_head, &renderer_response_info); | 457 ToResourceResponseInfo(*request_info, response_head, &renderer_response_info); |
457 if (request_info->peer->OnReceivedRedirect(new_url, renderer_response_info, | 458 if (request_info->peer->OnReceivedRedirect(new_url, renderer_response_info, |
458 &has_new_first_party_for_cookies, | 459 &has_new_first_party_for_cookies, |
459 &new_first_party_for_cookies)) { | 460 &new_first_party_for_cookies)) { |
460 // Double-check if the request is still around. The call above could | 461 // Double-check if the request is still around. The call above could |
(...skipping 23 matching lines...) Expand all Loading... |
484 | 485 |
485 void ResourceDispatcher::OnRequestComplete( | 486 void ResourceDispatcher::OnRequestComplete( |
486 int request_id, | 487 int request_id, |
487 int error_code, | 488 int error_code, |
488 bool was_ignored_by_handler, | 489 bool was_ignored_by_handler, |
489 const std::string& security_info, | 490 const std::string& security_info, |
490 const base::TimeTicks& browser_completion_time) { | 491 const base::TimeTicks& browser_completion_time) { |
491 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 492 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
492 if (!request_info) | 493 if (!request_info) |
493 return; | 494 return; |
494 request_info->completion_time = base::TimeTicks::Now(); | 495 request_info->completion_time = consume_io_timestamp(); |
495 request_info->buffer.reset(); | 496 request_info->buffer.reset(); |
496 request_info->buffer_size = 0; | 497 request_info->buffer_size = 0; |
497 | 498 |
498 ResourceLoaderBridge::Peer* peer = request_info->peer; | 499 ResourceLoaderBridge::Peer* peer = request_info->peer; |
499 | 500 |
500 if (delegate_) { | 501 if (delegate_) { |
501 ResourceLoaderBridge::Peer* new_peer = | 502 ResourceLoaderBridge::Peer* new_peer = |
502 delegate_->OnRequestComplete( | 503 delegate_->OnRequestComplete( |
503 request_info->peer, request_info->resource_type, error_code); | 504 request_info->peer, request_info->resource_type, error_code); |
504 if (new_peer) | 505 if (new_peer) |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 // TODO(simonjam): The optimal lower bound should be the most recent value of | 696 // TODO(simonjam): The optimal lower bound should be the most recent value of |
696 // TimeTicks::Now() returned to WebKit. Is it worth trying to cache that? | 697 // TimeTicks::Now() returned to WebKit. Is it worth trying to cache that? |
697 // Until then, |response_start| is used as it is the most recent value | 698 // Until then, |response_start| is used as it is the most recent value |
698 // returned for this request. | 699 // returned for this request. |
699 int64 result = std::max(browser_completion_time.ToInternalValue(), | 700 int64 result = std::max(browser_completion_time.ToInternalValue(), |
700 request_info.response_start.ToInternalValue()); | 701 request_info.response_start.ToInternalValue()); |
701 result = std::min(result, request_info.completion_time.ToInternalValue()); | 702 result = std::min(result, request_info.completion_time.ToInternalValue()); |
702 return base::TimeTicks::FromInternalValue(result); | 703 return base::TimeTicks::FromInternalValue(result); |
703 } | 704 } |
704 | 705 |
| 706 base::TimeTicks ResourceDispatcher::consume_io_timestamp() { |
| 707 if (io_timestamp_ == base::TimeTicks()) |
| 708 return base::TimeTicks::Now(); |
| 709 base::TimeTicks result = io_timestamp_; |
| 710 io_timestamp_ = base::TimeTicks(); |
| 711 return result; |
| 712 } |
| 713 |
705 // static | 714 // static |
706 bool ResourceDispatcher::IsResourceDispatcherMessage( | 715 bool ResourceDispatcher::IsResourceDispatcherMessage( |
707 const IPC::Message& message) { | 716 const IPC::Message& message) { |
708 switch (message.type()) { | 717 switch (message.type()) { |
709 case ResourceMsg_UploadProgress::ID: | 718 case ResourceMsg_UploadProgress::ID: |
710 case ResourceMsg_ReceivedResponse::ID: | 719 case ResourceMsg_ReceivedResponse::ID: |
711 case ResourceMsg_ReceivedCachedMetadata::ID: | 720 case ResourceMsg_ReceivedCachedMetadata::ID: |
712 case ResourceMsg_ReceivedRedirect::ID: | 721 case ResourceMsg_ReceivedRedirect::ID: |
713 case ResourceMsg_SetDataBuffer::ID: | 722 case ResourceMsg_SetDataBuffer::ID: |
714 case ResourceMsg_DataReceived::ID: | 723 case ResourceMsg_DataReceived::ID: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { | 759 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { |
751 while (!queue->empty()) { | 760 while (!queue->empty()) { |
752 IPC::Message* message = queue->front(); | 761 IPC::Message* message = queue->front(); |
753 ReleaseResourcesInDataMessage(*message); | 762 ReleaseResourcesInDataMessage(*message); |
754 queue->pop_front(); | 763 queue->pop_front(); |
755 delete message; | 764 delete message; |
756 } | 765 } |
757 } | 766 } |
758 | 767 |
759 } // namespace content | 768 } // namespace content |
OLD | NEW |