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

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

Issue 1366883002: [Reland] Post loading tasks on the appropriate WebFrameScheduler's queue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix android compile Created 5 years, 2 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 <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "components/mime_util/mime_util.h" 18 #include "components/mime_util/mime_util.h"
19 #include "components/scheduler/child/web_task_runner_impl.h"
19 #include "content/child/child_thread_impl.h" 20 #include "content/child/child_thread_impl.h"
20 #include "content/child/ftp_directory_listing_response_delegate.h" 21 #include "content/child/ftp_directory_listing_response_delegate.h"
21 #include "content/child/multipart_response_delegate.h" 22 #include "content/child/multipart_response_delegate.h"
22 #include "content/child/request_extra_data.h" 23 #include "content/child/request_extra_data.h"
23 #include "content/child/request_info.h" 24 #include "content/child/request_info.h"
24 #include "content/child/resource_dispatcher.h" 25 #include "content/child/resource_dispatcher.h"
25 #include "content/child/shared_memory_data_consumer_handle.h" 26 #include "content/child/shared_memory_data_consumer_handle.h"
26 #include "content/child/sync_load_response.h" 27 #include "content/child/sync_load_response.h"
27 #include "content/child/web_url_request_util.h" 28 #include "content/child/web_url_request_util.h"
28 #include "content/child/weburlresponse_extradata_impl.h" 29 #include "content/child/weburlresponse_extradata_impl.h"
29 #include "content/common/resource_messages.h" 30 #include "content/common/resource_messages.h"
30 #include "content/common/resource_request_body.h" 31 #include "content/common/resource_request_body.h"
31 #include "content/common/service_worker/service_worker_types.h" 32 #include "content/common/service_worker/service_worker_types.h"
32 #include "content/common/ssl_status_serialization.h" 33 #include "content/common/ssl_status_serialization.h"
33 #include "content/public/child/fixed_received_data.h" 34 #include "content/public/child/fixed_received_data.h"
34 #include "content/public/child/request_peer.h" 35 #include "content/public/child/request_peer.h"
35 #include "content/public/common/content_switches.h" 36 #include "content/public/common/content_switches.h"
36 #include "net/base/data_url.h" 37 #include "net/base/data_url.h"
37 #include "net/base/filename_util.h" 38 #include "net/base/filename_util.h"
38 #include "net/base/net_errors.h" 39 #include "net/base/net_errors.h"
39 #include "net/http/http_response_headers.h" 40 #include "net/http/http_response_headers.h"
40 #include "net/http/http_util.h" 41 #include "net/http/http_util.h"
41 #include "net/ssl/ssl_cipher_suite_names.h" 42 #include "net/ssl/ssl_cipher_suite_names.h"
42 #include "net/ssl/ssl_connection_status_flags.h" 43 #include "net/ssl/ssl_connection_status_flags.h"
43 #include "net/url_request/url_request_data_job.h" 44 #include "net/url_request/url_request_data_job.h"
44 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" 45 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h"
46 #include "third_party/WebKit/public/platform/WebTraceLocation.h"
45 #include "third_party/WebKit/public/platform/WebURL.h" 47 #include "third_party/WebKit/public/platform/WebURL.h"
46 #include "third_party/WebKit/public/platform/WebURLError.h" 48 #include "third_party/WebKit/public/platform/WebURLError.h"
47 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" 49 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h"
48 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" 50 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
49 #include "third_party/WebKit/public/platform/WebURLRequest.h" 51 #include "third_party/WebKit/public/platform/WebURLRequest.h"
50 #include "third_party/WebKit/public/platform/WebURLResponse.h" 52 #include "third_party/WebKit/public/platform/WebURLResponse.h"
51 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 53 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
52 54
53 using base::Time; 55 using base::Time;
54 using base::TimeTicks; 56 using base::TimeTicks;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // WebURLLoaderImpl::Context -------------------------------------------------- 249 // WebURLLoaderImpl::Context --------------------------------------------------
248 250
249 // This inner class exists since the WebURLLoader may be deleted while inside a 251 // This inner class exists since the WebURLLoader may be deleted while inside a
250 // call to WebURLLoaderClient. Refcounting is to keep the context from being 252 // call to WebURLLoaderClient. Refcounting is to keep the context from being
251 // deleted if it may have work to do after calling into the client. 253 // deleted if it may have work to do after calling into the client.
252 class WebURLLoaderImpl::Context : public base::RefCounted<Context>, 254 class WebURLLoaderImpl::Context : public base::RefCounted<Context>,
253 public RequestPeer { 255 public RequestPeer {
254 public: 256 public:
255 Context(WebURLLoaderImpl* loader, 257 Context(WebURLLoaderImpl* loader,
256 ResourceDispatcher* resource_dispatcher, 258 ResourceDispatcher* resource_dispatcher,
257 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 259 scoped_ptr<blink::WebTaskRunner> task_runner);
258 260
259 WebURLLoaderClient* client() const { return client_; } 261 WebURLLoaderClient* client() const { return client_; }
260 void set_client(WebURLLoaderClient* client) { client_ = client; } 262 void set_client(WebURLLoaderClient* client) { client_ = client; }
261 263
262 void Cancel(); 264 void Cancel();
263 void SetDefersLoading(bool value); 265 void SetDefersLoading(bool value);
264 void DidChangePriority(WebURLRequest::Priority new_priority, 266 void DidChangePriority(WebURLRequest::Priority new_priority,
265 int intra_priority_value); 267 int intra_priority_value);
266 bool AttachThreadedDataReceiver( 268 bool AttachThreadedDataReceiver(
267 blink::WebThreadedDataReceiver* threaded_data_receiver); 269 blink::WebThreadedDataReceiver* threaded_data_receiver);
268 void Start(const WebURLRequest& request, 270 void Start(const WebURLRequest& request,
269 SyncLoadResponse* sync_load_response); 271 SyncLoadResponse* sync_load_response);
272 void SetWebTaskRunner(scoped_ptr<blink::WebTaskRunner> task_runner);
270 273
271 // RequestPeer methods: 274 // RequestPeer methods:
272 void OnUploadProgress(uint64 position, uint64 size) override; 275 void OnUploadProgress(uint64 position, uint64 size) override;
273 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, 276 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info,
274 const ResourceResponseInfo& info) override; 277 const ResourceResponseInfo& info) override;
275 void OnReceivedResponse(const ResourceResponseInfo& info) override; 278 void OnReceivedResponse(const ResourceResponseInfo& info) override;
276 void OnDownloadedData(int len, int encoded_data_length) override; 279 void OnDownloadedData(int len, int encoded_data_length) override;
277 void OnReceivedData(scoped_ptr<ReceivedData> data) override; 280 void OnReceivedData(scoped_ptr<ReceivedData> data) override;
278 void OnReceivedCachedMetadata(const char* data, int len) override; 281 void OnReceivedCachedMetadata(const char* data, int len) override;
279 void OnCompletedRequest(int error_code, 282 void OnCompletedRequest(int error_code,
280 bool was_ignored_by_handler, 283 bool was_ignored_by_handler,
281 bool stale_copy_in_cache, 284 bool stale_copy_in_cache,
282 const std::string& security_info, 285 const std::string& security_info,
283 const base::TimeTicks& completion_time, 286 const base::TimeTicks& completion_time,
284 int64 total_transfer_size) override; 287 int64 total_transfer_size) override;
285 void OnReceivedCompletedResponse(const ResourceResponseInfo& info, 288 void OnReceivedCompletedResponse(const ResourceResponseInfo& info,
286 scoped_ptr<ReceivedData> data, 289 scoped_ptr<ReceivedData> data,
287 int error_code, 290 int error_code,
288 bool was_ignored_by_handler, 291 bool was_ignored_by_handler,
289 bool stale_copy_in_cache, 292 bool stale_copy_in_cache,
290 const std::string& security_info, 293 const std::string& security_info,
291 const base::TimeTicks& completion_time, 294 const base::TimeTicks& completion_time,
292 int64 total_transfer_size) override; 295 int64 total_transfer_size) override;
293 296
294 private: 297 private:
295 friend class base::RefCounted<Context>; 298 friend class base::RefCounted<Context>;
296 ~Context() override; 299 ~Context() override;
297 300
301 class HandleDataURLTask : public blink::WebTaskRunner::Task {
302 public:
303 explicit HandleDataURLTask(Context* context) : context_(context) {}
Sami 2015/09/30 13:03:16 nit: scoped_refptr
alex clarke (OOO till 29th) 2015/09/30 13:37:17 Done.
304
305 void run() override {
306 context_->HandleDataURL();
307 }
308
309 private:
310 scoped_refptr<Context> context_;
311 };
312
298 // Called when the body data stream is detached from the reader side. 313 // Called when the body data stream is detached from the reader side.
299 void CancelBodyStreaming(); 314 void CancelBodyStreaming();
300 // We can optimize the handling of data URLs in most cases. 315 // We can optimize the handling of data URLs in most cases.
301 bool CanHandleDataURLRequestLocally() const; 316 bool CanHandleDataURLRequestLocally() const;
302 void HandleDataURL(); 317 void HandleDataURL();
303 318
304 WebURLLoaderImpl* loader_; 319 WebURLLoaderImpl* loader_;
305 WebURLRequest request_; 320 WebURLRequest request_;
306 WebURLLoaderClient* client_; 321 WebURLLoaderClient* client_;
307 ResourceDispatcher* resource_dispatcher_; 322 ResourceDispatcher* resource_dispatcher_;
308 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 323 scoped_ptr<blink::WebTaskRunner> web_task_runner_;
309 WebReferrerPolicy referrer_policy_; 324 WebReferrerPolicy referrer_policy_;
310 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; 325 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_;
311 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; 326 scoped_ptr<MultipartResponseDelegate> multipart_delegate_;
312 scoped_ptr<StreamOverrideParameters> stream_override_; 327 scoped_ptr<StreamOverrideParameters> stream_override_;
313 scoped_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; 328 scoped_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_;
314 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; 329 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA};
315 DeferState defers_loading_; 330 DeferState defers_loading_;
316 int request_id_; 331 int request_id_;
317 }; 332 };
318 333
319 WebURLLoaderImpl::Context::Context( 334 WebURLLoaderImpl::Context::Context(
320 WebURLLoaderImpl* loader, 335 WebURLLoaderImpl* loader,
321 ResourceDispatcher* resource_dispatcher, 336 ResourceDispatcher* resource_dispatcher,
322 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 337 scoped_ptr<blink::WebTaskRunner> web_task_runner)
323 : loader_(loader), 338 : loader_(loader),
324 client_(NULL), 339 client_(NULL),
325 resource_dispatcher_(resource_dispatcher), 340 resource_dispatcher_(resource_dispatcher),
326 task_runner_(task_runner), 341 web_task_runner_(web_task_runner.Pass()),
327 referrer_policy_(blink::WebReferrerPolicyDefault), 342 referrer_policy_(blink::WebReferrerPolicyDefault),
328 defers_loading_(NOT_DEFERRING), 343 defers_loading_(NOT_DEFERRING),
329 request_id_(-1) { 344 request_id_(-1) {
330 } 345 }
331 346
332 void WebURLLoaderImpl::Context::Cancel() { 347 void WebURLLoaderImpl::Context::Cancel() {
333 if (resource_dispatcher_ && // NULL in unittest. 348 if (resource_dispatcher_ && // NULL in unittest.
334 request_id_ != -1) { 349 request_id_ != -1) {
335 resource_dispatcher_->Cancel(request_id_); 350 resource_dispatcher_->Cancel(request_id_);
336 request_id_ = -1; 351 request_id_ = -1;
(...skipping 15 matching lines...) Expand all
352 loader_ = NULL; 367 loader_ = NULL;
353 } 368 }
354 369
355 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) { 370 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) {
356 if (request_id_ != -1) 371 if (request_id_ != -1)
357 resource_dispatcher_->SetDefersLoading(request_id_, value); 372 resource_dispatcher_->SetDefersLoading(request_id_, value);
358 if (value && defers_loading_ == NOT_DEFERRING) { 373 if (value && defers_loading_ == NOT_DEFERRING) {
359 defers_loading_ = SHOULD_DEFER; 374 defers_loading_ = SHOULD_DEFER;
360 } else if (!value && defers_loading_ != NOT_DEFERRING) { 375 } else if (!value && defers_loading_ != NOT_DEFERRING) {
361 if (defers_loading_ == DEFERRED_DATA) { 376 if (defers_loading_ == DEFERRED_DATA) {
362 task_runner_->PostTask(FROM_HERE, 377 // TODO(alexclarke): Find a way to let blink and chromium FROM_HERE
363 base::Bind(&Context::HandleDataURL, this)); 378 // coexist.
379 web_task_runner_->postTask(
380 ::blink::WebTraceLocation(__FUNCTION__, __FILE__),
381 new HandleDataURLTask(this));
364 } 382 }
365 defers_loading_ = NOT_DEFERRING; 383 defers_loading_ = NOT_DEFERRING;
366 } 384 }
367 } 385 }
368 386
369 void WebURLLoaderImpl::Context::DidChangePriority( 387 void WebURLLoaderImpl::Context::DidChangePriority(
370 WebURLRequest::Priority new_priority, int intra_priority_value) { 388 WebURLRequest::Priority new_priority, int intra_priority_value) {
371 if (request_id_ != -1) { 389 if (request_id_ != -1) {
372 resource_dispatcher_->DidChangePriority( 390 resource_dispatcher_->DidChangePriority(
373 request_id_, 391 request_id_,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 429 }
412 430
413 if (CanHandleDataURLRequestLocally()) { 431 if (CanHandleDataURLRequestLocally()) {
414 if (sync_load_response) { 432 if (sync_load_response) {
415 // This is a sync load. Do the work now. 433 // This is a sync load. Do the work now.
416 sync_load_response->url = url; 434 sync_load_response->url = url;
417 sync_load_response->error_code = 435 sync_load_response->error_code =
418 GetInfoFromDataURL(sync_load_response->url, sync_load_response, 436 GetInfoFromDataURL(sync_load_response->url, sync_load_response,
419 &sync_load_response->data); 437 &sync_load_response->data);
420 } else { 438 } else {
421 task_runner_->PostTask(FROM_HERE, 439 // TODO(alexclarke): Find a way to let blink and chromium FROM_HERE
422 base::Bind(&Context::HandleDataURL, this)); 440 // coexist.
441 web_task_runner_->postTask(
442 ::blink::WebTraceLocation(__FUNCTION__, __FILE__),
443 new HandleDataURLTask(this));
423 } 444 }
424 return; 445 return;
425 } 446 }
426 447
427 // PlzNavigate: outside of tests, the only navigation requests going through 448 // PlzNavigate: outside of tests, the only navigation requests going through
428 // the WebURLLoader are the ones created by CommitNavigation. Several browser 449 // the WebURLLoader are the ones created by CommitNavigation. Several browser
429 // tests load HTML directly through a data url which will be handled by the 450 // tests load HTML directly through a data url which will be handled by the
430 // block above. 451 // block above.
431 DCHECK_IMPLIES(base::CommandLine::ForCurrentProcess()->HasSwitch( 452 DCHECK_IMPLIES(base::CommandLine::ForCurrentProcess()->HasSwitch(
432 switches::kEnableBrowserSideNavigation), 453 switches::kEnableBrowserSideNavigation),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 request_info.fetch_credentials_mode = 496 request_info.fetch_credentials_mode =
476 GetFetchCredentialsModeForWebURLRequest(request); 497 GetFetchCredentialsModeForWebURLRequest(request);
477 request_info.fetch_redirect_mode = 498 request_info.fetch_redirect_mode =
478 GetFetchRedirectModeForWebURLRequest(request); 499 GetFetchRedirectModeForWebURLRequest(request);
479 request_info.fetch_request_context_type = 500 request_info.fetch_request_context_type =
480 GetRequestContextTypeForWebURLRequest(request); 501 GetRequestContextTypeForWebURLRequest(request);
481 request_info.fetch_frame_type = 502 request_info.fetch_frame_type =
482 GetRequestContextFrameTypeForWebURLRequest(request); 503 GetRequestContextFrameTypeForWebURLRequest(request);
483 request_info.extra_data = request.extraData(); 504 request_info.extra_data = request.extraData();
484 request_info.report_raw_headers = request.reportRawHeaders(); 505 request_info.report_raw_headers = request.reportRawHeaders();
506 request_info.loading_web_task_runner.reset(web_task_runner_->clone());
485 507
486 scoped_refptr<ResourceRequestBody> request_body = 508 scoped_refptr<ResourceRequestBody> request_body =
487 GetRequestBodyForWebURLRequest(request).get(); 509 GetRequestBodyForWebURLRequest(request).get();
488 510
489 if (sync_load_response) { 511 if (sync_load_response) {
490 resource_dispatcher_->StartSync( 512 resource_dispatcher_->StartSync(
491 request_info, request_body.get(), sync_load_response); 513 request_info, request_body.get(), sync_load_response);
492 return; 514 return;
493 } 515 }
494 516
495 request_id_ = resource_dispatcher_->StartAsync( 517 request_id_ = resource_dispatcher_->StartAsync(
496 request_info, request_body.get(), this); 518 request_info, request_body.get(), this);
497 } 519 }
498 520
521 void WebURLLoaderImpl::Context::SetWebTaskRunner(
522 scoped_ptr<blink::WebTaskRunner> web_task_runner) {
523 web_task_runner_ = web_task_runner.Pass();
524 }
525
499 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) { 526 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) {
500 if (client_) 527 if (client_)
501 client_->didSendData(loader_, position, size); 528 client_->didSendData(loader_, position, size);
502 } 529 }
503 530
504 bool WebURLLoaderImpl::Context::OnReceivedRedirect( 531 bool WebURLLoaderImpl::Context::OnReceivedRedirect(
505 const net::RedirectInfo& redirect_info, 532 const net::RedirectInfo& redirect_info,
506 const ResourceResponseInfo& info) { 533 const ResourceResponseInfo& info) {
507 if (!client_) 534 if (!client_)
508 return false; 535 return false;
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 } 861 }
835 862
836 OnCompletedRequest(error_code, false, false, info.security_info, 863 OnCompletedRequest(error_code, false, false, info.security_info,
837 base::TimeTicks::Now(), 0); 864 base::TimeTicks::Now(), 0);
838 } 865 }
839 866
840 // WebURLLoaderImpl ----------------------------------------------------------- 867 // WebURLLoaderImpl -----------------------------------------------------------
841 868
842 WebURLLoaderImpl::WebURLLoaderImpl( 869 WebURLLoaderImpl::WebURLLoaderImpl(
843 ResourceDispatcher* resource_dispatcher, 870 ResourceDispatcher* resource_dispatcher,
844 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 871 scoped_ptr<blink::WebTaskRunner> web_task_runner)
845 : context_(new Context(this, resource_dispatcher, task_runner)) { 872 : context_(new Context(this, resource_dispatcher, web_task_runner.Pass())) {
846 } 873 }
847 874
848 WebURLLoaderImpl::~WebURLLoaderImpl() { 875 WebURLLoaderImpl::~WebURLLoaderImpl() {
849 cancel(); 876 cancel();
850 } 877 }
851 878
852 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, 879 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url,
853 const ResourceResponseInfo& info, 880 const ResourceResponseInfo& info,
854 WebURLResponse* response, 881 WebURLResponse* response,
855 bool report_security_info) { 882 bool report_security_info) {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority, 1079 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority,
1053 int intra_priority_value) { 1080 int intra_priority_value) {
1054 context_->DidChangePriority(new_priority, intra_priority_value); 1081 context_->DidChangePriority(new_priority, intra_priority_value);
1055 } 1082 }
1056 1083
1057 bool WebURLLoaderImpl::attachThreadedDataReceiver( 1084 bool WebURLLoaderImpl::attachThreadedDataReceiver(
1058 blink::WebThreadedDataReceiver* threaded_data_receiver) { 1085 blink::WebThreadedDataReceiver* threaded_data_receiver) {
1059 return context_->AttachThreadedDataReceiver(threaded_data_receiver); 1086 return context_->AttachThreadedDataReceiver(threaded_data_receiver);
1060 } 1087 }
1061 1088
1089 void WebURLLoaderImpl::setLoadingTaskRunner(
1090 blink::WebTaskRunner* loading_task_runner) {
1091 // There's no guarantee on the lifetime of |loading_task_runner| so we take a
1092 // copy.
1093 context_->SetWebTaskRunner(make_scoped_ptr(loading_task_runner->clone()));
1094 }
1095
1062 } // namespace content 1096 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698