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

Side by Side Diff: chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc

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

Powered by Google App Engine
This is Rietveld 408576698