2018-08-23 15:51:46 +00:00
|
|
|
// Copyright (c) 2018 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/fake_location_provider.h"
|
2018-08-23 15:51:46 +00:00
|
|
|
|
2023-02-03 11:43:42 +00:00
|
|
|
#include "base/functional/callback.h"
|
2018-08-23 15:51:46 +00:00
|
|
|
#include "base/time/time.h"
|
2023-05-10 14:47:48 +00:00
|
|
|
#include "services/device/public/mojom/geoposition.mojom-shared.h"
|
|
|
|
#include "services/device/public/mojom/geoposition.mojom.h"
|
2018-08-23 15:51:46 +00:00
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
FakeLocationProvider::FakeLocationProvider() {
|
2023-05-10 14:47:48 +00:00
|
|
|
result_ = device::mojom::GeopositionResult::NewError(
|
|
|
|
device::mojom::GeopositionError::New(
|
|
|
|
device::mojom::GeopositionErrorCode::kPositionUnavailable,
|
|
|
|
"Position unavailable.", ""));
|
2018-08-23 15:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FakeLocationProvider::~FakeLocationProvider() = default;
|
|
|
|
|
2023-06-22 08:51:15 +00:00
|
|
|
void FakeLocationProvider::FillDiagnostics(
|
|
|
|
device::mojom::GeolocationDiagnostics& diagnostics) {
|
|
|
|
diagnostics.provider_state = state_;
|
|
|
|
}
|
|
|
|
|
2018-08-23 15:51:46 +00:00
|
|
|
void FakeLocationProvider::SetUpdateCallback(
|
|
|
|
const LocationProviderUpdateCallback& callback) {
|
|
|
|
callback_ = callback;
|
|
|
|
}
|
|
|
|
|
2023-06-22 08:51:15 +00:00
|
|
|
void FakeLocationProvider::StartProvider(bool high_accuracy) {
|
|
|
|
state_ =
|
|
|
|
high_accuracy
|
|
|
|
? device::mojom::GeolocationDiagnostics::ProviderState::kHighAccuracy
|
|
|
|
: device::mojom::GeolocationDiagnostics::ProviderState::kLowAccuracy;
|
|
|
|
}
|
2018-08-23 15:51:46 +00:00
|
|
|
|
2023-06-22 08:51:15 +00:00
|
|
|
void FakeLocationProvider::StopProvider() {
|
|
|
|
state_ = device::mojom::GeolocationDiagnostics::ProviderState::kStopped;
|
|
|
|
}
|
2018-08-23 15:51:46 +00:00
|
|
|
|
2023-05-10 14:47:48 +00:00
|
|
|
const device::mojom::GeopositionResult* FakeLocationProvider::GetPosition() {
|
|
|
|
return result_.get();
|
2018-08-23 15:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FakeLocationProvider::OnPermissionGranted() {
|
|
|
|
if (!callback_.is_null()) {
|
2023-05-10 14:47:48 +00:00
|
|
|
callback_.Run(this, result_.Clone());
|
2018-08-23 15:51:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace electron
|