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

Unified Diff: chrome/browser/android/search_geolocation_disclosure_tab_helper.cc

Issue 2518963002: Record metric of geo permission before and after showing the disclosure. (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/search_geolocation_disclosure_tab_helper.cc
diff --git a/chrome/browser/android/search_geolocation_disclosure_tab_helper.cc b/chrome/browser/android/search_geolocation_disclosure_tab_helper.cc
index 248f5ede52acfb34feb232191821b7de353c7778..41f1080e7671f7f7475298999f94c5b981255654 100644
--- a/chrome/browser/android/search_geolocation_disclosure_tab_helper.cc
+++ b/chrome/browser/android/search_geolocation_disclosure_tab_helper.cc
@@ -6,6 +6,7 @@
#include "base/feature_list.h"
#include "base/logging.h"
+#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/android/search_geolocation_disclosure_infobar_delegate.h"
@@ -80,31 +81,14 @@ void SearchGeolocationDisclosureTabHelper::RegisterProfilePrefs(
0);
registry->RegisterInt64Pref(prefs::kSearchGeolocationDisclosureLastShowDate,
0);
+ registry->RegisterBooleanPref(
+ prefs::kSearchGeolocationPreDisclosureMetricsRecorded, false);
+ registry->RegisterBooleanPref(
+ prefs::kSearchGeolocationPostDisclosureMetricsRecorded, false);
}
void SearchGeolocationDisclosureTabHelper::
MaybeShowDefaultSearchGeolocationDisclosure(GURL gurl) {
- // Don't show the infobar if the user has dismissed it.
- PrefService* prefs = GetProfile()->GetPrefs();
- bool dismissed_already =
- prefs->GetBoolean(prefs::kSearchGeolocationDisclosureDismissed);
- if (dismissed_already)
- return;
-
- // Or if they've seen it enough times already.
- int shown_count =
- prefs->GetInteger(prefs::kSearchGeolocationDisclosureShownCount);
- if (shown_count >= GetMaxShowCount())
- return;
-
- // Or if it has been shown too recently.
- base::Time last_shown = base::Time::FromInternalValue(
- prefs->GetInt64(prefs::kSearchGeolocationDisclosureLastShowDate));
- if (base::Time::Now() - last_shown <
- base::TimeDelta::FromDays(GetDaysPerShow())) {
- return;
- }
-
// Only show the disclosure for default search navigations from the omnibox.
TemplateURLService* template_url_service =
TemplateURLServiceFactory::GetForProfile(GetProfile());
@@ -123,6 +107,32 @@ void SearchGeolocationDisclosureTabHelper::
return;
}
+ // Record metrics for the state of permissions before the disclosure has been
+ // shown.
+ RecordPreDisclosureMetrics(gurl);
+
+ // Don't show the infobar if the user has dismissed it, or they've seen it
+ // enough times already.
+ PrefService* prefs = GetProfile()->GetPrefs();
+ bool dismissed_already =
+ prefs->GetBoolean(prefs::kSearchGeolocationDisclosureDismissed);
+ int shown_count =
+ prefs->GetInteger(prefs::kSearchGeolocationDisclosureShownCount);
+ if (dismissed_already || shown_count >= GetMaxShowCount()) {
+ // Record metrics for the state of permissions after the disclosure has been
+ // shown.
raymes 2016/11/22 01:54:00 nit: Perhaps // shown and won't be shown again.
benwells 2016/11/22 02:23:07 Done.
+ RecordPostDisclosureMetrics(gurl);
+ return;
+ }
+
+ // Or if it has been shown too recently.
+ base::Time last_shown = base::Time::FromInternalValue(
+ prefs->GetInt64(prefs::kSearchGeolocationDisclosureLastShowDate));
+ if (base::Time::Now() - last_shown <
+ base::TimeDelta::FromDays(GetDaysPerShow())) {
+ return;
+ }
+
// Check that the Chrome app has geolocation permission.
JNIEnv* env = base::android::AttachCurrentThread();
if (!Java_GeolocationHeader_hasGeolocationPermission(env))
@@ -145,6 +155,44 @@ void SearchGeolocationDisclosureTabHelper::
base::Time::Now().ToInternalValue());
}
+void SearchGeolocationDisclosureTabHelper::RecordPreDisclosureMetrics(
+ GURL gurl) {
+ PrefService* prefs = GetProfile()->GetPrefs();
+ if (!prefs->GetBoolean(
+ prefs::kSearchGeolocationPreDisclosureMetricsRecorded)) {
+ blink::mojom::PermissionStatus status =
+ PermissionManager::Get(GetProfile())
+ ->GetPermissionStatus(content::PermissionType::GEOLOCATION, gurl,
+ gurl);
+ UMA_HISTOGRAM_ENUMERATION("GeolocationDisclosure.PreDisclosurePermission",
+ static_cast<base::HistogramBase::Sample>(status),
+ static_cast<base::HistogramBase::Sample>(
+ blink::mojom::PermissionStatus::LAST) +
+ 1);
+ prefs->SetBoolean(prefs::kSearchGeolocationPreDisclosureMetricsRecorded,
+ true);
+ }
+}
+
+void SearchGeolocationDisclosureTabHelper::RecordPostDisclosureMetrics(
+ GURL gurl) {
+ PrefService* prefs = GetProfile()->GetPrefs();
+ if (!prefs->GetBoolean(
+ prefs::kSearchGeolocationPostDisclosureMetricsRecorded)) {
+ blink::mojom::PermissionStatus status =
+ PermissionManager::Get(GetProfile())
+ ->GetPermissionStatus(content::PermissionType::GEOLOCATION, gurl,
+ gurl);
+ UMA_HISTOGRAM_ENUMERATION("GeolocationDisclosure.PostDisclosurePermission",
+ static_cast<base::HistogramBase::Sample>(status),
+ static_cast<base::HistogramBase::Sample>(
+ blink::mojom::PermissionStatus::LAST) +
+ 1);
+ prefs->SetBoolean(prefs::kSearchGeolocationPostDisclosureMetricsRecorded,
+ true);
+ }
+}
+
Profile* SearchGeolocationDisclosureTabHelper::GetProfile() {
return Profile::FromBrowserContext(web_contents()->GetBrowserContext());
}

Powered by Google App Engine
This is Rietveld 408576698