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

Side by Side 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: Feedback 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "chrome/browser/android/search_geolocation_disclosure_tab_helper.h" 5 #include "chrome/browser/android/search_geolocation_disclosure_tab_helper.h"
6 6
7 #include "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram_macros.h"
9 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #include "chrome/browser/android/search_geolocation_disclosure_infobar_delegate. h" 12 #include "chrome/browser/android/search_geolocation_disclosure_infobar_delegate. h"
12 #include "chrome/browser/permissions/permission_manager.h" 13 #include "chrome/browser/permissions/permission_manager.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/search_engines/template_url_service_factory.h" 15 #include "chrome/browser/search_engines/template_url_service_factory.h"
15 #include "chrome/common/chrome_features.h" 16 #include "chrome/common/chrome_features.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 #include "components/pref_registry/pref_registry_syncable.h" 18 #include "components/pref_registry/pref_registry_syncable.h"
18 #include "components/prefs/pref_service.h" 19 #include "components/prefs/pref_service.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 74
74 // static 75 // static
75 void SearchGeolocationDisclosureTabHelper::RegisterProfilePrefs( 76 void SearchGeolocationDisclosureTabHelper::RegisterProfilePrefs(
76 user_prefs::PrefRegistrySyncable* registry) { 77 user_prefs::PrefRegistrySyncable* registry) {
77 registry->RegisterBooleanPref(prefs::kSearchGeolocationDisclosureDismissed, 78 registry->RegisterBooleanPref(prefs::kSearchGeolocationDisclosureDismissed,
78 false); 79 false);
79 registry->RegisterIntegerPref(prefs::kSearchGeolocationDisclosureShownCount, 80 registry->RegisterIntegerPref(prefs::kSearchGeolocationDisclosureShownCount,
80 0); 81 0);
81 registry->RegisterInt64Pref(prefs::kSearchGeolocationDisclosureLastShowDate, 82 registry->RegisterInt64Pref(prefs::kSearchGeolocationDisclosureLastShowDate,
82 0); 83 0);
84 registry->RegisterBooleanPref(
85 prefs::kSearchGeolocationPreDisclosureMetricsRecorded, false);
86 registry->RegisterBooleanPref(
87 prefs::kSearchGeolocationPostDisclosureMetricsRecorded, false);
83 } 88 }
84 89
85 void SearchGeolocationDisclosureTabHelper:: 90 void SearchGeolocationDisclosureTabHelper::
86 MaybeShowDefaultSearchGeolocationDisclosure(GURL gurl) { 91 MaybeShowDefaultSearchGeolocationDisclosure(const GURL& gurl) {
87 // Don't show the infobar if the user has dismissed it.
88 PrefService* prefs = GetProfile()->GetPrefs();
89 bool dismissed_already =
90 prefs->GetBoolean(prefs::kSearchGeolocationDisclosureDismissed);
91 if (dismissed_already)
92 return;
93
94 // Or if they've seen it enough times already.
95 int shown_count =
96 prefs->GetInteger(prefs::kSearchGeolocationDisclosureShownCount);
97 if (shown_count >= GetMaxShowCount())
98 return;
99
100 // Or if it has been shown too recently.
101 base::Time last_shown = base::Time::FromInternalValue(
102 prefs->GetInt64(prefs::kSearchGeolocationDisclosureLastShowDate));
103 if (base::Time::Now() - last_shown <
104 base::TimeDelta::FromDays(GetDaysPerShow())) {
105 return;
106 }
107
108 // Only show the disclosure for default search navigations from the omnibox. 92 // Only show the disclosure for default search navigations from the omnibox.
109 TemplateURLService* template_url_service = 93 TemplateURLService* template_url_service =
110 TemplateURLServiceFactory::GetForProfile(GetProfile()); 94 TemplateURLServiceFactory::GetForProfile(GetProfile());
111 bool is_search_url = 95 bool is_search_url =
112 template_url_service->IsSearchResultsPageFromDefaultSearchProvider( 96 template_url_service->IsSearchResultsPageFromDefaultSearchProvider(
113 gurl); 97 gurl);
114 if (!is_search_url) 98 if (!is_search_url)
115 return; 99 return;
116 100
117 // Only show the disclosure if Google is the default search engine. 101 // Only show the disclosure if Google is the default search engine.
118 TemplateURL* default_search = 102 TemplateURL* default_search =
119 template_url_service->GetDefaultSearchProvider(); 103 template_url_service->GetDefaultSearchProvider();
120 if (!default_search || 104 if (!default_search ||
121 !default_search->url_ref().HasGoogleBaseURLs( 105 !default_search->url_ref().HasGoogleBaseURLs(
122 template_url_service->search_terms_data())) { 106 template_url_service->search_terms_data())) {
123 return; 107 return;
124 } 108 }
125 109
110 // Record metrics for the state of permissions before the disclosure has been
111 // shown.
112 RecordPreDisclosureMetrics(gurl);
113
114 // Don't show the infobar if the user has dismissed it, or they've seen it
115 // enough times already.
116 PrefService* prefs = GetProfile()->GetPrefs();
117 bool dismissed_already =
118 prefs->GetBoolean(prefs::kSearchGeolocationDisclosureDismissed);
119 int shown_count =
120 prefs->GetInteger(prefs::kSearchGeolocationDisclosureShownCount);
121 if (dismissed_already || shown_count >= GetMaxShowCount()) {
122 // Record metrics for the state of permissions after the disclosure has been
123 // shown.
124 RecordPostDisclosureMetrics(gurl);
gone 2016/11/22 21:36:59 Why does this happen up here instead of at the end
benwells 2016/11/22 21:42:34 I will update the comment to the below. Is it clea
gone 2016/11/22 21:48:22 Ah yeah, that'd be good. Thanks!
benwells 2016/11/23 02:31:22 Done.
125 return;
126 }
127
128 // Or if it has been shown too recently.
129 base::Time last_shown = base::Time::FromInternalValue(
130 prefs->GetInt64(prefs::kSearchGeolocationDisclosureLastShowDate));
131 if (base::Time::Now() - last_shown <
132 base::TimeDelta::FromDays(GetDaysPerShow())) {
133 return;
134 }
135
126 // Check that the Chrome app has geolocation permission. 136 // Check that the Chrome app has geolocation permission.
127 JNIEnv* env = base::android::AttachCurrentThread(); 137 JNIEnv* env = base::android::AttachCurrentThread();
128 if (!Java_GeolocationHeader_hasGeolocationPermission(env)) 138 if (!Java_GeolocationHeader_hasGeolocationPermission(env))
129 return; 139 return;
130 140
131 // Only show the disclosure if the geolocation permission is set to ASK 141 // Only show the disclosure if the geolocation permission is set to ASK
132 // (i.e. has not been explicitly set or revoked). 142 // (i.e. has not been explicitly set or revoked).
133 blink::mojom::PermissionStatus status = 143 blink::mojom::PermissionStatus status =
134 PermissionManager::Get(GetProfile()) 144 PermissionManager::Get(GetProfile())
135 ->GetPermissionStatus(content::PermissionType::GEOLOCATION, gurl, 145 ->GetPermissionStatus(content::PermissionType::GEOLOCATION, gurl,
136 gurl); 146 gurl);
137 if (status != blink::mojom::PermissionStatus::ASK) 147 if (status != blink::mojom::PermissionStatus::ASK)
138 return; 148 return;
139 149
140 // All good, let's show the disclosure and increment the shown count. 150 // All good, let's show the disclosure and increment the shown count.
141 SearchGeolocationDisclosureInfoBarDelegate::Create(web_contents(), gurl); 151 SearchGeolocationDisclosureInfoBarDelegate::Create(web_contents(), gurl);
142 shown_count++; 152 shown_count++;
143 prefs->SetInteger(prefs::kSearchGeolocationDisclosureShownCount, shown_count); 153 prefs->SetInteger(prefs::kSearchGeolocationDisclosureShownCount, shown_count);
144 prefs->SetInt64(prefs::kSearchGeolocationDisclosureLastShowDate, 154 prefs->SetInt64(prefs::kSearchGeolocationDisclosureLastShowDate,
145 base::Time::Now().ToInternalValue()); 155 base::Time::Now().ToInternalValue());
146 } 156 }
147 157
158 void SearchGeolocationDisclosureTabHelper::RecordPreDisclosureMetrics(
159 const GURL& gurl) {
160 PrefService* prefs = GetProfile()->GetPrefs();
161 if (!prefs->GetBoolean(
162 prefs::kSearchGeolocationPreDisclosureMetricsRecorded)) {
163 blink::mojom::PermissionStatus status =
164 PermissionManager::Get(GetProfile())
165 ->GetPermissionStatus(content::PermissionType::GEOLOCATION, gurl,
166 gurl);
167 UMA_HISTOGRAM_ENUMERATION("GeolocationDisclosure.PreDisclosurePermission",
168 static_cast<base::HistogramBase::Sample>(status),
169 static_cast<base::HistogramBase::Sample>(
170 blink::mojom::PermissionStatus::LAST) +
Ilya Sherman 2016/11/22 22:36:16 Near its definition, please document that this enu
benwells 2016/11/23 02:31:22 Done.
171 1);
172 prefs->SetBoolean(prefs::kSearchGeolocationPreDisclosureMetricsRecorded,
173 true);
174 }
175 }
176
177 void SearchGeolocationDisclosureTabHelper::RecordPostDisclosureMetrics(
178 const GURL& gurl) {
179 PrefService* prefs = GetProfile()->GetPrefs();
180 if (!prefs->GetBoolean(
181 prefs::kSearchGeolocationPostDisclosureMetricsRecorded)) {
182 blink::mojom::PermissionStatus status =
183 PermissionManager::Get(GetProfile())
184 ->GetPermissionStatus(content::PermissionType::GEOLOCATION, gurl,
185 gurl);
186 UMA_HISTOGRAM_ENUMERATION("GeolocationDisclosure.PostDisclosurePermission",
187 static_cast<base::HistogramBase::Sample>(status),
188 static_cast<base::HistogramBase::Sample>(
189 blink::mojom::PermissionStatus::LAST) +
190 1);
191 prefs->SetBoolean(prefs::kSearchGeolocationPostDisclosureMetricsRecorded,
192 true);
193 }
194 }
195
148 Profile* SearchGeolocationDisclosureTabHelper::GetProfile() { 196 Profile* SearchGeolocationDisclosureTabHelper::GetProfile() {
149 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 197 return Profile::FromBrowserContext(web_contents()->GetBrowserContext());
150 } 198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698