Commit e6c5166a authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Chromium LUCI CQ

[iOS] Add an experiment for omnibox location

This CL is adding a way of experimenting with the location sent with
omnibox requests.
It allows to add experiment with no location, restricted location or
the precise location.
The Feature is checked only on iOS 14 and when the location can be
used to reduce biais in the groups.

Bug: 1165796
Change-Id: I6aa2bf1214c3ecc548a0220c668bbf658a775306
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2624672
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Auto-Submit: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845587}
parent c56129a9
...@@ -45,6 +45,12 @@ ...@@ -45,6 +45,12 @@
// Stops updating device location. // Stops updating device location.
- (void)stopUpdatingLocation; - (void)stopUpdatingLocation;
// Changes the desired accuracy for the location.
// TODO(crbug.com/1165794): This method has been added for an experiment. Do not
// use it and remove it once the experiment is done.
- (void)setDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy
distanceFilter:(CLLocationDistance)distanceFilter;
@end @end
#endif // IOS_CHROME_BROWSER_GEOLOCATION_LOCATION_MANAGER_H_ #endif // IOS_CHROME_BROWSER_GEOLOCATION_LOCATION_MANAGER_H_
...@@ -107,6 +107,12 @@ const NSTimeInterval kLocationUpdateInterval = 365.0 * 24.0 * 60.0 * 60.0; ...@@ -107,6 +107,12 @@ const NSTimeInterval kLocationUpdateInterval = 365.0 * 24.0 * 60.0 * 60.0;
[_locationUpdater setEnabled:NO]; [_locationUpdater setEnabled:NO];
} }
- (void)setDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy
distanceFilter:(CLLocationDistance)distanceFilter {
[_locationUpdater setDesiredAccuracy:desiredAccuracy
distanceFilter:distanceFilter];
}
#pragma mark - Private #pragma mark - Private
- (void)handleLocationUpdateNotification:(NSNotification*)notification { - (void)handleLocationUpdateNotification:(NSNotification*)notification {
......
...@@ -36,6 +36,44 @@ ...@@ -36,6 +36,44 @@
namespace { namespace {
// Feature to control how the location is use when sending omnibox requests.
const base::Feature kSendLocationInOmnibox{"SendLocationInOmnibox",
base::FEATURE_DISABLED_BY_DEFAULT};
const char kSendLocationInOmniboxParamName[] = "location";
const char kSendLocationInOmniboxParamNoLocation[] = "none";
const char kSendLocationInOmniboxParamCoarseLocation[] = "coarse";
// Returns whether the geolocation should be omitted when sending omnibox
// requests.
bool ShouldOmitLocation() {
if (@available(iOS 14, *)) {
// Check only on iOS 14 as the restricted location is only available on
// iOS 14.
if (!base::FeatureList::IsEnabled(kSendLocationInOmnibox))
return false;
std::string field_trial_param = base::GetFieldTrialParamValueByFeature(
kSendLocationInOmnibox, kSendLocationInOmniboxParamName);
return field_trial_param == kSendLocationInOmniboxParamNoLocation;
}
return false;
}
// Returns whether the geolocation should be using the restricted settings when
// sending omnibox requests.
bool ShouldUseCoarseLocation() {
if (@available(iOS 14, *)) {
if (!base::FeatureList::IsEnabled(kSendLocationInOmnibox))
return false;
std::string field_trial_param = base::GetFieldTrialParamValueByFeature(
kSendLocationInOmnibox, kSendLocationInOmniboxParamName);
return field_trial_param == kSendLocationInOmniboxParamCoarseLocation;
}
return false;
}
// Values for the histogram that records whether we sent the X-Geo header for // Values for the histogram that records whether we sent the X-Geo header for
// an Omnibox query or why we did not do so. These match the definition of // an Omnibox query or why we did not do so. These match the definition of
// GeolocationHeaderSentOrNot in Chromium // GeolocationHeaderSentOrNot in Chromium
...@@ -128,6 +166,12 @@ const char* const kGeolocationAuthorizationActionNewUser = ...@@ -128,6 +166,12 @@ const char* const kGeolocationAuthorizationActionNewUser =
// in webStateDestroyed. // in webStateDestroyed.
@property(nonatomic) web::WebState* webStateToReload; @property(nonatomic) web::WebState* webStateToReload;
// Whether the accuracy has been/should be reduced or not.
// TODO(crbug.com/1165794): Those properties have been added for an experiment.
// Do not use them and remove them once the experiment is done.
@property(nonatomic, assign) BOOL accuracyReduced;
@property(nonatomic, assign) BOOL shouldReduceAccuracy;
// Returns YES if and only if |url| and |transition| specify an Omnibox query // Returns YES if and only if |url| and |transition| specify an Omnibox query
// that is eligible for geolocation. // that is eligible for geolocation.
- (BOOL)URLIsEligibleQueryURL:(const GURL&)url - (BOOL)URLIsEligibleQueryURL:(const GURL&)url
...@@ -376,9 +420,20 @@ const char* const kGeolocationAuthorizationActionNewUser = ...@@ -376,9 +420,20 @@ const char* const kGeolocationAuthorizationActionNewUser =
#pragma mark - Private #pragma mark - Private
- (BOOL)enabled { - (BOOL)enabled {
return self.locationManager.locationServicesEnabled && BOOL enabled = self.locationManager.locationServicesEnabled &&
self.localState.authorizationState == self.localState.authorizationState ==
geolocation::kAuthorizationStateAuthorized; geolocation::kAuthorizationStateAuthorized;
if (enabled) {
// Check what to do with the location only if it was already enabled to
// avoid having bias in groups (users with location disabled in the
// "precise" group).
if (ShouldOmitLocation()) {
enabled = NO;
} else {
self.shouldReduceAccuracy = ShouldUseCoarseLocation();
}
}
return enabled;
} }
- (OmniboxGeolocationLocalState*)localState { - (OmniboxGeolocationLocalState*)localState {
...@@ -393,6 +448,8 @@ const char* const kGeolocationAuthorizationActionNewUser = ...@@ -393,6 +448,8 @@ const char* const kGeolocationAuthorizationActionNewUser =
if (!_locationManager) { if (!_locationManager) {
_locationManager = [[LocationManager alloc] init]; _locationManager = [[LocationManager alloc] init];
[_locationManager setDelegate:self]; [_locationManager setDelegate:self];
self.accuracyReduced = NO;
self.shouldReduceAccuracy = NO;
} }
return _locationManager; return _locationManager;
} }
...@@ -443,6 +500,14 @@ const char* const kGeolocationAuthorizationActionNewUser = ...@@ -443,6 +500,14 @@ const char* const kGeolocationAuthorizationActionNewUser =
} }
- (void)startUpdatingLocation { - (void)startUpdatingLocation {
if (@available(iOS 14, *)) {
if (self.shouldReduceAccuracy && !self.accuracyReduced) {
[self.locationManager
setDesiredAccuracy:kCLLocationAccuracyReduced
distanceFilter:kCLLocationAccuracyHundredMeters];
self.accuracyReduced = YES;
}
}
// Note that GeolocationUpdater will stop itself automatically after 5 // Note that GeolocationUpdater will stop itself automatically after 5
// seconds. // seconds.
[self.locationManager startUpdatingLocation]; [self.locationManager startUpdatingLocation];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment