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

Unified Diff: ios/chrome/browser/physical_web/start_physical_web_discovery.mm

Issue 2573923002: Modify Physical Web auto-optin behavior on Chrome for iOS (Closed)
Patch Set: remove utf_string_conversions include Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/physical_web/start_physical_web_discovery.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a61a7652105be59e3e7dba528aabce5d29c9aede 100644
--- a/ios/chrome/browser/physical_web/start_physical_web_discovery.mm
+++ b/ios/chrome/browser/physical_web/start_physical_web_discovery.mm
@@ -7,15 +7,19 @@
#import <CoreLocation/CoreLocation.h>
#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 +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.
+ 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 +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());
-}
« no previous file with comments | « ios/chrome/browser/physical_web/start_physical_web_discovery.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698