Chromium Code Reviews| Index: ios/chrome/browser/physical_web/start_physical_web_discovery.mm |
| diff --git a/ios/chrome/browser/physical_web/start_physical_web_discovery.mm b/ios/chrome/browser/physical_web/start_physical_web_discovery.mm |
| index e1b9502f4d8cc56e01ed7dbdf06d8108e2fde45f..a4ddd343a08006a368d1a4c5223f5429264eedfe 100644 |
| --- a/ios/chrome/browser/physical_web/start_physical_web_discovery.mm |
| +++ b/ios/chrome/browser/physical_web/start_physical_web_discovery.mm |
| @@ -6,16 +6,21 @@ |
| #import <CoreLocation/CoreLocation.h> |
| +#include "base/strings/utf_string_conversions.h" |
|
sdefresne
2016/12/15 10:46:46
I think you can remove this include now that you u
mattreynolds
2016/12/15 18:43:24
Done.
|
| #include "components/physical_web/data_source/physical_web_data_source.h" |
| +#include "components/search_engines/search_terms_data.h" |
| +#include "components/search_engines/template_url_service.h" |
| #include "ios/chrome/browser/application_context.h" |
| #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| #import "ios/chrome/browser/experimental_flags.h" |
| #import "ios/chrome/browser/geolocation/omnibox_geolocation_config.h" |
| #include "ios/chrome/browser/physical_web/physical_web_constants.h" |
| #include "ios/chrome/browser/pref_names.h" |
| +#include "ios/chrome/browser/search_engines/template_url_service_factory.h" |
| #include "url/gurl.h" |
| -void StartPhysicalWebDiscovery(PrefService* pref_service, bool is_incognito) { |
| +void StartPhysicalWebDiscovery(PrefService* pref_service, |
| + ios::ChromeBrowserState* browser_state) { |
| // Do not scan if the Physical Web feature is disabled by a command line flag |
| // or Chrome Variations experiment. |
| if (!experimental_flags::IsPhysicalWebEnabled()) { |
| @@ -28,6 +33,10 @@ void StartPhysicalWebDiscovery(PrefService* pref_service, bool is_incognito) { |
| int preference_state = |
| pref_service->GetInteger(prefs::kIosPhysicalWebEnabled); |
| if (preference_state == physical_web::kPhysicalWebOnboarding) { |
| + // Check whether the user is in Incognito mode. Physical Web will only be |
| + // auto-enabled if the user is not in Incognito. |
| + bool is_incognito = browser_state->IsOffTheRecord(); |
| + |
| // Check that Location Services is enabled. |
| bool location_services_enabled = |
| [CLLocationManager locationServicesEnabled]; |
| @@ -43,13 +52,22 @@ void StartPhysicalWebDiscovery(PrefService* pref_service, bool is_incognito) { |
| bool geolocation_eligible = [[OmniboxGeolocationConfig sharedInstance] |
| URLHasEligibleDomain:GURL("https://www.google.com")]; |
| - if (!is_incognito && location_services_enabled && location_authorized && |
| - geolocation_eligible) { |
| - pref_service->SetInteger(prefs::kIosPhysicalWebEnabled, |
| - physical_web::kPhysicalWebOn); |
| - preference_state = |
| - pref_service->GetInteger(prefs::kIosPhysicalWebEnabled); |
| - } |
| + // Check that Google Search is configured as the default search engine. |
| + const TemplateURL* default_search_provider = |
| + ios::TemplateURLServiceFactory::GetForBrowserState(browser_state) |
| + ->GetDefaultSearchProvider(); |
| + bool google_search_enabled = |
| + default_search_provider->IsGoogleSearchURLWithReplaceableKeyword( |
| + SearchTermsData()); |
| + |
| + bool auto_enable = !is_incognito && location_services_enabled && |
| + location_authorized && geolocation_eligible && |
| + google_search_enabled; |
| + |
| + pref_service->SetInteger(prefs::kIosPhysicalWebEnabled, |
| + auto_enable ? physical_web::kPhysicalWebOn |
| + : physical_web::kPhysicalWebOff); |
| + preference_state = pref_service->GetInteger(prefs::kIosPhysicalWebEnabled); |
| } |
| // Scan only if the feature is enabled. |
| @@ -60,7 +78,3 @@ void StartPhysicalWebDiscovery(PrefService* pref_service, bool is_incognito) { |
| } |
| } |
| -void StartPhysicalWebDiscovery(PrefService* pref_service, |
| - ios::ChromeBrowserState* browser_state) { |
| - StartPhysicalWebDiscovery(pref_service, browser_state->IsOffTheRecord()); |
| -} |