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

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

Issue 2798953002: [PageLoadMetrics] Keep track of Ad Sizes on Pages (Closed)
Patch Set: Add tests Created 3 years, 8 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/loader/chrome_resource_dispatcher_host_delegate.h" 5 #include "chrome/browser/loader/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>
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.Success", 344 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.Success",
345 request_loading_time); 345 request_loading_time);
346 } else if (net_error == net::ERR_ABORTED) { 346 } else if (net_error == net::ERR_ABORTED) {
347 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.ErrAborted", 347 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.ErrAborted",
348 request_loading_time); 348 request_loading_time);
349 } 349 }
350 } 350 }
351 } 351 }
352 352
353 void NotifyUIThreadOfRequestComplete( 353 void NotifyUIThreadOfRequestComplete(
354 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, 354 const content::ResourceRequestInfo::RenderFrameHostGetter&
355 render_frame_host_getter,
355 const GURL& url, 356 const GURL& url,
356 const content::GlobalRequestID& request_id, 357 const content::GlobalRequestID& request_id,
358 int frame_tree_node_id,
357 ResourceType resource_type, 359 ResourceType resource_type,
358 bool was_cached, 360 bool was_cached,
359 bool used_data_reduction_proxy, 361 bool used_data_reduction_proxy,
360 int net_error, 362 int net_error,
361 int64_t total_received_bytes, 363 int64_t total_received_bytes,
362 int64_t raw_body_bytes, 364 int64_t raw_body_bytes,
363 int64_t original_content_length, 365 int64_t original_content_length,
364 base::TimeTicks request_creation_time, 366 base::TimeTicks request_creation_time,
365 base::TimeDelta request_loading_time) { 367 base::TimeDelta request_loading_time) {
366 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 368 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
367 content::WebContents* web_contents = web_contents_getter.Run(); 369 content::RenderFrameHost* render_frame_host = render_frame_host_getter.Run();
370 if (!render_frame_host)
371 return;
372 content::WebContents* web_contents =
373 content::WebContents::FromRenderFrameHost(render_frame_host);
368 if (!web_contents) 374 if (!web_contents)
369 return; 375 return;
376
370 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { 377 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) {
371 LogMainFrameMetricsOnUIThread(url, net_error, request_loading_time, 378 LogMainFrameMetricsOnUIThread(url, net_error, request_loading_time,
372 web_contents); 379 web_contents);
373 } 380 }
374 if (!was_cached) { 381 if (!was_cached) {
375 UpdatePrerenderNetworkBytesCallback(web_contents, total_received_bytes); 382 UpdatePrerenderNetworkBytesCallback(web_contents, total_received_bytes);
376 #if defined(OS_ANDROID) 383 #if defined(OS_ANDROID)
377 offline_pages::BackgroundLoaderOffliner* background_loader = 384 offline_pages::BackgroundLoaderOffliner* background_loader =
378 offline_pages::BackgroundLoaderOffliner::FromWebContents(web_contents); 385 offline_pages::BackgroundLoaderOffliner::FromWebContents(web_contents);
379 386
380 if (background_loader) 387 if (background_loader)
381 background_loader->OnNetworkBytesChanged(total_received_bytes); 388 background_loader->OnNetworkBytesChanged(total_received_bytes);
382 #endif // OS_ANDROID 389 #endif // OS_ANDROID
383 } 390 }
384 page_load_metrics::MetricsWebContentsObserver* metrics_observer = 391 page_load_metrics::MetricsWebContentsObserver* metrics_observer =
385 page_load_metrics::MetricsWebContentsObserver::FromWebContents( 392 page_load_metrics::MetricsWebContentsObserver::FromWebContents(
386 web_contents); 393 web_contents);
387 if (metrics_observer) { 394 if (metrics_observer) {
388 metrics_observer->OnRequestComplete( 395 metrics_observer->OnRequestComplete(
389 request_id, resource_type, was_cached, used_data_reduction_proxy, 396 url, render_frame_host->GetFrameTreeNodeId(), request_id, resource_type,
390 raw_body_bytes, original_content_length, request_creation_time); 397 was_cached, used_data_reduction_proxy, raw_body_bytes,
398 original_content_length, request_creation_time);
391 } 399 }
392 } 400 }
393 401
394 } // namespace 402 } // namespace
395 403
396 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate() 404 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate()
397 : download_request_limiter_(g_browser_process->download_request_limiter()), 405 : download_request_limiter_(g_browser_process->download_request_limiter()),
398 safe_browsing_(g_browser_process->safe_browsing_service()) 406 safe_browsing_(g_browser_process->safe_browsing_service())
399 #if BUILDFLAG(ENABLE_EXTENSIONS) 407 #if BUILDFLAG(ENABLE_EXTENSIONS)
400 , user_script_listener_(new extensions::UserScriptListener()) 408 , user_script_listener_(new extensions::UserScriptListener())
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 data_reduction_proxy::DataReductionProxyData::GetData(*url_request); 858 data_reduction_proxy::DataReductionProxyData::GetData(*url_request);
851 bool used_data_reduction_proxy = data && data->used_data_reduction_proxy(); 859 bool used_data_reduction_proxy = data && data->used_data_reduction_proxy();
852 int64_t original_content_length = 860 int64_t original_content_length =
853 used_data_reduction_proxy 861 used_data_reduction_proxy
854 ? data_reduction_proxy::util::CalculateEffectiveOCL(*url_request) 862 ? data_reduction_proxy::util::CalculateEffectiveOCL(*url_request)
855 : url_request->GetRawBodyBytes(); 863 : url_request->GetRawBodyBytes();
856 864
857 BrowserThread::PostTask( 865 BrowserThread::PostTask(
858 BrowserThread::UI, FROM_HERE, 866 BrowserThread::UI, FROM_HERE,
859 base::Bind(&NotifyUIThreadOfRequestComplete, 867 base::Bind(&NotifyUIThreadOfRequestComplete,
860 info->GetWebContentsGetterForRequest(), url_request->url(), 868 info->GetRenderFrameHostGetterForRequest(), url_request->url(),
861 info->GetGlobalRequestID(), info->GetResourceType(), 869 info->GetGlobalRequestID(), info->GetFrameTreeNodeId(),
862 url_request->was_cached(), used_data_reduction_proxy, 870 info->GetResourceType(), url_request->was_cached(),
863 net_error, url_request->GetTotalReceivedBytes(), 871 used_data_reduction_proxy, net_error,
872 url_request->GetTotalReceivedBytes(),
864 url_request->GetRawBodyBytes(), original_content_length, 873 url_request->GetRawBodyBytes(), original_content_length,
865 url_request->creation_time(), 874 url_request->creation_time(),
866 base::TimeTicks::Now() - url_request->creation_time())); 875 base::TimeTicks::Now() - url_request->creation_time()));
867 } 876 }
868 877
869 content::PreviewsState ChromeResourceDispatcherHostDelegate::GetPreviewsState( 878 content::PreviewsState ChromeResourceDispatcherHostDelegate::GetPreviewsState(
870 const net::URLRequest& url_request, 879 const net::URLRequest& url_request,
871 content::ResourceContext* resource_context) { 880 content::ResourceContext* resource_context) {
872 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); 881 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
873 data_reduction_proxy::DataReductionProxyIOData* data_reduction_proxy_io_data = 882 data_reduction_proxy::DataReductionProxyIOData* data_reduction_proxy_io_data =
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 base::Bind(&ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad, 947 base::Bind(&ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad,
939 base::Unretained(this), url, request_loading_time)); 948 base::Unretained(this), url, request_loading_time));
940 return; 949 return;
941 } 950 }
942 951
943 std::string metric_name = (request_loading_time.InMilliseconds() < 100 ? 952 std::string metric_name = (request_loading_time.InMilliseconds() < 100 ?
944 "Net.ErrAborted.Fast" : "Net.ErrAborted.Slow"); 953 "Net.ErrAborted.Fast" : "Net.ErrAborted.Slow");
945 rappor::SampleDomainAndRegistryFromGURL( 954 rappor::SampleDomainAndRegistryFromGURL(
946 g_browser_process->rappor_service(), metric_name, url); 955 g_browser_process->rappor_service(), metric_name, url);
947 } 956 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698