| 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 NotifyUIThreadOfRequestComplete to log metrics |
| 285 // resources. | 284 // about main frame 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& | 289 DCHECK(web_contents); |
| 291 web_contents_getter) { | |
| 292 content::WebContents* web_contents = web_contents_getter.Run(); | |
| 293 if (!web_contents) | |
| 294 return; | |
| 295 Profile* profile = | 290 Profile* profile = |
| 296 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 291 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 297 | 292 |
| 298 // The rest of the function is only concerned about NTP metrics. | 293 // The rest of the function is only concerned about NTP metrics. |
| 299 if (!profile || !search::IsNTPURL(url, profile)) | 294 if (!profile || !search::IsNTPURL(url, profile)) |
| 300 return; | 295 return; |
| 301 | 296 |
| 302 // A http/s scheme implies that the new tab page is remote. The local NTP is | 297 // 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 | 298 // served from chrome-search://. To segment out remote NTPs, use the |
| 304 // TemplateURLService to find the default search engine. Note that if the | 299 // TemplateURLService to find the default search engine. Note that if the |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 if (net_error == net::OK) { | 331 if (net_error == net::OK) { |
| 337 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.Success", | 332 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.Success", |
| 338 request_loading_time); | 333 request_loading_time); |
| 339 } else if (net_error == net::ERR_ABORTED) { | 334 } else if (net_error == net::ERR_ABORTED) { |
| 340 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.ErrAborted", | 335 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.ErrAborted", |
| 341 request_loading_time); | 336 request_loading_time); |
| 342 } | 337 } |
| 343 } | 338 } |
| 344 } | 339 } |
| 345 | 340 |
| 341 void NotifyUIThreadOfRequestComplete( |
| 342 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, |
| 343 const GURL& url, |
| 344 content::ResourceType resource_type, |
| 345 bool was_cached, |
| 346 int net_error, |
| 347 int64_t total_received_bytes, |
| 348 base::TimeDelta request_loading_time) { |
| 349 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 350 content::WebContents* web_contents = web_contents_getter.Run(); |
| 351 if (!web_contents) |
| 352 return; |
| 353 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { |
| 354 LogMainFrameMetricsOnUIThread(url, net_error, request_loading_time, |
| 355 web_contents); |
| 356 } |
| 357 if (!was_cached) |
| 358 UpdatePrerenderNetworkBytesCallback(web_contents, total_received_bytes); |
| 359 page_load_metrics::MetricsWebContentsObserver* metrics_observer = |
| 360 page_load_metrics::MetricsWebContentsObserver::FromWebContents( |
| 361 web_contents); |
| 362 if (metrics_observer) { |
| 363 metrics_observer->OnRequestComplete(resource_type, was_cached, net_error); |
| 364 } |
| 365 } |
| 366 |
| 346 } // namespace | 367 } // namespace |
| 347 | 368 |
| 348 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate() | 369 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate() |
| 349 : download_request_limiter_(g_browser_process->download_request_limiter()), | 370 : download_request_limiter_(g_browser_process->download_request_limiter()), |
| 350 safe_browsing_(g_browser_process->safe_browsing_service()) | 371 safe_browsing_(g_browser_process->safe_browsing_service()) |
| 351 #if defined(ENABLE_EXTENSIONS) | 372 #if defined(ENABLE_EXTENSIONS) |
| 352 , user_script_listener_(new extensions::UserScriptListener()) | 373 , user_script_listener_(new extensions::UserScriptListener()) |
| 353 #endif | 374 #endif |
| 354 { | 375 { |
| 355 BrowserThread::PostTask( | 376 BrowserThread::PostTask( |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 redirect_url, request); | 804 redirect_url, request); |
| 784 } | 805 } |
| 785 | 806 |
| 786 if (io_data->policy_header_helper()) | 807 if (io_data->policy_header_helper()) |
| 787 io_data->policy_header_helper()->AddPolicyHeaders(redirect_url, request); | 808 io_data->policy_header_helper()->AddPolicyHeaders(redirect_url, request); |
| 788 } | 809 } |
| 789 | 810 |
| 790 // Notification that a request has completed. | 811 // Notification that a request has completed. |
| 791 void ChromeResourceDispatcherHostDelegate::RequestComplete( | 812 void ChromeResourceDispatcherHostDelegate::RequestComplete( |
| 792 net::URLRequest* url_request) { | 813 net::URLRequest* url_request) { |
| 793 // Jump on the UI thread and inform the prerender about the bytes. | 814 if (!url_request) |
| 815 return; |
| 794 const ResourceRequestInfo* info = | 816 const ResourceRequestInfo* info = |
| 795 ResourceRequestInfo::ForRequest(url_request); | 817 ResourceRequestInfo::ForRequest(url_request); |
| 796 if (url_request && !url_request->was_cached()) { | 818 BrowserThread::PostTask( |
| 797 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 819 BrowserThread::UI, FROM_HERE, |
| 798 base::Bind(&UpdatePrerenderNetworkBytesCallback, | 820 base::Bind(&NotifyUIThreadOfRequestComplete, |
| 799 info->GetWebContentsGetterForRequest(), | 821 info->GetWebContentsGetterForRequest(), url_request->url(), |
| 800 url_request->GetTotalReceivedBytes())); | 822 info->GetResourceType(), url_request->was_cached(), |
| 801 } | 823 url_request->status().error(), |
| 802 | 824 url_request->GetTotalReceivedBytes(), |
| 803 if (url_request && | 825 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 } | 826 } |
| 813 | 827 |
| 814 bool ChromeResourceDispatcherHostDelegate::ShouldEnableLoFiMode( | 828 bool ChromeResourceDispatcherHostDelegate::ShouldEnableLoFiMode( |
| 815 const net::URLRequest& url_request, | 829 const net::URLRequest& url_request, |
| 816 content::ResourceContext* resource_context) { | 830 content::ResourceContext* resource_context) { |
| 817 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 831 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 818 data_reduction_proxy::DataReductionProxyIOData* data_reduction_proxy_io_data = | 832 data_reduction_proxy::DataReductionProxyIOData* data_reduction_proxy_io_data = |
| 819 io_data->data_reduction_proxy_io_data(); | 833 io_data->data_reduction_proxy_io_data(); |
| 820 | 834 |
| 821 if (data_reduction_proxy_io_data) | 835 if (data_reduction_proxy_io_data) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 848 data->SetDataReductionProxyData(data_reduction_proxy_data->DeepCopy()); | 862 data->SetDataReductionProxyData(data_reduction_proxy_data->DeepCopy()); |
| 849 return data; | 863 return data; |
| 850 } | 864 } |
| 851 | 865 |
| 852 std::unique_ptr<net::ClientCertStore> | 866 std::unique_ptr<net::ClientCertStore> |
| 853 ChromeResourceDispatcherHostDelegate::CreateClientCertStore( | 867 ChromeResourceDispatcherHostDelegate::CreateClientCertStore( |
| 854 content::ResourceContext* resource_context) { | 868 content::ResourceContext* resource_context) { |
| 855 return ProfileIOData::FromResourceContext(resource_context)-> | 869 return ProfileIOData::FromResourceContext(resource_context)-> |
| 856 CreateClientCertStore(); | 870 CreateClientCertStore(); |
| 857 } | 871 } |
| OLD | NEW |