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/browser/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
8 | 8 |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "base/memory/ptr_util.h" | 25 #include "base/memory/ptr_util.h" |
26 #include "base/memory/shared_memory.h" | 26 #include "base/memory/shared_memory.h" |
27 #include "base/message_loop/message_loop.h" | 27 #include "base/message_loop/message_loop.h" |
28 #include "base/metrics/field_trial.h" | 28 #include "base/metrics/field_trial.h" |
29 #include "base/metrics/histogram_macros.h" | 29 #include "base/metrics/histogram_macros.h" |
30 #include "base/metrics/sparse_histogram.h" | 30 #include "base/metrics/sparse_histogram.h" |
31 #include "base/profiler/scoped_tracker.h" | 31 #include "base/profiler/scoped_tracker.h" |
32 #include "base/stl_util.h" | 32 #include "base/stl_util.h" |
33 #include "base/strings/string_util.h" | 33 #include "base/strings/string_util.h" |
34 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 34 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 35 #include "base/threading/thread_task_runner_handle.h" |
35 #include "base/timer/timer.h" | 36 #include "base/timer/timer.h" |
36 #include "content/browser/appcache/appcache_interceptor.h" | 37 #include "content/browser/appcache/appcache_interceptor.h" |
37 #include "content/browser/appcache/appcache_navigation_handle_core.h" | 38 #include "content/browser/appcache/appcache_navigation_handle_core.h" |
38 #include "content/browser/appcache/chrome_appcache_service.h" | 39 #include "content/browser/appcache/chrome_appcache_service.h" |
39 #include "content/browser/bad_message.h" | 40 #include "content/browser/bad_message.h" |
40 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 41 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
41 #include "content/browser/child_process_security_policy_impl.h" | 42 #include "content/browser/child_process_security_policy_impl.h" |
42 #include "content/browser/frame_host/navigation_request_info.h" | 43 #include "content/browser/frame_host/navigation_request_info.h" |
43 #include "content/browser/loader/async_resource_handler.h" | 44 #include "content/browser/loader/async_resource_handler.h" |
44 #include "content/browser/loader/detachable_resource_handler.h" | 45 #include "content/browser/loader/detachable_resource_handler.h" |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 332 |
332 ResourceDispatcherHostImpl::HeaderInterceptorInfo::HeaderInterceptorInfo( | 333 ResourceDispatcherHostImpl::HeaderInterceptorInfo::HeaderInterceptorInfo( |
333 const HeaderInterceptorInfo& other) {} | 334 const HeaderInterceptorInfo& other) {} |
334 | 335 |
335 // static | 336 // static |
336 ResourceDispatcherHost* ResourceDispatcherHost::Get() { | 337 ResourceDispatcherHost* ResourceDispatcherHost::Get() { |
337 return g_resource_dispatcher_host; | 338 return g_resource_dispatcher_host; |
338 } | 339 } |
339 | 340 |
340 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl( | 341 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl( |
341 CreateDownloadHandlerIntercept download_handler_intercept) | 342 CreateDownloadHandlerIntercept download_handler_intercept, |
| 343 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_runner) |
342 : request_id_(-1), | 344 : request_id_(-1), |
343 is_shutdown_(false), | 345 is_shutdown_(false), |
344 num_in_flight_requests_(0), | 346 num_in_flight_requests_(0), |
345 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), | 347 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), |
346 max_num_in_flight_requests_per_process_(static_cast<int>( | 348 max_num_in_flight_requests_per_process_(static_cast<int>( |
347 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), | 349 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), |
348 max_outstanding_requests_cost_per_process_( | 350 max_outstanding_requests_cost_per_process_( |
349 kMaxOutstandingRequestsCostPerProcess), | 351 kMaxOutstandingRequestsCostPerProcess), |
350 delegate_(nullptr), | 352 delegate_(nullptr), |
351 loader_delegate_(nullptr), | 353 loader_delegate_(nullptr), |
352 allow_cross_origin_auth_prompt_(false), | 354 allow_cross_origin_auth_prompt_(false), |
353 create_download_handler_intercept_(download_handler_intercept) { | 355 create_download_handler_intercept_(download_handler_intercept), |
354 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 356 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 357 io_thread_task_runner_(io_thread_runner) { |
| 358 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
355 DCHECK(!g_resource_dispatcher_host); | 359 DCHECK(!g_resource_dispatcher_host); |
356 g_resource_dispatcher_host = this; | 360 g_resource_dispatcher_host = this; |
357 | 361 |
358 ANNOTATE_BENIGN_RACE( | 362 ANNOTATE_BENIGN_RACE( |
359 &last_user_gesture_time_, | 363 &last_user_gesture_time_, |
360 "We don't care about the precise value, see http://crbug.com/92889"); | 364 "We don't care about the precise value, see http://crbug.com/92889"); |
361 | 365 |
362 BrowserThread::PostTask(BrowserThread::IO, | 366 io_thread_task_runner_->PostTask( |
363 FROM_HERE, | 367 FROM_HERE, |
364 base::Bind(&ResourceDispatcherHostImpl::OnInit, | 368 base::Bind(&ResourceDispatcherHostImpl::OnInit, base::Unretained(this))); |
365 base::Unretained(this))); | |
366 | 369 |
367 update_load_states_timer_.reset(new base::RepeatingTimer()); | 370 update_load_states_timer_.reset(new base::RepeatingTimer()); |
368 } | 371 } |
369 | 372 |
| 373 // The default ctor is only used by unittests. It is reasonable to assume that |
| 374 // the main thread and the IO thread are the same for unittests. |
370 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() | 375 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() |
371 : ResourceDispatcherHostImpl(CreateDownloadHandlerIntercept()) {} | 376 : ResourceDispatcherHostImpl(CreateDownloadHandlerIntercept(), |
| 377 base::ThreadTaskRunnerHandle::Get()) {} |
372 | 378 |
373 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { | 379 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { |
374 DCHECK(outstanding_requests_stats_map_.empty()); | 380 DCHECK(outstanding_requests_stats_map_.empty()); |
375 DCHECK(g_resource_dispatcher_host); | 381 DCHECK(g_resource_dispatcher_host); |
376 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 382 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
377 g_resource_dispatcher_host = NULL; | 383 g_resource_dispatcher_host = NULL; |
378 } | 384 } |
379 | 385 |
380 // static | 386 // static |
381 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { | 387 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { |
382 return g_resource_dispatcher_host; | 388 return g_resource_dispatcher_host; |
383 } | 389 } |
384 | 390 |
385 void ResourceDispatcherHostImpl::SetDelegate( | 391 void ResourceDispatcherHostImpl::SetDelegate( |
386 ResourceDispatcherHostDelegate* delegate) { | 392 ResourceDispatcherHostDelegate* delegate) { |
387 delegate_ = delegate; | 393 delegate_ = delegate; |
388 } | 394 } |
389 | 395 |
390 void ResourceDispatcherHostImpl::SetAllowCrossOriginAuthPrompt(bool value) { | 396 void ResourceDispatcherHostImpl::SetAllowCrossOriginAuthPrompt(bool value) { |
391 allow_cross_origin_auth_prompt_ = value; | 397 allow_cross_origin_auth_prompt_ = value; |
392 } | 398 } |
393 | 399 |
394 void ResourceDispatcherHostImpl::CancelRequestsForContext( | 400 void ResourceDispatcherHostImpl::CancelRequestsForContext( |
395 ResourceContext* context) { | 401 ResourceContext* context) { |
396 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 402 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); |
397 DCHECK(context); | 403 DCHECK(context); |
398 | 404 |
399 // Note that request cancellation has side effects. Therefore, we gather all | 405 // Note that request cancellation has side effects. Therefore, we gather all |
400 // the requests to cancel first, and then we start cancelling. We assert at | 406 // the requests to cancel first, and then we start cancelling. We assert at |
401 // the end that there are no more to cancel since the context is about to go | 407 // the end that there are no more to cancel since the context is about to go |
402 // away. | 408 // away. |
403 typedef std::vector<std::unique_ptr<ResourceLoader>> LoaderList; | 409 typedef std::vector<std::unique_ptr<ResourceLoader>> LoaderList; |
404 LoaderList loaders_to_cancel; | 410 LoaderList loaders_to_cancel; |
405 | 411 |
406 for (LoaderMap::iterator i = pending_loaders_.begin(); | 412 for (LoaderMap::iterator i = pending_loaders_.begin(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 http_header_interceptor_map_.end()); | 491 http_header_interceptor_map_.end()); |
486 | 492 |
487 HeaderInterceptorInfo interceptor_info; | 493 HeaderInterceptorInfo interceptor_info; |
488 interceptor_info.starts_with = starts_with; | 494 interceptor_info.starts_with = starts_with; |
489 interceptor_info.interceptor = interceptor; | 495 interceptor_info.interceptor = interceptor; |
490 | 496 |
491 http_header_interceptor_map_[http_header] = interceptor_info; | 497 http_header_interceptor_map_[http_header] = interceptor_info; |
492 } | 498 } |
493 | 499 |
494 void ResourceDispatcherHostImpl::Shutdown() { | 500 void ResourceDispatcherHostImpl::Shutdown() { |
495 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 501 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
496 BrowserThread::PostTask(BrowserThread::IO, | 502 io_thread_task_runner_->PostTask( |
497 FROM_HERE, | 503 FROM_HERE, base::Bind(&ResourceDispatcherHostImpl::OnShutdown, |
498 base::Bind(&ResourceDispatcherHostImpl::OnShutdown, | 504 base::Unretained(this))); |
499 base::Unretained(this))); | |
500 } | 505 } |
501 | 506 |
502 std::unique_ptr<ResourceHandler> | 507 std::unique_ptr<ResourceHandler> |
503 ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( | 508 ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( |
504 net::URLRequest* request, | 509 net::URLRequest* request, |
505 bool is_content_initiated, | 510 bool is_content_initiated, |
506 bool must_download, | 511 bool must_download, |
507 bool is_new_request) { | 512 bool is_new_request) { |
508 DCHECK(!create_download_handler_intercept_.is_null()); | 513 DCHECK(!create_download_handler_intercept_.is_null()); |
509 // TODO(ananta) | 514 // TODO(ananta) |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 ResourceDispatcherHostImpl::CreateClientCertStore(ResourceLoader* loader) { | 778 ResourceDispatcherHostImpl::CreateClientCertStore(ResourceLoader* loader) { |
774 return delegate_->CreateClientCertStore( | 779 return delegate_->CreateClientCertStore( |
775 loader->GetRequestInfo()->GetContext()); | 780 loader->GetRequestInfo()->GetContext()); |
776 } | 781 } |
777 | 782 |
778 void ResourceDispatcherHostImpl::OnInit() { | 783 void ResourceDispatcherHostImpl::OnInit() { |
779 scheduler_.reset(new ResourceScheduler); | 784 scheduler_.reset(new ResourceScheduler); |
780 } | 785 } |
781 | 786 |
782 void ResourceDispatcherHostImpl::OnShutdown() { | 787 void ResourceDispatcherHostImpl::OnShutdown() { |
783 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 788 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); |
784 | 789 |
785 is_shutdown_ = true; | 790 is_shutdown_ = true; |
786 pending_loaders_.clear(); | 791 pending_loaders_.clear(); |
787 | 792 |
788 // Make sure we shutdown the timer now, otherwise by the time our destructor | 793 // Make sure we shutdown the timer now, otherwise by the time our destructor |
789 // runs if the timer is still running the Task is deleted twice (once by | 794 // runs if the timer is still running the Task is deleted twice (once by |
790 // the MessageLoop and the second time by RepeatingTimer). | 795 // the MessageLoop and the second time by RepeatingTimer). |
791 update_load_states_timer_.reset(); | 796 update_load_states_timer_.reset(); |
792 | 797 |
793 // Clear blocked requests if any left. | 798 // Clear blocked requests if any left. |
(...skipping 10 matching lines...) Expand all Loading... |
804 for (const auto& routing_id : ids) { | 809 for (const auto& routing_id : ids) { |
805 CancelBlockedRequestsForRoute(routing_id); | 810 CancelBlockedRequestsForRoute(routing_id); |
806 } | 811 } |
807 | 812 |
808 scheduler_.reset(); | 813 scheduler_.reset(); |
809 } | 814 } |
810 | 815 |
811 bool ResourceDispatcherHostImpl::OnMessageReceived( | 816 bool ResourceDispatcherHostImpl::OnMessageReceived( |
812 const IPC::Message& message, | 817 const IPC::Message& message, |
813 ResourceRequesterInfo* requester_info) { | 818 ResourceRequesterInfo* requester_info) { |
814 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 819 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); |
815 | 820 |
816 bool handled = true; | 821 bool handled = true; |
817 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ResourceDispatcherHostImpl, message, | 822 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ResourceDispatcherHostImpl, message, |
818 requester_info) | 823 requester_info) |
819 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) | 824 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) |
820 IPC_MESSAGE_HANDLER_WITH_PARAM_DELAY_REPLY(ResourceHostMsg_SyncLoad, | 825 IPC_MESSAGE_HANDLER_WITH_PARAM_DELAY_REPLY(ResourceHostMsg_SyncLoad, |
821 OnSyncLoad) | 826 OnSyncLoad) |
822 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, | 827 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, |
823 OnReleaseDownloadedFile) | 828 OnReleaseDownloadedFile) |
824 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) | 829 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1518 delegate_->RequestBeginning(request, | 1523 delegate_->RequestBeginning(request, |
1519 resource_context, | 1524 resource_context, |
1520 appcache_service, | 1525 appcache_service, |
1521 resource_type, | 1526 resource_type, |
1522 &throttles); | 1527 &throttles); |
1523 } | 1528 } |
1524 | 1529 |
1525 if (request->has_upload()) { | 1530 if (request->has_upload()) { |
1526 // Block power save while uploading data. | 1531 // Block power save while uploading data. |
1527 throttles.push_back(base::MakeUnique<PowerSaveBlockResourceThrottle>( | 1532 throttles.push_back(base::MakeUnique<PowerSaveBlockResourceThrottle>( |
1528 request->url().host(), | 1533 request->url().host(), main_thread_task_runner_, |
1529 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | |
1530 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 1534 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
1531 } | 1535 } |
1532 | 1536 |
1533 // TODO(ricea): Stop looking this up so much. | 1537 // TODO(ricea): Stop looking this up so much. |
1534 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); | 1538 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); |
1535 throttles.push_back(scheduler_->ScheduleRequest(child_id, route_id, | 1539 throttles.push_back(scheduler_->ScheduleRequest(child_id, route_id, |
1536 info->IsAsync(), request)); | 1540 info->IsAsync(), request)); |
1537 | 1541 |
1538 // Split the handler in two groups: the ones that need to execute | 1542 // Split the handler in two groups: the ones that need to execute |
1539 // WillProcessResponse before mime sniffing and the others. | 1543 // WillProcessResponse before mime sniffing and the others. |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2195 | 2199 |
2196 void ResourceDispatcherHostImpl::InitializeURLRequest( | 2200 void ResourceDispatcherHostImpl::InitializeURLRequest( |
2197 net::URLRequest* request, | 2201 net::URLRequest* request, |
2198 const Referrer& referrer, | 2202 const Referrer& referrer, |
2199 bool is_download, | 2203 bool is_download, |
2200 int render_process_host_id, | 2204 int render_process_host_id, |
2201 int render_view_routing_id, | 2205 int render_view_routing_id, |
2202 int render_frame_routing_id, | 2206 int render_frame_routing_id, |
2203 PreviewsState previews_state, | 2207 PreviewsState previews_state, |
2204 ResourceContext* context) { | 2208 ResourceContext* context) { |
2205 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2209 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); |
2206 DCHECK(!request->is_pending()); | 2210 DCHECK(!request->is_pending()); |
2207 | 2211 |
2208 Referrer::SetReferrerForRequest(request, referrer); | 2212 Referrer::SetReferrerForRequest(request, referrer); |
2209 | 2213 |
2210 ResourceRequestInfoImpl* info = CreateRequestInfo( | 2214 ResourceRequestInfoImpl* info = CreateRequestInfo( |
2211 render_process_host_id, render_view_routing_id, render_frame_routing_id, | 2215 render_process_host_id, render_view_routing_id, render_frame_routing_id, |
2212 previews_state, is_download, context); | 2216 previews_state, is_download, context); |
2213 // Request takes ownership. | 2217 // Request takes ownership. |
2214 info->AssociateWithRequest(request); | 2218 info->AssociateWithRequest(request); |
2215 } | 2219 } |
2216 | 2220 |
2217 void ResourceDispatcherHostImpl::BeginURLRequest( | 2221 void ResourceDispatcherHostImpl::BeginURLRequest( |
2218 std::unique_ptr<net::URLRequest> request, | 2222 std::unique_ptr<net::URLRequest> request, |
2219 std::unique_ptr<ResourceHandler> handler, | 2223 std::unique_ptr<ResourceHandler> handler, |
2220 bool is_download, | 2224 bool is_download, |
2221 bool is_content_initiated, | 2225 bool is_content_initiated, |
2222 bool do_not_prompt_for_login, | 2226 bool do_not_prompt_for_login, |
2223 ResourceContext* context) { | 2227 ResourceContext* context) { |
2224 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2228 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); |
2225 DCHECK(!request->is_pending()); | 2229 DCHECK(!request->is_pending()); |
2226 | 2230 |
2227 ResourceRequestInfoImpl* info = | 2231 ResourceRequestInfoImpl* info = |
2228 ResourceRequestInfoImpl::ForRequest(request.get()); | 2232 ResourceRequestInfoImpl::ForRequest(request.get()); |
2229 DCHECK(info); | 2233 DCHECK(info); |
2230 info->set_do_not_prompt_for_login(do_not_prompt_for_login); | 2234 info->set_do_not_prompt_for_login(do_not_prompt_for_login); |
2231 | 2235 |
2232 // TODO(ananta) | 2236 // TODO(ananta) |
2233 // Find a better place for notifying the delegate about the download start. | 2237 // Find a better place for notifying the delegate about the download start. |
2234 if (is_download && delegate()) { | 2238 if (is_download && delegate()) { |
(...skipping 11 matching lines...) Expand all Loading... |
2246 request->original_url())); | 2250 request->original_url())); |
2247 } | 2251 } |
2248 handler = HandleDownloadStarted( | 2252 handler = HandleDownloadStarted( |
2249 request.get(), std::move(handler), is_content_initiated, | 2253 request.get(), std::move(handler), is_content_initiated, |
2250 true /* force_download */, true /* is_new_request */); | 2254 true /* force_download */, true /* is_new_request */); |
2251 } | 2255 } |
2252 BeginRequestInternal(std::move(request), std::move(handler)); | 2256 BeginRequestInternal(std::move(request), std::move(handler)); |
2253 } | 2257 } |
2254 | 2258 |
2255 int ResourceDispatcherHostImpl::MakeRequestID() { | 2259 int ResourceDispatcherHostImpl::MakeRequestID() { |
2256 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2260 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); |
2257 return --request_id_; | 2261 return --request_id_; |
2258 } | 2262 } |
2259 | 2263 |
2260 void ResourceDispatcherHostImpl::CancelRequestFromRenderer( | 2264 void ResourceDispatcherHostImpl::CancelRequestFromRenderer( |
2261 GlobalRequestID request_id) { | 2265 GlobalRequestID request_id) { |
2262 // When the old renderer dies, it sends a message to us to cancel its | 2266 // When the old renderer dies, it sends a message to us to cancel its |
2263 // requests. | 2267 // requests. |
2264 if (IsTransferredNavigation(request_id)) | 2268 if (IsTransferredNavigation(request_id)) |
2265 return; | 2269 return; |
2266 | 2270 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2320 | 2324 |
2321 if (a_uploading_size != b_uploading_size) | 2325 if (a_uploading_size != b_uploading_size) |
2322 return a_uploading_size > b_uploading_size; | 2326 return a_uploading_size > b_uploading_size; |
2323 | 2327 |
2324 return a.load_state.state > b.load_state.state; | 2328 return a.load_state.state > b.load_state.state; |
2325 } | 2329 } |
2326 | 2330 |
2327 // static | 2331 // static |
2328 void ResourceDispatcherHostImpl::UpdateLoadStateOnUI( | 2332 void ResourceDispatcherHostImpl::UpdateLoadStateOnUI( |
2329 LoaderDelegate* loader_delegate, std::unique_ptr<LoadInfoList> infos) { | 2333 LoaderDelegate* loader_delegate, std::unique_ptr<LoadInfoList> infos) { |
2330 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2334 DCHECK(Get()->main_thread_task_runner_->BelongsToCurrentThread()); |
| 2335 |
2331 std::unique_ptr<LoadInfoMap> info_map = | 2336 std::unique_ptr<LoadInfoMap> info_map = |
2332 PickMoreInterestingLoadInfos(std::move(infos)); | 2337 PickMoreInterestingLoadInfos(std::move(infos)); |
2333 for (const auto& load_info: *info_map) { | 2338 for (const auto& load_info: *info_map) { |
2334 loader_delegate->LoadStateChanged( | 2339 loader_delegate->LoadStateChanged( |
2335 load_info.first, | 2340 load_info.first, |
2336 load_info.second.url, load_info.second.load_state, | 2341 load_info.second.url, load_info.second.load_state, |
2337 load_info.second.upload_position, load_info.second.upload_size); | 2342 load_info.second.upload_position, load_info.second.upload_size); |
2338 } | 2343 } |
2339 } | 2344 } |
2340 | 2345 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2387 if (infos->empty() || !scheduler_->HasLoadingClients()) { | 2392 if (infos->empty() || !scheduler_->HasLoadingClients()) { |
2388 update_load_states_timer_->Stop(); | 2393 update_load_states_timer_->Stop(); |
2389 return; | 2394 return; |
2390 } | 2395 } |
2391 | 2396 |
2392 // We need to be able to compare all requests to find the most important one | 2397 // We need to be able to compare all requests to find the most important one |
2393 // per tab. Since some requests may be navigation requests and we don't have | 2398 // per tab. Since some requests may be navigation requests and we don't have |
2394 // their render frame routing IDs yet (which is what we have for subresource | 2399 // their render frame routing IDs yet (which is what we have for subresource |
2395 // requests), we must go to the UI thread and compare the requests using their | 2400 // requests), we must go to the UI thread and compare the requests using their |
2396 // WebContents. | 2401 // WebContents. |
2397 BrowserThread::PostTask( | 2402 main_thread_task_runner_->PostTask( |
2398 BrowserThread::UI, | 2403 FROM_HERE, |
2399 FROM_HERE, | 2404 base::Bind(UpdateLoadStateOnUI, loader_delegate_, base::Passed(&infos))); |
2400 base::Bind(UpdateLoadStateOnUI, | |
2401 loader_delegate_, base::Passed(&infos))); | |
2402 } | 2405 } |
2403 | 2406 |
2404 void ResourceDispatcherHostImpl::BlockRequestsForRoute( | 2407 void ResourceDispatcherHostImpl::BlockRequestsForRoute( |
2405 const GlobalFrameRoutingId& global_routing_id) { | 2408 const GlobalFrameRoutingId& global_routing_id) { |
2406 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2409 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); |
2407 DCHECK(blocked_loaders_map_.find(global_routing_id) == | 2410 DCHECK(blocked_loaders_map_.find(global_routing_id) == |
2408 blocked_loaders_map_.end()) | 2411 blocked_loaders_map_.end()) |
2409 << "BlockRequestsForRoute called multiple time for the same RFH"; | 2412 << "BlockRequestsForRoute called multiple time for the same RFH"; |
2410 blocked_loaders_map_[global_routing_id] = | 2413 blocked_loaders_map_[global_routing_id] = |
2411 base::MakeUnique<BlockedLoadersList>(); | 2414 base::MakeUnique<BlockedLoadersList>(); |
2412 } | 2415 } |
2413 | 2416 |
2414 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute( | 2417 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute( |
2415 const GlobalFrameRoutingId& global_routing_id) { | 2418 const GlobalFrameRoutingId& global_routing_id) { |
2416 ProcessBlockedRequestsForRoute(global_routing_id, false); | 2419 ProcessBlockedRequestsForRoute(global_routing_id, false); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2471 } | 2474 } |
2472 | 2475 |
2473 bool ResourceDispatcherHostImpl::IsTransferredNavigation( | 2476 bool ResourceDispatcherHostImpl::IsTransferredNavigation( |
2474 const GlobalRequestID& id) const { | 2477 const GlobalRequestID& id) const { |
2475 ResourceLoader* loader = GetLoader(id); | 2478 ResourceLoader* loader = GetLoader(id); |
2476 return loader ? loader->is_transferring() : false; | 2479 return loader ? loader->is_transferring() : false; |
2477 } | 2480 } |
2478 | 2481 |
2479 ResourceLoader* ResourceDispatcherHostImpl::GetLoader( | 2482 ResourceLoader* ResourceDispatcherHostImpl::GetLoader( |
2480 const GlobalRequestID& id) const { | 2483 const GlobalRequestID& id) const { |
2481 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2484 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); |
2482 | 2485 |
2483 LoaderMap::const_iterator i = pending_loaders_.find(id); | 2486 LoaderMap::const_iterator i = pending_loaders_.find(id); |
2484 if (i == pending_loaders_.end()) | 2487 if (i == pending_loaders_.end()) |
2485 return NULL; | 2488 return NULL; |
2486 | 2489 |
2487 return i->second.get(); | 2490 return i->second.get(); |
2488 } | 2491 } |
2489 | 2492 |
2490 ResourceLoader* ResourceDispatcherHostImpl::GetLoader(int child_id, | 2493 ResourceLoader* ResourceDispatcherHostImpl::GetLoader(int child_id, |
2491 int request_id) const { | 2494 int request_id) const { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2613 &throttles); | 2616 &throttles); |
2614 if (!throttles.empty()) { | 2617 if (!throttles.empty()) { |
2615 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, | 2618 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, |
2616 std::move(throttles))); | 2619 std::move(throttles))); |
2617 } | 2620 } |
2618 } | 2621 } |
2619 return handler; | 2622 return handler; |
2620 } | 2623 } |
2621 | 2624 |
2622 } // namespace content | 2625 } // namespace content |
OLD | NEW |