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

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

Issue 2780003003: Send an event to the page load metrics to track resource starting. (Closed)
Patch Set: Fix browser 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 if (net_error == net::OK) { 338 if (net_error == net::OK) {
339 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.Success", 339 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.Success",
340 request_loading_time); 340 request_loading_time);
341 } else if (net_error == net::ERR_ABORTED) { 341 } else if (net_error == net::ERR_ABORTED) {
342 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.ErrAborted", 342 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.ErrAborted",
343 request_loading_time); 343 request_loading_time);
344 } 344 }
345 } 345 }
346 } 346 }
347 347
348 void NotifyUIThreadOfRequestStarted(
349 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
350 const content::GlobalRequestID& request_id,
351 ResourceType resource_type,
352 base::TimeTicks request_creation_time) {
353 content::WebContents* web_contents = web_contents_getter.Run();
354
355 if (!web_contents)
356 return;
357
358 page_load_metrics::MetricsWebContentsObserver* metrics_observer =
359 page_load_metrics::MetricsWebContentsObserver::FromWebContents(
360 web_contents);
361
362 if (metrics_observer) {
363 metrics_observer->OnRequestStarted(request_id, resource_type,
364 request_creation_time);
365 }
366 }
367
348 void NotifyUIThreadOfRequestComplete( 368 void NotifyUIThreadOfRequestComplete(
349 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, 369 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
350 const GURL& url, 370 const GURL& url,
351 const content::GlobalRequestID& request_id, 371 const content::GlobalRequestID& request_id,
352 ResourceType resource_type, 372 ResourceType resource_type,
353 bool was_cached, 373 bool was_cached,
354 bool used_data_reduction_proxy, 374 bool used_data_reduction_proxy,
355 int net_error, 375 int net_error,
356 int64_t total_received_bytes, 376 int64_t total_received_bytes,
357 int64_t raw_body_bytes, 377 int64_t raw_body_bytes,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 net::URLRequest* request, 457 net::URLRequest* request,
438 content::ResourceContext* resource_context, 458 content::ResourceContext* resource_context,
439 content::AppCacheService* appcache_service, 459 content::AppCacheService* appcache_service,
440 ResourceType resource_type, 460 ResourceType resource_type,
441 std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) { 461 std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) {
442 if (safe_browsing_.get()) 462 if (safe_browsing_.get())
443 safe_browsing_->OnResourceRequest(request); 463 safe_browsing_->OnResourceRequest(request);
444 464
445 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 465 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
446 466
467 // TODO(petewil): Unify the safe browsing request and the metrics observer
468 // request if possible so we only have to cross to the main thread once.
469 BrowserThread::PostTask(
470 BrowserThread::UI, FROM_HERE,
471 base::Bind(&NotifyUIThreadOfRequestStarted,
472 info->GetWebContentsGetterForRequest(),
473 info->GetGlobalRequestID(), info->GetResourceType(),
474 request->creation_time()));
475
447 // The lowering of request priority causes issues with scheduling, since 476 // The lowering of request priority causes issues with scheduling, since
448 // content::ResourceScheduler uses it to delay and throttle requests. This is 477 // content::ResourceScheduler uses it to delay and throttle requests. This is
449 // disabled only on Android, as the prerenders are not likely to compete with 478 // disabled only on Android, as the prerenders are not likely to compete with
450 // page loads there. 479 // page loads there.
451 // See https://crbug.com/652746 for details. 480 // See https://crbug.com/652746 for details.
452 // TODO(lizeb,droger): Fix the issue on all platforms. 481 // TODO(lizeb,droger): Fix the issue on all platforms.
453 #if !defined(OS_ANDROID) 482 #if !defined(OS_ANDROID)
454 bool is_prerendering = 483 bool is_prerendering =
455 info->GetVisibilityState() == blink::kWebPageVisibilityStatePrerender; 484 info->GetVisibilityState() == blink::kWebPageVisibilityStatePrerender;
456 if (is_prerendering) { 485 if (is_prerendering) {
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 base::Bind(&ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad, 962 base::Bind(&ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad,
934 base::Unretained(this), url, request_loading_time)); 963 base::Unretained(this), url, request_loading_time));
935 return; 964 return;
936 } 965 }
937 966
938 std::string metric_name = (request_loading_time.InMilliseconds() < 100 ? 967 std::string metric_name = (request_loading_time.InMilliseconds() < 100 ?
939 "Net.ErrAborted.Fast" : "Net.ErrAborted.Slow"); 968 "Net.ErrAborted.Fast" : "Net.ErrAborted.Slow");
940 rappor::SampleDomainAndRegistryFromGURL( 969 rappor::SampleDomainAndRegistryFromGURL(
941 g_browser_process->rappor_service(), metric_name, url); 970 g_browser_process->rappor_service(), metric_name, url);
942 } 971 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698