| OLD | NEW |
| (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/android_page_load_metrics_o
bserver.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" |
| 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "components/page_load_metrics/browser/page_load_metrics_util.h" |
| 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/web_contents.h" |
| 15 #include "jni/PageLoadMetrics_jni.h" |
| 16 #include "url/gurl.h" |
| 17 |
| 18 AndroidPageLoadMetricsObserver::AndroidPageLoadMetricsObserver( |
| 19 content::WebContents* web_contents) |
| 20 : web_contents_(web_contents), has_seen_first_contentful_paint_(false) {} |
| 21 |
| 22 void AndroidPageLoadMetricsObserver::OnTimingUpdate( |
| 23 const page_load_metrics::PageLoadTiming& timing, |
| 24 const page_load_metrics::PageLoadExtraInfo& extra_info) { |
| 25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 26 if (has_seen_first_contentful_paint_ || !timing.first_contentful_paint) |
| 27 return; |
| 28 double first_contentful_paint_ms = |
| 29 timing.first_contentful_paint->InMillisecondsF(); |
| 30 base::android::ScopedJavaLocalRef<jobject> java_web_contents = |
| 31 web_contents_->GetJavaWebContents(); |
| 32 JNIEnv* env = base::android::AttachCurrentThread(); |
| 33 Java_PageLoadMetrics_onFirstContentfulPaintMetricUpdate( |
| 34 env, java_web_contents.obj(), first_contentful_paint_ms); |
| 35 has_seen_first_contentful_paint_ = true; |
| 36 } |
| 37 |
| 38 bool RegisterPageLoadMetricsBindings(JNIEnv* env) { |
| 39 return RegisterNativesImpl(env); |
| 40 } |
| OLD | NEW |