Chromium Code Reviews| 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 "components/ukm/ukm_entry_builder.h" | |
| 11 #include "content/public/browser/global_request_id.h" | |
| 12 | |
| 13 namespace internal { | |
| 14 | |
| 15 // Name constants are exposed here so they can be referenced from tests. | |
| 16 extern const char kUkmPageLoadEventName[]; | |
| 17 extern const char kUkmFirstContentfulPaintName[]; | |
| 18 | |
| 19 } // namespace internal | |
| 10 | 20 |
| 11 // If URL-Keyed-Metrics (UKM) is enabled in the system, this is used to | 21 // If URL-Keyed-Metrics (UKM) is enabled in the system, this is used to |
| 12 // populate it with top-level page-load metrics. | 22 // populate it with top-level page-load metrics. |
| 13 class UkmPageLoadMetricsObserver | 23 class UkmPageLoadMetricsObserver |
| 14 : public page_load_metrics::PageLoadMetricsObserver { | 24 : public page_load_metrics::PageLoadMetricsObserver { |
| 15 public: | 25 public: |
| 16 // Returns a UkmPageLoadMetricsObserver, or nullptr if it is not needed. | 26 // Returns a UkmPageLoadMetricsObserver, or nullptr if it is not needed. |
| 17 static std::unique_ptr<page_load_metrics::PageLoadMetricsObserver> | 27 static std::unique_ptr<page_load_metrics::PageLoadMetricsObserver> |
| 18 CreateIfNeeded(); | 28 CreateIfNeeded(); |
| 19 | 29 |
| 20 UkmPageLoadMetricsObserver(); | 30 UkmPageLoadMetricsObserver(); |
| 31 ~UkmPageLoadMetricsObserver() override; | |
| 21 | 32 |
| 22 // page_load_metrics::PageLoadMetricsObserver implementation: | 33 // page_load_metrics::PageLoadMetricsObserver implementation: |
| 23 ObservePolicy OnStart(content::NavigationHandle* navigation_handle, | 34 ObservePolicy OnStart(content::NavigationHandle* navigation_handle, |
| 24 const GURL& currently_committed_url, | 35 const GURL& currently_committed_url, |
| 25 bool started_in_foreground) override; | 36 bool started_in_foreground) override; |
| 26 | 37 |
| 27 ObservePolicy FlushMetricsOnAppEnterBackground( | 38 ObservePolicy FlushMetricsOnAppEnterBackground( |
| 28 const page_load_metrics::PageLoadTiming& timing, | 39 const page_load_metrics::PageLoadTiming& timing, |
| 29 const page_load_metrics::PageLoadExtraInfo& info) override; | 40 const page_load_metrics::PageLoadExtraInfo& info) override; |
| 30 | 41 |
| 31 ObservePolicy OnHidden( | 42 ObservePolicy OnHidden( |
| 32 const page_load_metrics::PageLoadTiming& timing, | 43 const page_load_metrics::PageLoadTiming& timing, |
| 33 const page_load_metrics::PageLoadExtraInfo& info) override; | 44 const page_load_metrics::PageLoadExtraInfo& info) override; |
| 34 | 45 |
| 46 void OnFailedProvisionalLoad( | |
| 47 const page_load_metrics::FailedProvisionalLoadInfo& failed_load_info, | |
| 48 const page_load_metrics::PageLoadExtraInfo& extra_info) override; | |
| 49 | |
| 35 void OnComplete(const page_load_metrics::PageLoadTiming& timing, | 50 void OnComplete(const page_load_metrics::PageLoadTiming& timing, |
| 36 const page_load_metrics::PageLoadExtraInfo& info) override; | 51 const page_load_metrics::PageLoadExtraInfo& info) override; |
| 37 | 52 |
| 38 private: | 53 private: |
| 39 void SendMetricsToUkm(const page_load_metrics::PageLoadTiming& timing, | 54 void AddTimingMetrics(const page_load_metrics::PageLoadTiming& timing); |
| 40 const page_load_metrics::PageLoadExtraInfo& info); | 55 void AddPageLoadExtraInfoMetrics( |
| 56 const page_load_metrics::PageLoadExtraInfo& info, | |
| 57 base::TimeTicks app_background_time); | |
| 58 | |
| 59 const content::GlobalRequestID global_request_id_; | |
| 60 std::unique_ptr<ukm::UkmEntryBuilder> builder_; | |
|
Zhen Wang
2017/03/01 19:18:00
Builder will only add UkmEntry to UkmService when
| |
| 41 | 61 |
| 42 DISALLOW_COPY_AND_ASSIGN(UkmPageLoadMetricsObserver); | 62 DISALLOW_COPY_AND_ASSIGN(UkmPageLoadMetricsObserver); |
| 43 }; | 63 }; |
| 44 | 64 |
| 45 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_UKM_PAGE_LOAD_METRICS_OBSE RVER_H_ | 65 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_UKM_PAGE_LOAD_METRICS_OBSE RVER_H_ |
| OLD | NEW |