Home | History | Annotate | Download | only in metrics
      1 // Copyright 2015 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 package org.chromium.base.metrics;
      6 
      7 import org.chromium.base.ThreadUtils;
      8 import org.chromium.base.annotations.JNINamespace;
      9 
     10 /**
     11  * Java API for recording UMA actions.
     12  *
     13  * WARNINGS:
     14  * JNI calls are relatively costly - avoid using in performance-critical code.
     15  *
     16  * We use a script (extract_actions.py) to scan the source code and extract actions. A string
     17  * literal (not a variable) must be passed to record().
     18  */
     19 @JNINamespace("base::android")
     20 public class RecordUserAction {
     21     public static void record(final String action) {
     22         if (ThreadUtils.runningOnUiThread()) {
     23             nativeRecordUserAction(action);
     24             return;
     25         }
     26 
     27         ThreadUtils.runOnUiThread(new Runnable() {
     28             @Override
     29             public void run() {
     30                 nativeRecordUserAction(action);
     31             }
     32         });
     33     }
     34 
     35     private static native void nativeRecordUserAction(String action);
     36 }
     37