Commit 57ea9b92 authored by Findit's avatar Findit

Revert "fallback to Network Provider if wifi is turned off"

This reverts commit e13a069e.

Reason for revert:

Findit (https://goo.gl/kROfz5) identified CL at revision 829053 as the
culprit for flakes in the build cycles as shown on:
https://analysis.chromium.org/p/chromium/flake-portal/analysis/culprit?key=ag9zfmZpbmRpdC1mb3ItbWVyQwsSDEZsYWtlQ3VscHJpdCIxY2hyb21pdW0vZTEzYTA2OWUyZmNmZmU3OWM4MmRlNTAzMmEwMzVhMDRjNDIwMmZkMgw

Sample Failed Build: https://ci.chromium.org/b/8863210065181297712

Sample Failed Step: services_unittests on (none) GPU on Mac on Mac-10.13.6

Sample Flaky Test: CoreLocationProviderTest.ShouldUseCallbackTest

Original change's description:
> fallback to Network Provider if wifi is turned off
> 
> If Wifi is disabled Core Location does not work. In this case we will
> fallback to the Network Location Provider which can use the IP address
> to get an much less precise location.
> 
> Bug: 1135766
> Change-Id: I3f5fa8e78fbb34bcec36dbd6eeb0e6adc06c64c6
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2453437
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Commit-Queue: James Hollyer <jameshollyer@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#829053}


Change-Id: Iecd1cf5b4e3a36fdac2b11d5c52754fab8772c31
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1135766
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2549832
Cr-Commit-Position: refs/heads/master@{#829193}
parent 490d7c0f
...@@ -39,7 +39,6 @@ source_set("geolocation") { ...@@ -39,7 +39,6 @@ source_set("geolocation") {
"public_ip_address_geolocator.h", "public_ip_address_geolocator.h",
"public_ip_address_location_notifier.cc", "public_ip_address_location_notifier.cc",
"public_ip_address_location_notifier.h", "public_ip_address_location_notifier.h",
"system_location_provider.h",
"wifi_data.cc", "wifi_data.cc",
"wifi_data.h", "wifi_data.h",
"wifi_data_provider.cc", "wifi_data_provider.cc",
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#import <CoreLocation/CoreLocation.h> #import <CoreLocation/CoreLocation.h>
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "services/device/geolocation/system_location_provider.h"
#include "services/device/public/cpp/geolocation/location_provider.h" #include "services/device/public/cpp/geolocation/location_provider.h"
#include "services/device/public/mojom/geoposition.mojom.h" #include "services/device/public/mojom/geoposition.mojom.h"
...@@ -17,7 +16,7 @@ ...@@ -17,7 +16,7 @@
namespace device { namespace device {
// Location provider for macOS using the platform's Core Location API. // Location provider for macOS using the platform's Core Location API.
class CoreLocationProvider : public SystemLocationProvider { class CoreLocationProvider : public LocationProvider {
public: public:
CoreLocationProvider(); CoreLocationProvider();
~CoreLocationProvider() override; ~CoreLocationProvider() override;
...@@ -30,23 +29,16 @@ class CoreLocationProvider : public SystemLocationProvider { ...@@ -30,23 +29,16 @@ class CoreLocationProvider : public SystemLocationProvider {
const mojom::Geoposition& GetPosition() override; const mojom::Geoposition& GetPosition() override;
void OnPermissionGranted() override; void OnPermissionGranted() override;
// SystemLocationProvider implementation
void SetShouldUseSystemProviderCallback(
const ShouldUseCallback& callback) override;
void SystemLocationPermissionGranted(); void SystemLocationPermissionGranted();
void SystemLocationPermissionDenied(); void SystemLocationPermissionDenied();
void DidUpdatePosition(CLLocation* location); void DidUpdatePosition(CLLocation* location);
void SetManagerForTesting(CLLocationManager* location_manager); void SetManagerForTesting(CLLocationManager* location_manager);
void StopUsing();
private: private:
base::scoped_nsobject<CLLocationManager> location_manager_; base::scoped_nsobject<CLLocationManager> location_manager_;
base::scoped_nsobject<LocationDelegate> delegate_; base::scoped_nsobject<LocationDelegate> delegate_;
mojom::Geoposition last_position_; mojom::Geoposition last_position_;
LocationProviderUpdateCallback callback_; LocationProviderUpdateCallback callback_;
ShouldUseCallback should_use_callback_;
bool is_being_used_ = false;
bool has_permission_ = false; bool has_permission_ = false;
bool provider_start_attemped_ = false; bool provider_start_attemped_ = false;
base::WeakPtrFactory<CoreLocationProvider> weak_ptr_factory_{this}; base::WeakPtrFactory<CoreLocationProvider> weak_ptr_factory_{this};
......
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
didUpdateLocations:(NSArray*)locations; didUpdateLocations:(NSArray*)locations;
- (void)locationManager:(CLLocationManager*)manager - (void)locationManager:(CLLocationManager*)manager
didChangeAuthorizationStatus:(CLAuthorizationStatus)status; didChangeAuthorizationStatus:(CLAuthorizationStatus)status;
- (void)locationManager:(CLLocationManager*)manager
didFailWithError:(NSError*)error;
@end @end
...@@ -47,17 +45,6 @@ ...@@ -47,17 +45,6 @@
} }
} }
- (void)locationManager:(CLLocationManager*)manager
didFailWithError:(NSError*)error {
[error localizedDescription];
if ([error code] == kCLErrorLocationUnknown) {
// Fallback to network provider because Core Location is not able to
// determine location. This is likely due to wifi adapter being turned off.
if (provider_)
provider_->StopUsing();
}
}
- (void)locationManager:(CLLocationManager*)manager - (void)locationManager:(CLLocationManager*)manager
didUpdateLocations:(NSArray*)locations { didUpdateLocations:(NSArray*)locations {
if (provider_) if (provider_)
...@@ -115,11 +102,6 @@ void CoreLocationProvider::OnPermissionGranted() { ...@@ -115,11 +102,6 @@ void CoreLocationProvider::OnPermissionGranted() {
// Nothing to do here. // Nothing to do here.
} }
void CoreLocationProvider::SetShouldUseSystemProviderCallback(
const ShouldUseCallback& callback) {
should_use_callback_ = callback;
}
void CoreLocationProvider::SystemLocationPermissionGranted() { void CoreLocationProvider::SystemLocationPermissionGranted() {
has_permission_ = true; has_permission_ = true;
if (provider_start_attemped_) { if (provider_start_attemped_) {
...@@ -132,17 +114,7 @@ void CoreLocationProvider::SystemLocationPermissionDenied() { ...@@ -132,17 +114,7 @@ void CoreLocationProvider::SystemLocationPermissionDenied() {
has_permission_ = false; has_permission_ = false;
} }
void CoreLocationProvider::StopUsing() {
if (should_use_callback_)
should_use_callback_.Run(/*should_use=*/false);
is_being_used_ = false;
}
void CoreLocationProvider::DidUpdatePosition(CLLocation* location) { void CoreLocationProvider::DidUpdatePosition(CLLocation* location) {
if (!is_being_used_ && should_use_callback_) {
should_use_callback_.Run(/*should_use=*/true);
is_being_used_ = true;
}
// The error values in CLLocation correlate exactly to our error values. // The error values in CLLocation correlate exactly to our error values.
last_position_.latitude = location.coordinate.latitude; last_position_.latitude = location.coordinate.latitude;
last_position_.longitude = location.coordinate.longitude; last_position_.longitude = location.coordinate.longitude;
...@@ -153,6 +125,7 @@ void CoreLocationProvider::DidUpdatePosition(CLLocation* location) { ...@@ -153,6 +125,7 @@ void CoreLocationProvider::DidUpdatePosition(CLLocation* location) {
last_position_.altitude_accuracy = location.verticalAccuracy; last_position_.altitude_accuracy = location.verticalAccuracy;
last_position_.speed = location.speed; last_position_.speed = location.speed;
last_position_.heading = location.course; last_position_.heading = location.course;
callback_.Run(this, last_position_); callback_.Run(this, last_position_);
} }
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
// Utility functions. // Utility functions.
- (void)fakeUpdatePosition:(CLLocation*)test_location; - (void)fakeUpdatePosition:(CLLocation*)test_location;
- (void)fakeUpdatePermission:(CLAuthorizationStatus)status; - (void)fakeUpdatePermission:(CLAuthorizationStatus)status;
- (void)fakeTurnOffWifi;
@end @end
@implementation FakeCLLocationManager @implementation FakeCLLocationManager
...@@ -57,16 +56,6 @@ ...@@ -57,16 +56,6 @@
[_delegate locationManager:(id)self didChangeAuthorizationStatus:status]; [_delegate locationManager:(id)self didChangeAuthorizationStatus:status];
} }
- (void)fakeTurnOffWifi {
[_delegate locationManager:(id)self
didFailWithError:[NSError errorWithDomain:NSURLErrorDomain
code:kCLErrorLocationUnknown
userInfo:@{
@"Error reason" :
@"Test wifi turning off"
}]];
}
@end @end
namespace device { namespace device {
...@@ -75,8 +64,6 @@ class CoreLocationProviderTest : public testing::Test { ...@@ -75,8 +64,6 @@ class CoreLocationProviderTest : public testing::Test {
public: public:
std::unique_ptr<CoreLocationProvider> provider_; std::unique_ptr<CoreLocationProvider> provider_;
void ShouldUseCallback(bool should_use) { should_use_tracker_ = should_use; }
protected: protected:
CoreLocationProviderTest() {} CoreLocationProviderTest() {}
...@@ -88,8 +75,6 @@ class CoreLocationProviderTest : public testing::Test { ...@@ -88,8 +75,6 @@ class CoreLocationProviderTest : public testing::Test {
bool IsUpdating() { return [fake_location_manager_ updating]; } bool IsUpdating() { return [fake_location_manager_ updating]; }
bool ShouldUse() { return should_use_tracker_; }
// updates the position synchronously // updates the position synchronously
void FakeUpdatePosition(CLLocation* location) { void FakeUpdatePosition(CLLocation* location) {
[fake_location_manager_ fakeUpdatePosition:location]; [fake_location_manager_ fakeUpdatePosition:location];
...@@ -102,7 +87,6 @@ class CoreLocationProviderTest : public testing::Test { ...@@ -102,7 +87,6 @@ class CoreLocationProviderTest : public testing::Test {
base::test::TaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
const LocationProvider::LocationProviderUpdateCallback callback_; const LocationProvider::LocationProviderUpdateCallback callback_;
FakeCLLocationManager* fake_location_manager_; FakeCLLocationManager* fake_location_manager_;
bool should_use_tracker_ = false;
}; };
TEST_F(CoreLocationProviderTest, CreateDestroy) { TEST_F(CoreLocationProviderTest, CreateDestroy) {
...@@ -209,32 +193,4 @@ TEST_F(CoreLocationProviderTest, GetPositionUpdates) { ...@@ -209,32 +193,4 @@ TEST_F(CoreLocationProviderTest, GetPositionUpdates) {
provider_.reset(); provider_.reset();
} }
TEST_F(CoreLocationProviderTest, ShouldUseCallbackTest) {
InitializeProvider();
provider_->StartProvider(/*high_accuracy=*/true);
provider_->SetShouldUseSystemProviderCallback(base::BindRepeating(
&CoreLocationProviderTest::ShouldUseCallback, base::Unretained(this)));
CLLocationCoordinate2D coors;
coors.latitude = 147.147;
coors.longitude = 101.101;
CLLocation* test_mac_location =
[[CLLocation alloc] initWithCoordinate:coors
altitude:417.417
horizontalAccuracy:10.5
verticalAccuracy:15.5
timestamp:[NSDate date]];
provider_->SetUpdateCallback(
base::BindLambdaForTesting([&](const LocationProvider* provider,
const mojom::Geoposition& position) {}));
EXPECT_FALSE(ShouldUse());
FakeUpdatePosition(test_mac_location);
EXPECT_TRUE(ShouldUse());
[fake_location_manager_ fakeTurnOffWifi];
EXPECT_FALSE(ShouldUse());
}
} // namespace device } // namespace device
...@@ -21,10 +21,7 @@ namespace device { ...@@ -21,10 +21,7 @@ namespace device {
FakeLocationProvider::FakeLocationProvider() FakeLocationProvider::FakeLocationProvider()
: provider_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} : provider_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
FakeLocationProvider::~FakeLocationProvider() { FakeLocationProvider::~FakeLocationProvider() = default;
if (destructor_callback_)
destructor_callback_.Run();
}
void FakeLocationProvider::HandlePositionChanged( void FakeLocationProvider::HandlePositionChanged(
const mojom::Geoposition& position) { const mojom::Geoposition& position) {
...@@ -62,18 +59,4 @@ void FakeLocationProvider::OnPermissionGranted() { ...@@ -62,18 +59,4 @@ void FakeLocationProvider::OnPermissionGranted() {
is_permission_granted_ = true; is_permission_granted_ = true;
} }
void FakeLocationProvider::SetShouldUseSystemProviderCallback(
const ShouldUseCallback& callback) {
should_use_system_provider_callback_ = callback;
}
void FakeLocationProvider::CallShouldUseSystemProvider(bool should_use) {
should_use_system_provider_callback_.Run(should_use);
}
void FakeLocationProvider::SetProviderDestroyedCallback(
const base::RepeatingClosure& callback) {
destructor_callback_ = callback;
}
} // namespace device } // namespace device
...@@ -10,14 +10,13 @@ ...@@ -10,14 +10,13 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "services/device/geolocation/system_location_provider.h"
#include "services/device/public/cpp/geolocation/location_provider.h" #include "services/device/public/cpp/geolocation/location_provider.h"
#include "services/device/public/mojom/geoposition.mojom.h" #include "services/device/public/mojom/geoposition.mojom.h"
namespace device { namespace device {
// Fake implementation of a location provider for testing. // Fake implementation of a location provider for testing.
class FakeLocationProvider : public SystemLocationProvider { class FakeLocationProvider : public LocationProvider {
public: public:
enum State { STOPPED, LOW_ACCURACY, HIGH_ACCURACY } state_ = STOPPED; enum State { STOPPED, LOW_ACCURACY, HIGH_ACCURACY } state_ = STOPPED;
...@@ -38,22 +37,12 @@ class FakeLocationProvider : public SystemLocationProvider { ...@@ -38,22 +37,12 @@ class FakeLocationProvider : public SystemLocationProvider {
const mojom::Geoposition& GetPosition() override; const mojom::Geoposition& GetPosition() override;
void OnPermissionGranted() override; void OnPermissionGranted() override;
// SystemLocationProvider implementation
void SetShouldUseSystemProviderCallback(
const ShouldUseCallback& callback) override;
void CallShouldUseSystemProvider(bool should_use);
void SetProviderDestroyedCallback(const base::RepeatingClosure& callback);
scoped_refptr<base::SingleThreadTaskRunner> provider_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> provider_task_runner_;
private: private:
bool is_permission_granted_ = false; bool is_permission_granted_ = false;
mojom::Geoposition position_; mojom::Geoposition position_;
LocationProviderUpdateCallback callback_; LocationProviderUpdateCallback callback_;
ShouldUseCallback should_use_system_provider_callback_;
base::RepeatingClosure destructor_callback_;
DISALLOW_COPY_AND_ASSIGN(FakeLocationProvider); DISALLOW_COPY_AND_ASSIGN(FakeLocationProvider);
}; };
......
...@@ -46,46 +46,24 @@ bool LocationArbitrator::HasPermissionBeenGrantedForTest() const { ...@@ -46,46 +46,24 @@ bool LocationArbitrator::HasPermissionBeenGrantedForTest() const {
return is_permission_granted_; return is_permission_granted_;
} }
void LocationArbitrator::ShouldUseSystemProvider(bool should_use) {
force_ignore_system_location_ = !should_use;
if (!should_use && !network_location_provider_) {
network_location_provider_ =
NewNetworkLocationProvider(url_loader_factory_, api_key_);
RegisterProvider(network_location_provider_.get());
}
if (should_use && network_location_provider_)
network_location_provider_.reset();
DoStartProviders();
}
void LocationArbitrator::OnPermissionGranted() { void LocationArbitrator::OnPermissionGranted() {
is_permission_granted_ = true; is_permission_granted_ = true;
for (const auto& provider : providers_)
#if defined(OS_MAC) provider->OnPermissionGranted();
// On macOS we always want to keep the |system_location_provider_| in the most
// up to date state because it is the preferred provider if it is returning
// position data.
if (system_location_provider_ && force_ignore_system_location_)
system_location_provider_->OnPermissionGranted();
#endif
auto* current_provider = GetProvider();
if (current_provider)
current_provider->OnPermissionGranted();
} }
void LocationArbitrator::StartProvider(bool enable_high_accuracy) { void LocationArbitrator::StartProvider(bool enable_high_accuracy) {
is_running_ = true; is_running_ = true;
enable_high_accuracy_ = enable_high_accuracy; enable_high_accuracy_ = enable_high_accuracy;
if (!HasProvider()) if (providers_.empty()) {
RegisterProviders(); RegisterProviders();
}
DoStartProviders(); DoStartProviders();
} }
void LocationArbitrator::DoStartProviders() { void LocationArbitrator::DoStartProviders() {
if (!HasProvider()) { if (providers_.empty()) {
// If no providers are available, we report an error to avoid // If no providers are available, we report an error to avoid
// callers waiting indefinitely for a reply. // callers waiting indefinitely for a reply.
mojom::Geoposition position; mojom::Geoposition position;
...@@ -93,16 +71,9 @@ void LocationArbitrator::DoStartProviders() { ...@@ -93,16 +71,9 @@ void LocationArbitrator::DoStartProviders() {
arbitrator_update_callback_.Run(this, position); arbitrator_update_callback_.Run(this, position);
return; return;
} }
// On macOS we always want to start the |system_location_provider_| even if it for (const auto& provider : providers_) {
// is currently being ignored because we want to switch to it if it starts provider->StartProvider(enable_high_accuracy_);
// producing valid data. }
#if defined(OS_MAC)
if (system_location_provider_ && force_ignore_system_location_)
system_location_provider_->StartProvider(enable_high_accuracy_);
#endif
auto* current_provider = GetProvider();
if (current_provider)
current_provider->StartProvider(enable_high_accuracy_);
} }
void LocationArbitrator::StopProvider() { void LocationArbitrator::StopProvider() {
...@@ -112,51 +83,38 @@ void LocationArbitrator::StopProvider() { ...@@ -112,51 +83,38 @@ void LocationArbitrator::StopProvider() {
position_provider_ = nullptr; position_provider_ = nullptr;
position_ = mojom::Geoposition(); position_ = mojom::Geoposition();
custom_location_provider_.reset(); providers_.clear();
if (system_location_provider_)
system_location_provider_->StopProvider();
network_location_provider_.reset();
is_running_ = false; is_running_ = false;
} }
void LocationArbitrator::RegisterProvider(LocationProvider* provider) { void LocationArbitrator::RegisterProvider(
std::unique_ptr<LocationProvider> provider) {
if (!provider) if (!provider)
return; return;
// Using base::Unretained is safe here because the |provider| is owned by
// this and therefore will be destroyed before this is.
provider->SetUpdateCallback(base::BindRepeating( provider->SetUpdateCallback(base::BindRepeating(
&LocationArbitrator::OnLocationUpdate, base::Unretained(this))); &LocationArbitrator::OnLocationUpdate, base::Unretained(this)));
if (is_permission_granted_) if (is_permission_granted_)
provider->OnPermissionGranted(); provider->OnPermissionGranted();
providers_.push_back(std::move(provider));
} }
void LocationArbitrator::RegisterProviders() { void LocationArbitrator::RegisterProviders() {
if (custom_location_provider_getter_) { if (custom_location_provider_getter_) {
auto custom_provider = custom_location_provider_getter_.Run(); auto custom_provider = custom_location_provider_getter_.Run();
if (custom_provider) { if (custom_provider) {
RegisterProvider(custom_provider.get()); RegisterProvider(std::move(custom_provider));
custom_location_provider_ = std::move(custom_provider);
return; return;
} }
} }
auto system_provider = NewSystemLocationProvider(); auto system_provider = NewSystemLocationProvider();
if (system_provider) { if (system_provider) {
RegisterProvider(system_provider.get()); RegisterProvider(std::move(system_provider));
system_location_provider_ = std::move(system_provider); return;
// Using base::Unretained is safe here because the
// |system_location_provider_| is owned by this and therefore will be
// destroyed before this is.
system_location_provider_->SetShouldUseSystemProviderCallback(
base::BindRepeating(&LocationArbitrator::ShouldUseSystemProvider,
base::Unretained(this)));
} }
if (url_loader_factory_) { if (url_loader_factory_)
network_location_provider_ = RegisterProvider(NewNetworkLocationProvider(url_loader_factory_, api_key_));
NewNetworkLocationProvider(url_loader_factory_, api_key_);
RegisterProvider(network_location_provider_.get());
}
} }
void LocationArbitrator::OnLocationUpdate( void LocationArbitrator::OnLocationUpdate(
...@@ -196,7 +154,7 @@ LocationArbitrator::NewNetworkLocationProvider( ...@@ -196,7 +154,7 @@ LocationArbitrator::NewNetworkLocationProvider(
#endif #endif
} }
std::unique_ptr<SystemLocationProvider> std::unique_ptr<LocationProvider>
LocationArbitrator::NewSystemLocationProvider() { LocationArbitrator::NewSystemLocationProvider() {
#if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_FUCHSIA) #if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_FUCHSIA)
return nullptr; return nullptr;
...@@ -236,23 +194,4 @@ bool LocationArbitrator::IsNewPositionBetter( ...@@ -236,23 +194,4 @@ bool LocationArbitrator::IsNewPositionBetter(
return false; return false;
} }
bool LocationArbitrator::HasProvider() {
return custom_location_provider_ ||
(system_location_provider_ && !force_ignore_system_location_) ||
network_location_provider_;
}
LocationProvider* LocationArbitrator::GetProvider() {
if (custom_location_provider_)
return custom_location_provider_.get();
if (system_location_provider_ && !force_ignore_system_location_)
return system_location_provider_.get();
if (network_location_provider_)
return network_location_provider_.get();
return nullptr;
}
} // namespace device } // namespace device
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "services/device/geolocation/geolocation_provider_impl.h" #include "services/device/geolocation/geolocation_provider_impl.h"
#include "services/device/geolocation/network_location_provider.h" #include "services/device/geolocation/network_location_provider.h"
#include "services/device/geolocation/position_cache.h" #include "services/device/geolocation/position_cache.h"
#include "services/device/geolocation/system_location_provider.h"
#include "services/device/public/cpp/geolocation/location_provider.h" #include "services/device/public/cpp/geolocation/location_provider.h"
#include "services/device/public/mojom/geoposition.mojom.h" #include "services/device/public/mojom/geoposition.mojom.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -50,7 +49,6 @@ class LocationArbitrator : public LocationProvider { ...@@ -50,7 +49,6 @@ class LocationArbitrator : public LocationProvider {
static GURL DefaultNetworkProviderURL(); static GURL DefaultNetworkProviderURL();
bool HasPermissionBeenGrantedForTest() const; bool HasPermissionBeenGrantedForTest() const;
void ShouldUseSystemProvider(bool should_use);
// LocationProvider implementation. // LocationProvider implementation.
void SetUpdateCallback( void SetUpdateCallback(
...@@ -66,7 +64,7 @@ class LocationArbitrator : public LocationProvider { ...@@ -66,7 +64,7 @@ class LocationArbitrator : public LocationProvider {
virtual std::unique_ptr<LocationProvider> NewNetworkLocationProvider( virtual std::unique_ptr<LocationProvider> NewNetworkLocationProvider(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::string& api_key); const std::string& api_key);
virtual std::unique_ptr<SystemLocationProvider> NewSystemLocationProvider(); virtual std::unique_ptr<LocationProvider> NewSystemLocationProvider();
virtual base::Time GetTimeNow() const; virtual base::Time GetTimeNow() const;
private: private:
...@@ -74,7 +72,7 @@ class LocationArbitrator : public LocationProvider { ...@@ -74,7 +72,7 @@ class LocationArbitrator : public LocationProvider {
// Provider will either be added to |providers_| or // Provider will either be added to |providers_| or
// deleted on error (e.g. it fails to start). // deleted on error (e.g. it fails to start).
void RegisterProvider(LocationProvider* provider); void RegisterProvider(std::unique_ptr<LocationProvider> provider);
void RegisterProviders(); void RegisterProviders();
// Tells all registered providers to start. // Tells all registered providers to start.
...@@ -94,19 +92,13 @@ class LocationArbitrator : public LocationProvider { ...@@ -94,19 +92,13 @@ class LocationArbitrator : public LocationProvider {
const mojom::Geoposition& new_position, const mojom::Geoposition& new_position,
bool from_same_provider) const; bool from_same_provider) const;
bool HasProvider();
LocationProvider* GetProvider();
const CustomLocationProviderCallback custom_location_provider_getter_; const CustomLocationProviderCallback custom_location_provider_getter_;
const scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_; const scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
const std::string api_key_; const std::string api_key_;
LocationProvider::LocationProviderUpdateCallback arbitrator_update_callback_; LocationProvider::LocationProviderUpdateCallback arbitrator_update_callback_;
std::unique_ptr<LocationProvider> custom_location_provider_; std::vector<std::unique_ptr<LocationProvider>> providers_;
std::unique_ptr<LocationProvider> network_location_provider_;
std::unique_ptr<SystemLocationProvider> system_location_provider_;
bool force_ignore_system_location_ = true;
bool enable_high_accuracy_; bool enable_high_accuracy_;
// The provider which supplied the current |position_| // The provider which supplied the current |position_|
const LocationProvider* position_provider_; const LocationProvider* position_provider_;
...@@ -124,7 +116,7 @@ class LocationArbitrator : public LocationProvider { ...@@ -124,7 +116,7 @@ class LocationArbitrator : public LocationProvider {
// Factory functions for the various types of location provider to abstract // Factory functions for the various types of location provider to abstract
// over the platform-dependent implementations. // over the platform-dependent implementations.
std::unique_ptr<SystemLocationProvider> NewSystemLocationProvider(); std::unique_ptr<LocationProvider> NewSystemLocationProvider();
} // namespace device } // namespace device
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "build/build_config.h"
#include "services/device/geolocation/fake_location_provider.h" #include "services/device/geolocation/fake_location_provider.h"
#include "services/device/geolocation/fake_position_cache.h" #include "services/device/geolocation/fake_position_cache.h"
#include "services/device/public/cpp/geolocation/geoposition.h" #include "services/device/public/cpp/geolocation/geoposition.h"
...@@ -103,14 +102,10 @@ class TestingLocationArbitrator : public LocationArbitrator { ...@@ -103,14 +102,10 @@ class TestingLocationArbitrator : public LocationArbitrator {
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::string& api_key) override { const std::string& api_key) override {
network_location_provider_ = new FakeLocationProvider; network_location_provider_ = new FakeLocationProvider;
network_location_provider_->SetProviderDestroyedCallback(
base::BindRepeating(
&TestingLocationArbitrator::FakeLocationProviderDestructorCallback,
base::Unretained(this)));
return base::WrapUnique(network_location_provider_); return base::WrapUnique(network_location_provider_);
} }
std::unique_ptr<SystemLocationProvider> NewSystemLocationProvider() override { std::unique_ptr<LocationProvider> NewSystemLocationProvider() override {
if (!should_use_system_location_provider_) { if (!should_use_system_location_provider_) {
return nullptr; return nullptr;
} }
...@@ -119,10 +114,6 @@ class TestingLocationArbitrator : public LocationArbitrator { ...@@ -119,10 +114,6 @@ class TestingLocationArbitrator : public LocationArbitrator {
return base::WrapUnique(system_location_provider_); return base::WrapUnique(system_location_provider_);
} }
void FakeLocationProviderDestructorCallback() {
network_location_provider_ = nullptr;
}
FakeLocationProvider* network_location_provider_ = nullptr; FakeLocationProvider* network_location_provider_ = nullptr;
FakeLocationProvider* system_location_provider_ = nullptr; FakeLocationProvider* system_location_provider_ = nullptr;
bool should_use_system_location_provider_; bool should_use_system_location_provider_;
...@@ -248,31 +239,27 @@ TEST_F(GeolocationLocationArbitratorTest, NormalUsageSystem) { ...@@ -248,31 +239,27 @@ TEST_F(GeolocationLocationArbitratorTest, NormalUsageSystem) {
EXPECT_FALSE(system_location_provider()); EXPECT_FALSE(system_location_provider());
arbitrator_->StartProvider(false); arbitrator_->StartProvider(false);
auto* location_provider = network_location_provider(); EXPECT_FALSE(network_location_provider());
EXPECT_TRUE(location_provider); ASSERT_TRUE(system_location_provider());
EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY,
#if defined(OS_MAC) system_location_provider()->state_);
location_provider = system_location_provider();
EXPECT_TRUE(location_provider);
#endif
EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, location_provider->state_);
EXPECT_FALSE(ValidateGeoposition(observer_->last_position())); EXPECT_FALSE(ValidateGeoposition(observer_->last_position()));
EXPECT_EQ(mojom::Geoposition::ErrorCode::NONE, EXPECT_EQ(mojom::Geoposition::ErrorCode::NONE,
observer_->last_position().error_code); observer_->last_position().error_code);
SetReferencePosition(location_provider); SetReferencePosition(system_location_provider());
EXPECT_TRUE(ValidateGeoposition(observer_->last_position()) || EXPECT_TRUE(ValidateGeoposition(observer_->last_position()) ||
observer_->last_position().error_code != observer_->last_position().error_code !=
mojom::Geoposition::ErrorCode::NONE); mojom::Geoposition::ErrorCode::NONE);
EXPECT_EQ(location_provider->GetPosition().latitude, EXPECT_EQ(system_location_provider()->GetPosition().latitude,
observer_->last_position().latitude); observer_->last_position().latitude);
EXPECT_FALSE(location_provider->is_permission_granted()); EXPECT_FALSE(system_location_provider()->is_permission_granted());
EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest());
arbitrator_->OnPermissionGranted(); arbitrator_->OnPermissionGranted();
EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest());
EXPECT_TRUE(location_provider->is_permission_granted()); EXPECT_TRUE(system_location_provider()->is_permission_granted());
} }
// Tests basic operation (single position fix) with no network location // Tests basic operation (single position fix) with no network location
...@@ -362,48 +349,4 @@ TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) { ...@@ -362,48 +349,4 @@ TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) {
CheckLastPositionInfo(3, 139, 150); CheckLastPositionInfo(3, 139, 150);
} }
#if defined(OS_MAC)
TEST_F(GeolocationLocationArbitratorTest, NetworkProviderFallback) {
InitializeArbitrator(
base::BindRepeating(&GetCustomLocationProviderForTest, nullptr),
url_loader_factory_, /*should_use_system_location_provider=*/true);
ASSERT_TRUE(arbitrator_);
arbitrator_->StartProvider(false);
EXPECT_EQ(network_location_provider()->state(),
FakeLocationProvider::State::LOW_ACCURACY);
EXPECT_EQ(system_location_provider()->state(),
FakeLocationProvider::State::LOW_ACCURACY);
system_location_provider()->CallShouldUseSystemProvider(/*should_use=*/true);
EXPECT_FALSE(network_location_provider());
EXPECT_EQ(system_location_provider()->state(),
FakeLocationProvider::State::LOW_ACCURACY);
arbitrator_->StopProvider();
arbitrator_->StartProvider(/*high_accuracy=*/false);
EXPECT_FALSE(network_location_provider());
EXPECT_EQ(system_location_provider()->state(),
FakeLocationProvider::State::LOW_ACCURACY);
system_location_provider()->CallShouldUseSystemProvider(/*should_use=*/false);
EXPECT_EQ(network_location_provider()->state(),
FakeLocationProvider::State::LOW_ACCURACY);
EXPECT_EQ(system_location_provider()->state(),
FakeLocationProvider::State::LOW_ACCURACY);
arbitrator_->StopProvider();
arbitrator_->StartProvider(/*high_accuracy=*/false);
EXPECT_EQ(network_location_provider()->state(),
FakeLocationProvider::State::LOW_ACCURACY);
EXPECT_EQ(system_location_provider()->state(),
FakeLocationProvider::State::LOW_ACCURACY);
}
#endif
} // namespace device } // namespace device
...@@ -57,14 +57,8 @@ void LocationProviderAndroid::OnPermissionGranted() { ...@@ -57,14 +57,8 @@ void LocationProviderAndroid::OnPermissionGranted() {
// Nothing to do here. // Nothing to do here.
} }
void LocationProviderAndroid::SetShouldUseSystemProviderCallback(
const ShouldUseCallback& callback) {
// Androids's location provider should always be used.
callback.Run(/*should_use=*/true);
}
// static // static
std::unique_ptr<SystemLocationProvider> NewSystemLocationProvider() { std::unique_ptr<LocationProvider> NewSystemLocationProvider() {
return base::WrapUnique(new LocationProviderAndroid); return base::WrapUnique(new LocationProviderAndroid);
} }
......
...@@ -8,14 +8,13 @@ ...@@ -8,14 +8,13 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "services/device/geolocation/system_location_provider.h"
#include "services/device/public/cpp/geolocation/location_provider.h" #include "services/device/public/cpp/geolocation/location_provider.h"
#include "services/device/public/mojom/geoposition.mojom.h" #include "services/device/public/mojom/geoposition.mojom.h"
namespace device { namespace device {
// Location provider for Android using the platform provider over JNI. // Location provider for Android using the platform provider over JNI.
class LocationProviderAndroid : public SystemLocationProvider { class LocationProviderAndroid : public LocationProvider {
public: public:
LocationProviderAndroid(); LocationProviderAndroid();
~LocationProviderAndroid() override; ~LocationProviderAndroid() override;
...@@ -31,10 +30,6 @@ class LocationProviderAndroid : public SystemLocationProvider { ...@@ -31,10 +30,6 @@ class LocationProviderAndroid : public SystemLocationProvider {
const mojom::Geoposition& GetPosition() override; const mojom::Geoposition& GetPosition() override;
void OnPermissionGranted() override; void OnPermissionGranted() override;
// SystemLocationProvider implementation.
void SetShouldUseSystemProviderCallback(
const ShouldUseCallback& callback) override;
private: private:
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_DEVICE_GEOLOCATION_SYSTEM_LOCATION_PROVIDER_H_
#define SERVICES_DEVICE_GEOLOCATION_SYSTEM_LOCATION_PROVIDER_H_
#include "services/device/public/cpp/geolocation/location_provider.h"
namespace device {
class SystemLocationProvider : public LocationProvider {
public:
using ShouldUseCallback = base::RepeatingCallback<void(bool)>;
// SystemLocationProviders are sometimes flaky (so far this is only used for
// macOS). Therefore the LocationArbitrator will default to using the
// NetworkLocationProvider until the SystemLocationProvider determines it is
// working properly. At this time the provided callback should be called with
// |should_use|=true. If at any time the SystemLocationProvider stops working
// this callback should again be used with |should_use|=false to notify the
// LocationArbitrator that it can no longer rely on the
// SystemLocationProvider. For example the macOS SystemLocationProvider no
// longer works when the WiFi adapter is turned off.
virtual void SetShouldUseSystemProviderCallback(
const ShouldUseCallback& callback) {}
};
} // namespace device
#endif // SERVICES_DEVICE_GEOLOCATION_SYSTEM_LOCATION_PROVIDER_H_
\ No newline at end of file
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "services/device/geolocation/wifi_data_provider_common.h" #include "services/device/geolocation/wifi_data_provider_common.h"
#include "services/device/geolocation/wifi_data_provider_manager.h" #include "services/device/geolocation/wifi_data_provider_manager.h"
#include "services/device/public/cpp/device_features.h"
namespace device { namespace device {
...@@ -102,12 +101,6 @@ WifiDataProviderMac::~WifiDataProviderMac() {} ...@@ -102,12 +101,6 @@ WifiDataProviderMac::~WifiDataProviderMac() {}
std::unique_ptr<WifiDataProviderMac::WlanApiInterface> std::unique_ptr<WifiDataProviderMac::WlanApiInterface>
WifiDataProviderMac::CreateWlanApi() { WifiDataProviderMac::CreateWlanApi() {
// With the Core Location backend enabled the NetworkLocationProvider is only
// needed when WiFi is turned off in order to provide a fallback location
// using the device IP address. Disable the WlanApi so avoid collecting more
// data than is necessary.
if (base::FeatureList::IsEnabled(features::kMacCoreLocationBackend))
return nullptr;
return std::make_unique<CoreWlanApi>(); return std::make_unique<CoreWlanApi>();
} }
......
...@@ -456,14 +456,8 @@ HRESULT LocationProviderWinrt::GetGeolocator(IGeolocator** geo_locator) { ...@@ -456,14 +456,8 @@ HRESULT LocationProviderWinrt::GetGeolocator(IGeolocator** geo_locator) {
return hr; return hr;
} }
void LocationProviderWinrt::SetShouldUseSystemProviderCallback(
const ShouldUseCallback& callback) {
// WinRT's location provider should always be used if available.
callback.Run(/*should_use=*/true);
}
// static // static
std::unique_ptr<SystemLocationProvider> NewSystemLocationProvider() { std::unique_ptr<LocationProvider> NewSystemLocationProvider() {
if (!base::FeatureList::IsEnabled( if (!base::FeatureList::IsEnabled(
features::kWinrtGeolocationImplementation) || features::kWinrtGeolocationImplementation) ||
!IsWinRTSupported() || !IsSystemLocationSettingEnabled()) { !IsWinRTSupported() || !IsSystemLocationSettingEnabled()) {
......
...@@ -9,14 +9,13 @@ ...@@ -9,14 +9,13 @@
#include <wrl/client.h> #include <wrl/client.h>
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "services/device/geolocation/system_location_provider.h"
#include "services/device/public/cpp/geolocation/location_provider.h" #include "services/device/public/cpp/geolocation/location_provider.h"
#include "services/device/public/mojom/geoposition.mojom.h" #include "services/device/public/mojom/geoposition.mojom.h"
namespace device { namespace device {
// Location provider for Windows 8/10 using the WinRT platform apis // Location provider for Windows 8/10 using the WinRT platform apis
class LocationProviderWinrt : public SystemLocationProvider { class LocationProviderWinrt : public LocationProvider {
public: public:
LocationProviderWinrt(); LocationProviderWinrt();
~LocationProviderWinrt() override; ~LocationProviderWinrt() override;
...@@ -29,10 +28,6 @@ class LocationProviderWinrt : public SystemLocationProvider { ...@@ -29,10 +28,6 @@ class LocationProviderWinrt : public SystemLocationProvider {
const mojom::Geoposition& GetPosition() override; const mojom::Geoposition& GetPosition() override;
void OnPermissionGranted() override; void OnPermissionGranted() override;
// SystemLocationProvider implementation
void SetShouldUseSystemProviderCallback(
const ShouldUseCallback& callback) override;
protected: protected:
virtual HRESULT GetGeolocator( virtual HRESULT GetGeolocator(
ABI::Windows::Devices::Geolocation::IGeolocator** geo_locator); ABI::Windows::Devices::Geolocation::IGeolocator** geo_locator);
......
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