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

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

Issue 2449933003: Use Associated interfaces for mojo-loading (Closed)
Patch Set: fix Created 4 years, 1 month 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/web_url_loader_impl.h ('k') | content/child/web_url_loader_impl_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 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 20 matching lines...) Expand all
31 #include "content/child/web_url_request_util.h" 31 #include "content/child/web_url_request_util.h"
32 #include "content/child/weburlresponse_extradata_impl.h" 32 #include "content/child/weburlresponse_extradata_impl.h"
33 #include "content/common/resource_messages.h" 33 #include "content/common/resource_messages.h"
34 #include "content/common/resource_request.h" 34 #include "content/common/resource_request.h"
35 #include "content/common/resource_request_body_impl.h" 35 #include "content/common/resource_request_body_impl.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/url_loader.mojom.h" 37 #include "content/common/url_loader.mojom.h"
38 #include "content/public/child/fixed_received_data.h" 38 #include "content/public/child/fixed_received_data.h"
39 #include "content/public/child/request_peer.h" 39 #include "content/public/child/request_peer.h"
40 #include "content/public/common/browser_side_navigation_policy.h" 40 #include "content/public/common/browser_side_navigation_policy.h"
41 #include "mojo/public/cpp/bindings/associated_group.h"
41 #include "net/base/data_url.h" 42 #include "net/base/data_url.h"
42 #include "net/base/filename_util.h" 43 #include "net/base/filename_util.h"
43 #include "net/base/net_errors.h" 44 #include "net/base/net_errors.h"
44 #include "net/cert/cert_status_flags.h" 45 #include "net/cert/cert_status_flags.h"
45 #include "net/cert/ct_sct_to_string.h" 46 #include "net/cert/ct_sct_to_string.h"
46 #include "net/cert/x509_util.h" 47 #include "net/cert/x509_util.h"
47 #include "net/http/http_response_headers.h" 48 #include "net/http/http_response_headers.h"
48 #include "net/http/http_util.h" 49 #include "net/http/http_util.h"
49 #include "net/ssl/ssl_cipher_suite_names.h" 50 #include "net/ssl/ssl_cipher_suite_names.h"
50 #include "net/ssl/ssl_connection_status_flags.h" 51 #include "net/ssl/ssl_connection_status_flags.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 356
356 // This inner class exists since the WebURLLoader may be deleted while inside a 357 // This inner class exists since the WebURLLoader may be deleted while inside a
357 // call to WebURLLoaderClient. Refcounting is to keep the context from being 358 // call to WebURLLoaderClient. Refcounting is to keep the context from being
358 // deleted if it may have work to do after calling into the client. 359 // deleted if it may have work to do after calling into the client.
359 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { 360 class WebURLLoaderImpl::Context : public base::RefCounted<Context> {
360 public: 361 public:
361 using ReceivedData = RequestPeer::ReceivedData; 362 using ReceivedData = RequestPeer::ReceivedData;
362 363
363 Context(WebURLLoaderImpl* loader, 364 Context(WebURLLoaderImpl* loader,
364 ResourceDispatcher* resource_dispatcher, 365 ResourceDispatcher* resource_dispatcher,
365 mojom::URLLoaderFactory* factory); 366 mojom::URLLoaderFactory* factory,
367 mojo::AssociatedGroup* associated_group);
366 368
367 WebURLLoaderClient* client() const { return client_; } 369 WebURLLoaderClient* client() const { return client_; }
368 void set_client(WebURLLoaderClient* client) { client_ = client; } 370 void set_client(WebURLLoaderClient* client) { client_ = client; }
369 371
370 void Cancel(); 372 void Cancel();
371 void SetDefersLoading(bool value); 373 void SetDefersLoading(bool value);
372 void DidChangePriority(WebURLRequest::Priority new_priority, 374 void DidChangePriority(WebURLRequest::Priority new_priority,
373 int intra_priority_value); 375 int intra_priority_value);
374 void Start(const WebURLRequest& request, 376 void Start(const WebURLRequest& request,
375 SyncLoadResponse* sync_load_response); 377 SyncLoadResponse* sync_load_response);
(...skipping 28 matching lines...) Expand all
404 WebURLLoaderClient* client_; 406 WebURLLoaderClient* client_;
405 ResourceDispatcher* resource_dispatcher_; 407 ResourceDispatcher* resource_dispatcher_;
406 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 408 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
407 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; 409 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_;
408 std::unique_ptr<StreamOverrideParameters> stream_override_; 410 std::unique_ptr<StreamOverrideParameters> stream_override_;
409 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; 411 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_;
410 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; 412 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA};
411 DeferState defers_loading_; 413 DeferState defers_loading_;
412 int request_id_; 414 int request_id_;
413 415
416 // These are owned by the Blink::Platform singleton.
414 mojom::URLLoaderFactory* url_loader_factory_; 417 mojom::URLLoaderFactory* url_loader_factory_;
418 mojo::AssociatedGroup* associated_group_;
415 }; 419 };
416 420
417 // A thin wrapper class for Context to ensure its lifetime while it is 421 // A thin wrapper class for Context to ensure its lifetime while it is
418 // handling IPC messages coming from ResourceDispatcher. Owns one ref to 422 // handling IPC messages coming from ResourceDispatcher. Owns one ref to
419 // Context and held by ResourceDispatcher. 423 // Context and held by ResourceDispatcher.
420 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { 424 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer {
421 public: 425 public:
422 explicit RequestPeerImpl(Context* context); 426 explicit RequestPeerImpl(Context* context);
423 427
424 // RequestPeer methods: 428 // RequestPeer methods:
(...skipping 12 matching lines...) Expand all
437 441
438 private: 442 private:
439 scoped_refptr<Context> context_; 443 scoped_refptr<Context> context_;
440 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); 444 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl);
441 }; 445 };
442 446
443 // WebURLLoaderImpl::Context -------------------------------------------------- 447 // WebURLLoaderImpl::Context --------------------------------------------------
444 448
445 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader, 449 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader,
446 ResourceDispatcher* resource_dispatcher, 450 ResourceDispatcher* resource_dispatcher,
447 mojom::URLLoaderFactory* url_loader_factory) 451 mojom::URLLoaderFactory* url_loader_factory,
452 mojo::AssociatedGroup* associated_group)
448 : loader_(loader), 453 : loader_(loader),
449 client_(NULL), 454 client_(NULL),
450 resource_dispatcher_(resource_dispatcher), 455 resource_dispatcher_(resource_dispatcher),
451 task_runner_(base::ThreadTaskRunnerHandle::Get()), 456 task_runner_(base::ThreadTaskRunnerHandle::Get()),
452 defers_loading_(NOT_DEFERRING), 457 defers_loading_(NOT_DEFERRING),
453 request_id_(-1), 458 request_id_(-1),
454 url_loader_factory_(url_loader_factory) {} 459 url_loader_factory_(url_loader_factory),
460 associated_group_(associated_group) {}
455 461
456 void WebURLLoaderImpl::Context::Cancel() { 462 void WebURLLoaderImpl::Context::Cancel() {
457 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, 463 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this,
458 TRACE_EVENT_FLAG_FLOW_IN); 464 TRACE_EVENT_FLAG_FLOW_IN);
459 if (resource_dispatcher_ && // NULL in unittest. 465 if (resource_dispatcher_ && // NULL in unittest.
460 request_id_ != -1) { 466 request_id_ != -1) {
461 resource_dispatcher_->Cancel(request_id_); 467 resource_dispatcher_->Cancel(request_id_);
462 request_id_ = -1; 468 request_id_ = -1;
463 } 469 }
464 470
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 request.getLoadingIPCType(), url_loader_factory_); 621 request.getLoadingIPCType(), url_loader_factory_);
616 return; 622 return;
617 } 623 }
618 624
619 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, 625 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this,
620 TRACE_EVENT_FLAG_FLOW_OUT); 626 TRACE_EVENT_FLAG_FLOW_OUT);
621 request_id_ = resource_dispatcher_->StartAsync( 627 request_id_ = resource_dispatcher_->StartAsync(
622 std::move(resource_request), request.requestorID(), task_runner_, 628 std::move(resource_request), request.requestorID(), task_runner_,
623 extra_data->frame_origin(), 629 extra_data->frame_origin(),
624 base::MakeUnique<WebURLLoaderImpl::RequestPeerImpl>(this), 630 base::MakeUnique<WebURLLoaderImpl::RequestPeerImpl>(this),
625 request.getLoadingIPCType(), url_loader_factory_); 631 request.getLoadingIPCType(), url_loader_factory_, associated_group_);
626 632
627 if (defers_loading_ != NOT_DEFERRING) 633 if (defers_loading_ != NOT_DEFERRING)
628 resource_dispatcher_->SetDefersLoading(request_id_, true); 634 resource_dispatcher_->SetDefersLoading(request_id_, true);
629 } 635 }
630 636
631 void WebURLLoaderImpl::Context::SetTaskRunner( 637 void WebURLLoaderImpl::Context::SetTaskRunner(
632 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { 638 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {
633 task_runner_ = task_runner; 639 task_runner_ = task_runner;
634 } 640 }
635 641
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 const base::TimeTicks& completion_time, 1006 const base::TimeTicks& completion_time,
1001 int64_t total_transfer_size) { 1007 int64_t total_transfer_size) {
1002 context_->OnCompletedRequest(error_code, was_ignored_by_handler, 1008 context_->OnCompletedRequest(error_code, was_ignored_by_handler,
1003 stale_copy_in_cache, completion_time, 1009 stale_copy_in_cache, completion_time,
1004 total_transfer_size); 1010 total_transfer_size);
1005 } 1011 }
1006 1012
1007 // WebURLLoaderImpl ----------------------------------------------------------- 1013 // WebURLLoaderImpl -----------------------------------------------------------
1008 1014
1009 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher, 1015 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher,
1010 mojom::URLLoaderFactory* url_loader_factory) 1016 mojom::URLLoaderFactory* url_loader_factory,
1011 : context_(new Context(this, resource_dispatcher, url_loader_factory)) {} 1017 mojo::AssociatedGroup* associated_group)
1018 : context_(new Context(this,
1019 resource_dispatcher,
1020 url_loader_factory,
1021 associated_group)) {}
1012 1022
1013 WebURLLoaderImpl::~WebURLLoaderImpl() { 1023 WebURLLoaderImpl::~WebURLLoaderImpl() {
1014 cancel(); 1024 cancel();
1015 } 1025 }
1016 1026
1017 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, 1027 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url,
1018 const ResourceResponseInfo& info, 1028 const ResourceResponseInfo& info,
1019 WebURLResponse* response, 1029 WebURLResponse* response,
1020 bool report_security_info) { 1030 bool report_security_info) {
1021 response->setURL(url); 1031 response->setURL(url);
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 int intra_priority_value) { 1249 int intra_priority_value) {
1240 context_->DidChangePriority(new_priority, intra_priority_value); 1250 context_->DidChangePriority(new_priority, intra_priority_value);
1241 } 1251 }
1242 1252
1243 void WebURLLoaderImpl::setLoadingTaskRunner( 1253 void WebURLLoaderImpl::setLoadingTaskRunner(
1244 base::SingleThreadTaskRunner* loading_task_runner) { 1254 base::SingleThreadTaskRunner* loading_task_runner) {
1245 context_->SetTaskRunner(loading_task_runner); 1255 context_->SetTaskRunner(loading_task_runner);
1246 } 1256 }
1247 1257
1248 } // namespace content 1258 } // namespace content
OLDNEW
« no previous file with comments | « content/child/web_url_loader_impl.h ('k') | content/child/web_url_loader_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698