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

Side by Side Diff: chrome/browser/android/search_geolocation/search_geolocation_disclosure_tab_helper.cc

Issue 2661303003: Improve performance of search geolocation disclosure check. (Closed)
Patch Set: Created 3 years, 10 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/search_geolocation_disclosur e_tab_helper.h" 5 #include "chrome/browser/android/search_geolocation/search_geolocation_disclosur e_tab_helper.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/feature_list.h" 9 #include "base/feature_list.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 const content::LoadCommittedDetails& load_details) { 80 const content::LoadCommittedDetails& load_details) {
81 if (consistent_geolocation_enabled_) 81 if (consistent_geolocation_enabled_)
82 MaybeShowDisclosure(web_contents()->GetVisibleURL()); 82 MaybeShowDisclosure(web_contents()->GetVisibleURL());
83 } 83 }
84 84
85 void SearchGeolocationDisclosureTabHelper::MaybeShowDisclosure( 85 void SearchGeolocationDisclosureTabHelper::MaybeShowDisclosure(
86 const GURL& gurl) { 86 const GURL& gurl) {
87 if (!ShouldShowDisclosureForUrl(gurl)) 87 if (!ShouldShowDisclosureForUrl(gurl))
88 return; 88 return;
89 89
90 // Check that the Chrome app has geolocation permission.
91 JNIEnv* env = base::android::AttachCurrentThread();
92 if (!Java_GeolocationHeader_hasGeolocationPermission(env))
93 return;
94
95 // Don't show the infobar if the user has dismissed it, or they've seen it 90 // Don't show the infobar if the user has dismissed it, or they've seen it
96 // enough times already. 91 // enough times already.
97 PrefService* prefs = GetProfile()->GetPrefs(); 92 PrefService* prefs = GetProfile()->GetPrefs();
98 bool dismissed_already = 93 bool dismissed_already =
99 prefs->GetBoolean(prefs::kSearchGeolocationDisclosureDismissed); 94 prefs->GetBoolean(prefs::kSearchGeolocationDisclosureDismissed);
100 int shown_count = 95 int shown_count =
101 prefs->GetInteger(prefs::kSearchGeolocationDisclosureShownCount); 96 prefs->GetInteger(prefs::kSearchGeolocationDisclosureShownCount);
102 if (dismissed_already || shown_count >= GetMaxShowCount()) { 97 if (dismissed_already || shown_count >= GetMaxShowCount()) {
103 // Record metrics for the state of permissions after the disclosure has been 98 // Record metrics for the state of permissions after the disclosure has been
104 // shown. This is not done immediately after showing the last disclosure 99 // shown. This is not done immediately after showing the last disclosure
105 // (i.e. at the end of this function), but on the next omnibox search, to 100 // (i.e. at the end of this function), but on the next omnibox search, to
106 // allow the metric to capture changes to settings done by the user as a 101 // allow the metric to capture changes to settings done by the user as a
107 // result of clicking on the Settings link in the disclosure. 102 // result of clicking on the Settings link in the disclosure.
108 RecordPostDisclosureMetrics(gurl); 103 RecordPostDisclosureMetrics(gurl);
109 return; 104 return;
110 } 105 }
111 106
112 // Or if it has been shown too recently. 107 // Or if it has been shown too recently.
113 base::Time last_shown = base::Time::FromInternalValue( 108 base::Time last_shown = base::Time::FromInternalValue(
114 prefs->GetInt64(prefs::kSearchGeolocationDisclosureLastShowDate)); 109 prefs->GetInt64(prefs::kSearchGeolocationDisclosureLastShowDate));
115 if (GetTimeNow() - last_shown < base::TimeDelta::FromDays(GetDaysPerShow())) { 110 if (GetTimeNow() - last_shown < base::TimeDelta::FromDays(GetDaysPerShow())) {
116 return; 111 return;
117 } 112 }
118 113
114 // Check that the Chrome app has geolocation permission.
115 JNIEnv* env = base::android::AttachCurrentThread();
116 if (!Java_GeolocationHeader_hasGeolocationPermission(env))
117 return;
raymes 2017/02/01 18:04:41 As discussed in person, we may want to move this r
118
119 // Record metrics for the state of permissions before the disclosure has been 119 // Record metrics for the state of permissions before the disclosure has been
120 // shown. 120 // shown.
121 RecordPreDisclosureMetrics(gurl); 121 RecordPreDisclosureMetrics(gurl);
122 122
123 // Only show the disclosure if the geolocation permission is set ask (i.e. has 123 // Only show the disclosure if the geolocation permission is set ask (i.e. has
124 // not been explicitly set or revoked). 124 // not been explicitly set or revoked).
125 ContentSetting status = 125 ContentSetting status =
126 HostContentSettingsMapFactory::GetForProfile(GetProfile()) 126 HostContentSettingsMapFactory::GetForProfile(GetProfile())
127 ->GetContentSetting(gurl, gurl, CONTENT_SETTINGS_TYPE_GEOLOCATION, 127 ->GetContentSetting(gurl, gurl, CONTENT_SETTINGS_TYPE_GEOLOCATION,
128 std::string()); 128 std::string());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 const base::android::JavaParamRef<jclass>& clazz) { 235 const base::android::JavaParamRef<jclass>& clazz) {
236 gIgnoreUrlChecksForTesting = true; 236 gIgnoreUrlChecksForTesting = true;
237 } 237 }
238 238
239 // static 239 // static
240 void SetDayOffsetForTesting(JNIEnv* env, 240 void SetDayOffsetForTesting(JNIEnv* env,
241 const base::android::JavaParamRef<jclass>& clazz, 241 const base::android::JavaParamRef<jclass>& clazz,
242 jint days) { 242 jint days) {
243 gDayOffsetForTesting = days; 243 gDayOffsetForTesting = days;
244 } 244 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698