| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "content/browser/download/download_resource_handler.h" | 42 #include "content/browser/download/download_resource_handler.h" |
| 43 #include "content/browser/download/save_file_manager.h" | 43 #include "content/browser/download/save_file_manager.h" |
| 44 #include "content/browser/download/save_file_resource_handler.h" | 44 #include "content/browser/download/save_file_resource_handler.h" |
| 45 #include "content/browser/frame_host/frame_tree.h" | 45 #include "content/browser/frame_host/frame_tree.h" |
| 46 #include "content/browser/frame_host/navigation_request_info.h" | 46 #include "content/browser/frame_host/navigation_request_info.h" |
| 47 #include "content/browser/frame_host/navigator.h" | 47 #include "content/browser/frame_host/navigator.h" |
| 48 #include "content/browser/loader/async_resource_handler.h" | 48 #include "content/browser/loader/async_resource_handler.h" |
| 49 #include "content/browser/loader/async_revalidation_manager.h" | 49 #include "content/browser/loader/async_revalidation_manager.h" |
| 50 #include "content/browser/loader/cross_site_resource_handler.h" | 50 #include "content/browser/loader/cross_site_resource_handler.h" |
| 51 #include "content/browser/loader/detachable_resource_handler.h" | 51 #include "content/browser/loader/detachable_resource_handler.h" |
| 52 #include "content/browser/loader/loader_delegate.h" |
| 52 #include "content/browser/loader/mime_type_resource_handler.h" | 53 #include "content/browser/loader/mime_type_resource_handler.h" |
| 53 #include "content/browser/loader/navigation_resource_handler.h" | 54 #include "content/browser/loader/navigation_resource_handler.h" |
| 54 #include "content/browser/loader/navigation_resource_throttle.h" | 55 #include "content/browser/loader/navigation_resource_throttle.h" |
| 55 #include "content/browser/loader/navigation_url_loader_impl_core.h" | 56 #include "content/browser/loader/navigation_url_loader_impl_core.h" |
| 56 #include "content/browser/loader/power_save_block_resource_throttle.h" | 57 #include "content/browser/loader/power_save_block_resource_throttle.h" |
| 57 #include "content/browser/loader/redirect_to_file_resource_handler.h" | 58 #include "content/browser/loader/redirect_to_file_resource_handler.h" |
| 58 #include "content/browser/loader/resource_message_filter.h" | 59 #include "content/browser/loader/resource_message_filter.h" |
| 59 #include "content/browser/loader/resource_request_info_impl.h" | 60 #include "content/browser/loader/resource_request_info_impl.h" |
| 60 #include "content/browser/loader/stream_resource_handler.h" | 61 #include "content/browser/loader/stream_resource_handler.h" |
| 61 #include "content/browser/loader/sync_resource_handler.h" | 62 #include "content/browser/loader/sync_resource_handler.h" |
| 62 #include "content/browser/loader/throttling_resource_handler.h" | 63 #include "content/browser/loader/throttling_resource_handler.h" |
| 63 #include "content/browser/loader/upload_data_stream_builder.h" | 64 #include "content/browser/loader/upload_data_stream_builder.h" |
| 64 #include "content/browser/renderer_host/render_view_host_impl.h" | |
| 65 #include "content/browser/resource_context_impl.h" | 65 #include "content/browser/resource_context_impl.h" |
| 66 #include "content/browser/service_worker/foreign_fetch_request_handler.h" | 66 #include "content/browser/service_worker/foreign_fetch_request_handler.h" |
| 67 #include "content/browser/service_worker/link_header_support.h" | 67 #include "content/browser/service_worker/link_header_support.h" |
| 68 #include "content/browser/service_worker/service_worker_request_handler.h" | 68 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 69 #include "content/browser/streams/stream.h" | 69 #include "content/browser/streams/stream.h" |
| 70 #include "content/browser/streams/stream_context.h" | 70 #include "content/browser/streams/stream_context.h" |
| 71 #include "content/browser/streams/stream_registry.h" | 71 #include "content/browser/streams/stream_registry.h" |
| 72 #include "content/browser/web_contents/web_contents_impl.h" | 72 #include "content/browser/web_contents/web_contents_impl.h" |
| 73 #include "content/common/navigation_params.h" | 73 #include "content/common/navigation_params.h" |
| 74 #include "content/common/net/url_request_service_worker_data.h" | 74 #include "content/common/net/url_request_service_worker_data.h" |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() | 540 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() |
| 541 : save_file_manager_(new SaveFileManager()), | 541 : save_file_manager_(new SaveFileManager()), |
| 542 request_id_(-1), | 542 request_id_(-1), |
| 543 is_shutdown_(false), | 543 is_shutdown_(false), |
| 544 num_in_flight_requests_(0), | 544 num_in_flight_requests_(0), |
| 545 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), | 545 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), |
| 546 max_num_in_flight_requests_per_process_(static_cast<int>( | 546 max_num_in_flight_requests_per_process_(static_cast<int>( |
| 547 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), | 547 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), |
| 548 max_outstanding_requests_cost_per_process_( | 548 max_outstanding_requests_cost_per_process_( |
| 549 kMaxOutstandingRequestsCostPerProcess), | 549 kMaxOutstandingRequestsCostPerProcess), |
| 550 filter_(NULL), | 550 filter_(nullptr), |
| 551 delegate_(NULL), | 551 delegate_(nullptr), |
| 552 loader_delegate_(nullptr), |
| 552 allow_cross_origin_auth_prompt_(false), | 553 allow_cross_origin_auth_prompt_(false), |
| 553 cert_store_for_testing_(nullptr) { | 554 cert_store_for_testing_(nullptr) { |
| 554 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 555 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 555 DCHECK(!g_resource_dispatcher_host); | 556 DCHECK(!g_resource_dispatcher_host); |
| 556 g_resource_dispatcher_host = this; | 557 g_resource_dispatcher_host = this; |
| 557 | 558 |
| 558 GetContentClient()->browser()->ResourceDispatcherHostCreated(); | 559 GetContentClient()->browser()->ResourceDispatcherHostCreated(); |
| 559 | 560 |
| 560 ANNOTATE_BENIGN_RACE( | 561 ANNOTATE_BENIGN_RACE( |
| 561 &last_user_gesture_time_, | 562 &last_user_gesture_time_, |
| (...skipping 1741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2303 std::move(handler)); | 2304 std::move(handler)); |
| 2304 | 2305 |
| 2305 BeginRequestInternal(std::move(new_request), std::move(handler)); | 2306 BeginRequestInternal(std::move(new_request), std::move(handler)); |
| 2306 } | 2307 } |
| 2307 | 2308 |
| 2308 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { | 2309 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { |
| 2309 if (!async_revalidation_manager_) | 2310 if (!async_revalidation_manager_) |
| 2310 async_revalidation_manager_.reset(new AsyncRevalidationManager); | 2311 async_revalidation_manager_.reset(new AsyncRevalidationManager); |
| 2311 } | 2312 } |
| 2312 | 2313 |
| 2314 void ResourceDispatcherHostImpl::SetLoaderDelegate( |
| 2315 LoaderDelegate* loader_delegate) { |
| 2316 loader_delegate_ = loader_delegate; |
| 2317 } |
| 2318 |
| 2313 // static | 2319 // static |
| 2314 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( | 2320 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
| 2315 net::URLRequest* request) { | 2321 net::URLRequest* request) { |
| 2316 // The following fields should be a minor size contribution (experimentally | 2322 // The following fields should be a minor size contribution (experimentally |
| 2317 // on the order of 100). However since they are variable length, it could | 2323 // on the order of 100). However since they are variable length, it could |
| 2318 // in theory be a sizeable contribution. | 2324 // in theory be a sizeable contribution. |
| 2319 int strings_cost = request->extra_request_headers().ToString().size() + | 2325 int strings_cost = request->extra_request_headers().ToString().size() + |
| 2320 request->original_url().spec().size() + | 2326 request->original_url().spec().size() + |
| 2321 request->referrer().size() + | 2327 request->referrer().size() + |
| 2322 request->method().size(); | 2328 request->method().size(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2418 uint64_t b_uploading_size = 0; | 2424 uint64_t b_uploading_size = 0; |
| 2419 if (b.load_state.state == net::LOAD_STATE_SENDING_REQUEST) | 2425 if (b.load_state.state == net::LOAD_STATE_SENDING_REQUEST) |
| 2420 b_uploading_size = b.upload_size; | 2426 b_uploading_size = b.upload_size; |
| 2421 | 2427 |
| 2422 if (a_uploading_size != b_uploading_size) | 2428 if (a_uploading_size != b_uploading_size) |
| 2423 return a_uploading_size > b_uploading_size; | 2429 return a_uploading_size > b_uploading_size; |
| 2424 | 2430 |
| 2425 return a.load_state.state > b.load_state.state; | 2431 return a.load_state.state > b.load_state.state; |
| 2426 } | 2432 } |
| 2427 | 2433 |
| 2428 // static | |
| 2429 void ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread( | |
| 2430 std::unique_ptr<LoadInfoMap> info_map) { | |
| 2431 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 | |
| 2432 // is fixed. | |
| 2433 tracked_objects::ScopedTracker tracking_profile( | |
| 2434 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
| 2435 "466285 ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread")); | |
| 2436 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 2437 for (const auto& load_info : *info_map) { | |
| 2438 RenderViewHostImpl* view = RenderViewHostImpl::FromID( | |
| 2439 load_info.first.child_id, load_info.first.route_id); | |
| 2440 // The view could be gone at this point. | |
| 2441 if (view) { | |
| 2442 view->LoadStateChanged(load_info.second.url, load_info.second.load_state, | |
| 2443 load_info.second.upload_position, | |
| 2444 load_info.second.upload_size); | |
| 2445 } | |
| 2446 } | |
| 2447 } | |
| 2448 | |
| 2449 std::unique_ptr<ResourceDispatcherHostImpl::LoadInfoMap> | 2434 std::unique_ptr<ResourceDispatcherHostImpl::LoadInfoMap> |
| 2450 ResourceDispatcherHostImpl::GetLoadInfoForAllRoutes() { | 2435 ResourceDispatcherHostImpl::GetLoadInfoForAllRoutes() { |
| 2451 // Populate this map with load state changes, and then send them on to the UI | 2436 // Populate this map with load state changes, and then send them on to the UI |
| 2452 // thread where they can be passed along to the respective RVHs. | 2437 // thread where they can be passed along to the respective RVHs. |
| 2453 std::unique_ptr<LoadInfoMap> info_map(new LoadInfoMap()); | 2438 std::unique_ptr<LoadInfoMap> info_map(new LoadInfoMap()); |
| 2454 | 2439 |
| 2455 for (const auto& loader : pending_loaders_) { | 2440 for (const auto& loader : pending_loaders_) { |
| 2456 net::URLRequest* request = loader.second->request(); | 2441 net::URLRequest* request = loader.second->request(); |
| 2457 net::UploadProgress upload_progress = request->GetUploadProgress(); | 2442 net::UploadProgress upload_progress = request->GetUploadProgress(); |
| 2458 | 2443 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2478 | 2463 |
| 2479 // Stop the timer if there are no more pending requests. Future new requests | 2464 // Stop the timer if there are no more pending requests. Future new requests |
| 2480 // will restart it as necessary. | 2465 // will restart it as necessary. |
| 2481 // Also stop the timer if there are no loading clients, to avoid waking up | 2466 // Also stop the timer if there are no loading clients, to avoid waking up |
| 2482 // unnecessarily when there is a long running (hanging get) request. | 2467 // unnecessarily when there is a long running (hanging get) request. |
| 2483 if (info_map->empty() || !scheduler_->HasLoadingClients()) { | 2468 if (info_map->empty() || !scheduler_->HasLoadingClients()) { |
| 2484 update_load_states_timer_->Stop(); | 2469 update_load_states_timer_->Stop(); |
| 2485 return; | 2470 return; |
| 2486 } | 2471 } |
| 2487 | 2472 |
| 2488 BrowserThread::PostTask( | 2473 for (const auto& load_info : *info_map) { |
| 2489 BrowserThread::UI, FROM_HERE, | 2474 loader_delegate_->LoadStateChanged( |
| 2490 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread, | 2475 load_info.first.child_id, load_info.first.route_id, |
| 2491 base::Passed(&info_map))); | 2476 load_info.second.url, load_info.second.load_state, |
| 2477 load_info.second.upload_position, load_info.second.upload_size); |
| 2478 } |
| 2492 } | 2479 } |
| 2493 | 2480 |
| 2494 void ResourceDispatcherHostImpl::BlockRequestsForRoute( | 2481 void ResourceDispatcherHostImpl::BlockRequestsForRoute( |
| 2495 const GlobalFrameRoutingId& global_routing_id) { | 2482 const GlobalFrameRoutingId& global_routing_id) { |
| 2496 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2483 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 2497 DCHECK(blocked_loaders_map_.find(global_routing_id) == | 2484 DCHECK(blocked_loaders_map_.find(global_routing_id) == |
| 2498 blocked_loaders_map_.end()) | 2485 blocked_loaders_map_.end()) |
| 2499 << "BlockRequestsForRoute called multiple time for the same RFH"; | 2486 << "BlockRequestsForRoute called multiple time for the same RFH"; |
| 2500 blocked_loaders_map_[global_routing_id] = | 2487 blocked_loaders_map_[global_routing_id] = |
| 2501 base::WrapUnique(new BlockedLoadersList()); | 2488 base::WrapUnique(new BlockedLoadersList()); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2649 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); | 2636 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); |
| 2650 response->head.security_info = SerializeSecurityInfo(ssl); | 2637 response->head.security_info = SerializeSecurityInfo(ssl); |
| 2651 } | 2638 } |
| 2652 | 2639 |
| 2653 CertStore* ResourceDispatcherHostImpl::GetCertStore() { | 2640 CertStore* ResourceDispatcherHostImpl::GetCertStore() { |
| 2654 return cert_store_for_testing_ ? cert_store_for_testing_ | 2641 return cert_store_for_testing_ ? cert_store_for_testing_ |
| 2655 : CertStore::GetInstance(); | 2642 : CertStore::GetInstance(); |
| 2656 } | 2643 } |
| 2657 | 2644 |
| 2658 } // namespace content | 2645 } // namespace content |
| OLD | NEW |