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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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/mime_type_resource_handler.h" | 52 #include "content/browser/loader/mime_type_resource_handler.h" |
53 #include "content/browser/loader/navigation_resource_handler.h" | 53 #include "content/browser/loader/navigation_resource_handler.h" |
54 #include "content/browser/loader/navigation_resource_throttle.h" | 54 #include "content/browser/loader/navigation_resource_throttle.h" |
55 #include "content/browser/loader/navigation_url_loader_impl_core.h" | 55 #include "content/browser/loader/navigation_url_loader_impl_core.h" |
56 #include "content/browser/loader/power_save_block_resource_throttle.h" | 56 #include "content/browser/loader/power_save_block_resource_throttle.h" |
57 #include "content/browser/loader/redirect_to_file_resource_handler.h" | 57 #include "content/browser/loader/redirect_to_file_resource_handler.h" |
58 #include "content/browser/loader/resource_message_filter.h" | 58 #include "content/browser/loader/resource_message_filter.h" |
59 #include "content/browser/loader/resource_request_info_impl.h" | |
60 #include "content/browser/loader/stream_resource_handler.h" | 59 #include "content/browser/loader/stream_resource_handler.h" |
61 #include "content/browser/loader/sync_resource_handler.h" | 60 #include "content/browser/loader/sync_resource_handler.h" |
62 #include "content/browser/loader/throttling_resource_handler.h" | 61 #include "content/browser/loader/throttling_resource_handler.h" |
63 #include "content/browser/loader/upload_data_stream_builder.h" | 62 #include "content/browser/loader/upload_data_stream_builder.h" |
64 #include "content/browser/renderer_host/render_view_host_delegate.h" | 63 #include "content/browser/renderer_host/render_view_host_delegate.h" |
65 #include "content/browser/renderer_host/render_view_host_impl.h" | 64 #include "content/browser/renderer_host/render_view_host_impl.h" |
66 #include "content/browser/resource_context_impl.h" | 65 #include "content/browser/resource_context_impl.h" |
67 #include "content/browser/service_worker/foreign_fetch_request_handler.h" | 66 #include "content/browser/service_worker/foreign_fetch_request_handler.h" |
68 #include "content/browser/service_worker/link_header_support.h" | 67 #include "content/browser/service_worker/link_header_support.h" |
69 #include "content/browser/service_worker/service_worker_request_handler.h" | 68 #include "content/browser/service_worker/service_worker_request_handler.h" |
(...skipping 2387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2457 uint64_t b_uploading_size = 0; | 2456 uint64_t b_uploading_size = 0; |
2458 if (b.load_state.state == net::LOAD_STATE_SENDING_REQUEST) | 2457 if (b.load_state.state == net::LOAD_STATE_SENDING_REQUEST) |
2459 b_uploading_size = b.upload_size; | 2458 b_uploading_size = b.upload_size; |
2460 | 2459 |
2461 if (a_uploading_size != b_uploading_size) | 2460 if (a_uploading_size != b_uploading_size) |
2462 return a_uploading_size > b_uploading_size; | 2461 return a_uploading_size > b_uploading_size; |
2463 | 2462 |
2464 return a.load_state.state > b.load_state.state; | 2463 return a.load_state.state > b.load_state.state; |
2465 } | 2464 } |
2466 | 2465 |
2466 ResourceDispatcherHostImpl::LoadInfo::LoadInfo() {} | |
2467 | |
2468 ResourceDispatcherHostImpl::LoadInfo::~LoadInfo() {} | |
2469 | |
2470 ResourceDispatcherHostImpl::LoadInfo::LoadInfo(const LoadInfo& info) { | |
2471 url = info.url; | |
2472 load_state = info.load_state; | |
2473 upload_position = info.upload_position; | |
2474 upload_size = info.upload_size; | |
2475 web_contents_getter = info.web_contents_getter; | |
2476 } | |
2477 | |
2478 // Note that GetLoadInfoForAllRoutes de-dupes based on frame, but not based on | |
2479 // tab. Thus, logic here also constructs a map and finds the most interesting | |
2480 // load state per WebContents. | |
2467 // static | 2481 // static |
2468 void ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread( | 2482 void ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread( |
2469 std::unique_ptr<LoadInfoMap> info_map) { | 2483 std::unique_ptr<LoadInfoMap> info_map) { |
2470 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 | 2484 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
2471 // is fixed. | 2485 // is fixed. |
2472 tracked_objects::ScopedTracker tracking_profile( | 2486 tracked_objects::ScopedTracker tracking_profile( |
2473 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 2487 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
2474 "466285 ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread")); | 2488 "466285 ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread")); |
2475 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2489 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
2490 std::map<WebContentsImpl*, const LoadInfo*> contents_map; | |
2476 for (const auto& load_info : *info_map) { | 2491 for (const auto& load_info : *info_map) { |
2477 RenderViewHostImpl* view = RenderViewHostImpl::FromID( | 2492 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
2478 load_info.first.child_id, load_info.first.route_id); | 2493 load_info.second.web_contents_getter.Run()); |
2479 // The view could be gone at this point. | 2494 if (!web_contents) |
2480 if (view) { | 2495 continue; |
2481 view->LoadStateChanged(load_info.second.url, load_info.second.load_state, | 2496 auto existing = contents_map.find(web_contents); |
2482 load_info.second.upload_position, | 2497 if (existing == contents_map.end() || |
2483 load_info.second.upload_size); | 2498 LoadInfoIsMoreInteresting(load_info.second, *existing->second)) { |
2499 contents_map[web_contents] = &load_info.second; | |
mmenke
2016/05/17 21:25:36
Why construct a map, instead of just calling LoadS
Charlie Harrison
2016/05/17 21:35:28
We want to call LoadStateChanged with the load ass
mmenke
2016/05/17 21:44:04
Ah, I missed the LoadInfoIsMoreInteresting call.
Charlie Harrison
2016/05/17 21:53:27
Yeah it's a little awkward. I think this is better
| |
2484 } | 2500 } |
2485 } | 2501 } |
2502 for (const auto& it : contents_map) { | |
2503 it.first->LoadStateChanged(it.second->url, it.second->load_state, | |
2504 it.second->upload_position, | |
2505 it.second->upload_size); | |
2506 } | |
2486 } | 2507 } |
2487 | 2508 |
2488 std::unique_ptr<ResourceDispatcherHostImpl::LoadInfoMap> | 2509 std::unique_ptr<ResourceDispatcherHostImpl::LoadInfoMap> |
2489 ResourceDispatcherHostImpl::GetLoadInfoForAllRoutes() { | 2510 ResourceDispatcherHostImpl::GetLoadInfoForAllRoutes() { |
2490 // Populate this map with load state changes, and then send them on to the UI | 2511 // Populate this map with load state changes, and then send them on to the UI |
2491 // thread where they can be passed along to the respective RVHs. | 2512 // thread where they can be passed along to the respective WebContents. |
2492 std::unique_ptr<LoadInfoMap> info_map(new LoadInfoMap()); | 2513 std::unique_ptr<LoadInfoMap> info_map(new LoadInfoMap()); |
2493 | 2514 |
2494 for (const auto& loader : pending_loaders_) { | 2515 for (const auto& loader : pending_loaders_) { |
2495 net::URLRequest* request = loader.second->request(); | 2516 net::URLRequest* request = loader.second->request(); |
2496 net::UploadProgress upload_progress = request->GetUploadProgress(); | 2517 net::UploadProgress upload_progress = request->GetUploadProgress(); |
2497 | 2518 |
2498 LoadInfo load_info; | 2519 LoadInfo load_info; |
2499 load_info.url = request->url(); | 2520 load_info.url = request->url(); |
2500 load_info.load_state = request->GetLoadState(); | 2521 load_info.load_state = request->GetLoadState(); |
2501 load_info.upload_size = upload_progress.size(); | 2522 load_info.upload_size = upload_progress.size(); |
2502 load_info.upload_position = upload_progress.position(); | 2523 load_info.upload_position = upload_progress.position(); |
2524 load_info.web_contents_getter = | |
2525 loader.second->GetRequestInfo()->GetWebContentsGetterForRequest(); | |
2503 | 2526 |
2504 GlobalRoutingID id(loader.second->GetRequestInfo()->GetGlobalRoutingID()); | 2527 GlobalFrameRoutingId id( |
2528 loader.second->GetRequestInfo()->GetGlobalFrameRoutingId()); | |
2505 LoadInfoMap::iterator existing = info_map->find(id); | 2529 LoadInfoMap::iterator existing = info_map->find(id); |
2506 | 2530 |
2507 if (existing == info_map->end() || | 2531 if (existing == info_map->end() || |
2508 LoadInfoIsMoreInteresting(load_info, existing->second)) { | 2532 LoadInfoIsMoreInteresting(load_info, existing->second)) { |
2509 (*info_map)[id] = load_info; | 2533 (*info_map)[id] = load_info; |
2510 } | 2534 } |
2511 } | 2535 } |
2512 return info_map; | 2536 return info_map; |
2513 } | 2537 } |
2514 | 2538 |
2515 void ResourceDispatcherHostImpl::UpdateLoadInfo() { | 2539 void ResourceDispatcherHostImpl::UpdateLoadInfo() { |
2540 // Group load info by frame, then pass to the UI thread where each WebContents | |
2541 // picks the most interesting one. | |
2516 std::unique_ptr<LoadInfoMap> info_map(GetLoadInfoForAllRoutes()); | 2542 std::unique_ptr<LoadInfoMap> info_map(GetLoadInfoForAllRoutes()); |
2517 | 2543 |
2518 // Stop the timer if there are no more pending requests. Future new requests | 2544 // Stop the timer if there are no more pending requests. Future new requests |
2519 // will restart it as necessary. | 2545 // will restart it as necessary. |
2520 // Also stop the timer if there are no loading clients, to avoid waking up | 2546 // Also stop the timer if there are no loading clients, to avoid waking up |
2521 // unnecessarily when there is a long running (hanging get) request. | 2547 // unnecessarily when there is a long running (hanging get) request. |
2522 if (info_map->empty() || !scheduler_->HasLoadingClients()) { | 2548 if (info_map->empty() || !scheduler_->HasLoadingClients()) { |
2523 update_load_states_timer_->Stop(); | 2549 update_load_states_timer_->Stop(); |
2524 return; | 2550 return; |
2525 } | 2551 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2688 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); | 2714 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); |
2689 response->head.security_info = SerializeSecurityInfo(ssl); | 2715 response->head.security_info = SerializeSecurityInfo(ssl); |
2690 } | 2716 } |
2691 | 2717 |
2692 CertStore* ResourceDispatcherHostImpl::GetCertStore() { | 2718 CertStore* ResourceDispatcherHostImpl::GetCertStore() { |
2693 return cert_store_for_testing_ ? cert_store_for_testing_ | 2719 return cert_store_for_testing_ ? cert_store_for_testing_ |
2694 : CertStore::GetInstance(); | 2720 : CertStore::GetInstance(); |
2695 } | 2721 } |
2696 | 2722 |
2697 } // namespace content | 2723 } // namespace content |
OLD | NEW |