1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/android/metrics/launch_metrics.h"
7 #include "base/android/jni_string.h"
8 #include "base/metrics/histogram_macros.h"
9 #include "base/metrics/user_metrics.h"
10 #include "chrome/browser/android/shortcut_info.h"
11 #include "chrome/browser/banners/app_banner_settings_helper.h"
12 #include "chrome/browser/browser_process.h"
13 #include "components/rappor/rappor_utils.h"
14 #include "content/public/browser/web_contents.h"
15 #include "jni/LaunchMetrics_jni.h"
20 enum HomeScreenLaunch
{
21 HOME_SCREEN_LAUNCH_STANDALONE
= 0,
22 HOME_SCREEN_LAUNCH_SHORTCUT
= 1,
23 HOME_SCREEN_LAUNCH_COUNT
= 2
26 bool RegisterLaunchMetrics(JNIEnv
* env
) {
27 return RegisterNativesImpl(env
);
30 static void RecordLaunch(JNIEnv
* env
,
31 const JavaParamRef
<jclass
>& caller
,
33 const JavaParamRef
<jstring
>& jurl
,
35 const JavaParamRef
<jobject
>& jweb_contents
) {
36 GURL
url(base::android::ConvertJavaStringToUTF8(env
, jurl
));
38 content::WebContents
* web_contents
=
39 content::WebContents::FromJavaWebContents(jweb_contents
);
40 if (web_contents
&& source
== ShortcutInfo::SOURCE_APP_BANNER
) {
41 // What a user has installed on the Home screen can become disconnected from
42 // what Chrome believes is on the Home screen if the user clears their data.
43 // Use the launch as a signal that the shortcut still exists.
44 AppBannerSettingsHelper::RecordBannerEvent(
45 web_contents
, url
, url
.spec(),
46 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN
,
50 std::string rappor_metric_source
;
51 if (source
== ShortcutInfo::SOURCE_ADD_TO_HOMESCREEN
)
52 rappor_metric_source
= "Launch.HomeScreenSource.AddToHomeScreen";
53 else if (source
== ShortcutInfo::SOURCE_APP_BANNER
)
54 rappor_metric_source
= "Launch.HomeScreenSource.AppBanner";
55 else if (source
== ShortcutInfo::SOURCE_BOOKMARK_NAVIGATOR_WIDGET
)
56 rappor_metric_source
= "Launch.HomeScreenSource.BookmarkNavigatorWidget";
57 else if (source
== ShortcutInfo::SOURCE_BOOKMARK_SHORTCUT_WIDGET
)
58 rappor_metric_source
= "Launch.HomeScreenSource.BookmarkShortcutWidget";
60 rappor_metric_source
= "Launch.HomeScreenSource.Unknown";
62 UMA_HISTOGRAM_ENUMERATION("Launch.HomeScreenSource", source
,
63 ShortcutInfo::SOURCE_COUNT
);
65 rappor::SampleDomainAndRegistryFromGURL(g_browser_process
->rappor_service(),
66 rappor_metric_source
, url
);
68 int action
= standalone
? HOME_SCREEN_LAUNCH_STANDALONE
69 : HOME_SCREEN_LAUNCH_SHORTCUT
;
70 std::string rappor_metric_action
= standalone
? "Launch.HomeScreen.Standalone"
71 : "Launch.HomeScreen.Shortcut";
73 UMA_HISTOGRAM_ENUMERATION("Launch.HomeScreen", action
,
74 HOME_SCREEN_LAUNCH_COUNT
);
76 rappor::SampleDomainAndRegistryFromGURL(g_browser_process
->rappor_service(),
77 rappor_metric_action
, url
);
80 }; // namespace metrics