Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 1564963002: [on hold] Remove dependency on RenderViewHost from LoadState notifications Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make LoadInfo CONTENT_EXPORT for tests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
2480 // Note that GetLoadInfoForAllRoutes de-dupes based on frame, but not based on
2481 // tab. Thus, logic here also constructs a map and finds the most interesting
2482 // load state per WebContents.
mmenke 2016/06/01 15:19:32 Suggest moving this inside the method, or to the h
Charlie Harrison 2016/06/02 14:22:28 Moved to the header.
2469 // static 2483 // static
2470 void ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread( 2484 void ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread(
2471 std::unique_ptr<LoadInfoMap> info_map) { 2485 std::unique_ptr<LoadInfoMap> info_map) {
2472 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 2486 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
2473 // is fixed. 2487 // is fixed.
2474 tracked_objects::ScopedTracker tracking_profile( 2488 tracked_objects::ScopedTracker tracking_profile(
2475 FROM_HERE_WITH_EXPLICIT_FUNCTION( 2489 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2476 "466285 ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread")); 2490 "466285 ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread"));
2477 DCHECK_CURRENTLY_ON(BrowserThread::UI); 2491 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2492 std::map<WebContentsImpl*, const LoadInfo*> contents_map;
2478 for (const auto& load_info : *info_map) { 2493 for (const auto& load_info : *info_map) {
2479 RenderViewHostImpl* view = RenderViewHostImpl::FromID( 2494 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
2480 load_info.first.child_id, load_info.first.route_id); 2495 load_info.second.web_contents_getter.Run());
2481 // The view could be gone at this point. 2496 if (!web_contents)
2482 if (view) { 2497 continue;
2483 view->LoadStateChanged(load_info.second.url, load_info.second.load_state, 2498 auto existing = contents_map.find(web_contents);
2484 load_info.second.upload_position, 2499 if (existing == contents_map.end() ||
2485 load_info.second.upload_size); 2500 LoadInfoIsMoreInteresting(load_info.second, *existing->second)) {
2501 contents_map[web_contents] = &load_info.second;
2486 } 2502 }
2487 } 2503 }
2504 for (const auto& it : contents_map) {
2505 it.first->LoadStateChanged(it.second->url, it.second->load_state,
2506 it.second->upload_position,
2507 it.second->upload_size);
mmenke 2016/06/01 15:19:32 Is it possible that calling LoadStateChanged on on
nasko 2016/06/01 16:54:00 If it is possible with the new code, it was possib
mmenke 2016/06/01 16:58:49 The way the old code was written here, though, it
Charlie Harrison 2016/06/02 14:22:28 You're right. I would say it's reasonable to assum
2508 }
2488 } 2509 }
2489 2510
2490 std::unique_ptr<ResourceDispatcherHostImpl::LoadInfoMap> 2511 std::unique_ptr<ResourceDispatcherHostImpl::LoadInfoMap>
2491 ResourceDispatcherHostImpl::GetLoadInfoForAllRoutes() { 2512 ResourceDispatcherHostImpl::GetLoadInfoForAllRoutes() {
2492 // Populate this map with load state changes, and then send them on to the UI 2513 // 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. 2514 // thread where they can be passed along to the respective WebContents.
2494 std::unique_ptr<LoadInfoMap> info_map(new LoadInfoMap()); 2515 std::unique_ptr<LoadInfoMap> info_map(new LoadInfoMap());
2495 2516
2496 for (const auto& loader : pending_loaders_) { 2517 for (const auto& loader : pending_loaders_) {
2497 net::URLRequest* request = loader.second->request(); 2518 net::URLRequest* request = loader.second->request();
2498 net::UploadProgress upload_progress = request->GetUploadProgress(); 2519 net::UploadProgress upload_progress = request->GetUploadProgress();
2499 2520
2500 LoadInfo load_info; 2521 LoadInfo load_info;
2501 load_info.url = request->url(); 2522 load_info.url = request->url();
2502 load_info.load_state = request->GetLoadState(); 2523 load_info.load_state = request->GetLoadState();
2503 load_info.upload_size = upload_progress.size(); 2524 load_info.upload_size = upload_progress.size();
2504 load_info.upload_position = upload_progress.position(); 2525 load_info.upload_position = upload_progress.position();
2526 load_info.web_contents_getter =
2527 loader.second->GetRequestInfo()->GetWebContentsGetterForRequest();
2505 2528
2506 GlobalRoutingID id(loader.second->GetRequestInfo()->GetGlobalRoutingID()); 2529 GlobalFrameRoutingId id(
2530 loader.second->GetRequestInfo()->GetGlobalFrameRoutingId());
2507 LoadInfoMap::iterator existing = info_map->find(id); 2531 LoadInfoMap::iterator existing = info_map->find(id);
2508 2532
2509 if (existing == info_map->end() || 2533 if (existing == info_map->end() ||
2510 LoadInfoIsMoreInteresting(load_info, existing->second)) { 2534 LoadInfoIsMoreInteresting(load_info, existing->second)) {
2511 (*info_map)[id] = load_info; 2535 (*info_map)[id] = load_info;
2512 } 2536 }
2513 } 2537 }
2514 return info_map; 2538 return info_map;
2515 } 2539 }
2516 2540
2517 void ResourceDispatcherHostImpl::UpdateLoadInfo() { 2541 void ResourceDispatcherHostImpl::UpdateLoadInfo() {
2542 // Group load info by frame, then pass to the UI thread where each WebContents
nasko 2016/06/01 16:54:00 nit: s/load info/LoadInfo/
Charlie Harrison 2016/06/02 14:22:28 Done.
2543 // picks the most interesting one.
2518 std::unique_ptr<LoadInfoMap> info_map(GetLoadInfoForAllRoutes()); 2544 std::unique_ptr<LoadInfoMap> info_map(GetLoadInfoForAllRoutes());
2519 2545
2520 // Stop the timer if there are no more pending requests. Future new requests 2546 // Stop the timer if there are no more pending requests. Future new requests
2521 // will restart it as necessary. 2547 // will restart it as necessary.
2522 // Also stop the timer if there are no loading clients, to avoid waking up 2548 // 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. 2549 // unnecessarily when there is a long running (hanging get) request.
2524 if (info_map->empty() || !scheduler_->HasLoadingClients()) { 2550 if (info_map->empty() || !scheduler_->HasLoadingClients()) {
2525 update_load_states_timer_->Stop(); 2551 update_load_states_timer_->Stop();
2526 return; 2552 return;
2527 } 2553 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
2690 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); 2716 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id);
2691 response->head.security_info = SerializeSecurityInfo(ssl); 2717 response->head.security_info = SerializeSecurityInfo(ssl);
2692 } 2718 }
2693 2719
2694 CertStore* ResourceDispatcherHostImpl::GetCertStore() { 2720 CertStore* ResourceDispatcherHostImpl::GetCertStore() {
2695 return cert_store_for_testing_ ? cert_store_for_testing_ 2721 return cert_store_for_testing_ ? cert_store_for_testing_
2696 : CertStore::GetInstance(); 2722 : CertStore::GetInstance();
2697 } 2723 }
2698 2724
2699 } // namespace content 2725 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698