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 if (io_timestamp_ == base::TimeTicks()) |
339 request_info->response_start = base::TimeTicks::Now(); | |
340 else { | |
341 request_info->response_start = io_timestamp_; | |
342 io_timestamp_ = base::TimeTicks(); | |
343 } | |
338 | 344 |
339 if (delegate_) { | 345 if (delegate_) { |
340 ResourceLoaderBridge::Peer* new_peer = | 346 ResourceLoaderBridge::Peer* new_peer = |
341 delegate_->OnReceivedResponse( | 347 delegate_->OnReceivedResponse( |
342 request_info->peer, response_head.mime_type, request_info->url); | 348 request_info->peer, response_head.mime_type, request_info->url); |
343 if (new_peer) | 349 if (new_peer) |
344 request_info->peer = new_peer; | 350 request_info->peer = new_peer; |
345 } | 351 } |
346 | 352 |
347 ResourceResponseInfo renderer_response_info; | 353 ResourceResponseInfo renderer_response_info; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 } | 446 } |
441 | 447 |
442 void ResourceDispatcher::OnReceivedRedirect( | 448 void ResourceDispatcher::OnReceivedRedirect( |
443 const IPC::Message& message, | 449 const IPC::Message& message, |
444 int request_id, | 450 int request_id, |
445 const GURL& new_url, | 451 const GURL& new_url, |
446 const ResourceResponseHead& response_head) { | 452 const ResourceResponseHead& response_head) { |
447 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 453 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
448 if (!request_info) | 454 if (!request_info) |
449 return; | 455 return; |
450 request_info->response_start = base::TimeTicks::Now(); | 456 if (io_timestamp_ == base::TimeTicks()) |
457 request_info->response_start = base::TimeTicks::Now(); | |
458 else { | |
459 request_info->response_start = io_timestamp_; | |
460 io_timestamp_ = base::TimeTicks(); | |
461 } | |
451 | 462 |
452 int32 routing_id = message.routing_id(); | 463 int32 routing_id = message.routing_id(); |
453 bool has_new_first_party_for_cookies = false; | 464 bool has_new_first_party_for_cookies = false; |
454 GURL new_first_party_for_cookies; | 465 GURL new_first_party_for_cookies; |
455 ResourceResponseInfo renderer_response_info; | 466 ResourceResponseInfo renderer_response_info; |
456 ToResourceResponseInfo(*request_info, response_head, &renderer_response_info); | 467 ToResourceResponseInfo(*request_info, response_head, &renderer_response_info); |
457 if (request_info->peer->OnReceivedRedirect(new_url, renderer_response_info, | 468 if (request_info->peer->OnReceivedRedirect(new_url, renderer_response_info, |
458 &has_new_first_party_for_cookies, | 469 &has_new_first_party_for_cookies, |
459 &new_first_party_for_cookies)) { | 470 &new_first_party_for_cookies)) { |
460 // Double-check if the request is still around. The call above could | 471 // Double-check if the request is still around. The call above could |
(...skipping 23 matching lines...) Expand all Loading... | |
484 | 495 |
485 void ResourceDispatcher::OnRequestComplete( | 496 void ResourceDispatcher::OnRequestComplete( |
486 int request_id, | 497 int request_id, |
487 int error_code, | 498 int error_code, |
488 bool was_ignored_by_handler, | 499 bool was_ignored_by_handler, |
489 const std::string& security_info, | 500 const std::string& security_info, |
490 const base::TimeTicks& browser_completion_time) { | 501 const base::TimeTicks& browser_completion_time) { |
491 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 502 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
492 if (!request_info) | 503 if (!request_info) |
493 return; | 504 return; |
494 request_info->completion_time = base::TimeTicks::Now(); | 505 if (io_timestamp_ == base::TimeTicks()) |
506 request_info->completion_time = base::TimeTicks::Now(); | |
507 else { | |
508 request_info->completion_time = io_timestamp_; | |
509 io_timestamp_ = base::TimeTicks(); | |
510 } | |
Charlie Reis
2013/05/23 20:13:11
Please abstract this into a helper method rather t
eustas
2013/05/24 15:22:28
Done.
| |
495 request_info->buffer.reset(); | 511 request_info->buffer.reset(); |
496 request_info->buffer_size = 0; | 512 request_info->buffer_size = 0; |
497 | 513 |
498 ResourceLoaderBridge::Peer* peer = request_info->peer; | 514 ResourceLoaderBridge::Peer* peer = request_info->peer; |
499 | 515 |
500 if (delegate_) { | 516 if (delegate_) { |
501 ResourceLoaderBridge::Peer* new_peer = | 517 ResourceLoaderBridge::Peer* new_peer = |
502 delegate_->OnRequestComplete( | 518 delegate_->OnRequestComplete( |
503 request_info->peer, request_info->resource_type, error_code); | 519 request_info->peer, request_info->resource_type, error_code); |
504 if (new_peer) | 520 if (new_peer) |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
750 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { | 766 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { |
751 while (!queue->empty()) { | 767 while (!queue->empty()) { |
752 IPC::Message* message = queue->front(); | 768 IPC::Message* message = queue->front(); |
753 ReleaseResourcesInDataMessage(*message); | 769 ReleaseResourcesInDataMessage(*message); |
754 queue->pop_front(); | 770 queue->pop_front(); |
755 delete message; | 771 delete message; |
756 } | 772 } |
757 } | 773 } |
758 | 774 |
759 } // namespace content | 775 } // namespace content |
OLD | NEW |