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