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

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

Issue 2766623003: Make Android Clipboard Keep Track of Last Modified Time (Closed)
Patch Set: final attempt at restoring Created 3 years, 8 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
« no previous file with comments | « no previous file | chrome/android/junit/src/org/chromium/chrome/browser/DisableHistogramsRule.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.annotations.JNINamespace; 9 import org.chromium.base.annotations.JNINamespace;
9 10
10 /** 11 /**
11 * Java API for recording UMA actions. 12 * Java API for recording UMA actions.
12 * 13 *
13 * WARNINGS: 14 * WARNINGS:
14 * JNI calls are relatively costly - avoid using in performance-critical code. 15 * JNI calls are relatively costly - avoid using in performance-critical code.
15 * 16 *
16 * 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
17 * literal (not a variable) must be passed to record(). 18 * literal (not a variable) must be passed to record().
18 */ 19 */
19 @JNINamespace("base::android") 20 @JNINamespace("base::android")
20 public class RecordUserAction { 21 public class RecordUserAction {
22 private static Throwable sDisabledBy;
23
24 /**
25 * Tests may not have native initialized, so they may need to disable metric s. The value should
26 * be reset after the test done, to avoid carrying over state to unrelated t ests.
27 */
28 @VisibleForTesting
29 public static void setDisabledForTests(boolean disabled) {
30 if (disabled && sDisabledBy != null) {
31 throw new IllegalStateException("UserActions are already disabled.", sDisabledBy);
32 }
33 sDisabledBy = disabled ? new Throwable() : null;
34 }
35
21 public static void record(final String action) { 36 public static void record(final String action) {
37 if (sDisabledBy != null) return;
38
22 if (ThreadUtils.runningOnUiThread()) { 39 if (ThreadUtils.runningOnUiThread()) {
23 nativeRecordUserAction(action); 40 nativeRecordUserAction(action);
24 return; 41 return;
25 } 42 }
26 43
27 ThreadUtils.runOnUiThread(new Runnable() { 44 ThreadUtils.runOnUiThread(new Runnable() {
28 @Override 45 @Override
29 public void run() { 46 public void run() {
30 nativeRecordUserAction(action); 47 nativeRecordUserAction(action);
31 } 48 }
32 }); 49 });
33 } 50 }
34 51
35 private static native void nativeRecordUserAction(String action); 52 private static native void nativeRecordUserAction(String action);
36 } 53 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/junit/src/org/chromium/chrome/browser/DisableHistogramsRule.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698