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..91bab32f6b18edd273a8ff6bdbee52d64a690cf3 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,20 @@ |
#import <CoreLocation/CoreLocation.h> |
+#include "base/strings/utf_string_conversions.h" |
#include "components/physical_web/data_source/physical_web_data_source.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 +32,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 +51,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. |
+ TemplateURLService* template_url_service = |
+ ios::TemplateURLServiceFactory::GetForBrowserState(browser_state); |
+ const base::string16& default_search_name = |
sdefresne
2016/12/14 10:15:56
components/google/core/browser/google_util.h has a
mattreynolds
2016/12/14 20:35:02
I couldn't get IsGoogleSearchUrl to work since the
|
+ template_url_service->GetDefaultSearchProvider()->short_name(); |
+ bool google_search_enabled = |
+ (default_search_name == base::UTF8ToUTF16("Google")); |
+ |
+ bool auto_enable = !is_incognito && location_services_enabled && |
+ location_authorized && geolocation_eligible && |
+ google_search_enabled; |
+ |
+ pref_service->SetInteger(prefs::kIosPhysicalWebEnabled, |
sdefresne
2016/12/14 10:15:56
If I understand correctly, since all new install u
mattreynolds
2016/12/14 20:35:02
We have five requirements for auto-enable:
* Loca
|
+ auto_enable ? physical_web::kPhysicalWebOn |
+ : physical_web::kPhysicalWebOff); |
+ preference_state = pref_service->GetInteger(prefs::kIosPhysicalWebEnabled); |
} |
// Scan only if the feature is enabled. |
@@ -60,7 +77,3 @@ void StartPhysicalWebDiscovery(PrefService* pref_service, bool is_incognito) { |
} |
} |
-void StartPhysicalWebDiscovery(PrefService* pref_service, |
- ios::ChromeBrowserState* browser_state) { |
- StartPhysicalWebDiscovery(pref_service, browser_state->IsOffTheRecord()); |
-} |