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

Side by Side Diff: base/android/java/src/org/chromium/base/metrics/RecordUserAction.java

Issue 2548013002: Remove redundant field initialization in Java code. (Closed)
Patch Set: rebase Created 4 years 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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.base.metrics; 5 package org.chromium.base.metrics;
6 6
7 import org.chromium.base.ThreadUtils; 7 import org.chromium.base.ThreadUtils;
8 import org.chromium.base.VisibleForTesting; 8 import org.chromium.base.VisibleForTesting;
9 import org.chromium.base.annotations.JNINamespace; 9 import org.chromium.base.annotations.JNINamespace;
10 10
11 /** 11 /**
12 * Java API for recording UMA actions. 12 * Java API for recording UMA actions.
13 * 13 *
14 * WARNINGS: 14 * WARNINGS:
15 * JNI calls are relatively costly - avoid using in performance-critical code. 15 * JNI calls are relatively costly - avoid using in performance-critical code.
16 * 16 *
17 * We use a script (extract_actions.py) to scan the source code and extract acti ons. A string 17 * We use a script (extract_actions.py) to scan the source code and extract acti ons. A string
18 * literal (not a variable) must be passed to record(). 18 * literal (not a variable) must be passed to record().
19 */ 19 */
20 @JNINamespace("base::android") 20 @JNINamespace("base::android")
21 public class RecordUserAction { 21 public class RecordUserAction {
22 private static boolean sIsDisabledForTests = false; 22 private static boolean sIsDisabledForTests;
23 23
24 /** 24 /**
25 * Tests may not have native initialized, so they may need to disable metric s. 25 * Tests may not have native initialized, so they may need to disable metric s.
26 */ 26 */
27 @VisibleForTesting 27 @VisibleForTesting
28 public static void disableForTests() { 28 public static void disableForTests() {
29 sIsDisabledForTests = true; 29 sIsDisabledForTests = true;
30 } 30 }
31 31
32 public static void record(final String action) { 32 public static void record(final String action) {
33 if (sIsDisabledForTests) return; 33 if (sIsDisabledForTests) return;
34 34
35 if (ThreadUtils.runningOnUiThread()) { 35 if (ThreadUtils.runningOnUiThread()) {
36 nativeRecordUserAction(action); 36 nativeRecordUserAction(action);
37 return; 37 return;
38 } 38 }
39 39
40 ThreadUtils.runOnUiThread(new Runnable() { 40 ThreadUtils.runOnUiThread(new Runnable() {
41 @Override 41 @Override
42 public void run() { 42 public void run() {
43 nativeRecordUserAction(action); 43 nativeRecordUserAction(action);
44 } 44 }
45 }); 45 });
46 } 46 }
47 47
48 private static native void nativeRecordUserAction(String action); 48 private static native void nativeRecordUserAction(String action);
49 } 49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698