Bug 1009315 - Part 3: Replace TelemetryContract interfaces with enums. r=liuche

This commit is contained in:
Michael Comella 2014-05-30 16:53:28 -07:00
parent 9e0f801dc4
commit e3eef4c979
7 changed files with 179 additions and 69 deletions

View File

@ -1703,7 +1703,9 @@ abstract public class BrowserApp extends GeckoApp
// Otherwise, construct a search query from the bookmark keyword.
final String searchUrl = keywordUrl.replace("%s", URLEncoder.encode(keywordSearch));
Tabs.getInstance().loadUrl(searchUrl, Tabs.LOADURL_USER_ENTERED);
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, "", "keyword");
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL,
TelemetryContract.Method.NONE,
"keyword");
}
});
}

View File

@ -127,8 +127,7 @@ public class DataReportingNotification {
result = true;
} finally {
// We want to track any errors, so record notification outcome.
final String notificationEvent = TelemetryContract.Event.POLICY_NOTIFICATION_SUCCESS + result;
Telemetry.sendUIEvent(notificationEvent);
Telemetry.sendUIEvent(TelemetryContract.Event.POLICY_NOTIFICATION_SUCCESS, result);
}
}
}

View File

@ -6,13 +6,17 @@
package org.mozilla.gecko;
import org.mozilla.gecko.mozglue.RobocopTarget;
import org.mozilla.gecko.TelemetryContract.Event;
import org.mozilla.gecko.TelemetryContract.Method;
import org.mozilla.gecko.TelemetryContract.Reason;
import org.mozilla.gecko.TelemetryContract.Session;
import android.os.SystemClock;
import android.util.Log;
/**
* All telemetry times are relative to one of two clocks:
*
*
* * Real time since the device was booted, including deep sleep. Use this
* as a substitute for wall clock.
* * Uptime since the device was booted, excluding deep sleep. Use this to
@ -107,41 +111,89 @@ public class Telemetry {
}
}
public static void startUISession(String sessionName) {
public static void startUISession(final Session session, final String sessionNameSuffix) {
final String sessionName = getSessionName(session, sessionNameSuffix);
Log.d(LOGTAG, "StartUISession: " + sessionName);
GeckoEvent event = GeckoEvent.createTelemetryUISessionStartEvent(sessionName, realtime());
GeckoAppShell.sendEventToGecko(event);
final GeckoEvent geckoEvent =
GeckoEvent.createTelemetryUISessionStartEvent(sessionName, realtime());
GeckoAppShell.sendEventToGecko(geckoEvent);
}
public static void stopUISession(String sessionName, String reason) {
public static void startUISession(final Session session) {
startUISession(session, null);
}
public static void stopUISession(final Session session, final String sessionNameSuffix,
final Reason reason) {
final String sessionName = getSessionName(session, sessionNameSuffix);
Log.d(LOGTAG, "StopUISession: " + sessionName + ", reason=" + reason);
GeckoEvent event = GeckoEvent.createTelemetryUISessionStopEvent(sessionName, reason, realtime());
GeckoAppShell.sendEventToGecko(event);
final GeckoEvent geckoEvent = GeckoEvent.createTelemetryUISessionStopEvent(
sessionName, reason.toString(), realtime());
GeckoAppShell.sendEventToGecko(geckoEvent);
}
public static void stopUISession(String sessionName) {
stopUISession(sessionName, null);
public static void stopUISession(final Session session, final Reason reason) {
stopUISession(session, null, reason);
}
public static void sendUIEvent(String action, String method, long timestamp, String extras) {
Log.d(LOGTAG, "SendUIEvent: action = " + action + " method = " + method + " timestamp = " + timestamp + " extras = " + extras);
GeckoEvent event = GeckoEvent.createTelemetryUIEvent(action, method, timestamp, extras);
GeckoAppShell.sendEventToGecko(event);
public static void stopUISession(final Session session, final String sessionNameSuffix) {
stopUISession(session, sessionNameSuffix, Reason.NONE);
}
public static void sendUIEvent(String action, String method, long timestamp) {
sendUIEvent(action, method, timestamp, null);
public static void stopUISession(final Session session) {
stopUISession(session, null, Reason.NONE);
}
public static void sendUIEvent(String action, String method, String extras) {
sendUIEvent(action, method, realtime(), extras);
private static String getSessionName(final Session session, final String sessionNameSuffix) {
if (sessionNameSuffix != null) {
return session.toString() + ":" + sessionNameSuffix;
} else {
return session.toString();
}
}
public static void sendUIEvent(String action, String method) {
sendUIEvent(action, method, realtime(), null);
private static void sendUIEvent(final String eventName, final Method method,
final long timestamp, final String extras) {
Log.d(LOGTAG, "SendUIEvent: event = " + eventName + " method = " + method +
" timestamp = " + timestamp + " extras = " + extras);
final GeckoEvent geckoEvent = GeckoEvent.createTelemetryUIEvent(
eventName, method.toString(), timestamp, extras);
GeckoAppShell.sendEventToGecko(geckoEvent);
}
public static void sendUIEvent(String action) {
sendUIEvent(action, null, realtime(), null);
public static void sendUIEvent(final Event event, final Method method, final long timestamp,
final String extras) {
sendUIEvent(event.toString(), method, timestamp, extras);
}
public static void sendUIEvent(final Event event, final Method method, final long timestamp) {
sendUIEvent(event, method, timestamp, null);
}
public static void sendUIEvent(final Event event, final Method method, final String extras) {
sendUIEvent(event, method, realtime(), extras);
}
public static void sendUIEvent(final Event event, final Method method) {
sendUIEvent(event, method, realtime(), null);
}
public static void sendUIEvent(final Event event) {
sendUIEvent(event, Method.NONE, realtime(), null);
}
/**
* Sends a UIEvent with the given status appended to the event name.
*
* This method is a slight bend of the Telemetry framework so chances
* are that you don't want to use this: please think really hard before you do.
*
* Intended for use with data policy notifications.
*/
public static void sendUIEvent(final Event event, final boolean eventStatus) {
final String eventName = event + ":" + eventStatus;
sendUIEvent(eventName, Method.NONE, realtime(), null);
}
}

View File

@ -18,52 +18,64 @@ public interface TelemetryContract {
*
* Please keep this list sorted.
*/
public interface Event {
public enum Event {
// Generic action, usually for tracking menu and toolbar actions.
public static final String ACTION = "action.1";
ACTION("action.1"),
// Cancel a state, action, etc.
public static final String CANCEL = "cancel.1";
CANCEL("cancel.1"),
// Editing an item.
public static final String EDIT = "edit.1";
EDIT("edit.1"),
// Launching (opening) an external application.
// Note: Only used in JavaScript for now, but here for completeness.
public static final String LAUNCH = "launch.1";
LAUNCH("launch.1"),
// Loading a URL.
public static final String LOAD_URL = "loadurl.1";
LOAD_URL("loadurl.1"),
public static final String LOCALE_BROWSER_RESET = "locale.browser.reset.1";
public static final String LOCALE_BROWSER_SELECTED = "locale.browser.selected.1";
public static final String LOCALE_BROWSER_UNSELECTED = "locale.browser.unselected.1";
LOCALE_BROWSER_RESET("locale.browser.reset.1"),
LOCALE_BROWSER_SELECTED("locale.browser.selected.1"),
LOCALE_BROWSER_UNSELECTED("locale.browser.unselected.1"),
// Set default panel.
public static final String PANEL_SET_DEFAULT = "setdefault.1";
PANEL_SET_DEFAULT("setdefault.1"),
// Pinning an item.
public static final String PIN = "pin.1";
PIN("pin.1"),
// Outcome of data policy notification: can be true or false.
public static final String POLICY_NOTIFICATION_SUCCESS = "policynotification.success.1:";
POLICY_NOTIFICATION_SUCCESS("policynotification.success.1"),
// Sanitizing private data.
public static final String SANITIZE = "sanitize.1";
SANITIZE("sanitize.1"),
// Saving a resource (reader, bookmark, etc) for viewing later.
// Note: Only used in JavaScript for now, but here for completeness.
public static final String SAVE = "save.1";
SAVE("save.1"),
// Sharing content.
public static final String SHARE = "share.1";
SHARE("share.1"),
// Unpinning an item.
public static final String UNPIN = "unpin.1";
UNPIN("unpin.1"),
// Stop holding a resource (reader, bookmark, etc) for viewing later.
// Note: Only used in JavaScript for now, but here for completeness.
public static final String UNSAVE = "unsave.1";
UNSAVE("unsave.1"),
;
private final String string;
Event(final String string) {
this.string = string;
}
@Override
public String toString() {
return string;
}
}
/**
@ -72,43 +84,58 @@ public interface TelemetryContract {
*
* Please keep this list sorted.
*/
public interface Method {
public enum Method {
// Action triggered from the action bar (including the toolbar).
public static final String ACTIONBAR = "actionbar";
ACTIONBAR("actionbar"),
// Action triggered by hitting the Android back button.
public static final String BACK = "back";
BACK("back"),
// Action triggered from a button.
public static final String BUTTON = "button";
BUTTON("button"),
// Action occurred via a context menu.
public static final String CONTEXT_MENU = "contextmenu";
CONTEXT_MENU("contextmenu"),
// Action triggered from a dialog.
public static final String DIALOG = "dialog";
DIALOG("dialog"),
// Action triggered from a view grid item, like a thumbnail.
public static final String GRID_ITEM = "griditem";
GRID_ITEM("griditem"),
// Action occurred via an intent.
public static final String INTENT = "intent";
INTENT("intent"),
// Action triggered from a list.
public static final String LIST = "list";
LIST("list"),
// Action triggered from a view list item, like a row of a list.
public static final String LIST_ITEM = "listitem";
LIST_ITEM("listitem"),
// Action occurred via the main menu.
public static final String MENU = "menu";
MENU("menu"),
// No method is specified.
NONE(null),
// Action triggered from a pageaction in the URLBar.
// Note: Only used in JavaScript for now, but here for completeness.
public static final String PAGEACTION = "pageaction";
PAGEACTION("pageaction"),
// Action triggered from a suggestion provided to the user.
public static final String SUGGESTION = "suggestion";
SUGGESTION("suggestion"),
;
private final String string;
Method(final String string) {
this.string = string;
}
@Override
public String toString() {
return string;
}
}
/**
@ -117,26 +144,38 @@ public interface TelemetryContract {
*
* Please keep this list sorted.
*/
public interface Session {
public enum Session {
// Awesomescreen (including frecency search) is active.
public static final String AWESOMESCREEN = "awesomescreen.1";
AWESOMESCREEN("awesomescreen.1"),
// Started the very first time we believe the application has been launched.
public static final String FIRSTRUN = "firstrun.1";
FIRSTRUN("firstrun.1"),
// Awesomescreen frecency search is active.
public static final String FRECENCY = "frecency.1";
FRECENCY("frecency.1"),
// Started when a user enters about:home.
public static final String HOME = "home.1";
HOME("home.1"),
// Started when a user enters a given home panel.
// Session name is dynamic, encoded as "homepanel.1:<panel_id>"
public static final String HOME_PANEL = "homepanel.1:";
HOME_PANEL("homepanel.1"),
// Started when a Reader viewer becomes active in the foreground.
// Note: Only used in JavaScript for now, but here for completeness.
public static final String READER = "reader.1";
READER("reader.1"),
;
private final String string;
Session(final String string) {
this.string = string;
}
@Override
public String toString() {
return string;
}
}
/**
@ -145,8 +184,23 @@ public interface TelemetryContract {
*
* Please keep this list sorted.
*/
public interface Reason {
public enum Reason {
// Changes were committed.
public static final String COMMIT = "commit";
COMMIT("commit"),
// No reason is specified.
NONE(null),
;
private final String string;
Reason(final String string) {
this.string = string;
}
@Override
public String toString() {
return string;
}
}
}

View File

@ -53,7 +53,8 @@ public class HomePager extends ViewPager {
private final Drawable mOriginalBackground;
// Telemetry session for current panel.
private String mCurrentPanelSession;
private TelemetryContract.Session mCurrentPanelSession;
private String mCurrentPanelSessionSuffix;
// Current load state of HomePager.
private LoadState mLoadState;
@ -509,8 +510,9 @@ public class HomePager extends ViewPager {
// Stop the current panel's session if we have one.
stopCurrentPanelTelemetrySession();
mCurrentPanelSession = TelemetryContract.Session.HOME_PANEL + panelId;
Telemetry.startUISession(mCurrentPanelSession);
mCurrentPanelSession = TelemetryContract.Session.HOME_PANEL;
mCurrentPanelSessionSuffix = panelId;
Telemetry.startUISession(mCurrentPanelSession, mCurrentPanelSessionSuffix);
}
/**
@ -518,8 +520,9 @@ public class HomePager extends ViewPager {
*/
private void stopCurrentPanelTelemetrySession() {
if (mCurrentPanelSession != null) {
Telemetry.stopUISession(mCurrentPanelSession);
Telemetry.stopUISession(mCurrentPanelSession, mCurrentPanelSessionSuffix);
mCurrentPanelSession = null;
mCurrentPanelSessionSuffix = null;
}
}
}

View File

@ -113,7 +113,7 @@ public class TopSitesGridView extends GridView {
// If not, navigate to the page given by the url.
if (type != TopSites.TYPE_BLANK) {
if (mUrlOpenListener != null) {
final String method;
final TelemetryContract.Method method;
if (type == TopSites.TYPE_SUGGESTED) {
method = TelemetryContract.Method.SUGGESTION;
} else {

View File

@ -70,7 +70,7 @@ class RemoteTabsList extends ExpandableListView
return true;
}
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, "", "remote");
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.NONE, "remote");
Tabs.getInstance().loadUrl(tab.get("url"), Tabs.LOADURL_NEW_TAB);
autoHidePanel();