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

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: 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
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 18 matching lines...) Expand all
29 #include "content/child/request_info.h" 29 #include "content/child/request_info.h"
30 #include "content/child/resource_dispatcher.h" 30 #include "content/child/resource_dispatcher.h"
31 #include "content/child/shared_memory_data_consumer_handle.h" 31 #include "content/child/shared_memory_data_consumer_handle.h"
32 #include "content/child/sync_load_response.h" 32 #include "content/child/sync_load_response.h"
33 #include "content/child/web_url_request_util.h" 33 #include "content/child/web_url_request_util.h"
34 #include "content/child/weburlresponse_extradata_impl.h" 34 #include "content/child/weburlresponse_extradata_impl.h"
35 #include "content/common/resource_messages.h" 35 #include "content/common/resource_messages.h"
36 #include "content/common/resource_request_body_impl.h" 36 #include "content/common/resource_request_body_impl.h"
37 #include "content/common/service_worker/service_worker_types.h" 37 #include "content/common/service_worker/service_worker_types.h"
38 #include "content/common/ssl_status_serialization.h" 38 #include "content/common/ssl_status_serialization.h"
39 #include "content/common/url_loader.mojom.h"
39 #include "content/public/child/fixed_received_data.h" 40 #include "content/public/child/fixed_received_data.h"
40 #include "content/public/child/request_peer.h" 41 #include "content/public/child/request_peer.h"
41 #include "content/public/common/browser_side_navigation_policy.h" 42 #include "content/public/common/browser_side_navigation_policy.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/ct_sct_to_string.h" 48 #include "net/cert/ct_sct_to_string.h"
48 #include "net/http/http_response_headers.h" 49 #include "net/http/http_response_headers.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 301
301 // This inner class exists since the WebURLLoader may be deleted while inside a 302 // This inner class exists since the WebURLLoader may be deleted while inside a
302 // call to WebURLLoaderClient. Refcounting is to keep the context from being 303 // call to WebURLLoaderClient. Refcounting is to keep the context from being
303 // deleted if it may have work to do after calling into the client. 304 // deleted if it may have work to do after calling into the client.
304 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { 305 class WebURLLoaderImpl::Context : public base::RefCounted<Context> {
305 public: 306 public:
306 using ReceivedData = RequestPeer::ReceivedData; 307 using ReceivedData = RequestPeer::ReceivedData;
307 308
308 Context(WebURLLoaderImpl* loader, 309 Context(WebURLLoaderImpl* loader,
309 ResourceDispatcher* resource_dispatcher, 310 ResourceDispatcher* resource_dispatcher,
310 std::unique_ptr<blink::WebTaskRunner> task_runner); 311 std::unique_ptr<blink::WebTaskRunner> task_runner,
312 mojom::URLLoaderFactory* factory);
311 313
312 WebURLLoaderClient* client() const { return client_; } 314 WebURLLoaderClient* client() const { return client_; }
313 void set_client(WebURLLoaderClient* client) { client_ = client; } 315 void set_client(WebURLLoaderClient* client) { client_ = client; }
314 316
315 void Cancel(); 317 void Cancel();
316 void SetDefersLoading(bool value); 318 void SetDefersLoading(bool value);
317 void DidChangePriority(WebURLRequest::Priority new_priority, 319 void DidChangePriority(WebURLRequest::Priority new_priority,
318 int intra_priority_value); 320 int intra_priority_value);
319 void Start(const WebURLRequest& request, 321 void Start(const WebURLRequest& request,
320 SyncLoadResponse* sync_load_response); 322 SyncLoadResponse* sync_load_response);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 WebURLLoaderClient* client_; 364 WebURLLoaderClient* client_;
363 ResourceDispatcher* resource_dispatcher_; 365 ResourceDispatcher* resource_dispatcher_;
364 std::unique_ptr<blink::WebTaskRunner> web_task_runner_; 366 std::unique_ptr<blink::WebTaskRunner> web_task_runner_;
365 WebReferrerPolicy referrer_policy_; 367 WebReferrerPolicy referrer_policy_;
366 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; 368 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_;
367 std::unique_ptr<StreamOverrideParameters> stream_override_; 369 std::unique_ptr<StreamOverrideParameters> stream_override_;
368 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; 370 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_;
369 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; 371 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA};
370 DeferState defers_loading_; 372 DeferState defers_loading_;
371 int request_id_; 373 int request_id_;
374
375 mojom::URLLoaderFactory* url_loader_factory_;
372 }; 376 };
373 377
374 // A thin wrapper class for Context to ensure its lifetime while it is 378 // A thin wrapper class for Context to ensure its lifetime while it is
375 // handling IPC messages coming from ResourceDispatcher. Owns one ref to 379 // handling IPC messages coming from ResourceDispatcher. Owns one ref to
376 // Context and held by ResourceDispatcher. 380 // Context and held by ResourceDispatcher.
377 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { 381 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer {
378 public: 382 public:
379 explicit RequestPeerImpl(Context* context); 383 explicit RequestPeerImpl(Context* context);
380 384
381 // RequestPeer methods: 385 // RequestPeer methods:
(...skipping 14 matching lines...) Expand all
396 private: 400 private:
397 scoped_refptr<Context> context_; 401 scoped_refptr<Context> context_;
398 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); 402 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl);
399 }; 403 };
400 404
401 // WebURLLoaderImpl::Context -------------------------------------------------- 405 // WebURLLoaderImpl::Context --------------------------------------------------
402 406
403 WebURLLoaderImpl::Context::Context( 407 WebURLLoaderImpl::Context::Context(
404 WebURLLoaderImpl* loader, 408 WebURLLoaderImpl* loader,
405 ResourceDispatcher* resource_dispatcher, 409 ResourceDispatcher* resource_dispatcher,
406 std::unique_ptr<blink::WebTaskRunner> web_task_runner) 410 std::unique_ptr<blink::WebTaskRunner> web_task_runner,
411 mojom::URLLoaderFactory* url_loader_factory)
407 : loader_(loader), 412 : loader_(loader),
408 client_(NULL), 413 client_(NULL),
409 resource_dispatcher_(resource_dispatcher), 414 resource_dispatcher_(resource_dispatcher),
410 web_task_runner_(std::move(web_task_runner)), 415 web_task_runner_(std::move(web_task_runner)),
411 referrer_policy_(blink::WebReferrerPolicyDefault), 416 referrer_policy_(blink::WebReferrerPolicyDefault),
412 defers_loading_(NOT_DEFERRING), 417 defers_loading_(NOT_DEFERRING),
413 request_id_(-1) {} 418 request_id_(-1),
419 url_loader_factory_(url_loader_factory) {}
414 420
415 void WebURLLoaderImpl::Context::Cancel() { 421 void WebURLLoaderImpl::Context::Cancel() {
416 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, 422 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this,
417 TRACE_EVENT_FLAG_FLOW_IN); 423 TRACE_EVENT_FLAG_FLOW_IN);
418 if (resource_dispatcher_ && // NULL in unittest. 424 if (resource_dispatcher_ && // NULL in unittest.
419 request_id_ != -1) { 425 request_id_ != -1) {
420 resource_dispatcher_->Cancel(request_id_); 426 resource_dispatcher_->Cancel(request_id_);
421 request_id_ = -1; 427 request_id_ = -1;
422 } 428 }
423 429
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 if (stream_override_.get()) { 568 if (stream_override_.get()) {
563 CHECK(IsBrowserSideNavigationEnabled()); 569 CHECK(IsBrowserSideNavigationEnabled());
564 DCHECK(!sync_load_response); 570 DCHECK(!sync_load_response);
565 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType()); 571 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType());
566 request_info.resource_body_stream_url = stream_override_->stream_url; 572 request_info.resource_body_stream_url = stream_override_->stream_url;
567 } 573 }
568 574
569 if (sync_load_response) { 575 if (sync_load_response) {
570 DCHECK(defers_loading_ == NOT_DEFERRING); 576 DCHECK(defers_loading_ == NOT_DEFERRING);
571 resource_dispatcher_->StartSync( 577 resource_dispatcher_->StartSync(
572 request_info, request_body.get(), sync_load_response); 578 request_info, request_body.get(), sync_load_response,
579 request.getLoadingIPCType(), url_loader_factory_);
573 return; 580 return;
574 } 581 }
575 582
576 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, 583 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this,
577 TRACE_EVENT_FLAG_FLOW_OUT); 584 TRACE_EVENT_FLAG_FLOW_OUT);
578 request_id_ = resource_dispatcher_->StartAsync( 585 request_id_ = resource_dispatcher_->StartAsync(
579 request_info, request_body.get(), 586 request_info, request_body.get(),
580 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this))); 587 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this)),
588 request.getLoadingIPCType(), url_loader_factory_);
581 589
582 if (defers_loading_ != NOT_DEFERRING) 590 if (defers_loading_ != NOT_DEFERRING)
583 resource_dispatcher_->SetDefersLoading(request_id_, true); 591 resource_dispatcher_->SetDefersLoading(request_id_, true);
584 } 592 }
585 593
586 void WebURLLoaderImpl::Context::SetWebTaskRunner( 594 void WebURLLoaderImpl::Context::SetWebTaskRunner(
587 std::unique_ptr<blink::WebTaskRunner> web_task_runner) { 595 std::unique_ptr<blink::WebTaskRunner> web_task_runner) {
588 web_task_runner_ = std::move(web_task_runner); 596 web_task_runner_ = std::move(web_task_runner);
589 } 597 }
590 598
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 int64_t total_transfer_size) { 951 int64_t total_transfer_size) {
944 context_->OnCompletedRequest(error_code, was_ignored_by_handler, 952 context_->OnCompletedRequest(error_code, was_ignored_by_handler,
945 stale_copy_in_cache, security_info, 953 stale_copy_in_cache, security_info,
946 completion_time, total_transfer_size); 954 completion_time, total_transfer_size);
947 } 955 }
948 956
949 // WebURLLoaderImpl ----------------------------------------------------------- 957 // WebURLLoaderImpl -----------------------------------------------------------
950 958
951 WebURLLoaderImpl::WebURLLoaderImpl( 959 WebURLLoaderImpl::WebURLLoaderImpl(
952 ResourceDispatcher* resource_dispatcher, 960 ResourceDispatcher* resource_dispatcher,
953 std::unique_ptr<blink::WebTaskRunner> web_task_runner) 961 std::unique_ptr<blink::WebTaskRunner> web_task_runner,
954 : context_( 962 mojom::URLLoaderFactory* url_loader_factory)
955 new Context(this, resource_dispatcher, std::move(web_task_runner))) {} 963 : context_(new Context(this,
964 resource_dispatcher,
965 std::move(web_task_runner),
966 url_loader_factory)) {}
956 967
957 WebURLLoaderImpl::~WebURLLoaderImpl() { 968 WebURLLoaderImpl::~WebURLLoaderImpl() {
958 cancel(); 969 cancel();
959 } 970 }
960 971
961 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, 972 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url,
962 const ResourceResponseInfo& info, 973 const ResourceResponseInfo& info,
963 WebURLResponse* response, 974 WebURLResponse* response,
964 bool report_security_info) { 975 bool report_security_info) {
965 response->setURL(url); 976 response->setURL(url);
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 response->clearHTTPHeaderField(webStringName); 1245 response->clearHTTPHeaderField(webStringName);
1235 while (response_headers->EnumerateHeader(&iterator, name, &value)) { 1246 while (response_headers->EnumerateHeader(&iterator, name, &value)) {
1236 response->addHTTPHeaderField(webStringName, 1247 response->addHTTPHeaderField(webStringName,
1237 WebString::fromLatin1(value)); 1248 WebString::fromLatin1(value));
1238 } 1249 }
1239 } 1250 }
1240 return true; 1251 return true;
1241 } 1252 }
1242 1253
1243 } // namespace content 1254 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698