| 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 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_UKM_PAGE_LOAD_METRICS_OBSERVE
R_H_ | 5 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_UKM_PAGE_LOAD_METRICS_OBSERVE
R_H_ |
| 6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_UKM_PAGE_LOAD_METRICS_OBSERVE
R_H_ | 6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_UKM_PAGE_LOAD_METRICS_OBSERVE
R_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" | 9 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" |
| 10 #include "net/nqe/network_quality_estimator.h" |
| 11 |
| 12 namespace content { |
| 13 class WebContents; |
| 14 } |
| 10 | 15 |
| 11 namespace internal { | 16 namespace internal { |
| 12 | 17 |
| 13 // Name constants are exposed here so they can be referenced from tests. | 18 // Name constants are exposed here so they can be referenced from tests. |
| 14 extern const char kUkmPageLoadEventName[]; | 19 extern const char kUkmPageLoadEventName[]; |
| 15 extern const char kUkmParseStartName[]; | 20 extern const char kUkmParseStartName[]; |
| 16 extern const char kUkmDomContentLoadedName[]; | 21 extern const char kUkmDomContentLoadedName[]; |
| 17 extern const char kUkmLoadEventName[]; | 22 extern const char kUkmLoadEventName[]; |
| 18 extern const char kUkmFirstContentfulPaintName[]; | 23 extern const char kUkmFirstContentfulPaintName[]; |
| 19 extern const char kUkmFirstMeaningfulPaintName[]; | 24 extern const char kUkmFirstMeaningfulPaintName[]; |
| 20 extern const char kUkmForegroundDurationName[]; | 25 extern const char kUkmForegroundDurationName[]; |
| 26 extern const char kUkmEffectiveConnectionType[]; |
| 21 | 27 |
| 22 } // namespace internal | 28 } // namespace internal |
| 23 | 29 |
| 24 // If URL-Keyed-Metrics (UKM) is enabled in the system, this is used to | 30 // If URL-Keyed-Metrics (UKM) is enabled in the system, this is used to |
| 25 // populate it with top-level page-load metrics. | 31 // populate it with top-level page-load metrics. |
| 26 class UkmPageLoadMetricsObserver | 32 class UkmPageLoadMetricsObserver |
| 27 : public page_load_metrics::PageLoadMetricsObserver { | 33 : public page_load_metrics::PageLoadMetricsObserver { |
| 28 public: | 34 public: |
| 29 // Returns a UkmPageLoadMetricsObserver, or nullptr if it is not needed. | 35 // Returns a UkmPageLoadMetricsObserver, or nullptr if it is not needed. |
| 30 static std::unique_ptr<page_load_metrics::PageLoadMetricsObserver> | 36 static std::unique_ptr<page_load_metrics::PageLoadMetricsObserver> |
| 31 CreateIfNeeded(); | 37 CreateIfNeeded(content::WebContents* web_contents); |
| 32 | 38 |
| 33 UkmPageLoadMetricsObserver(); | 39 explicit UkmPageLoadMetricsObserver( |
| 40 net::NetworkQualityEstimator::NetworkQualityProvider* |
| 41 network_quality_provider); |
| 34 ~UkmPageLoadMetricsObserver() override; | 42 ~UkmPageLoadMetricsObserver() override; |
| 35 | 43 |
| 36 // page_load_metrics::PageLoadMetricsObserver implementation: | 44 // page_load_metrics::PageLoadMetricsObserver implementation: |
| 37 ObservePolicy OnStart(content::NavigationHandle* navigation_handle, | 45 ObservePolicy OnStart(content::NavigationHandle* navigation_handle, |
| 38 const GURL& currently_committed_url, | 46 const GURL& currently_committed_url, |
| 39 bool started_in_foreground) override; | 47 bool started_in_foreground) override; |
| 40 | 48 |
| 41 ObservePolicy FlushMetricsOnAppEnterBackground( | 49 ObservePolicy FlushMetricsOnAppEnterBackground( |
| 42 const page_load_metrics::PageLoadTiming& timing, | 50 const page_load_metrics::PageLoadTiming& timing, |
| 43 const page_load_metrics::PageLoadExtraInfo& info) override; | 51 const page_load_metrics::PageLoadExtraInfo& info) override; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 58 // as first contentful paint. | 66 // as first contentful paint. |
| 59 void RecordTimingMetrics(const page_load_metrics::PageLoadTiming& timing); | 67 void RecordTimingMetrics(const page_load_metrics::PageLoadTiming& timing); |
| 60 | 68 |
| 61 // Records metrics based on the PageLoadExtraInfo struct, as well as updating | 69 // Records metrics based on the PageLoadExtraInfo struct, as well as updating |
| 62 // the URL. |app_background_time| should be set to a timestamp if the app was | 70 // the URL. |app_background_time| should be set to a timestamp if the app was |
| 63 // backgrounded, otherwise it should be set to a null TimeTicks. | 71 // backgrounded, otherwise it should be set to a null TimeTicks. |
| 64 void RecordPageLoadExtraInfoMetrics( | 72 void RecordPageLoadExtraInfoMetrics( |
| 65 const page_load_metrics::PageLoadExtraInfo& info, | 73 const page_load_metrics::PageLoadExtraInfo& info, |
| 66 base::TimeTicks app_background_time); | 74 base::TimeTicks app_background_time); |
| 67 | 75 |
| 76 net::NetworkQualityEstimator::NetworkQualityProvider* const |
| 77 network_quality_provider_; |
| 78 |
| 68 // Unique UKM identifier for the page load we are recording metrics for. | 79 // Unique UKM identifier for the page load we are recording metrics for. |
| 69 const int32_t source_id_; | 80 const int32_t source_id_; |
| 70 | 81 |
| 82 net::EffectiveConnectionType effective_connection_type_ = |
| 83 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
| 84 |
| 71 DISALLOW_COPY_AND_ASSIGN(UkmPageLoadMetricsObserver); | 85 DISALLOW_COPY_AND_ASSIGN(UkmPageLoadMetricsObserver); |
| 72 }; | 86 }; |
| 73 | 87 |
| 74 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_UKM_PAGE_LOAD_METRICS_OBSE
RVER_H_ | 88 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_UKM_PAGE_LOAD_METRICS_OBSE
RVER_H_ |
| OLD | NEW |