OLD | NEW |
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/metrics/histogram_macros.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if (base::Time::Now() - last_shown < | 131 if (base::Time::Now() - last_shown < |
132 base::TimeDelta::FromDays(GetDaysPerShow())) { | 132 base::TimeDelta::FromDays(GetDaysPerShow())) { |
133 return; | 133 return; |
134 } | 134 } |
135 | 135 |
136 // Check that the Chrome app has geolocation permission. | 136 // Check that the Chrome app has geolocation permission. |
137 JNIEnv* env = base::android::AttachCurrentThread(); | 137 JNIEnv* env = base::android::AttachCurrentThread(); |
138 if (!Java_GeolocationHeader_hasGeolocationPermission(env)) | 138 if (!Java_GeolocationHeader_hasGeolocationPermission(env)) |
139 return; | 139 return; |
140 | 140 |
| 141 // Record metrics for the state of permissions before the disclosure has been |
| 142 // shown. |
| 143 RecordPreDisclosureMetrics(gurl); |
| 144 |
141 // Only show the disclosure if the geolocation permission is set to ASK | 145 // Only show the disclosure if the geolocation permission is set to ASK |
142 // (i.e. has not been explicitly set or revoked). | 146 // (i.e. has not been explicitly set or revoked). |
143 blink::mojom::PermissionStatus status = | 147 blink::mojom::PermissionStatus status = |
144 PermissionManager::Get(GetProfile()) | 148 PermissionManager::Get(GetProfile()) |
145 ->GetPermissionStatus(content::PermissionType::GEOLOCATION, gurl, | 149 ->GetPermissionStatus(content::PermissionType::GEOLOCATION, gurl, |
146 gurl); | 150 gurl); |
147 if (status != blink::mojom::PermissionStatus::ASK) | 151 if (status != blink::mojom::PermissionStatus::ASK) |
148 return; | 152 return; |
149 | 153 |
150 // Record metrics for the state of permissions before the disclosure has been | |
151 // shown. | |
152 RecordPreDisclosureMetrics(gurl); | |
153 | |
154 // All good, let's show the disclosure and increment the shown count. | 154 // All good, let's show the disclosure and increment the shown count. |
155 SearchGeolocationDisclosureInfoBarDelegate::Create(web_contents(), gurl); | 155 SearchGeolocationDisclosureInfoBarDelegate::Create(web_contents(), gurl); |
156 shown_count++; | 156 shown_count++; |
157 prefs->SetInteger(prefs::kSearchGeolocationDisclosureShownCount, shown_count); | 157 prefs->SetInteger(prefs::kSearchGeolocationDisclosureShownCount, shown_count); |
158 prefs->SetInt64(prefs::kSearchGeolocationDisclosureLastShowDate, | 158 prefs->SetInt64(prefs::kSearchGeolocationDisclosureLastShowDate, |
159 base::Time::Now().ToInternalValue()); | 159 base::Time::Now().ToInternalValue()); |
160 } | 160 } |
161 | 161 |
162 void SearchGeolocationDisclosureTabHelper::RecordPreDisclosureMetrics( | 162 void SearchGeolocationDisclosureTabHelper::RecordPreDisclosureMetrics( |
163 const GURL& gurl) { | 163 const GURL& gurl) { |
(...skipping 29 matching lines...) Expand all Loading... |
193 blink::mojom::PermissionStatus::LAST) + | 193 blink::mojom::PermissionStatus::LAST) + |
194 1); | 194 1); |
195 prefs->SetBoolean(prefs::kSearchGeolocationPostDisclosureMetricsRecorded, | 195 prefs->SetBoolean(prefs::kSearchGeolocationPostDisclosureMetricsRecorded, |
196 true); | 196 true); |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 Profile* SearchGeolocationDisclosureTabHelper::GetProfile() { | 200 Profile* SearchGeolocationDisclosureTabHelper::GetProfile() { |
201 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 201 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
202 } | 202 } |
OLD | NEW |