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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/metrics/LaunchMetrics.java

Issue 1220813010: Add UMA metrics to track the source of homescreen icons on launch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding missing SOURCE gets and puts Created 5 years, 5 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
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.chrome.browser.metrics; 5 package org.chromium.chrome.browser.metrics;
6 6
7 import org.chromium.base.JNINamespace; 7 import org.chromium.base.JNINamespace;
8 import org.chromium.content_public.browser.WebContents; 8 import org.chromium.content_public.browser.WebContents;
9 9
10 import java.util.ArrayList; 10 import java.util.ArrayList;
11 import java.util.List; 11 import java.util.List;
12 12
13 /** 13 /**
14 * Used for recording metrics about Chrome launches. 14 * Used for recording metrics about Chrome launches.
15 */ 15 */
16 @JNINamespace("metrics") 16 @JNINamespace("metrics")
17 public class LaunchMetrics { 17 public class LaunchMetrics {
18 private static final List<String> sActivityUrls = new ArrayList<String>(); 18 private static class UrlSourcePair {
19 private static final List<String> sTabUrls = new ArrayList<String>(); 19 // The source member stores the origin of the url, e.g. from the add to homescreen menu
20 // item, an app banner, or unknown. The mapping of int source values to their string names
21 // is found in the C++ ShortcutInfo struct.
22 private String mUrl;
23 private int mSource;
24
25 public UrlSourcePair(String url, int source) {
26 mUrl = url;
27 mSource = source;
28 }
29
30 public String getUrl() {
31 return mUrl;
32 }
33
34 public int getSource() {
35 return mSource;
36 }
37 }
38
39 private static final List<UrlSourcePair> sActivityUrls = new ArrayList<UrlSo urcePair>();
40 private static final List<UrlSourcePair> sTabUrls = new ArrayList<UrlSourceP air>();
20 41
21 /** 42 /**
22 * Records the launch of a standalone Activity for a URL (i.e. a WebappActiv ity). 43 * Records the launch of a standalone Activity for a URL (i.e. a WebappActiv ity)
44 * added from a specific source.
23 * @param url URL that kicked off the Activity's creation. 45 * @param url URL that kicked off the Activity's creation.
46 * @param source integer id of the source from where the URL was added.
24 */ 47 */
25 public static void recordHomeScreenLaunchIntoStandaloneActivity(String url) { 48 public static void recordHomeScreenLaunchIntoStandaloneActivity(String url, int source) {
26 sActivityUrls.add(url); 49 sActivityUrls.add(new UrlSourcePair(url, source));
27 } 50 }
28 51
29 /** 52 /**
30 * Records the launch of a Tab for a URL (i.e. a Home screen shortcut). 53 * Records the launch of a Tab for a URL (i.e. a Home screen shortcut).
31 * @param url URL that kicked off the Tab's creation. 54 * @param url URL that kicked off the Tab's creation.
55 * @param source integer id of the source from where the URL was added.
32 */ 56 */
33 public static void recordHomeScreenLaunchIntoTab(String url) { 57 public static void recordHomeScreenLaunchIntoTab(String url, int source) {
34 sTabUrls.add(url); 58 sTabUrls.add(new UrlSourcePair(url, source));
35 } 59 }
36 60
37 /** 61 /**
38 * Calls out to native code to record URLs that have been launched via the H ome screen. 62 * Calls out to native code to record URLs that have been launched via the H ome screen.
39 * This intermediate step is necessary because Activity.onCreate() may be ca lled when 63 * This intermediate step is necessary because Activity.onCreate() may be ca lled when
40 * the native library has not yet been loaded. 64 * the native library has not yet been loaded.
41 * @param webContents WebContents for the current Tab. 65 * @param webContents WebContents for the current Tab.
42 */ 66 */
43 public static void commitLaunchMetrics(WebContents webContents) { 67 public static void commitLaunchMetrics(WebContents webContents) {
44 for (String url : sActivityUrls) { 68 for (UrlSourcePair item : sActivityUrls) {
45 nativeRecordLaunch(true, url, webContents); 69 nativeRecordLaunch(true, item.getUrl(), item.getSource(), webContent s);
46 } 70 }
47 for (String url : sTabUrls) { 71 for (UrlSourcePair item : sTabUrls) {
48 nativeRecordLaunch(false, url, webContents); 72 nativeRecordLaunch(false, item.getUrl(), item.getSource(), webConten ts);
49 } 73 }
50 sActivityUrls.clear(); 74 sActivityUrls.clear();
51 sTabUrls.clear(); 75 sTabUrls.clear();
52 } 76 }
53 77
54 private static native void nativeRecordLaunch( 78 private static native void nativeRecordLaunch(
55 boolean standalone, String url, WebContents webContents); 79 boolean standalone, String url, int source, WebContents webContents) ;
56 } 80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698