Chromium Code Reviews| 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/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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 if (net_error == net::OK) { | 347 if (net_error == net::OK) { |
| 348 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.Success", | 348 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.Success", |
| 349 request_loading_time); | 349 request_loading_time); |
| 350 } else if (net_error == net::ERR_ABORTED) { | 350 } else if (net_error == net::ERR_ABORTED) { |
| 351 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.ErrAborted", | 351 UMA_HISTOGRAM_LONG_TIMES("Net.NTP.Local.RequestTime2.ErrAborted", |
| 352 request_loading_time); | 352 request_loading_time); |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 | 356 |
| 357 void NotifyUIThreadOfRequestStarted( | |
| 358 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | |
| 359 const GURL& url, | |
|
RyanSturm
2017/03/29 19:03:47
Are you using url here?
Pete Williamson
2017/04/13 23:10:21
Done.
| |
| 360 const content::GlobalRequestID& request_id, | |
| 361 ResourceType resource_type, | |
| 362 base::TimeTicks request_creation_time) { | |
| 363 content::WebContents* web_contents = web_contents_getter.Run(); | |
| 364 | |
| 365 page_load_metrics::MetricsWebContentsObserver* metrics_observer = | |
| 366 page_load_metrics::MetricsWebContentsObserver::FromWebContents( | |
| 367 web_contents); | |
| 368 | |
| 369 if (metrics_observer) { | |
| 370 metrics_observer->OnRequestStarted(request_id, resource_type, | |
| 371 request_creation_time); | |
| 372 } | |
| 373 } | |
| 374 | |
| 357 void NotifyUIThreadOfRequestComplete( | 375 void NotifyUIThreadOfRequestComplete( |
| 358 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | 376 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, |
| 359 const GURL& url, | 377 const GURL& url, |
| 360 const content::GlobalRequestID& request_id, | 378 const content::GlobalRequestID& request_id, |
| 361 ResourceType resource_type, | 379 ResourceType resource_type, |
| 362 bool was_cached, | 380 bool was_cached, |
| 363 bool used_data_reduction_proxy, | 381 bool used_data_reduction_proxy, |
| 364 int net_error, | 382 int net_error, |
| 365 int64_t total_received_bytes, | 383 int64_t total_received_bytes, |
| 366 int64_t raw_body_bytes, | 384 int64_t raw_body_bytes, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 base::FieldTrialList::FindFullName("Prefetch"); | 453 base::FieldTrialList::FindFullName("Prefetch"); |
| 436 if (base::StartsWith(prefetch_experiment, "ExperimentDisable", | 454 if (base::StartsWith(prefetch_experiment, "ExperimentDisable", |
| 437 base::CompareCase::INSENSITIVE_ASCII)) { | 455 base::CompareCase::INSENSITIVE_ASCII)) { |
| 438 return false; | 456 return false; |
| 439 } | 457 } |
| 440 } | 458 } |
| 441 | 459 |
| 442 return true; | 460 return true; |
| 443 } | 461 } |
| 444 | 462 |
| 463 // TODO: REVIEWERS: appcache_service is apparently not used. Is there any | |
| 464 // reason that I shouldn't remove it? (Maybe it's a part of some interface used | |
| 465 // elsewhere.) | |
| 445 void ChromeResourceDispatcherHostDelegate::RequestBeginning( | 466 void ChromeResourceDispatcherHostDelegate::RequestBeginning( |
| 446 net::URLRequest* request, | 467 net::URLRequest* request, |
| 447 content::ResourceContext* resource_context, | 468 content::ResourceContext* resource_context, |
| 448 content::AppCacheService* appcache_service, | 469 content::AppCacheService* appcache_service, |
| 449 ResourceType resource_type, | 470 ResourceType resource_type, |
| 450 std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) { | 471 std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) { |
| 451 if (safe_browsing_.get()) | 472 if (safe_browsing_.get()) |
| 452 safe_browsing_->OnResourceRequest(request); | 473 safe_browsing_->OnResourceRequest(request); |
| 453 | 474 |
| 454 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 475 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 455 | 476 |
| 477 // TODO(petewil): Unify the safe browsing request and the metrics observer | |
| 478 // request if possible so we only have to cross to the main thread once. | |
| 479 BrowserThread::PostTask( | |
| 480 BrowserThread::UI, FROM_HERE, | |
| 481 base::Bind(&NotifyUIThreadOfRequestStarted, | |
| 482 info->GetWebContentsGetterForRequest(), request->url(), | |
| 483 info->GetGlobalRequestID(), info->GetResourceType(), | |
| 484 request->creation_time())); | |
| 485 | |
| 456 // The lowering of request priority causes issues with scheduling, since | 486 // The lowering of request priority causes issues with scheduling, since |
| 457 // content::ResourceScheduler uses it to delay and throttle requests. This is | 487 // content::ResourceScheduler uses it to delay and throttle requests. This is |
| 458 // disabled only on Android, as the prerenders are not likely to compete with | 488 // disabled only on Android, as the prerenders are not likely to compete with |
| 459 // page loads there. | 489 // page loads there. |
| 460 // See https://crbug.com/652746 for details. | 490 // See https://crbug.com/652746 for details. |
| 461 // TODO(lizeb,droger): Fix the issue on all platforms. | 491 // TODO(lizeb,droger): Fix the issue on all platforms. |
| 462 #if !defined(OS_ANDROID) | 492 #if !defined(OS_ANDROID) |
| 463 bool is_prerendering = | 493 bool is_prerendering = |
| 464 info->GetVisibilityState() == blink::WebPageVisibilityStatePrerender; | 494 info->GetVisibilityState() == blink::WebPageVisibilityStatePrerender; |
| 465 if (is_prerendering) { | 495 if (is_prerendering) { |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 950 base::Bind(&ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad, | 980 base::Bind(&ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad, |
| 951 base::Unretained(this), url, request_loading_time)); | 981 base::Unretained(this), url, request_loading_time)); |
| 952 return; | 982 return; |
| 953 } | 983 } |
| 954 | 984 |
| 955 std::string metric_name = (request_loading_time.InMilliseconds() < 100 ? | 985 std::string metric_name = (request_loading_time.InMilliseconds() < 100 ? |
| 956 "Net.ErrAborted.Fast" : "Net.ErrAborted.Slow"); | 986 "Net.ErrAborted.Fast" : "Net.ErrAborted.Slow"); |
| 957 rappor::SampleDomainAndRegistryFromGURL( | 987 rappor::SampleDomainAndRegistryFromGURL( |
| 958 g_browser_process->rappor_service(), metric_name, url); | 988 g_browser_process->rappor_service(), metric_name, url); |
| 959 } | 989 } |
| OLD | NEW |