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

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

Issue 2804913005: Don't use the DSE geolocation setting when chrome doesn't have location. (Closed)
Patch Set: Fix other test Created 3 years, 8 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_service.h " 5 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h "
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/feature_list.h" 8 #include "base/feature_list.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/android/location_settings_impl.h"
10 #include "chrome/browser/android/search_geolocation/search_geolocation_disclosur e_tab_helper.h" 11 #include "chrome/browser/android/search_geolocation/search_geolocation_disclosur e_tab_helper.h"
11 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search_engines/template_url_service_factory.h" 14 #include "chrome/browser/search_engines/template_url_service_factory.h"
14 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 15 #include "chrome/browser/search_engines/ui_thread_search_terms_data.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/content_settings/core/browser/content_settings_utils.h" 18 #include "components/content_settings/core/browser/content_settings_utils.h"
18 #include "components/content_settings/core/browser/host_content_settings_map.h" 19 #include "components/content_settings/core/browser/host_content_settings_map.h"
19 #include "components/content_settings/core/common/content_settings_types.h" 20 #include "components/content_settings/core/common/content_settings_types.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 128
128 void SearchGeolocationService::Factory::RegisterProfilePrefs( 129 void SearchGeolocationService::Factory::RegisterProfilePrefs(
129 user_prefs::PrefRegistrySyncable* registry) { 130 user_prefs::PrefRegistrySyncable* registry) {
130 registry->RegisterDictionaryPref(prefs::kGoogleDSEGeolocationSetting); 131 registry->RegisterDictionaryPref(prefs::kGoogleDSEGeolocationSetting);
131 } 132 }
132 133
133 SearchGeolocationService::SearchGeolocationService(Profile* profile) 134 SearchGeolocationService::SearchGeolocationService(Profile* profile)
134 : profile_(profile), 135 : profile_(profile),
135 pref_service_(profile_->GetPrefs()), 136 pref_service_(profile_->GetPrefs()),
136 host_content_settings_map_( 137 host_content_settings_map_(
137 HostContentSettingsMapFactory::GetForProfile(profile_)) { 138 HostContentSettingsMapFactory::GetForProfile(profile_)),
139 location_settings_(new LocationSettingsImpl()) {
138 // This class should never be constructed in incognito. 140 // This class should never be constructed in incognito.
139 DCHECK(!profile_->IsOffTheRecord()); 141 DCHECK(!profile_->IsOffTheRecord());
140 142
141 if (!UseConsistentSearchGeolocation()) 143 if (!UseConsistentSearchGeolocation())
142 return; 144 return;
143 145
144 delegate_.reset(new SearchEngineDelegateImpl(profile_)); 146 delegate_.reset(new SearchEngineDelegateImpl(profile_));
145 delegate_->SetDSEChangedCallback(base::Bind( 147 delegate_->SetDSEChangedCallback(base::Bind(
146 &SearchGeolocationService::OnDSEChanged, base::Unretained(this))); 148 &SearchGeolocationService::OnDSEChanged, base::Unretained(this)));
147 149
(...skipping 16 matching lines...) Expand all
164 if (!requesting_origin.IsSameOriginWith(delegate_->GetGoogleDSECCTLD())) 166 if (!requesting_origin.IsSameOriginWith(delegate_->GetGoogleDSECCTLD()))
165 return false; 167 return false;
166 168
167 // If the content setting for the DSE CCTLD is controlled by policy, and is st 169 // If the content setting for the DSE CCTLD is controlled by policy, and is st
168 // to ASK, don't use the DSE geolocation setting. 170 // to ASK, don't use the DSE geolocation setting.
169 if (!IsContentSettingUserSettable() && 171 if (!IsContentSettingUserSettable() &&
170 GetCurrentContentSetting() == CONTENT_SETTING_ASK) { 172 GetCurrentContentSetting() == CONTENT_SETTING_ASK) {
171 return false; 173 return false;
172 } 174 }
173 175
176 if (!location_settings_->HasAndroidLocationPermission())
177 return false;
178
174 return true; 179 return true;
175 } 180 }
176 181
177 bool SearchGeolocationService::GetDSEGeolocationSetting() { 182 bool SearchGeolocationService::GetDSEGeolocationSetting() {
178 // Make sure the setting is valid, in case enterprise policy has changed. 183 // Make sure the setting is valid, in case enterprise policy has changed.
179 // TODO(benwells): Check if enterprise policy can change while Chrome is 184 // TODO(benwells): Check if enterprise policy can change while Chrome is
180 // running. If it can't this call is probably not needed. 185 // running. If it can't this call is probably not needed.
181 EnsureDSEGeolocationSettingIsValid(); 186 EnsureDSEGeolocationSettingIsValid();
182 187
183 return GetDSEGeolocationPref().setting; 188 return GetDSEGeolocationPref().setting;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 bool SearchGeolocationService::UseConsistentSearchGeolocation() { 317 bool SearchGeolocationService::UseConsistentSearchGeolocation() {
313 return base::FeatureList::IsEnabled(features::kConsistentOmniboxGeolocation); 318 return base::FeatureList::IsEnabled(features::kConsistentOmniboxGeolocation);
314 } 319 }
315 320
316 void SearchGeolocationService::SetSearchEngineDelegateForTest( 321 void SearchGeolocationService::SetSearchEngineDelegateForTest(
317 std::unique_ptr<SearchEngineDelegate> delegate) { 322 std::unique_ptr<SearchEngineDelegate> delegate) {
318 delegate_ = std::move(delegate); 323 delegate_ = std::move(delegate);
319 delegate_->SetDSEChangedCallback(base::Bind( 324 delegate_->SetDSEChangedCallback(base::Bind(
320 &SearchGeolocationService::OnDSEChanged, base::Unretained(this))); 325 &SearchGeolocationService::OnDSEChanged, base::Unretained(this)));
321 } 326 }
327
328 void SearchGeolocationService::SetLocationSettingsForTest(
329 std::unique_ptr<LocationSettings> settings) {
330 location_settings_ = std::move(settings);
331 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698