Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/page_load_metrics/observers/previews_ukm_observer.h" | |
| 6 | |
| 7 #include "base/optional.h" | |
| 8 #include "base/time/time.h" | |
| 9 #include "chrome/browser/browser_process.h" | |
| 10 #include "chrome/browser/loader/chrome_navigation_data.h" | |
| 11 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" | |
| 12 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | |
| 13 #include "chrome/common/page_load_metrics/page_load_timing.h" | |
| 14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" | |
| 15 #include "components/ukm/public/ukm_entry_builder.h" | |
| 16 #include "components/ukm/public/ukm_recorder.h" | |
| 17 #include "components/ukm/ukm_source.h" | |
| 18 #include "content/public/browser/navigation_handle.h" | |
| 19 | |
| 20 namespace previews { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 const char kPreviewsName[] = "Previews"; | |
| 25 const char kPreviewsType[] = "previews_type"; | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 PreviewsUKMObserver::PreviewsUKMObserver() {} | |
| 30 | |
| 31 PreviewsUKMObserver::~PreviewsUKMObserver() {} | |
| 32 | |
| 33 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | |
| 34 PreviewsUKMObserver::OnCommit(content::NavigationHandle* navigation_handle, | |
| 35 ukm::SourceId source_id) { | |
| 36 // As documented in content/public/browser/navigation_handle.h, this | |
| 37 // NavigationData is a clone of the NavigationData instance returned from | |
| 38 // ResourceDispatcherHostDelegate::GetNavigationData during commit. | |
| 39 // Because ChromeResourceDispatcherHostDelegate always returns a | |
| 40 // ChromeNavigationData, it is safe to static_cast here. | |
| 41 ChromeNavigationData* chrome_navigation_data = | |
| 42 static_cast<ChromeNavigationData*>( | |
| 43 navigation_handle->GetNavigationData()); | |
| 44 if (!chrome_navigation_data) | |
| 45 return CONTINUE_OBSERVING; | |
| 46 data_reduction_proxy::DataReductionProxyData* data = | |
| 47 chrome_navigation_data->GetDataReductionProxyData(); | |
| 48 if (data && data->used_data_reduction_proxy() && data->lite_page_received()) { | |
| 49 previews_types_ |= PREVIEWS_UKM_LITE_PAGE; | |
| 50 } | |
| 51 | |
| 52 return CONTINUE_OBSERVING; | |
| 53 } | |
| 54 | |
| 55 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | |
| 56 PreviewsUKMObserver::OnStart(content::NavigationHandle* navigation_handle, | |
| 57 const GURL& currently_committed_url, | |
| 58 bool started_in_foreground) { | |
| 59 if (!started_in_foreground) | |
| 60 return STOP_OBSERVING; | |
| 61 return CONTINUE_OBSERVING; | |
| 62 } | |
| 63 | |
| 64 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | |
| 65 PreviewsUKMObserver::FlushMetricsOnAppEnterBackground( | |
| 66 const page_load_metrics::mojom::PageLoadTiming& timing, | |
| 67 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 68 RecordPreviewsTypes(info); | |
| 69 return STOP_OBSERVING; | |
| 70 } | |
| 71 | |
| 72 void PreviewsUKMObserver::OnComplete( | |
| 73 const page_load_metrics::mojom::PageLoadTiming& timing, | |
| 74 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 75 RecordPreviewsTypes(info); | |
| 76 } | |
| 77 | |
| 78 void PreviewsUKMObserver::RecordPreviewsTypes( | |
| 79 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 80 if (previews_types_ == PREVIEWS_UKM_NONE) | |
| 81 return; | |
| 82 ukm::UkmRecorder* ukm_recorder = g_browser_process->ukm_recorder(); | |
|
Bryan McQuade
2017/06/28 13:13:40
i think you may need to check that ukm_recorder is
RyanSturm
2017/07/11 21:46:40
Done.
| |
| 83 std::unique_ptr<ukm::UkmEntryBuilder> builder = | |
| 84 ukm_recorder->GetEntryBuilder(info.source_id, kPreviewsName); | |
| 85 builder->AddMetric(kPreviewsType, previews_types_); | |
| 86 } | |
| 87 | |
| 88 void PreviewsUKMObserver::OnLoadedResource( | |
| 89 const page_load_metrics::ExtraRequestCompleteInfo& | |
| 90 extra_request_complete_info) { | |
| 91 if (extra_request_complete_info.data_reduction_proxy_data) { | |
| 92 if (extra_request_complete_info.data_reduction_proxy_data | |
| 93 ->lofi_received()) { | |
| 94 previews_types_ |= PREVIEWS_UKM_SERVER_LOFI; | |
| 95 } | |
| 96 if (extra_request_complete_info.data_reduction_proxy_data | |
| 97 ->client_lofi_requested()) { | |
| 98 previews_types_ |= PREVIEWS_UKM_CLIENT_LOFI; | |
| 99 } | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 } // namespace previews | |
| OLD | NEW |