| 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/child/resource_dispatcher.h" | 7 #include "content/child/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" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/debug/alias.h" | 12 #include "base/debug/alias.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/memory/shared_memory.h" | 14 #include "base/memory/shared_memory.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "content/child/request_extra_data.h" | 18 #include "content/child/request_extra_data.h" |
| 19 #include "content/child/request_info.h" | 19 #include "content/child/request_info.h" |
| 20 #include "content/child/site_isolation_policy.h" | 20 #include "content/child/site_isolation_policy.h" |
| 21 #include "content/child/sync_load_response.h" | 21 #include "content/child/sync_load_response.h" |
| 22 #include "content/common/inter_process_time_ticks_converter.h" | 22 #include "content/common/inter_process_time_ticks_converter.h" |
| 23 #include "content/common/resource_messages.h" | 23 #include "content/common/resource_messages.h" |
| 24 #include "content/common/service_worker/service_worker_types.h" | 24 #include "content/common/service_worker/service_worker_types.h" |
| 25 #include "content/public/child/request_delegate_peer.h" |
| 25 #include "content/public/child/resource_dispatcher_delegate.h" | 26 #include "content/public/child/resource_dispatcher_delegate.h" |
| 26 #include "content/public/common/resource_response.h" | 27 #include "content/public/common/resource_response.h" |
| 27 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 28 #include "net/base/net_util.h" | 29 #include "net/base/net_util.h" |
| 29 #include "net/base/request_priority.h" | 30 #include "net/base/request_priority.h" |
| 30 #include "net/http/http_response_headers.h" | 31 #include "net/http/http_response_headers.h" |
| 32 #include "webkit/child/resource_loader_bridge.h" |
| 31 #include "webkit/common/resource_type.h" | 33 #include "webkit/common/resource_type.h" |
| 32 | 34 |
| 33 using webkit_glue::ResourceLoaderBridge; | 35 using webkit_glue::ResourceLoaderBridge; |
| 34 using webkit_glue::ResourceResponseInfo; | 36 using webkit_glue::ResourceResponseInfo; |
| 35 | 37 |
| 36 namespace content { | 38 namespace content { |
| 37 | 39 |
| 38 namespace { | 40 namespace { |
| 39 | 41 |
| 40 // Converts |time| from a remote to local TimeTicks, overwriting the original | 42 // Converts |time| from a remote to local TimeTicks, overwriting the original |
| (...skipping 28 matching lines...) Expand all Loading... |
| 69 // ResourceLoaderBridge implementation ---------------------------------------- | 71 // ResourceLoaderBridge implementation ---------------------------------------- |
| 70 | 72 |
| 71 class IPCResourceLoaderBridge : public ResourceLoaderBridge { | 73 class IPCResourceLoaderBridge : public ResourceLoaderBridge { |
| 72 public: | 74 public: |
| 73 IPCResourceLoaderBridge(ResourceDispatcher* dispatcher, | 75 IPCResourceLoaderBridge(ResourceDispatcher* dispatcher, |
| 74 const RequestInfo& request_info); | 76 const RequestInfo& request_info); |
| 75 virtual ~IPCResourceLoaderBridge(); | 77 virtual ~IPCResourceLoaderBridge(); |
| 76 | 78 |
| 77 // ResourceLoaderBridge | 79 // ResourceLoaderBridge |
| 78 virtual void SetRequestBody(ResourceRequestBody* request_body) OVERRIDE; | 80 virtual void SetRequestBody(ResourceRequestBody* request_body) OVERRIDE; |
| 79 virtual bool Start(Peer* peer) OVERRIDE; | 81 virtual bool Start(RequestDelegatePeer* peer) OVERRIDE; |
| 80 virtual void Cancel() OVERRIDE; | 82 virtual void Cancel() OVERRIDE; |
| 81 virtual void SetDefersLoading(bool value) OVERRIDE; | 83 virtual void SetDefersLoading(bool value) OVERRIDE; |
| 82 virtual void DidChangePriority(net::RequestPriority new_priority) OVERRIDE; | 84 virtual void DidChangePriority(net::RequestPriority new_priority) OVERRIDE; |
| 83 virtual void SyncLoad(SyncLoadResponse* response) OVERRIDE; | 85 virtual void SyncLoad(SyncLoadResponse* response) OVERRIDE; |
| 84 | 86 |
| 85 private: | 87 private: |
| 86 ResourceLoaderBridge::Peer* peer_; | 88 RequestDelegatePeer* peer_; |
| 87 | 89 |
| 88 // The resource dispatcher for this loader. The bridge doesn't own it, but | 90 // The resource dispatcher for this loader. The bridge doesn't own it, but |
| 89 // it's guaranteed to outlive the bridge. | 91 // it's guaranteed to outlive the bridge. |
| 90 ResourceDispatcher* dispatcher_; | 92 ResourceDispatcher* dispatcher_; |
| 91 | 93 |
| 92 // The request to send, created on initialization for modification and | 94 // The request to send, created on initialization for modification and |
| 93 // appending data. | 95 // appending data. |
| 94 ResourceHostMsg_Request request_; | 96 ResourceHostMsg_Request request_; |
| 95 | 97 |
| 96 // ID for the request, valid once Start()ed, -1 if not valid yet. | 98 // ID for the request, valid once Start()ed, -1 if not valid yet. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 179 } |
| 178 } | 180 } |
| 179 | 181 |
| 180 void IPCResourceLoaderBridge::SetRequestBody( | 182 void IPCResourceLoaderBridge::SetRequestBody( |
| 181 ResourceRequestBody* request_body) { | 183 ResourceRequestBody* request_body) { |
| 182 DCHECK(request_id_ == -1) << "request already started"; | 184 DCHECK(request_id_ == -1) << "request already started"; |
| 183 request_.request_body = request_body; | 185 request_.request_body = request_body; |
| 184 } | 186 } |
| 185 | 187 |
| 186 // Writes a footer on the message and sends it | 188 // Writes a footer on the message and sends it |
| 187 bool IPCResourceLoaderBridge::Start(Peer* peer) { | 189 bool IPCResourceLoaderBridge::Start(RequestDelegatePeer* peer) { |
| 188 if (request_id_ != -1) { | 190 if (request_id_ != -1) { |
| 189 NOTREACHED() << "Starting a request twice"; | 191 NOTREACHED() << "Starting a request twice"; |
| 190 return false; | 192 return false; |
| 191 } | 193 } |
| 192 | 194 |
| 193 peer_ = peer; | 195 peer_ = peer; |
| 194 | 196 |
| 195 // generate the request ID, and append it to the message | 197 // generate the request ID, and append it to the message |
| 196 request_id_ = dispatcher_->AddPendingRequest(peer_, | 198 request_id_ = dispatcher_->AddPendingRequest(peer_, |
| 197 request_.resource_type, | 199 request_.resource_type, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 350 |
| 349 void ResourceDispatcher::OnReceivedResponse( | 351 void ResourceDispatcher::OnReceivedResponse( |
| 350 int request_id, const ResourceResponseHead& response_head) { | 352 int request_id, const ResourceResponseHead& response_head) { |
| 351 TRACE_EVENT0("loader", "ResourceDispatcher::OnReceivedResponse"); | 353 TRACE_EVENT0("loader", "ResourceDispatcher::OnReceivedResponse"); |
| 352 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 354 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
| 353 if (!request_info) | 355 if (!request_info) |
| 354 return; | 356 return; |
| 355 request_info->response_start = ConsumeIOTimestamp(); | 357 request_info->response_start = ConsumeIOTimestamp(); |
| 356 | 358 |
| 357 if (delegate_) { | 359 if (delegate_) { |
| 358 ResourceLoaderBridge::Peer* new_peer = | 360 RequestDelegatePeer* new_peer = |
| 359 delegate_->OnReceivedResponse( | 361 delegate_->OnReceivedResponse( |
| 360 request_info->peer, response_head.mime_type, request_info->url); | 362 request_info->peer, response_head.mime_type, request_info->url); |
| 361 if (new_peer) | 363 if (new_peer) |
| 362 request_info->peer = new_peer; | 364 request_info->peer = new_peer; |
| 363 } | 365 } |
| 364 | 366 |
| 365 ResourceResponseInfo renderer_response_info; | 367 ResourceResponseInfo renderer_response_info; |
| 366 ToResourceResponseInfo(*request_info, response_head, &renderer_response_info); | 368 ToResourceResponseInfo(*request_info, response_head, &renderer_response_info); |
| 367 request_info->site_isolation_metadata = | 369 request_info->site_isolation_metadata = |
| 368 SiteIsolationPolicy::OnReceivedResponse(request_info->frame_origin, | 370 SiteIsolationPolicy::OnReceivedResponse(request_info->frame_origin, |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 const ResourceMsg_RequestCompleteData& request_complete_data) { | 534 const ResourceMsg_RequestCompleteData& request_complete_data) { |
| 533 TRACE_EVENT0("loader", "ResourceDispatcher::OnRequestComplete"); | 535 TRACE_EVENT0("loader", "ResourceDispatcher::OnRequestComplete"); |
| 534 | 536 |
| 535 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 537 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
| 536 if (!request_info) | 538 if (!request_info) |
| 537 return; | 539 return; |
| 538 request_info->completion_time = ConsumeIOTimestamp(); | 540 request_info->completion_time = ConsumeIOTimestamp(); |
| 539 request_info->buffer.reset(); | 541 request_info->buffer.reset(); |
| 540 request_info->buffer_size = 0; | 542 request_info->buffer_size = 0; |
| 541 | 543 |
| 542 ResourceLoaderBridge::Peer* peer = request_info->peer; | 544 RequestDelegatePeer* peer = request_info->peer; |
| 543 | 545 |
| 544 if (delegate_) { | 546 if (delegate_) { |
| 545 ResourceLoaderBridge::Peer* new_peer = | 547 RequestDelegatePeer* new_peer = |
| 546 delegate_->OnRequestComplete( | 548 delegate_->OnRequestComplete( |
| 547 request_info->peer, request_info->resource_type, | 549 request_info->peer, request_info->resource_type, |
| 548 request_complete_data.error_code); | 550 request_complete_data.error_code); |
| 549 if (new_peer) | 551 if (new_peer) |
| 550 request_info->peer = new_peer; | 552 request_info->peer = new_peer; |
| 551 } | 553 } |
| 552 | 554 |
| 553 base::TimeTicks renderer_completion_time = ToRendererCompletionTime( | 555 base::TimeTicks renderer_completion_time = ToRendererCompletionTime( |
| 554 *request_info, request_complete_data.completion_time); | 556 *request_info, request_complete_data.completion_time); |
| 555 // The request ID will be removed from our pending list in the destructor. | 557 // The request ID will be removed from our pending list in the destructor. |
| 556 // Normally, dispatching this message causes the reference-counted request to | 558 // Normally, dispatching this message causes the reference-counted request to |
| 557 // die immediately. | 559 // die immediately. |
| 558 peer->OnCompletedRequest(request_complete_data.error_code, | 560 peer->OnCompletedRequest(request_complete_data.error_code, |
| 559 request_complete_data.was_ignored_by_handler, | 561 request_complete_data.was_ignored_by_handler, |
| 560 request_complete_data.exists_in_cache, | 562 request_complete_data.exists_in_cache, |
| 561 request_complete_data.security_info, | 563 request_complete_data.security_info, |
| 562 renderer_completion_time, | 564 renderer_completion_time, |
| 563 request_complete_data.encoded_data_length); | 565 request_complete_data.encoded_data_length); |
| 564 } | 566 } |
| 565 | 567 |
| 566 int ResourceDispatcher::AddPendingRequest( | 568 int ResourceDispatcher::AddPendingRequest(RequestDelegatePeer* callback, |
| 567 ResourceLoaderBridge::Peer* callback, | 569 ResourceType::Type resource_type, |
| 568 ResourceType::Type resource_type, | 570 int origin_pid, |
| 569 int origin_pid, | 571 const GURL& frame_origin, |
| 570 const GURL& frame_origin, | 572 const GURL& request_url) { |
| 571 const GURL& request_url) { | |
| 572 // Compute a unique request_id for this renderer process. | 573 // Compute a unique request_id for this renderer process. |
| 573 int id = MakeRequestID(); | 574 int id = MakeRequestID(); |
| 574 pending_requests_[id] = PendingRequestInfo( | 575 pending_requests_[id] = PendingRequestInfo( |
| 575 callback, resource_type, origin_pid, frame_origin, request_url); | 576 callback, resource_type, origin_pid, frame_origin, request_url); |
| 576 return id; | 577 return id; |
| 577 } | 578 } |
| 578 | 579 |
| 579 bool ResourceDispatcher::RemovePendingRequest(int request_id) { | 580 bool ResourceDispatcher::RemovePendingRequest(int request_id) { |
| 580 PendingRequestList::iterator it = pending_requests_.find(request_id); | 581 PendingRequestList::iterator it = pending_requests_.find(request_id); |
| 581 if (it == pending_requests_.end()) | 582 if (it == pending_requests_.end()) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 | 632 |
| 632 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo() | 633 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo() |
| 633 : peer(NULL), | 634 : peer(NULL), |
| 634 resource_type(ResourceType::SUB_RESOURCE), | 635 resource_type(ResourceType::SUB_RESOURCE), |
| 635 is_deferred(false), | 636 is_deferred(false), |
| 636 blocked_response(false), | 637 blocked_response(false), |
| 637 buffer_size(0) { | 638 buffer_size(0) { |
| 638 } | 639 } |
| 639 | 640 |
| 640 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo( | 641 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo( |
| 641 webkit_glue::ResourceLoaderBridge::Peer* peer, | 642 RequestDelegatePeer* peer, |
| 642 ResourceType::Type resource_type, | 643 ResourceType::Type resource_type, |
| 643 int origin_pid, | 644 int origin_pid, |
| 644 const GURL& frame_origin, | 645 const GURL& frame_origin, |
| 645 const GURL& request_url) | 646 const GURL& request_url) |
| 646 : peer(peer), | 647 : peer(peer), |
| 647 resource_type(resource_type), | 648 resource_type(resource_type), |
| 648 origin_pid(origin_pid), | 649 origin_pid(origin_pid), |
| 649 is_deferred(false), | 650 is_deferred(false), |
| 650 url(request_url), | 651 url(request_url), |
| 651 frame_origin(frame_origin), | 652 frame_origin(frame_origin), |
| 652 response_url(request_url), | 653 response_url(request_url), |
| 653 request_start(base::TimeTicks::Now()), | 654 request_start(base::TimeTicks::Now()), |
| 654 blocked_response(false) { | 655 blocked_response(false) {} |
| 655 } | |
| 656 | 656 |
| 657 ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {} | 657 ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {} |
| 658 | 658 |
| 659 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { | 659 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { |
| 660 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) | 660 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) |
| 661 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress) | 661 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress) |
| 662 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse) | 662 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse) |
| 663 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata, | 663 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata, |
| 664 OnReceivedCachedMetadata) | 664 OnReceivedCachedMetadata) |
| 665 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedRedirect, OnReceivedRedirect) | 665 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedRedirect, OnReceivedRedirect) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { | 812 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { |
| 813 while (!queue->empty()) { | 813 while (!queue->empty()) { |
| 814 IPC::Message* message = queue->front(); | 814 IPC::Message* message = queue->front(); |
| 815 ReleaseResourcesInDataMessage(*message); | 815 ReleaseResourcesInDataMessage(*message); |
| 816 queue->pop_front(); | 816 queue->pop_front(); |
| 817 delete message; | 817 delete message; |
| 818 } | 818 } |
| 819 } | 819 } |
| 820 | 820 |
| 821 } // namespace content | 821 } // namespace content |
| OLD | NEW |