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

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

Issue 1970693002: Use mojo for Chrome Loading, Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "content/child/web_url_loader_impl.h" 5 #include "content/child/web_url_loader_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 17 matching lines...) Expand all
28 #include "content/child/request_info.h" 28 #include "content/child/request_info.h"
29 #include "content/child/resource_dispatcher.h" 29 #include "content/child/resource_dispatcher.h"
30 #include "content/child/shared_memory_data_consumer_handle.h" 30 #include "content/child/shared_memory_data_consumer_handle.h"
31 #include "content/child/sync_load_response.h" 31 #include "content/child/sync_load_response.h"
32 #include "content/child/web_url_request_util.h" 32 #include "content/child/web_url_request_util.h"
33 #include "content/child/weburlresponse_extradata_impl.h" 33 #include "content/child/weburlresponse_extradata_impl.h"
34 #include "content/common/resource_messages.h" 34 #include "content/common/resource_messages.h"
35 #include "content/common/resource_request_body.h" 35 #include "content/common/resource_request_body.h"
36 #include "content/common/service_worker/service_worker_types.h" 36 #include "content/common/service_worker/service_worker_types.h"
37 #include "content/common/ssl_status_serialization.h" 37 #include "content/common/ssl_status_serialization.h"
38 #include "content/common/url_loader.mojom.h"
38 #include "content/public/child/fixed_received_data.h" 39 #include "content/public/child/fixed_received_data.h"
39 #include "content/public/child/request_peer.h" 40 #include "content/public/child/request_peer.h"
40 #include "content/public/common/browser_side_navigation_policy.h" 41 #include "content/public/common/browser_side_navigation_policy.h"
41 #include "content/public/common/signed_certificate_timestamp_id_and_status.h" 42 #include "content/public/common/signed_certificate_timestamp_id_and_status.h"
42 #include "content/public/common/ssl_status.h" 43 #include "content/public/common/ssl_status.h"
43 #include "net/base/data_url.h" 44 #include "net/base/data_url.h"
44 #include "net/base/filename_util.h" 45 #include "net/base/filename_util.h"
45 #include "net/base/net_errors.h" 46 #include "net/base/net_errors.h"
46 #include "net/cert/cert_status_flags.h" 47 #include "net/cert/cert_status_flags.h"
47 #include "net/cert/sct_status_flags.h" 48 #include "net/cert/sct_status_flags.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 296
296 // This inner class exists since the WebURLLoader may be deleted while inside a 297 // This inner class exists since the WebURLLoader may be deleted while inside a
297 // call to WebURLLoaderClient. Refcounting is to keep the context from being 298 // call to WebURLLoaderClient. Refcounting is to keep the context from being
298 // deleted if it may have work to do after calling into the client. 299 // deleted if it may have work to do after calling into the client.
299 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { 300 class WebURLLoaderImpl::Context : public base::RefCounted<Context> {
300 public: 301 public:
301 using ReceivedData = RequestPeer::ReceivedData; 302 using ReceivedData = RequestPeer::ReceivedData;
302 303
303 Context(WebURLLoaderImpl* loader, 304 Context(WebURLLoaderImpl* loader,
304 ResourceDispatcher* resource_dispatcher, 305 ResourceDispatcher* resource_dispatcher,
305 std::unique_ptr<blink::WebTaskRunner> task_runner); 306 std::unique_ptr<blink::WebTaskRunner> task_runner,
307 mojom::URLLoaderFactory* factory);
306 308
307 WebURLLoaderClient* client() const { return client_; } 309 WebURLLoaderClient* client() const { return client_; }
308 void set_client(WebURLLoaderClient* client) { client_ = client; } 310 void set_client(WebURLLoaderClient* client) { client_ = client; }
309 311
310 void Cancel(); 312 void Cancel();
311 void SetDefersLoading(bool value); 313 void SetDefersLoading(bool value);
312 void DidChangePriority(WebURLRequest::Priority new_priority, 314 void DidChangePriority(WebURLRequest::Priority new_priority,
313 int intra_priority_value); 315 int intra_priority_value);
314 void Start(const WebURLRequest& request, 316 void Start(const WebURLRequest& request,
315 SyncLoadResponse* sync_load_response); 317 SyncLoadResponse* sync_load_response);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 WebURLLoaderClient* client_; 359 WebURLLoaderClient* client_;
358 ResourceDispatcher* resource_dispatcher_; 360 ResourceDispatcher* resource_dispatcher_;
359 std::unique_ptr<blink::WebTaskRunner> web_task_runner_; 361 std::unique_ptr<blink::WebTaskRunner> web_task_runner_;
360 WebReferrerPolicy referrer_policy_; 362 WebReferrerPolicy referrer_policy_;
361 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; 363 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_;
362 std::unique_ptr<StreamOverrideParameters> stream_override_; 364 std::unique_ptr<StreamOverrideParameters> stream_override_;
363 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; 365 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_;
364 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; 366 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA};
365 DeferState defers_loading_; 367 DeferState defers_loading_;
366 int request_id_; 368 int request_id_;
369
370 mojom::URLLoaderFactory* url_loader_factory_;
367 }; 371 };
368 372
369 // A thin wrapper class for Context to ensure its lifetime while it is 373 // A thin wrapper class for Context to ensure its lifetime while it is
370 // handling IPC messages coming from ResourceDispatcher. Owns one ref to 374 // handling IPC messages coming from ResourceDispatcher. Owns one ref to
371 // Context and held by ResourceDispatcher. 375 // Context and held by ResourceDispatcher.
372 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { 376 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer {
373 public: 377 public:
374 explicit RequestPeerImpl(Context* context); 378 explicit RequestPeerImpl(Context* context);
375 379
376 // RequestPeer methods: 380 // RequestPeer methods:
(...skipping 14 matching lines...) Expand all
391 private: 395 private:
392 scoped_refptr<Context> context_; 396 scoped_refptr<Context> context_;
393 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); 397 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl);
394 }; 398 };
395 399
396 // WebURLLoaderImpl::Context -------------------------------------------------- 400 // WebURLLoaderImpl::Context --------------------------------------------------
397 401
398 WebURLLoaderImpl::Context::Context( 402 WebURLLoaderImpl::Context::Context(
399 WebURLLoaderImpl* loader, 403 WebURLLoaderImpl* loader,
400 ResourceDispatcher* resource_dispatcher, 404 ResourceDispatcher* resource_dispatcher,
401 std::unique_ptr<blink::WebTaskRunner> web_task_runner) 405 std::unique_ptr<blink::WebTaskRunner> web_task_runner,
406 mojom::URLLoaderFactory* url_loader_factory)
402 : loader_(loader), 407 : loader_(loader),
403 client_(NULL), 408 client_(NULL),
404 resource_dispatcher_(resource_dispatcher), 409 resource_dispatcher_(resource_dispatcher),
405 web_task_runner_(std::move(web_task_runner)), 410 web_task_runner_(std::move(web_task_runner)),
406 referrer_policy_(blink::WebReferrerPolicyDefault), 411 referrer_policy_(blink::WebReferrerPolicyDefault),
407 defers_loading_(NOT_DEFERRING), 412 defers_loading_(NOT_DEFERRING),
408 request_id_(-1) {} 413 request_id_(-1),
414 url_loader_factory_(url_loader_factory) {}
409 415
410 void WebURLLoaderImpl::Context::Cancel() { 416 void WebURLLoaderImpl::Context::Cancel() {
411 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, 417 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this,
412 TRACE_EVENT_FLAG_FLOW_IN); 418 TRACE_EVENT_FLAG_FLOW_IN);
413 if (resource_dispatcher_ && // NULL in unittest. 419 if (resource_dispatcher_ && // NULL in unittest.
414 request_id_ != -1) { 420 request_id_ != -1) {
415 resource_dispatcher_->Cancel(request_id_); 421 resource_dispatcher_->Cancel(request_id_);
416 request_id_ = -1; 422 request_id_ = -1;
417 } 423 }
418 424
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 // PlzNavigate: during navigation, the renderer should request a stream which 557 // PlzNavigate: during navigation, the renderer should request a stream which
552 // contains the body of the response. The network request has already been 558 // contains the body of the response. The network request has already been
553 // made by the browser. 559 // made by the browser.
554 if (stream_override_.get()) { 560 if (stream_override_.get()) {
555 CHECK(IsBrowserSideNavigationEnabled()); 561 CHECK(IsBrowserSideNavigationEnabled());
556 DCHECK(!sync_load_response); 562 DCHECK(!sync_load_response);
557 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType()); 563 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType());
558 request_info.resource_body_stream_url = stream_override_->stream_url; 564 request_info.resource_body_stream_url = stream_override_->stream_url;
559 } 565 }
560 566
567 mojom::URLLoaderPtr loader = nullptr;
568 if (request.loadingIPC() == blink::WebURLRequest::LoadingIPC::Mojo) {
569 url_loader_factory_->CreateURLLoader(GetProxy(&loader));
570 }
571
561 if (sync_load_response) { 572 if (sync_load_response) {
562 DCHECK(defers_loading_ == NOT_DEFERRING); 573 DCHECK(defers_loading_ == NOT_DEFERRING);
563 resource_dispatcher_->StartSync( 574 resource_dispatcher_->StartSync(request_info, request_body.get(),
564 request_info, request_body.get(), sync_load_response); 575 sync_load_response, std::move(loader));
565 return; 576 return;
566 } 577 }
567 578
568 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, 579 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this,
569 TRACE_EVENT_FLAG_FLOW_OUT); 580 TRACE_EVENT_FLAG_FLOW_OUT);
570 request_id_ = resource_dispatcher_->StartAsync( 581 request_id_ = resource_dispatcher_->StartAsync(
571 request_info, request_body.get(), 582 request_info, request_body.get(),
572 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this))); 583 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this)),
584 std::move(loader));
573 585
574 if (defers_loading_ != NOT_DEFERRING) 586 if (defers_loading_ != NOT_DEFERRING)
575 resource_dispatcher_->SetDefersLoading(request_id_, true); 587 resource_dispatcher_->SetDefersLoading(request_id_, true);
576 } 588 }
577 589
578 void WebURLLoaderImpl::Context::SetWebTaskRunner( 590 void WebURLLoaderImpl::Context::SetWebTaskRunner(
579 std::unique_ptr<blink::WebTaskRunner> web_task_runner) { 591 std::unique_ptr<blink::WebTaskRunner> web_task_runner) {
580 web_task_runner_ = std::move(web_task_runner); 592 web_task_runner_ = std::move(web_task_runner);
581 } 593 }
582 594
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 int64_t total_transfer_size) { 944 int64_t total_transfer_size) {
933 context_->OnCompletedRequest(error_code, was_ignored_by_handler, 945 context_->OnCompletedRequest(error_code, was_ignored_by_handler,
934 stale_copy_in_cache, security_info, 946 stale_copy_in_cache, security_info,
935 completion_time, total_transfer_size); 947 completion_time, total_transfer_size);
936 } 948 }
937 949
938 // WebURLLoaderImpl ----------------------------------------------------------- 950 // WebURLLoaderImpl -----------------------------------------------------------
939 951
940 WebURLLoaderImpl::WebURLLoaderImpl( 952 WebURLLoaderImpl::WebURLLoaderImpl(
941 ResourceDispatcher* resource_dispatcher, 953 ResourceDispatcher* resource_dispatcher,
942 std::unique_ptr<blink::WebTaskRunner> web_task_runner) 954 std::unique_ptr<blink::WebTaskRunner> web_task_runner,
943 : context_( 955 mojom::URLLoaderFactory* url_loader_factory)
944 new Context(this, resource_dispatcher, std::move(web_task_runner))) {} 956 : context_(new Context(this,
957 resource_dispatcher,
958 std::move(web_task_runner),
959 url_loader_factory)) {}
945 960
946 WebURLLoaderImpl::~WebURLLoaderImpl() { 961 WebURLLoaderImpl::~WebURLLoaderImpl() {
947 cancel(); 962 cancel();
948 } 963 }
949 964
950 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, 965 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url,
951 const ResourceResponseInfo& info, 966 const ResourceResponseInfo& info,
952 WebURLResponse* response, 967 WebURLResponse* response,
953 bool report_security_info) { 968 bool report_security_info) {
954 response->setURL(url); 969 response->setURL(url);
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 response->clearHTTPHeaderField(webStringName); 1228 response->clearHTTPHeaderField(webStringName);
1214 while (response_headers->EnumerateHeader(&iterator, name, &value)) { 1229 while (response_headers->EnumerateHeader(&iterator, name, &value)) {
1215 response->addHTTPHeaderField(webStringName, 1230 response->addHTTPHeaderField(webStringName,
1216 WebString::fromLatin1(value)); 1231 WebString::fromLatin1(value));
1217 } 1232 }
1218 } 1233 }
1219 return true; 1234 return true;
1220 } 1235 }
1221 1236
1222 } // namespace content 1237 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698