Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: content/child/resource_dispatcher.cc

Issue 1970693002: Use mojo for Chrome Loading, Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/child/resource_dispatcher.h ('k') | content/child/resource_dispatcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 9 #include <utility>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "base/metrics/histogram.h" 21 #include "base/metrics/histogram.h"
22 #include "base/rand_util.h" 22 #include "base/rand_util.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 #include "content/child/request_extra_data.h" 25 #include "content/child/request_extra_data.h"
26 #include "content/child/request_info.h" 26 #include "content/child/request_info.h"
27 #include "content/child/resource_scheduling_filter.h" 27 #include "content/child/resource_scheduling_filter.h"
28 #include "content/child/shared_memory_received_data_factory.h" 28 #include "content/child/shared_memory_received_data_factory.h"
29 #include "content/child/site_isolation_stats_gatherer.h" 29 #include "content/child/site_isolation_stats_gatherer.h"
30 #include "content/child/sync_load_response.h" 30 #include "content/child/sync_load_response.h"
31 #include "content/child/url_response_body_consumer.h"
31 #include "content/common/inter_process_time_ticks_converter.h" 32 #include "content/common/inter_process_time_ticks_converter.h"
32 #include "content/common/navigation_params.h" 33 #include "content/common/navigation_params.h"
33 #include "content/common/resource_messages.h" 34 #include "content/common/resource_messages.h"
34 #include "content/common/resource_request.h" 35 #include "content/common/resource_request.h"
35 #include "content/common/resource_request_completion_status.h" 36 #include "content/common/resource_request_completion_status.h"
36 #include "content/public/child/fixed_received_data.h" 37 #include "content/public/child/fixed_received_data.h"
37 #include "content/public/child/request_peer.h" 38 #include "content/public/child/request_peer.h"
38 #include "content/public/child/resource_dispatcher_delegate.h" 39 #include "content/public/child/resource_dispatcher_delegate.h"
39 #include "content/public/common/content_features.h" 40 #include "content/public/common/content_features.h"
40 #include "content/public/common/resource_response.h" 41 #include "content/public/common/resource_response.h"
41 #include "content/public/common/resource_type.h" 42 #include "content/public/common/resource_type.h"
43 #include "mojo/public/cpp/bindings/binding.h"
42 #include "net/base/net_errors.h" 44 #include "net/base/net_errors.h"
43 #include "net/base/request_priority.h" 45 #include "net/base/request_priority.h"
44 #include "net/http/http_response_headers.h" 46 #include "net/http/http_response_headers.h"
45 47
46 namespace content { 48 namespace content {
47 49
48 namespace { 50 namespace {
49 51
50 // Converts |time| from a remote to local TimeTicks, overwriting the original 52 // Converts |time| from a remote to local TimeTicks, overwriting the original
51 // value. 53 // value.
(...skipping 14 matching lines...) Expand all
66 68
67 // Each resource request is assigned an ID scoped to this process. 69 // Each resource request is assigned an ID scoped to this process.
68 int MakeRequestID() { 70 int MakeRequestID() {
69 // NOTE: The resource_dispatcher_host also needs probably unique 71 // NOTE: The resource_dispatcher_host also needs probably unique
70 // request_ids, so they count down from -2 (-1 is a special we're 72 // request_ids, so they count down from -2 (-1 is a special we're
71 // screwed value), while the renderer process counts up. 73 // screwed value), while the renderer process counts up.
72 static int next_request_id = 0; 74 static int next_request_id = 0;
73 return next_request_id++; 75 return next_request_id++;
74 } 76 }
75 77
78 class URLLoaderClientImpl final : public mojom::URLLoaderClient {
79 public:
80 URLLoaderClientImpl(int request_id,
81 ResourceDispatcher* resource_dispatcher,
82 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
83 : binding_(this),
84 request_id_(request_id),
85 resource_dispatcher_(resource_dispatcher),
86 task_runner_(std::move(task_runner)) {}
87 ~URLLoaderClientImpl() override {
88 if (body_consumer_)
89 body_consumer_->Cancel();
90 }
91
92 void OnReceiveResponse(const ResourceResponseHead& response_head) override {
93 resource_dispatcher_->OnMessageReceived(
94 ResourceMsg_ReceivedResponse(request_id_, response_head));
95 }
96
97 void OnStartLoadingResponseBody(
98 mojo::ScopedDataPipeConsumerHandle body) override {
99 DCHECK(!body_consumer_);
100 body_consumer_ = new URLResponseBodyConsumer(
101 request_id_, resource_dispatcher_, std::move(body), task_runner_.get());
102 }
103
104 void OnComplete(const ResourceRequestCompletionStatus& status) override {
105 body_consumer_->OnComplete(status);
106 }
107
108 mojom::URLLoaderClientPtr CreateInterfacePtrAndBind() {
109 return binding_.CreateInterfacePtrAndBind();
110 }
111
112 private:
113 mojo::Binding<mojom::URLLoaderClient> binding_;
114 scoped_refptr<URLResponseBodyConsumer> body_consumer_;
115 const int request_id_;
116 ResourceDispatcher* const resource_dispatcher_;
117 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
118 };
119
76 } // namespace 120 } // namespace
77 121
78 ResourceDispatcher::ResourceDispatcher( 122 ResourceDispatcher::ResourceDispatcher(
79 IPC::Sender* sender, 123 IPC::Sender* sender,
80 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) 124 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner)
81 : message_sender_(sender), 125 : message_sender_(sender),
82 delegate_(NULL), 126 delegate_(NULL),
83 io_timestamp_(base::TimeTicks()), 127 io_timestamp_(base::TimeTicks()),
84 main_thread_task_runner_(main_thread_task_runner), 128 main_thread_task_runner_(main_thread_task_runner),
85 weak_factory_(this) { 129 weak_factory_(this) {
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 if (index != pending_requests_.end()) { 582 if (index != pending_requests_.end()) {
539 PendingRequestInfo* pending_request = index->second.get(); 583 PendingRequestInfo* pending_request = index->second.get();
540 if (pending_request->is_deferred) { 584 if (pending_request->is_deferred) {
541 pending_request->deferred_message_queue.swap(q); 585 pending_request->deferred_message_queue.swap(q);
542 return; 586 return;
543 } 587 }
544 } 588 }
545 } 589 }
546 } 590 }
547 591
548 void ResourceDispatcher::StartSync(const RequestInfo& request_info, 592 void ResourceDispatcher::StartSync(
549 ResourceRequestBodyImpl* request_body, 593 const RequestInfo& request_info,
550 SyncLoadResponse* response) { 594 ResourceRequestBodyImpl* request_body,
595 SyncLoadResponse* response,
596 blink::WebURLRequest::LoadingIPCType ipc_type,
597 mojom::URLLoaderFactory* url_loader_factory) {
551 std::unique_ptr<ResourceRequest> request = 598 std::unique_ptr<ResourceRequest> request =
552 CreateRequest(request_info, request_body, NULL); 599 CreateRequest(request_info, request_body, NULL);
600 // TODO(yhirano): Use url_loader_factory otherwise.
601 DCHECK_EQ(blink::WebURLRequest::LoadingIPCType::ChromeIPC, ipc_type);
553 602
554 SyncLoadResult result; 603 SyncLoadResult result;
555 IPC::SyncMessage* msg = new ResourceHostMsg_SyncLoad( 604 IPC::SyncMessage* msg = new ResourceHostMsg_SyncLoad(
556 request_info.routing_id, MakeRequestID(), *request, &result); 605 request_info.routing_id, MakeRequestID(), *request, &result);
557 606
558 // NOTE: This may pump events (see RenderThread::Send). 607 // NOTE: This may pump events (see RenderThread::Send).
559 if (!message_sender_->Send(msg)) { 608 if (!message_sender_->Send(msg)) {
560 response->error_code = net::ERR_FAILED; 609 response->error_code = net::ERR_FAILED;
561 return; 610 return;
562 } 611 }
563 612
564 response->error_code = result.error_code; 613 response->error_code = result.error_code;
565 response->url = result.final_url; 614 response->url = result.final_url;
566 response->headers = result.headers; 615 response->headers = result.headers;
567 response->mime_type = result.mime_type; 616 response->mime_type = result.mime_type;
568 response->charset = result.charset; 617 response->charset = result.charset;
569 response->request_time = result.request_time; 618 response->request_time = result.request_time;
570 response->response_time = result.response_time; 619 response->response_time = result.response_time;
571 response->encoded_data_length = result.encoded_data_length; 620 response->encoded_data_length = result.encoded_data_length;
572 response->load_timing = result.load_timing; 621 response->load_timing = result.load_timing;
573 response->devtools_info = result.devtools_info; 622 response->devtools_info = result.devtools_info;
574 response->data.swap(result.data); 623 response->data.swap(result.data);
575 response->download_file_path = result.download_file_path; 624 response->download_file_path = result.download_file_path;
576 response->socket_address = result.socket_address; 625 response->socket_address = result.socket_address;
577 response->encoded_data_length = result.encoded_data_length; 626 response->encoded_data_length = result.encoded_data_length;
578 response->encoded_body_length = result.encoded_body_length; 627 response->encoded_body_length = result.encoded_body_length;
579 } 628 }
580 629
581 int ResourceDispatcher::StartAsync(const RequestInfo& request_info, 630 int ResourceDispatcher::StartAsync(
582 ResourceRequestBodyImpl* request_body, 631 const RequestInfo& request_info,
583 std::unique_ptr<RequestPeer> peer) { 632 ResourceRequestBodyImpl* request_body,
633 std::unique_ptr<RequestPeer> peer,
634 blink::WebURLRequest::LoadingIPCType ipc_type,
635 mojom::URLLoaderFactory* url_loader_factory) {
584 GURL frame_origin; 636 GURL frame_origin;
585 std::unique_ptr<ResourceRequest> request = 637 std::unique_ptr<ResourceRequest> request =
586 CreateRequest(request_info, request_body, &frame_origin); 638 CreateRequest(request_info, request_body, &frame_origin);
587 639
588 // Compute a unique request_id for this renderer process. 640 // Compute a unique request_id for this renderer process.
589 int request_id = MakeRequestID(); 641 int request_id = MakeRequestID();
590 pending_requests_[request_id] = base::WrapUnique(new PendingRequestInfo( 642 pending_requests_[request_id] = base::WrapUnique(new PendingRequestInfo(
591 std::move(peer), request->resource_type, request->origin_pid, 643 std::move(peer), request->resource_type, request->origin_pid,
592 frame_origin, request->url, request_info.download_to_file)); 644 frame_origin, request->url, request_info.download_to_file));
593 645
594 if (resource_scheduling_filter_.get() && request_info.loading_task_runner) { 646 if (resource_scheduling_filter_.get() && request_info.loading_task_runner) {
595 resource_scheduling_filter_->SetRequestIdTaskRunner( 647 resource_scheduling_filter_->SetRequestIdTaskRunner(
596 request_id, request_info.loading_task_runner); 648 request_id, request_info.loading_task_runner);
597 } 649 }
598 650
599 message_sender_->Send(new ResourceHostMsg_RequestResource( 651 if (ipc_type == blink::WebURLRequest::LoadingIPCType::Mojo) {
600 request_info.routing_id, request_id, *request)); 652 std::unique_ptr<URLLoaderClientImpl> client(
653 new URLLoaderClientImpl(request_id, this, main_thread_task_runner_));
654 mojom::URLLoaderPtr url_loader;
655 url_loader_factory->CreateLoaderAndStart(
656 GetProxy(&url_loader), request_id, *request,
657 client->CreateInterfacePtrAndBind());
658 pending_requests_[request_id]->url_loader = std::move(url_loader);
659 pending_requests_[request_id]->url_loader_client = std::move(client);
660 } else {
661 message_sender_->Send(new ResourceHostMsg_RequestResource(
662 request_info.routing_id, request_id, *request));
663 }
601 664
602 return request_id; 665 return request_id;
603 } 666 }
604 667
605 void ResourceDispatcher::ToResourceResponseInfo( 668 void ResourceDispatcher::ToResourceResponseInfo(
606 const PendingRequestInfo& request_info, 669 const PendingRequestInfo& request_info,
607 const ResourceResponseHead& browser_info, 670 const ResourceResponseHead& browser_info,
608 ResourceResponseInfo* renderer_info) const { 671 ResourceResponseInfo* renderer_info) const {
609 *renderer_info = browser_info; 672 *renderer_info = browser_info;
610 if (base::TimeTicks::IsConsistentAcrossProcesses() || 673 if (base::TimeTicks::IsConsistentAcrossProcesses() ||
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 *frame_origin = extra_data->frame_origin(); 875 *frame_origin = extra_data->frame_origin();
813 return request; 876 return request;
814 } 877 }
815 878
816 void ResourceDispatcher::SetResourceSchedulingFilter( 879 void ResourceDispatcher::SetResourceSchedulingFilter(
817 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter) { 880 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter) {
818 resource_scheduling_filter_ = resource_scheduling_filter; 881 resource_scheduling_filter_ = resource_scheduling_filter;
819 } 882 }
820 883
821 } // namespace content 884 } // namespace content
OLDNEW
« no previous file with comments | « content/child/resource_dispatcher.h ('k') | content/child/resource_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698