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

Side by Side 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: 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 unified diff | 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 »
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 "ios/chrome/browser/physical_web/start_physical_web_discovery.h" 5 #include "ios/chrome/browser/physical_web/start_physical_web_discovery.h"
6 6
7 #import <CoreLocation/CoreLocation.h> 7 #import <CoreLocation/CoreLocation.h>
8 8
9 #include "base/strings/utf_string_conversions.h"
9 #include "components/physical_web/data_source/physical_web_data_source.h" 10 #include "components/physical_web/data_source/physical_web_data_source.h"
11 #include "components/search_engines/template_url_service.h"
10 #include "ios/chrome/browser/application_context.h" 12 #include "ios/chrome/browser/application_context.h"
11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
12 #import "ios/chrome/browser/experimental_flags.h" 14 #import "ios/chrome/browser/experimental_flags.h"
13 #import "ios/chrome/browser/geolocation/omnibox_geolocation_config.h" 15 #import "ios/chrome/browser/geolocation/omnibox_geolocation_config.h"
14 #include "ios/chrome/browser/physical_web/physical_web_constants.h" 16 #include "ios/chrome/browser/physical_web/physical_web_constants.h"
15 #include "ios/chrome/browser/pref_names.h" 17 #include "ios/chrome/browser/pref_names.h"
18 #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
16 #include "url/gurl.h" 19 #include "url/gurl.h"
17 20
18 void StartPhysicalWebDiscovery(PrefService* pref_service, bool is_incognito) { 21 void StartPhysicalWebDiscovery(PrefService* pref_service,
22 ios::ChromeBrowserState* browser_state) {
19 // Do not scan if the Physical Web feature is disabled by a command line flag 23 // Do not scan if the Physical Web feature is disabled by a command line flag
20 // or Chrome Variations experiment. 24 // or Chrome Variations experiment.
21 if (!experimental_flags::IsPhysicalWebEnabled()) { 25 if (!experimental_flags::IsPhysicalWebEnabled()) {
22 return; 26 return;
23 } 27 }
24 28
25 // If the preference is in the default state, check if conditions allow us to 29 // If the preference is in the default state, check if conditions allow us to
26 // auto-enable it. The preference can be auto-enabled if the omnibox would 30 // auto-enable it. The preference can be auto-enabled if the omnibox would
27 // send the X-Geo geolocation header in search queries to www.google.com. 31 // send the X-Geo geolocation header in search queries to www.google.com.
28 int preference_state = 32 int preference_state =
29 pref_service->GetInteger(prefs::kIosPhysicalWebEnabled); 33 pref_service->GetInteger(prefs::kIosPhysicalWebEnabled);
30 if (preference_state == physical_web::kPhysicalWebOnboarding) { 34 if (preference_state == physical_web::kPhysicalWebOnboarding) {
35 // Check whether the user is in Incognito mode. Physical Web will only be
36 // auto-enabled if the user is not in Incognito.
37 bool is_incognito = browser_state->IsOffTheRecord();
38
31 // Check that Location Services is enabled. 39 // Check that Location Services is enabled.
32 bool location_services_enabled = 40 bool location_services_enabled =
33 [CLLocationManager locationServicesEnabled]; 41 [CLLocationManager locationServicesEnabled];
34 42
35 // Check that the user has authorized Chrome to use location. 43 // Check that the user has authorized Chrome to use location.
36 CLAuthorizationStatus auth_status = [CLLocationManager authorizationStatus]; 44 CLAuthorizationStatus auth_status = [CLLocationManager authorizationStatus];
37 bool location_authorized = 45 bool location_authorized =
38 auth_status == kCLAuthorizationStatusAuthorizedWhenInUse || 46 auth_status == kCLAuthorizationStatusAuthorizedWhenInUse ||
39 auth_status == kCLAuthorizationStatusAuthorizedAlways; 47 auth_status == kCLAuthorizationStatusAuthorizedAlways;
40 48
41 // Check that the user has not revoked the geolocation permission for 49 // Check that the user has not revoked the geolocation permission for
42 // Google. 50 // Google.
43 bool geolocation_eligible = [[OmniboxGeolocationConfig sharedInstance] 51 bool geolocation_eligible = [[OmniboxGeolocationConfig sharedInstance]
44 URLHasEligibleDomain:GURL("https://www.google.com")]; 52 URLHasEligibleDomain:GURL("https://www.google.com")];
45 53
46 if (!is_incognito && location_services_enabled && location_authorized && 54 // Check that Google Search is configured as the default search engine.
47 geolocation_eligible) { 55 TemplateURLService* template_url_service =
48 pref_service->SetInteger(prefs::kIosPhysicalWebEnabled, 56 ios::TemplateURLServiceFactory::GetForBrowserState(browser_state);
49 physical_web::kPhysicalWebOn); 57 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
50 preference_state = 58 template_url_service->GetDefaultSearchProvider()->short_name();
51 pref_service->GetInteger(prefs::kIosPhysicalWebEnabled); 59 bool google_search_enabled =
52 } 60 (default_search_name == base::UTF8ToUTF16("Google"));
61
62 bool auto_enable = !is_incognito && location_services_enabled &&
63 location_authorized && geolocation_eligible &&
64 google_search_enabled;
65
66 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
67 auto_enable ? physical_web::kPhysicalWebOn
68 : physical_web::kPhysicalWebOff);
69 preference_state = pref_service->GetInteger(prefs::kIosPhysicalWebEnabled);
53 } 70 }
54 71
55 // Scan only if the feature is enabled. 72 // Scan only if the feature is enabled.
56 if (preference_state == physical_web::kPhysicalWebOn) { 73 if (preference_state == physical_web::kPhysicalWebOn) {
57 GetApplicationContext()->GetPhysicalWebDataSource()->StartDiscovery(true); 74 GetApplicationContext()->GetPhysicalWebDataSource()->StartDiscovery(true);
58 } else { 75 } else {
59 GetApplicationContext()->GetPhysicalWebDataSource()->StopDiscovery(); 76 GetApplicationContext()->GetPhysicalWebDataSource()->StopDiscovery();
60 } 77 }
61 } 78 }
62 79
63 void StartPhysicalWebDiscovery(PrefService* pref_service,
64 ios::ChromeBrowserState* browser_state) {
65 StartPhysicalWebDiscovery(pref_service, browser_state->IsOffTheRecord());
66 }
OLDNEW
« 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