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

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: CR feedback per RyanSturm 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 void ChromeResourceDispatcherHostDelegate::RequestBeginning( 456 void ChromeResourceDispatcherHostDelegate::RequestBeginning(
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);
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.
RyanSturm 2017/04/17 19:57:08 Maybe you should create a bug (if you haven't) and
Pete Williamson 2017/04/17 20:46:36 Done.
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
476 // The lowering of request priority causes issues with scheduling, since
RyanSturm 2017/04/17 19:57:08 This block seems like a bad re-base.
Pete Williamson 2017/04/17 20:46:36 Good catch! Removed.
477 // content::ResourceScheduler uses it to delay and throttle requests. This is
478 // disabled only on Android, as the prerenders are not likely to compete with
479 // page loads there.
480 // See https://crbug.com/652746 for details.
481 // TODO(lizeb,droger): Fix the issue on all platforms.
482 #if !defined(OS_ANDROID)
483 bool is_prerendering =
484 info->GetVisibilityState() == blink::kWebPageVisibilityStatePrerender;
485 if (is_prerendering) {
486 // Requests with the IGNORE_LIMITS flag set (i.e., sync XHRs)
487 // should remain at MAXIMUM_PRIORITY.
488 if (request->load_flags() & net::LOAD_IGNORE_LIMITS) {
489 DCHECK_EQ(request->priority(), net::MAXIMUM_PRIORITY);
490 } else {
491 request->SetPriority(net::IDLE);
492 }
493 }
494 #endif // OS_ANDROID
495
446 ProfileIOData* io_data = ProfileIOData::FromResourceContext( 496 ProfileIOData* io_data = ProfileIOData::FromResourceContext(
447 resource_context); 497 resource_context);
448 498
449 #if defined(OS_ANDROID) 499 #if defined(OS_ANDROID)
450 if (resource_type != content::RESOURCE_TYPE_MAIN_FRAME) 500 if (resource_type != content::RESOURCE_TYPE_MAIN_FRAME)
451 InterceptNavigationDelegate::UpdateUserGestureCarryoverInfo(request); 501 InterceptNavigationDelegate::UpdateUserGestureCarryoverInfo(request);
452 #endif 502 #endif
453 503
454 #if defined(OS_CHROMEOS) 504 #if defined(OS_CHROMEOS)
455 // Check if we need to add merge session throttle. This throttle will postpone 505 // Check if we need to add merge session throttle. This throttle will postpone
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 base::Bind(&ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad, 962 base::Bind(&ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad,
913 base::Unretained(this), url, request_loading_time)); 963 base::Unretained(this), url, request_loading_time));
914 return; 964 return;
915 } 965 }
916 966
917 std::string metric_name = (request_loading_time.InMilliseconds() < 100 ? 967 std::string metric_name = (request_loading_time.InMilliseconds() < 100 ?
918 "Net.ErrAborted.Fast" : "Net.ErrAborted.Slow"); 968 "Net.ErrAborted.Fast" : "Net.ErrAborted.Slow");
919 rappor::SampleDomainAndRegistryFromGURL( 969 rappor::SampleDomainAndRegistryFromGURL(
920 g_browser_process->rappor_service(), metric_name, url); 970 g_browser_process->rappor_service(), metric_name, url);
921 } 971 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698