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

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

Powered by Google App Engine
This is Rietveld 408576698