| 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 | 10 |
| 11 namespace internal { |
| 12 |
| 13 // Name constants are exposed here so they can be referenced from tests. |
| 14 extern const char kUkmPageLoadEventName[]; |
| 15 extern const char kUkmFirstContentfulPaintName[]; |
| 16 |
| 17 } // namespace internal |
| 18 |
| 11 // If URL-Keyed-Metrics (UKM) is enabled in the system, this is used to | 19 // If URL-Keyed-Metrics (UKM) is enabled in the system, this is used to |
| 12 // populate it with top-level page-load metrics. | 20 // populate it with top-level page-load metrics. |
| 13 class UkmPageLoadMetricsObserver | 21 class UkmPageLoadMetricsObserver |
| 14 : public page_load_metrics::PageLoadMetricsObserver { | 22 : public page_load_metrics::PageLoadMetricsObserver { |
| 15 public: | 23 public: |
| 16 // Returns a UkmPageLoadMetricsObserver, or nullptr if it is not needed. | 24 // Returns a UkmPageLoadMetricsObserver, or nullptr if it is not needed. |
| 17 static std::unique_ptr<page_load_metrics::PageLoadMetricsObserver> | 25 static std::unique_ptr<page_load_metrics::PageLoadMetricsObserver> |
| 18 CreateIfNeeded(); | 26 CreateIfNeeded(); |
| 19 | 27 |
| 20 UkmPageLoadMetricsObserver(); | 28 UkmPageLoadMetricsObserver(); |
| 29 ~UkmPageLoadMetricsObserver() override; |
| 21 | 30 |
| 22 // page_load_metrics::PageLoadMetricsObserver implementation: | 31 // page_load_metrics::PageLoadMetricsObserver implementation: |
| 23 ObservePolicy OnStart(content::NavigationHandle* navigation_handle, | 32 ObservePolicy OnStart(content::NavigationHandle* navigation_handle, |
| 24 const GURL& currently_committed_url, | 33 const GURL& currently_committed_url, |
| 25 bool started_in_foreground) override; | 34 bool started_in_foreground) override; |
| 26 | 35 |
| 27 ObservePolicy FlushMetricsOnAppEnterBackground( | 36 ObservePolicy FlushMetricsOnAppEnterBackground( |
| 28 const page_load_metrics::PageLoadTiming& timing, | 37 const page_load_metrics::PageLoadTiming& timing, |
| 29 const page_load_metrics::PageLoadExtraInfo& info) override; | 38 const page_load_metrics::PageLoadExtraInfo& info) override; |
| 30 | 39 |
| 31 ObservePolicy OnHidden( | 40 ObservePolicy OnHidden( |
| 32 const page_load_metrics::PageLoadTiming& timing, | 41 const page_load_metrics::PageLoadTiming& timing, |
| 33 const page_load_metrics::PageLoadExtraInfo& info) override; | 42 const page_load_metrics::PageLoadExtraInfo& info) override; |
| 34 | 43 |
| 44 void OnFailedProvisionalLoad( |
| 45 const page_load_metrics::FailedProvisionalLoadInfo& failed_load_info, |
| 46 const page_load_metrics::PageLoadExtraInfo& extra_info) override; |
| 47 |
| 35 void OnComplete(const page_load_metrics::PageLoadTiming& timing, | 48 void OnComplete(const page_load_metrics::PageLoadTiming& timing, |
| 36 const page_load_metrics::PageLoadExtraInfo& info) override; | 49 const page_load_metrics::PageLoadExtraInfo& info) override; |
| 37 | 50 |
| 38 private: | 51 private: |
| 39 void SendMetricsToUkm(const page_load_metrics::PageLoadTiming& timing, | 52 // Records page load timing related metrics available in PageLoadTiming, such |
| 40 const page_load_metrics::PageLoadExtraInfo& info); | 53 // as first contentful paint. |
| 54 void RecordTimingMetrics(const page_load_metrics::PageLoadTiming& timing); |
| 55 |
| 56 // Records metrics based on the PageLoadExtraInfo struct, as well as updating |
| 57 // the URL. |
| 58 void RecordPageLoadExtraInfoMetrics( |
| 59 const page_load_metrics::PageLoadExtraInfo& info); |
| 60 |
| 61 // Unique UKM identifier for the page load we are recording metrics for. |
| 62 const int32_t source_id_; |
| 41 | 63 |
| 42 DISALLOW_COPY_AND_ASSIGN(UkmPageLoadMetricsObserver); | 64 DISALLOW_COPY_AND_ASSIGN(UkmPageLoadMetricsObserver); |
| 43 }; | 65 }; |
| 44 | 66 |
| 45 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_UKM_PAGE_LOAD_METRICS_OBSE
RVER_H_ | 67 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_UKM_PAGE_LOAD_METRICS_OBSE
RVER_H_ |
| OLD | NEW |