Chromium Code Reviews| 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 82942d1b19893444835be1d0c20694626e245dbb..19c56fab1fb010df6213a847cd594817aec8fcbf 100644 |
| --- a/chrome/browser/android/search_geolocation_disclosure_tab_helper.cc |
| +++ b/chrome/browser/android/search_geolocation_disclosure_tab_helper.cc |
| @@ -4,6 +4,8 @@ |
| #include "chrome/browser/android/search_geolocation_disclosure_tab_helper.h" |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_string.h" |
| #include "base/feature_list.h" |
| #include "base/logging.h" |
| #include "base/metrics/histogram_macros.h" |
| @@ -23,6 +25,7 @@ |
| #include "content/public/browser/permission_type.h" |
| #include "content/public/browser/web_contents.h" |
| #include "jni/GeolocationHeader_jni.h" |
| +#include "jni/SearchGeolocationDisclosureTabHelper_jni.h" |
| #include "third_party/WebKit/public/platform/modules/permissions/permission_status.mojom.h" |
| namespace { |
| @@ -32,6 +35,8 @@ const int kDefaultDaysPerShow = 1; |
| const char kMaxShowCountVariation[] = "MaxShowCount"; |
| const char kDaysPerShowVariation[] = "DaysPerShow"; |
| +bool gIgnoreUrlChecksForTesting = false; |
| + |
| int GetMaxShowCount() { |
| std::string variation = variations::GetVariationParamValueByFeature( |
| features::kConsistentOmniboxGeolocation, kMaxShowCountVariation); |
| @@ -94,31 +99,17 @@ void SearchGeolocationDisclosureTabHelper:: |
| if (GetProfile()->IsOffTheRecord()) |
| return; |
| - // Only show the disclosure for default search navigations from the omnibox. |
| - TemplateURLService* template_url_service = |
| - TemplateURLServiceFactory::GetForProfile(GetProfile()); |
| - bool is_search_url = |
| - template_url_service->IsSearchResultsPageFromDefaultSearchProvider( |
| - gurl); |
| - if (!is_search_url) |
| + if (!ShouldShowDisclosureForUrl(gurl)) |
| return; |
| - // Only show the disclosure if Google is the default search engine. |
| - TemplateURL* default_search = |
| - template_url_service->GetDefaultSearchProvider(); |
| - if (!default_search || |
| - !default_search->url_ref().HasGoogleBaseURLs( |
| - template_url_service->search_terms_data())) { |
| - return; |
| - } |
| - |
| - // Don't show the infobar if the user has dismissed it, or they've seen it |
| - // enough times already. |
|
benwells
2016/12/29 01:42:01
Losing this comment was a merge error; I'll put it
benwells
2016/12/29 01:50:14
Done.
|
| PrefService* prefs = GetProfile()->GetPrefs(); |
| + |
| bool dismissed_already = |
| prefs->GetBoolean(prefs::kSearchGeolocationDisclosureDismissed); |
| + |
|
benwells
2016/12/29 01:42:01
I'll also remove these empty lines, not sure how t
benwells
2016/12/29 01:50:14
Done.
|
| 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. This is not done immediately after showing the last disclosure |
| @@ -163,6 +154,32 @@ void SearchGeolocationDisclosureTabHelper:: |
| base::Time::Now().ToInternalValue()); |
| } |
| +bool SearchGeolocationDisclosureTabHelper::ShouldShowDisclosureForUrl( |
| + const GURL& gurl) { |
| + if (gIgnoreUrlChecksForTesting) |
| + return true; |
| + |
| + // Only show the disclosure for default search navigations from the omnibox. |
| + TemplateURLService* template_url_service = |
| + TemplateURLServiceFactory::GetForProfile(GetProfile()); |
| + bool is_search_url = |
| + template_url_service->IsSearchResultsPageFromDefaultSearchProvider( |
| + gurl); |
| + if (!is_search_url) |
| + return false; |
| + |
| + // Only show the disclosure if Google is the default search engine. |
| + TemplateURL* default_search = |
| + template_url_service->GetDefaultSearchProvider(); |
| + if (!default_search || |
| + !default_search->url_ref().HasGoogleBaseURLs( |
| + template_url_service->search_terms_data())) { |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| void SearchGeolocationDisclosureTabHelper::RecordPreDisclosureMetrics( |
| const GURL& gurl) { |
| PrefService* prefs = GetProfile()->GetPrefs(); |
| @@ -204,3 +221,15 @@ void SearchGeolocationDisclosureTabHelper::RecordPostDisclosureMetrics( |
| Profile* SearchGeolocationDisclosureTabHelper::GetProfile() { |
| return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| } |
| + |
| +// static |
| +bool SearchGeolocationDisclosureTabHelper::Register(JNIEnv* env) { |
|
benwells
2016/12/29 01:42:01
I'll move this up in the file to be under Register
benwells
2016/12/29 01:50:14
Done.
|
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +// static |
| +void SetIgnoreUrlChecks(JNIEnv* env, |
| + const base::android::JavaParamRef<jclass>& clazz, |
| + jboolean ignore) { |
| + gIgnoreUrlChecksForTesting = ignore; |
| +} |