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 2389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2459 uint64_t b_uploading_size = 0; | 2458 uint64_t b_uploading_size = 0; |
2460 if (b.load_state.state == net::LOAD_STATE_SENDING_REQUEST) | 2459 if (b.load_state.state == net::LOAD_STATE_SENDING_REQUEST) |
2461 b_uploading_size = b.upload_size; | 2460 b_uploading_size = b.upload_size; |
2462 | 2461 |
2463 if (a_uploading_size != b_uploading_size) | 2462 if (a_uploading_size != b_uploading_size) |
2464 return a_uploading_size > b_uploading_size; | 2463 return a_uploading_size > b_uploading_size; |
2465 | 2464 |
2466 return a.load_state.state > b.load_state.state; | 2465 return a.load_state.state > b.load_state.state; |
2467 } | 2466 } |
2468 | 2467 |
2469 // static | 2468 ResourceDispatcherHostImpl::LoadInfo::LoadInfo() {} |
2469 | |
2470 ResourceDispatcherHostImpl::LoadInfo::~LoadInfo() {} | |
2471 | |
2472 ResourceDispatcherHostImpl::LoadInfo::LoadInfo(const LoadInfo& info) { | |
2473 url = info.url; | |
2474 load_state = info.load_state; | |
2475 upload_position = info.upload_position; | |
2476 upload_size = info.upload_size; | |
2477 web_contents_getter = info.web_contents_getter; | |
2478 } | |
2479 | |
2470 void ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread( | 2480 void ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread( |
2471 std::unique_ptr<LoadInfoMap> info_map) { | 2481 std::unique_ptr<LoadInfoMap> info_map) { |
2472 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 | 2482 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
2473 // is fixed. | 2483 // is fixed. |
2474 tracked_objects::ScopedTracker tracking_profile( | 2484 tracked_objects::ScopedTracker tracking_profile( |
2475 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 2485 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
2476 "466285 ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread")); | 2486 "466285 ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread")); |
2477 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2487 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
2488 std::map<WebContents*, const LoadInfo*> contents_map; | |
2478 for (const auto& load_info : *info_map) { | 2489 for (const auto& load_info : *info_map) { |
2479 RenderViewHostImpl* view = RenderViewHostImpl::FromID( | 2490 WebContents* web_contents = load_info.second.web_contents_getter.Run(); |
2480 load_info.first.child_id, load_info.first.route_id); | 2491 if (!web_contents) |
2481 // The view could be gone at this point. | 2492 continue; |
2482 if (view) { | 2493 auto existing = contents_map.find(web_contents); |
2483 view->LoadStateChanged(load_info.second.url, load_info.second.load_state, | 2494 if (existing == contents_map.end() || |
2484 load_info.second.upload_position, | 2495 LoadInfoIsMoreInteresting(load_info.second, *existing->second)) { |
2485 load_info.second.upload_size); | 2496 contents_map[web_contents] = &load_info.second; |
2497 } | |
2498 } | |
2499 for (const auto& it : contents_map) { | |
2500 // Re-run the getter to prevent u-a-f errors if calling LoadStateChanged on | |
nasko
2016/06/02 22:04:21
Please expand u-a-f, as it isn't really common abb
Charlie Harrison
2016/06/06 15:39:53
Done.
| |
2501 // one WebContents deletes another one. | |
2502 WebContentsImpl* web_contents = | |
2503 static_cast<WebContentsImpl*>(it.second->web_contents_getter.Run()); | |
2504 if (web_contents) { | |
2505 web_contents->LoadStateChanged(it.second->url, it.second->load_state, | |
2506 it.second->upload_position, | |
2507 it.second->upload_size); | |
2486 } | 2508 } |
2487 } | 2509 } |
2488 } | 2510 } |
2489 | 2511 |
2490 std::unique_ptr<ResourceDispatcherHostImpl::LoadInfoMap> | 2512 std::unique_ptr<ResourceDispatcherHostImpl::LoadInfoMap> |
2491 ResourceDispatcherHostImpl::GetLoadInfoForAllRoutes() { | 2513 ResourceDispatcherHostImpl::GetLoadInfoForAllRoutes() { |
2492 // Populate this map with load state changes, and then send them on to the UI | 2514 // Populate this map with load state changes, and then send them on to the UI |
2493 // thread where they can be passed along to the respective RVHs. | 2515 // thread where they can be passed along to the respective WebContents. |
2494 std::unique_ptr<LoadInfoMap> info_map(new LoadInfoMap()); | 2516 std::unique_ptr<LoadInfoMap> info_map(new LoadInfoMap()); |
2495 | 2517 |
2496 for (const auto& loader : pending_loaders_) { | 2518 for (const auto& loader : pending_loaders_) { |
2497 net::URLRequest* request = loader.second->request(); | 2519 net::URLRequest* request = loader.second->request(); |
2498 net::UploadProgress upload_progress = request->GetUploadProgress(); | 2520 net::UploadProgress upload_progress = request->GetUploadProgress(); |
2499 | 2521 |
2500 LoadInfo load_info; | 2522 LoadInfo load_info; |
2501 load_info.url = request->url(); | 2523 load_info.url = request->url(); |
2502 load_info.load_state = request->GetLoadState(); | 2524 load_info.load_state = request->GetLoadState(); |
2503 load_info.upload_size = upload_progress.size(); | 2525 load_info.upload_size = upload_progress.size(); |
2504 load_info.upload_position = upload_progress.position(); | 2526 load_info.upload_position = upload_progress.position(); |
2527 load_info.web_contents_getter = | |
2528 loader.second->GetRequestInfo()->GetWebContentsGetterForRequest(); | |
2505 | 2529 |
2506 GlobalRoutingID id(loader.second->GetRequestInfo()->GetGlobalRoutingID()); | 2530 GlobalFrameRoutingId id( |
2531 loader.second->GetRequestInfo()->GetGlobalFrameRoutingId()); | |
2507 LoadInfoMap::iterator existing = info_map->find(id); | 2532 LoadInfoMap::iterator existing = info_map->find(id); |
2508 | 2533 |
2509 if (existing == info_map->end() || | 2534 if (existing == info_map->end() || |
2510 LoadInfoIsMoreInteresting(load_info, existing->second)) { | 2535 LoadInfoIsMoreInteresting(load_info, existing->second)) { |
2511 (*info_map)[id] = load_info; | 2536 (*info_map)[id] = load_info; |
2512 } | 2537 } |
2513 } | 2538 } |
2514 return info_map; | 2539 return info_map; |
2515 } | 2540 } |
2516 | 2541 |
2517 void ResourceDispatcherHostImpl::UpdateLoadInfo() { | 2542 void ResourceDispatcherHostImpl::UpdateLoadInfo() { |
2543 // Group LoadInfo by frame, then pass to the UI thread where each WebContents | |
2544 // picks the most interesting one. | |
2518 std::unique_ptr<LoadInfoMap> info_map(GetLoadInfoForAllRoutes()); | 2545 std::unique_ptr<LoadInfoMap> info_map(GetLoadInfoForAllRoutes()); |
2519 | 2546 |
2520 // Stop the timer if there are no more pending requests. Future new requests | 2547 // Stop the timer if there are no more pending requests. Future new requests |
2521 // will restart it as necessary. | 2548 // will restart it as necessary. |
2522 // Also stop the timer if there are no loading clients, to avoid waking up | 2549 // Also stop the timer if there are no loading clients, to avoid waking up |
2523 // unnecessarily when there is a long running (hanging get) request. | 2550 // unnecessarily when there is a long running (hanging get) request. |
2524 if (info_map->empty() || !scheduler_->HasLoadingClients()) { | 2551 if (info_map->empty() || !scheduler_->HasLoadingClients()) { |
2525 update_load_states_timer_->Stop(); | 2552 update_load_states_timer_->Stop(); |
2526 return; | 2553 return; |
2527 } | 2554 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2690 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); | 2717 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); |
2691 response->head.security_info = SerializeSecurityInfo(ssl); | 2718 response->head.security_info = SerializeSecurityInfo(ssl); |
2692 } | 2719 } |
2693 | 2720 |
2694 CertStore* ResourceDispatcherHostImpl::GetCertStore() { | 2721 CertStore* ResourceDispatcherHostImpl::GetCertStore() { |
2695 return cert_store_for_testing_ ? cert_store_for_testing_ | 2722 return cert_store_for_testing_ ? cert_store_for_testing_ |
2696 : CertStore::GetInstance(); | 2723 : CertStore::GetInstance(); |
2697 } | 2724 } |
2698 | 2725 |
2699 } // namespace content | 2726 } // namespace content |
OLD | NEW |