Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Side by Side Diff: chrome/browser/page_load_metrics/observers/ukm_page_load_metrics_observer.cc

Issue 2617883004: Initial UKMPageLoadMetricsObserver (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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/ukm_page_load_metrics_obser ver.h"
6 #include "chrome/browser/browser_process.h"
7 #include "components/ukm/ukm_service.h"
8 #include "components/ukm/ukm_source.h"
9
10 // static
11 std::unique_ptr<page_load_metrics::PageLoadMetricsObserver>
12 UKMPageLoadMetricsObserver::CreateIfNeeded() {
13 if (!g_browser_process->ukm_service())
14 return nullptr;
15
16 return base::MakeUnique<UKMPageLoadMetricsObserver>();
17 }
18
19 UKMPageLoadMetricsObserver::UKMPageLoadMetricsObserver() {}
20
21 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
22 UKMPageLoadMetricsObserver::OnStart(
Zhen Wang 2017/01/09 17:34:51 Probably also need to consider OnRedirect etc to m
oystein (OOO til 10th of July) 2017/01/24 19:21:41 Bryan: How do the other pageload metrics handle On
23 content::NavigationHandle* navigation_handle,
24 const GURL& currently_committed_url,
25 bool started_in_foreground) {
Steven Holte 2017/01/10 23:53:52 This seems like a good place to check sync pref:
oystein (OOO til 10th of July) 2017/01/24 19:21:41 we've had a couple of meetings since this; we deci
26 navigation_start_ = navigation_handle->NavigationStart();
27 return started_in_foreground ? CONTINUE_OBSERVING : STOP_OBSERVING;
28 }
29
30 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
31 UKMPageLoadMetricsObserver::OnHidden(
32 const page_load_metrics::PageLoadTiming& timing,
33 const page_load_metrics::PageLoadExtraInfo& extra_info) {
34 return STOP_OBSERVING;
Zhen Wang 2017/01/09 17:34:51 Does this we ignore the metrics whenever a page is
oystein (OOO til 10th of July) 2017/01/24 19:21:41 Yep. My intuition is that it's reasonable to restr
35 }
36
37 void UKMPageLoadMetricsObserver::OnComplete(
38 const page_load_metrics::PageLoadTiming& timing,
39 const page_load_metrics::PageLoadExtraInfo& info) {
40 if (info.committed_url.is_empty())
41 return;
42
43 LOG(ERROR) << "UKMPageLoadMetricsObserver::OnComplete for '"
44 << info.committed_url << "': FMP "
45 << timing.first_meaningful_paint.value();
46
47 ukm::UkmService* ukm_service = g_browser_process->ukm_service();
48 if (!ukm_service) {
49 LOG(ERROR) << "No UKM service :'(";
50 return;
51 }
52
53 std::unique_ptr<ukm::UkmSource> source =
54 base::WrapUnique(new ukm::UkmSource());
55 source->set_committed_url(info.committed_url);
56 source->set_navigation_start(navigation_start_);
Zhen Wang 2017/01/09 17:34:51 The |timing| parameter passed in also has |timing.
oystein (OOO til 10th of July) 2017/01/24 19:21:41 Done.
57 source->set_first_meaningful_paint(timing.first_meaningful_paint.value());
58
59 ukm_service->RecordSource(std::move(source));
60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698