Chromium Code Reviews| 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 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate. h" | 5 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate. h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/base64.h" | 12 #include "base/base64.h" |
| 13 #include "base/guid.h" | 13 #include "base/guid.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 21 #include "chrome/browser/component_updater/component_updater_resource_throttle.h " | 21 #include "chrome/browser/component_updater/component_updater_resource_throttle.h " |
| 22 #include "chrome/browser/download/download_request_limiter.h" | 22 #include "chrome/browser/download/download_request_limiter.h" |
| 23 #include "chrome/browser/download/download_resource_throttle.h" | 23 #include "chrome/browser/download/download_resource_throttle.h" |
| 24 #include "chrome/browser/mod_pagespeed/mod_pagespeed_metrics.h" | 24 #include "chrome/browser/mod_pagespeed/mod_pagespeed_metrics.h" |
| 25 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" | 25 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" |
| 26 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" | |
| 26 #include "chrome/browser/plugins/plugin_prefs.h" | 27 #include "chrome/browser/plugins/plugin_prefs.h" |
| 27 #include "chrome/browser/prerender/prerender_manager.h" | 28 #include "chrome/browser/prerender/prerender_manager.h" |
| 28 #include "chrome/browser/prerender/prerender_manager_factory.h" | 29 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 29 #include "chrome/browser/prerender/prerender_resource_throttle.h" | 30 #include "chrome/browser/prerender/prerender_resource_throttle.h" |
| 30 #include "chrome/browser/prerender/prerender_util.h" | 31 #include "chrome/browser/prerender/prerender_util.h" |
| 31 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 32 #include "chrome/browser/profiles/profile_io_data.h" | 33 #include "chrome/browser/profiles/profile_io_data.h" |
| 33 #include "chrome/browser/renderer_host/chrome_navigation_data.h" | 34 #include "chrome/browser/renderer_host/chrome_navigation_data.h" |
| 34 #include "chrome/browser/renderer_host/predictor_resource_throttle.h" | 35 #include "chrome/browser/renderer_host/predictor_resource_throttle.h" |
| 35 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h" | 36 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 if (!browser_context) | 154 if (!browser_context) |
| 154 return NULL; | 155 return NULL; |
| 155 | 156 |
| 156 Profile* profile = Profile::FromBrowserContext(browser_context); | 157 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 157 if (!profile) | 158 if (!profile) |
| 158 return NULL; | 159 return NULL; |
| 159 | 160 |
| 160 return prerender::PrerenderManagerFactory::GetForProfile(profile); | 161 return prerender::PrerenderManagerFactory::GetForProfile(profile); |
| 161 } | 162 } |
| 162 | 163 |
| 163 void UpdatePrerenderNetworkBytesCallback( | 164 void UpdatePrerenderNetworkBytesCallback(content::WebContents* web_contents, |
| 164 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | 165 int64_t bytes) { |
| 165 int64_t bytes) { | |
| 166 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 166 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 167 content::WebContents* web_contents = web_contents_getter.Run(); | |
| 168 // PrerenderContents::FromWebContents handles the NULL case. | 167 // PrerenderContents::FromWebContents handles the NULL case. |
| 169 prerender::PrerenderContents* prerender_contents = | 168 prerender::PrerenderContents* prerender_contents = |
| 170 prerender::PrerenderContents::FromWebContents(web_contents); | 169 prerender::PrerenderContents::FromWebContents(web_contents); |
| 171 | 170 |
| 172 if (prerender_contents) | 171 if (prerender_contents) |
| 173 prerender_contents->AddNetworkBytes(bytes); | 172 prerender_contents->AddNetworkBytes(bytes); |
| 174 | 173 |
| 175 prerender::PrerenderManager* prerender_manager = | 174 prerender::PrerenderManager* prerender_manager = |
| 176 GetPrerenderManager(web_contents); | 175 GetPrerenderManager(web_contents); |
| 177 if (prerender_manager) | 176 if (prerender_manager) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 | 273 |
| 275 if (crx_id) { | 274 if (crx_id) { |
| 276 // We got a component we need to install, so throttle the resource | 275 // We got a component we need to install, so throttle the resource |
| 277 // until the component is installed. | 276 // until the component is installed. |
| 278 throttles->push_back( | 277 throttles->push_back( |
| 279 component_updater::GetOnDemandResourceThrottle(cus, crx_id)); | 278 component_updater::GetOnDemandResourceThrottle(cus, crx_id)); |
| 280 } | 279 } |
| 281 } | 280 } |
| 282 #endif // !defined(DISABLE_NACL) | 281 #endif // !defined(DISABLE_NACL) |
| 283 | 282 |
| 284 // This function is called in RequestComplete to log metrics about main frame | 283 // This function is called in RequestComplete to log metrics about main frame |
|
Lei Zhang
2016/08/09 19:14:17
This comment is slightly out of date?
Charlie Harrison
2016/08/09 19:32:49
Updated.
| |
| 285 // resources. | 284 // resources. |
| 286 void LogMainFrameMetricsOnUIThread( | 285 void LogMainFrameMetricsOnUIThread(const GURL& url, |
| 287 const GURL& url, | 286 int net_error, |
| 288 int net_error, | 287 base::TimeDelta request_loading_time, |
| 289 base::TimeDelta request_loading_time, | 288 content::WebContents* web_contents) { |
| 290 const content::ResourceRequestInfo::WebContentsGetter& | |
| 291 web_contents_getter) { | |
| 292 content::WebContents* web_contents = web_contents_getter.Run(); | |
| 293 if (!web_contents) | 289 if (!web_contents) |
|
Lei Zhang
2016/08/09 19:14:17
Seems this should never eval to false now.
Charlie Harrison
2016/08/09 19:32:49
Removed.
| |
| 294 return; | 290 return; |
| 295 Profile* profile = | 291 Profile* profile = |
| 296 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 292 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 297 | 293 |
| 298 // The rest of the function is only concerned about NTP metrics. | 294 // The rest of the function is only concerned about NTP metrics. |
| 299 if (!profile || !search::IsNTPURL(url, profile)) | 295 if (!profile || !search::IsNTPURL(url, profile)) |
| 300 return; | 296 return; |
| 301 | 297 |
| 302 // A http/s scheme implies that the new tab page is remote. The local NTP is | 298 // A http/s scheme implies that the new tab page is remote. The local NTP is |
| 303 // served from chrome-search://. To segment out remote NTPs, use the | 299 // served from chrome-search://. To segment out remote NTPs, use the |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 if (net_error == net::OK) { | 332 if (net_error == net::OK) { |
| 337 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.Success", | 333 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.Success", |
| 338 request_loading_time); | 334 request_loading_time); |
| 339 } else if (net_error == net::ERR_ABORTED) { | 335 } else if (net_error == net::ERR_ABORTED) { |
| 340 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.ErrAborted", | 336 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.ErrAborted", |
| 341 request_loading_time); | 337 request_loading_time); |
| 342 } | 338 } |
| 343 } | 339 } |
| 344 } | 340 } |
| 345 | 341 |
| 342 void NotifyUIThreadOfRequestComplete( | |
| 343 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | |
| 344 const GURL& url, | |
| 345 content::ResourceType resource_type, | |
| 346 bool was_cached, | |
| 347 int net_error, | |
| 348 int64_t total_received_bytes, | |
| 349 base::TimeDelta request_loading_time) { | |
| 350 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 351 content::WebContents* web_contents = web_contents_getter.Run(); | |
| 352 if (!web_contents) | |
| 353 return; | |
| 354 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { | |
| 355 LogMainFrameMetricsOnUIThread(url, net_error, request_loading_time, | |
| 356 web_contents); | |
| 357 } | |
| 358 if (!was_cached) | |
| 359 UpdatePrerenderNetworkBytesCallback(web_contents, total_received_bytes); | |
| 360 page_load_metrics::MetricsWebContentsObserver* metrics_observer = | |
| 361 page_load_metrics::MetricsWebContentsObserver::FromWebContents( | |
| 362 web_contents); | |
| 363 if (metrics_observer) { | |
| 364 metrics_observer->OnRequestComplete(resource_type, was_cached, net_error); | |
| 365 } | |
| 366 } | |
| 367 | |
| 346 } // namespace | 368 } // namespace |
| 347 | 369 |
| 348 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate() | 370 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate() |
| 349 : download_request_limiter_(g_browser_process->download_request_limiter()), | 371 : download_request_limiter_(g_browser_process->download_request_limiter()), |
| 350 safe_browsing_(g_browser_process->safe_browsing_service()) | 372 safe_browsing_(g_browser_process->safe_browsing_service()) |
| 351 #if defined(ENABLE_EXTENSIONS) | 373 #if defined(ENABLE_EXTENSIONS) |
| 352 , user_script_listener_(new extensions::UserScriptListener()) | 374 , user_script_listener_(new extensions::UserScriptListener()) |
| 353 #endif | 375 #endif |
| 354 { | 376 { |
| 355 BrowserThread::PostTask( | 377 BrowserThread::PostTask( |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 redirect_url, request); | 805 redirect_url, request); |
| 784 } | 806 } |
| 785 | 807 |
| 786 if (io_data->policy_header_helper()) | 808 if (io_data->policy_header_helper()) |
| 787 io_data->policy_header_helper()->AddPolicyHeaders(redirect_url, request); | 809 io_data->policy_header_helper()->AddPolicyHeaders(redirect_url, request); |
| 788 } | 810 } |
| 789 | 811 |
| 790 // Notification that a request has completed. | 812 // Notification that a request has completed. |
| 791 void ChromeResourceDispatcherHostDelegate::RequestComplete( | 813 void ChromeResourceDispatcherHostDelegate::RequestComplete( |
| 792 net::URLRequest* url_request) { | 814 net::URLRequest* url_request) { |
| 793 // Jump on the UI thread and inform the prerender about the bytes. | 815 if (!url_request) |
| 816 return; | |
| 794 const ResourceRequestInfo* info = | 817 const ResourceRequestInfo* info = |
| 795 ResourceRequestInfo::ForRequest(url_request); | 818 ResourceRequestInfo::ForRequest(url_request); |
| 796 if (url_request && !url_request->was_cached()) { | 819 BrowserThread::PostTask( |
| 797 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 820 BrowserThread::UI, FROM_HERE, |
| 798 base::Bind(&UpdatePrerenderNetworkBytesCallback, | 821 base::Bind(&NotifyUIThreadOfRequestComplete, |
| 799 info->GetWebContentsGetterForRequest(), | 822 info->GetWebContentsGetterForRequest(), url_request->url(), |
| 800 url_request->GetTotalReceivedBytes())); | 823 info->GetResourceType(), url_request->was_cached(), |
| 801 } | 824 url_request->status().error(), |
| 802 | 825 url_request->GetTotalReceivedBytes(), |
| 803 if (url_request && | 826 base::TimeTicks::Now() - url_request->creation_time())); |
| 804 info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME) { | |
| 805 BrowserThread::PostTask( | |
| 806 BrowserThread::UI, FROM_HERE, | |
| 807 base::Bind(&LogMainFrameMetricsOnUIThread, url_request->url(), | |
| 808 url_request->status().error(), | |
| 809 base::TimeTicks::Now() - url_request->creation_time(), | |
| 810 info->GetWebContentsGetterForRequest())); | |
| 811 } | |
| 812 } | 827 } |
| 813 | 828 |
| 814 bool ChromeResourceDispatcherHostDelegate::ShouldEnableLoFiMode( | 829 bool ChromeResourceDispatcherHostDelegate::ShouldEnableLoFiMode( |
| 815 const net::URLRequest& url_request, | 830 const net::URLRequest& url_request, |
| 816 content::ResourceContext* resource_context) { | 831 content::ResourceContext* resource_context) { |
| 817 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 832 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 818 data_reduction_proxy::DataReductionProxyIOData* data_reduction_proxy_io_data = | 833 data_reduction_proxy::DataReductionProxyIOData* data_reduction_proxy_io_data = |
| 819 io_data->data_reduction_proxy_io_data(); | 834 io_data->data_reduction_proxy_io_data(); |
| 820 | 835 |
| 821 if (data_reduction_proxy_io_data) | 836 if (data_reduction_proxy_io_data) |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 848 data->SetDataReductionProxyData(data_reduction_proxy_data->DeepCopy()); | 863 data->SetDataReductionProxyData(data_reduction_proxy_data->DeepCopy()); |
| 849 return data; | 864 return data; |
| 850 } | 865 } |
| 851 | 866 |
| 852 std::unique_ptr<net::ClientCertStore> | 867 std::unique_ptr<net::ClientCertStore> |
| 853 ChromeResourceDispatcherHostDelegate::CreateClientCertStore( | 868 ChromeResourceDispatcherHostDelegate::CreateClientCertStore( |
| 854 content::ResourceContext* resource_context) { | 869 content::ResourceContext* resource_context) { |
| 855 return ProfileIOData::FromResourceContext(resource_context)-> | 870 return ProfileIOData::FromResourceContext(resource_context)-> |
| 856 CreateClientCertStore(); | 871 CreateClientCertStore(); |
| 857 } | 872 } |
| OLD | NEW |