| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
     e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
     e-loading | 
| 6 | 6 | 
| 7 #include "content/child/resource_dispatcher.h" | 7 #include "content/child/resource_dispatcher.h" | 
| 8 | 8 | 
| 9 #include <utility> | 9 #include <utility> | 
| 10 | 10 | 
| 11 #include "base/atomic_sequence_num.h" | 11 #include "base/atomic_sequence_num.h" | 
| 12 #include "base/bind.h" | 12 #include "base/bind.h" | 
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" | 
| 14 #include "base/debug/alias.h" | 14 #include "base/debug/alias.h" | 
| 15 #include "base/debug/dump_without_crashing.h" | 15 #include "base/debug/dump_without_crashing.h" | 
| 16 #include "base/debug/stack_trace.h" | 16 #include "base/debug/stack_trace.h" | 
| 17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" | 
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" | 
| 19 #include "base/memory/shared_memory.h" | 19 #include "base/memory/shared_memory.h" | 
| 20 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" | 
| 21 #include "base/metrics/histogram_macros.h" | 21 #include "base/metrics/histogram_macros.h" | 
| 22 #include "base/rand_util.h" | 22 #include "base/rand_util.h" | 
| 23 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" | 
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" | 
| 25 #include "content/child/request_extra_data.h" | 25 #include "content/child/request_extra_data.h" | 
| 26 #include "content/child/resource_scheduling_filter.h" | 26 #include "content/child/resource_scheduling_filter.h" | 
| 27 #include "content/child/shared_memory_received_data_factory.h" | 27 #include "content/child/shared_memory_received_data_factory.h" | 
| 28 #include "content/child/site_isolation_stats_gatherer.h" | 28 #include "content/child/site_isolation_stats_gatherer.h" | 
| 29 #include "content/child/sync_load_response.h" | 29 #include "content/child/sync_load_response.h" | 
|  | 30 #include "content/child/throttling_url_loader.h" | 
| 30 #include "content/child/url_loader_client_impl.h" | 31 #include "content/child/url_loader_client_impl.h" | 
| 31 #include "content/common/inter_process_time_ticks_converter.h" | 32 #include "content/common/inter_process_time_ticks_converter.h" | 
| 32 #include "content/common/navigation_params.h" | 33 #include "content/common/navigation_params.h" | 
| 33 #include "content/common/resource_messages.h" | 34 #include "content/common/resource_messages.h" | 
| 34 #include "content/common/resource_request.h" | 35 #include "content/common/resource_request.h" | 
| 35 #include "content/common/resource_request_completion_status.h" | 36 #include "content/common/resource_request_completion_status.h" | 
| 36 #include "content/public/child/fixed_received_data.h" | 37 #include "content/public/child/fixed_received_data.h" | 
| 37 #include "content/public/child/request_peer.h" | 38 #include "content/public/child/request_peer.h" | 
| 38 #include "content/public/child/resource_dispatcher_delegate.h" | 39 #include "content/public/child/resource_dispatcher_delegate.h" | 
| 39 #include "content/public/common/resource_response.h" | 40 #include "content/public/common/resource_response.h" | 
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 572       return; | 573       return; | 
| 573     } | 574     } | 
| 574   } | 575   } | 
| 575 } | 576 } | 
| 576 | 577 | 
| 577 void ResourceDispatcher::StartSync( | 578 void ResourceDispatcher::StartSync( | 
| 578     std::unique_ptr<ResourceRequest> request, | 579     std::unique_ptr<ResourceRequest> request, | 
| 579     int routing_id, | 580     int routing_id, | 
| 580     SyncLoadResponse* response, | 581     SyncLoadResponse* response, | 
| 581     blink::WebURLRequest::LoadingIPCType ipc_type, | 582     blink::WebURLRequest::LoadingIPCType ipc_type, | 
| 582     mojom::URLLoaderFactory* url_loader_factory) { | 583     mojom::URLLoaderFactory* url_loader_factory, | 
|  | 584     std::vector<std::unique_ptr<URLLoaderThrottle>> throttles) { | 
| 583   CheckSchemeForReferrerPolicy(*request); | 585   CheckSchemeForReferrerPolicy(*request); | 
| 584 | 586 | 
| 585   SyncLoadResult result; | 587   SyncLoadResult result; | 
| 586 | 588 | 
| 587   if (ipc_type == blink::WebURLRequest::LoadingIPCType::kMojo) { | 589   if (ipc_type == blink::WebURLRequest::LoadingIPCType::kMojo) { | 
|  | 590     // TODO(yzshen): There is no way to apply a throttle to sync loading. We | 
|  | 591     // could use async loading + sync handle watching to emulate this behavior. | 
|  | 592     // That may require to extend the bindings API to change the priority of | 
|  | 593     // messages. It would result in more messages during this blocking | 
|  | 594     // operation, but sync loading is discouraged anyway. | 
| 588     if (!url_loader_factory->SyncLoad( | 595     if (!url_loader_factory->SyncLoad( | 
| 589             routing_id, MakeRequestID(), *request, &result)) { | 596             routing_id, MakeRequestID(), *request, &result)) { | 
| 590       response->error_code = net::ERR_FAILED; | 597       response->error_code = net::ERR_FAILED; | 
| 591       return; | 598       return; | 
| 592     } | 599     } | 
| 593   } else { | 600   } else { | 
| 594     IPC::SyncMessage* msg = new ResourceHostMsg_SyncLoad( | 601     IPC::SyncMessage* msg = new ResourceHostMsg_SyncLoad( | 
| 595         routing_id, MakeRequestID(), *request, &result); | 602         routing_id, MakeRequestID(), *request, &result); | 
| 596 | 603 | 
| 597     // NOTE: This may pump events (see RenderThread::Send). | 604     // NOTE: This may pump events (see RenderThread::Send). | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 618 } | 625 } | 
| 619 | 626 | 
| 620 int ResourceDispatcher::StartAsync( | 627 int ResourceDispatcher::StartAsync( | 
| 621     std::unique_ptr<ResourceRequest> request, | 628     std::unique_ptr<ResourceRequest> request, | 
| 622     int routing_id, | 629     int routing_id, | 
| 623     scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner, | 630     scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner, | 
| 624     const url::Origin& frame_origin, | 631     const url::Origin& frame_origin, | 
| 625     std::unique_ptr<RequestPeer> peer, | 632     std::unique_ptr<RequestPeer> peer, | 
| 626     blink::WebURLRequest::LoadingIPCType ipc_type, | 633     blink::WebURLRequest::LoadingIPCType ipc_type, | 
| 627     mojom::URLLoaderFactory* url_loader_factory, | 634     mojom::URLLoaderFactory* url_loader_factory, | 
|  | 635     std::vector<std::unique_ptr<URLLoaderThrottle>> throttles, | 
| 628     mojo::ScopedDataPipeConsumerHandle consumer_handle) { | 636     mojo::ScopedDataPipeConsumerHandle consumer_handle) { | 
| 629   CheckSchemeForReferrerPolicy(*request); | 637   CheckSchemeForReferrerPolicy(*request); | 
| 630 | 638 | 
| 631   // Compute a unique request_id for this renderer process. | 639   // Compute a unique request_id for this renderer process. | 
| 632   int request_id = MakeRequestID(); | 640   int request_id = MakeRequestID(); | 
| 633   pending_requests_[request_id] = base::MakeUnique<PendingRequestInfo>( | 641   pending_requests_[request_id] = base::MakeUnique<PendingRequestInfo>( | 
| 634       std::move(peer), request->resource_type, request->origin_pid, | 642       std::move(peer), request->resource_type, request->origin_pid, | 
| 635       frame_origin, request->url, request->download_to_file); | 643       frame_origin, request->url, request->download_to_file); | 
| 636 | 644 | 
| 637   if (resource_scheduling_filter_.get() && loading_task_runner) { | 645   if (resource_scheduling_filter_.get() && loading_task_runner) { | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 652                                      base::Passed(std::move(consumer_handle)))); | 660                                      base::Passed(std::move(consumer_handle)))); | 
| 653 | 661 | 
| 654     return request_id; | 662     return request_id; | 
| 655   } | 663   } | 
| 656 | 664 | 
| 657   if (ipc_type == blink::WebURLRequest::LoadingIPCType::kMojo) { | 665   if (ipc_type == blink::WebURLRequest::LoadingIPCType::kMojo) { | 
| 658     scoped_refptr<base::SingleThreadTaskRunner> task_runner = | 666     scoped_refptr<base::SingleThreadTaskRunner> task_runner = | 
| 659         loading_task_runner ? loading_task_runner : thread_task_runner_; | 667         loading_task_runner ? loading_task_runner : thread_task_runner_; | 
| 660     std::unique_ptr<URLLoaderClientImpl> client( | 668     std::unique_ptr<URLLoaderClientImpl> client( | 
| 661         new URLLoaderClientImpl(request_id, this, std::move(task_runner))); | 669         new URLLoaderClientImpl(request_id, this, std::move(task_runner))); | 
| 662     mojom::URLLoaderPtr url_loader; | 670     std::unique_ptr<ThrottlingURLLoader> url_loader = | 
| 663     mojom::URLLoaderClientPtr client_ptr; | 671         ThrottlingURLLoader::CreateLoaderAndStart( | 
| 664     client->Bind(&client_ptr); | 672             url_loader_factory, std::move(throttles), routing_id, request_id, | 
| 665     url_loader_factory->CreateLoaderAndStart( | 673             mojom::kURLLoadOptionNone, std::move(request), client.get()); | 
| 666         MakeRequest(&url_loader), routing_id, request_id, |  | 
| 667         mojom::kURLLoadOptionNone, *request, std::move(client_ptr)); |  | 
| 668     pending_requests_[request_id]->url_loader = std::move(url_loader); | 674     pending_requests_[request_id]->url_loader = std::move(url_loader); | 
| 669     pending_requests_[request_id]->url_loader_client = std::move(client); | 675     pending_requests_[request_id]->url_loader_client = std::move(client); | 
| 670   } else { | 676   } else { | 
| 671     message_sender_->Send( | 677     message_sender_->Send( | 
| 672         new ResourceHostMsg_RequestResource(routing_id, request_id, *request)); | 678         new ResourceHostMsg_RequestResource(routing_id, request_id, *request)); | 
| 673   } | 679   } | 
| 674 | 680 | 
| 675   return request_id; | 681   return request_id; | 
| 676 } | 682 } | 
| 677 | 683 | 
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 839     delete message; | 845     delete message; | 
| 840   } | 846   } | 
| 841 } | 847 } | 
| 842 | 848 | 
| 843 void ResourceDispatcher::SetResourceSchedulingFilter( | 849 void ResourceDispatcher::SetResourceSchedulingFilter( | 
| 844     scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter) { | 850     scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter) { | 
| 845   resource_scheduling_filter_ = resource_scheduling_filter; | 851   resource_scheduling_filter_ = resource_scheduling_filter; | 
| 846 } | 852 } | 
| 847 | 853 | 
| 848 }  // namespace content | 854 }  // namespace content | 
| OLD | NEW | 
|---|