OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/page_load_metrics/observers/resource_prefetch_predictor
_page_load_metrics_observer.h" | 5 #include "chrome/browser/page_load_metrics/observers/resource_prefetch_predictor
_page_load_metrics_observer.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
8 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 10 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
| 11 #include "chrome/browser/predictors/loading_predictor.h" |
| 12 #include "chrome/browser/predictors/loading_predictor_factory.h" |
9 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 13 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
10 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | 14 #include "chrome/browser/profiles/profile.h" |
11 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
12 | 16 |
13 namespace internal { | 17 namespace internal { |
14 | 18 |
15 const char kHistogramResourcePrefetchPredictorFirstContentfulPaint[] = | 19 const char kHistogramResourcePrefetchPredictorFirstContentfulPaint[] = |
16 "PageLoad.Clients.ResourcePrefetchPredictor.PaintTiming." | 20 "PageLoad.Clients.ResourcePrefetchPredictor.PaintTiming." |
17 "NavigationToFirstContentfulPaint.Prefetchable"; | 21 "NavigationToFirstContentfulPaint.Prefetchable"; |
18 const char kHistogramResourcePrefetchPredictorFirstMeaningfulPaint[] = | 22 const char kHistogramResourcePrefetchPredictorFirstMeaningfulPaint[] = |
19 "PageLoad.Clients.ResourcePrefetchPredictor.Experimental.PaintTiming." | 23 "PageLoad.Clients.ResourcePrefetchPredictor.Experimental.PaintTiming." |
20 "NavigationToFirstMeaningfulPaint.Prefetchable"; | 24 "NavigationToFirstMeaningfulPaint.Prefetchable"; |
21 | 25 |
22 } // namespace internal | 26 } // namespace internal |
23 | 27 |
24 // static | 28 // static |
25 std::unique_ptr<ResourcePrefetchPredictorPageLoadMetricsObserver> | 29 std::unique_ptr<ResourcePrefetchPredictorPageLoadMetricsObserver> |
26 ResourcePrefetchPredictorPageLoadMetricsObserver::CreateIfNeeded( | 30 ResourcePrefetchPredictorPageLoadMetricsObserver::CreateIfNeeded( |
27 content::WebContents* web_contents) { | 31 content::WebContents* web_contents) { |
28 predictors::ResourcePrefetchPredictor* predictor = | 32 auto* loading_predictor = predictors::LoadingPredictorFactory::GetForProfile( |
29 predictors::ResourcePrefetchPredictorFactory::GetForProfile( | 33 Profile::FromBrowserContext(web_contents->GetBrowserContext())); |
30 web_contents->GetBrowserContext()); | 34 if (!loading_predictor) |
31 if (!predictor) | |
32 return nullptr; | 35 return nullptr; |
33 return base::MakeUnique<ResourcePrefetchPredictorPageLoadMetricsObserver>( | 36 return base::MakeUnique<ResourcePrefetchPredictorPageLoadMetricsObserver>( |
34 predictor, web_contents); | 37 loading_predictor->resource_prefetch_predictor(), web_contents); |
35 } | 38 } |
36 | 39 |
37 ResourcePrefetchPredictorPageLoadMetricsObserver:: | 40 ResourcePrefetchPredictorPageLoadMetricsObserver:: |
38 ResourcePrefetchPredictorPageLoadMetricsObserver( | 41 ResourcePrefetchPredictorPageLoadMetricsObserver( |
39 predictors::ResourcePrefetchPredictor* predictor, | 42 predictors::ResourcePrefetchPredictor* predictor, |
40 content::WebContents* web_contents) | 43 content::WebContents* web_contents) |
41 : predictor_(predictor), | 44 : predictor_(predictor), |
42 web_contents_(web_contents), | 45 web_contents_(web_contents), |
43 record_histograms_(false) { | 46 record_histograms_(false) { |
44 DCHECK(predictor_); | 47 DCHECK(predictor_); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 87 |
85 void ResourcePrefetchPredictorPageLoadMetricsObserver::OnFirstMeaningfulPaint( | 88 void ResourcePrefetchPredictorPageLoadMetricsObserver::OnFirstMeaningfulPaint( |
86 const page_load_metrics::PageLoadTiming& timing, | 89 const page_load_metrics::PageLoadTiming& timing, |
87 const page_load_metrics::PageLoadExtraInfo& extra_info) { | 90 const page_load_metrics::PageLoadExtraInfo& extra_info) { |
88 if (record_histograms_) { | 91 if (record_histograms_) { |
89 PAGE_LOAD_HISTOGRAM( | 92 PAGE_LOAD_HISTOGRAM( |
90 internal::kHistogramResourcePrefetchPredictorFirstMeaningfulPaint, | 93 internal::kHistogramResourcePrefetchPredictorFirstMeaningfulPaint, |
91 timing.paint_timing.first_meaningful_paint.value()); | 94 timing.paint_timing.first_meaningful_paint.value()); |
92 } | 95 } |
93 } | 96 } |
OLD | NEW |