Commit d33801eb authored by dfalcantara's avatar dfalcantara Committed by Commit bot

Record whenever an app is launched from the Home screen.

Because Android's API doesn't let us know when a user has
deleted a shortcut from the home screen, record that the
shortcut still exists whenever the shortcut is launched.
This applies to both regular shortcuts and web app launches.

BUG=460229

Review URL: https://codereview.chromium.org/1129293009

Cr-Commit-Position: refs/heads/master@{#329940}
parent 9629015f
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.metrics;
import org.chromium.base.JNINamespace;
import org.chromium.content_public.browser.WebContents;
import java.util.ArrayList;
import java.util.List;
......@@ -37,17 +38,19 @@ public class LaunchMetrics {
* Calls out to native code to record URLs that have been launched via the Home screen.
* This intermediate step is necessary because Activity.onCreate() may be called when
* the native library has not yet been loaded.
* @param webContents WebContents for the current Tab.
*/
public static void commitLaunchMetrics() {
public static void commitLaunchMetrics(WebContents webContents) {
for (String url : sActivityUrls) {
nativeRecordLaunch(true, url);
nativeRecordLaunch(true, url, webContents);
}
for (String url : sTabUrls) {
nativeRecordLaunch(false, url);
nativeRecordLaunch(false, url, webContents);
}
sActivityUrls.clear();
sTabUrls.clear();
}
private static native void nativeRecordLaunch(boolean standalone, String url);
private static native void nativeRecordLaunch(
boolean standalone, String url, WebContents webContents);
}
......@@ -7,8 +7,10 @@
#include "base/android/jni_string.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "chrome/browser/banners/app_banner_settings_helper.h"
#include "chrome/browser/browser_process.h"
#include "components/rappor/rappor_utils.h"
#include "content/public/browser/web_contents.h"
#include "jni/LaunchMetrics_jni.h"
#include "url/gurl.h"
......@@ -25,7 +27,21 @@ bool RegisterLaunchMetrics(JNIEnv* env) {
}
static void RecordLaunch(JNIEnv* env, jclass caller, jboolean standalone,
jstring jurl) {
jstring jurl, jobject jweb_contents) {
GURL url(base::android::ConvertJavaStringToUTF8(env, jurl));
content::WebContents* web_contents =
content::WebContents::FromJavaWebContents(jweb_contents);
if (web_contents) {
// What a user has installed on the Home screen can become disconnected from
// what Chrome believes is on the Home screen if the user clears their data.
// Use the launch as a signal that the shortcut still exists.
AppBannerSettingsHelper::RecordBannerEvent(
web_contents, url, url.spec(),
AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
base::Time::Now());
}
int action = standalone ? HOME_SCREEN_LAUNCH_STANDALONE
: HOME_SCREEN_LAUNCH_SHORTCUT;
std::string rappor_metric = standalone ? "Launch.HomeScreen.Standalone"
......@@ -34,9 +50,8 @@ static void RecordLaunch(JNIEnv* env, jclass caller, jboolean standalone,
UMA_HISTOGRAM_ENUMERATION("Launch.HomeScreen", action,
HOME_SCREEN_LAUNCH_COUNT);
std::string url = base::android::ConvertJavaStringToUTF8(env, jurl);
rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
rappor_metric, GURL(url));
rappor_metric, url);
}
}; // namespace metrics
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment