| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 package org.chromium.chrome.browser.metrics; | 5 package org.chromium.chrome.browser.metrics; |
| 6 | 6 |
| 7 import org.chromium.base.ObserverList; | 7 import org.chromium.base.ObserverList; |
| 8 import org.chromium.base.ThreadUtils; | 8 import org.chromium.base.ThreadUtils; |
| 9 import org.chromium.base.annotations.CalledByNative; | 9 import org.chromium.base.annotations.CalledByNative; |
| 10 import org.chromium.content_public.browser.WebContents; | 10 import org.chromium.content_public.browser.WebContents; |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * Receives the page load metrics updates from AndroidPageLoadMetricsObserver, a
nd notifies the | 13 * Receives the page load metrics updates from AndroidPageLoadMetricsObserver, a
nd notifies the |
| 14 * observers. | 14 * observers. |
| 15 * | 15 * |
| 16 * Threading: everything here must happen on the UI thread. | 16 * Threading: everything here must happen on the UI thread. |
| 17 */ | 17 */ |
| 18 public class PageLoadMetrics { | 18 public class PageLoadMetrics { |
| 19 public static final String FIRST_CONTENTFUL_PAINT = "firstContentfulPaint"; | 19 public static final String FIRST_CONTENTFUL_PAINT = "firstContentfulPaint"; |
| 20 public static final String NAVIGATION_START = "navigationStart"; |
| 20 | 21 |
| 21 /** Observer for page load metrics. */ | 22 /** Observer for page load metrics. */ |
| 22 public interface Observer { | 23 public interface Observer { |
| 23 /** | 24 /** |
| 24 * Called when the first contentful paint page load metric is available. | 25 * Called when the first contentful paint page load metric is available. |
| 25 * | 26 * |
| 26 * @param webContents the WebContents this metrics is related to. | 27 * @param webContents the WebContents this metrics is related to. |
| 28 * @param navigationStartTick Absolute navigation start time, as TimeTic
ks. |
| 27 * @param firstContentfulPaintMs Time to first contentful paint from nav
igation start. | 29 * @param firstContentfulPaintMs Time to first contentful paint from nav
igation start. |
| 28 */ | 30 */ |
| 29 public void onFirstContentfulPaint(WebContents webContents, long firstCo
ntentfulPaintMs); | 31 public void onFirstContentfulPaint( |
| 32 WebContents webContents, long navigationStartMs, long firstConte
ntfulPaintMs); |
| 30 } | 33 } |
| 31 | 34 |
| 32 private static ObserverList<Observer> sObservers; | 35 private static ObserverList<Observer> sObservers; |
| 33 | 36 |
| 34 /** Adds an observer. */ | 37 /** Adds an observer. */ |
| 35 public static boolean addObserver(Observer observer) { | 38 public static boolean addObserver(Observer observer) { |
| 36 ThreadUtils.assertOnUiThread(); | 39 ThreadUtils.assertOnUiThread(); |
| 37 if (sObservers == null) sObservers = new ObserverList<>(); | 40 if (sObservers == null) sObservers = new ObserverList<>(); |
| 38 return sObservers.addObserver(observer); | 41 return sObservers.addObserver(observer); |
| 39 } | 42 } |
| 40 | 43 |
| 41 /** Removes an observer. */ | 44 /** Removes an observer. */ |
| 42 public static boolean removeObserver(Observer observer) { | 45 public static boolean removeObserver(Observer observer) { |
| 43 ThreadUtils.assertOnUiThread(); | 46 ThreadUtils.assertOnUiThread(); |
| 44 if (sObservers == null) return false; | 47 if (sObservers == null) return false; |
| 45 return sObservers.removeObserver(observer); | 48 return sObservers.removeObserver(observer); |
| 46 } | 49 } |
| 47 | 50 |
| 48 @CalledByNative | 51 @CalledByNative |
| 49 static void onFirstContentfulPaint(WebContents webContents, long firstConten
tfulPaintMs) { | 52 static void onFirstContentfulPaint( |
| 53 WebContents webContents, long navigationStartTick, long firstContent
fulPaintMs) { |
| 50 ThreadUtils.assertOnUiThread(); | 54 ThreadUtils.assertOnUiThread(); |
| 51 if (sObservers == null) return; | 55 if (sObservers == null) return; |
| 52 for (Observer observer : sObservers) { | 56 for (Observer observer : sObservers) { |
| 53 observer.onFirstContentfulPaint(webContents, firstContentfulPaintMs)
; | 57 observer.onFirstContentfulPaint( |
| 58 webContents, navigationStartTick, firstContentfulPaintMs); |
| 54 } | 59 } |
| 55 } | 60 } |
| 56 | 61 |
| 57 private PageLoadMetrics() {} | 62 private PageLoadMetrics() {} |
| 58 } | 63 } |
| OLD | NEW |