Chromium Code Reviews| Index: content/child/resource_dispatcher.cc |
| diff --git a/content/child/resource_dispatcher.cc b/content/child/resource_dispatcher.cc |
| index 05603a5140fc99172fa9a202350b3e4f1ad38016..37916eae1d255e7b474e21c35d71489f08904c00 100644 |
| --- a/content/child/resource_dispatcher.cc |
| +++ b/content/child/resource_dispatcher.cc |
| @@ -28,6 +28,7 @@ |
| #include "content/child/shared_memory_received_data_factory.h" |
| #include "content/child/site_isolation_stats_gatherer.h" |
| #include "content/child/sync_load_response.h" |
| +#include "content/child/url_response_body_consumer.h" |
| #include "content/common/inter_process_time_ticks_converter.h" |
| #include "content/common/navigation_params.h" |
| #include "content/common/resource_messages.h" |
| @@ -39,6 +40,7 @@ |
| #include "content/public/common/content_features.h" |
| #include "content/public/common/resource_response.h" |
| #include "content/public/common/resource_type.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| #include "net/base/net_errors.h" |
| #include "net/base/request_priority.h" |
| #include "net/http/http_response_headers.h" |
| @@ -73,6 +75,40 @@ int MakeRequestID() { |
| return next_request_id++; |
| } |
| +class URLLoaderClientImpl final : public mojom::URLLoaderClient { |
| + public: |
| + URLLoaderClientImpl(int request_id, ResourceDispatcher* resource_dispatcher) |
| + : binding_(this), |
| + request_id_(request_id), |
| + resource_dispatcher_(resource_dispatcher) {} |
| + ~URLLoaderClientImpl() override { |
| + if (body_consumer_) |
| + body_consumer_->Cancel(); |
| + } |
| + |
| + void OnReceiveResponse(const ResourceResponseHead& response_head, |
| + mojo::ScopedDataPipeConsumerHandle body) override { |
| + body_consumer_ = new URLResponseBodyConsumer( |
|
kinuko
2016/05/20 09:38:51
nit: DCHECK(!body_consumer_) to make sure?
yhirano
2016/05/20 11:32:54
Done.
|
| + request_id_, resource_dispatcher_, std::move(body)); |
| + |
| + resource_dispatcher_->OnMessageReceived( |
| + ResourceMsg_ReceivedResponse(request_id_, response_head)); |
| + } |
| + void OnComplete(const ResourceRequestCompletionStatus& status) override { |
| + body_consumer_->OnComplete(status); |
| + } |
| + |
| + mojom::URLLoaderClientPtr CreateInterfacePtrAndBind() { |
| + return binding_.CreateInterfacePtrAndBind(); |
| + } |
| + |
| + private: |
| + mojo::Binding<mojom::URLLoaderClient> binding_; |
| + scoped_refptr<URLResponseBodyConsumer> body_consumer_; |
| + const int request_id_; |
| + ResourceDispatcher* const resource_dispatcher_; |
| +}; |
| + |
| } // namespace |
| ResourceDispatcher::ResourceDispatcher( |
| @@ -544,7 +580,8 @@ void ResourceDispatcher::FlushDeferredMessages(int request_id) { |
| void ResourceDispatcher::StartSync(const RequestInfo& request_info, |
| ResourceRequestBody* request_body, |
| - SyncLoadResponse* response) { |
| + SyncLoadResponse* response, |
| + mojom::URLLoaderPtr url_loader) { |
|
kinuko
2016/05/20 09:38:51
This one's not used (yet), but you still wanted to
yhirano
2016/05/20 11:32:54
Yes.
|
| std::unique_ptr<ResourceRequest> request = |
| CreateRequest(request_info, request_body, NULL); |
| @@ -575,7 +612,8 @@ void ResourceDispatcher::StartSync(const RequestInfo& request_info, |
| int ResourceDispatcher::StartAsync(const RequestInfo& request_info, |
| ResourceRequestBody* request_body, |
| - std::unique_ptr<RequestPeer> peer) { |
| + std::unique_ptr<RequestPeer> peer, |
| + mojom::URLLoaderPtr url_loader) { |
| GURL frame_origin; |
| std::unique_ptr<ResourceRequest> request = |
| CreateRequest(request_info, request_body, &frame_origin); |
| @@ -593,8 +631,17 @@ int ResourceDispatcher::StartAsync(const RequestInfo& request_info, |
| base::WrapUnique(request_info.loading_web_task_runner->clone())); |
| } |
| - message_sender_->Send(new ResourceHostMsg_RequestResource( |
| - request_info.routing_id, request_id, *request)); |
| + if (url_loader) { |
| + std::unique_ptr<URLLoaderClientImpl> client( |
| + new URLLoaderClientImpl(request_id, this)); |
| + url_loader->Load(request_id, *request, |
| + client->CreateInterfacePtrAndBind()); |
| + pending_requests_[request_id]->url_loader = std::move(url_loader); |
| + pending_requests_[request_id]->url_loader_client = std::move(client); |
| + } else { |
| + message_sender_->Send(new ResourceHostMsg_RequestResource( |
| + request_info.routing_id, request_id, *request)); |
| + } |
| return request_id; |
| } |