fake_location_provider.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2018 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/fake_location_provider.h"
  5. #include "base/functional/callback.h"
  6. #include "base/time/time.h"
  7. #include "services/device/public/mojom/geoposition.mojom-shared.h"
  8. #include "services/device/public/mojom/geoposition.mojom.h"
  9. namespace electron {
  10. FakeLocationProvider::FakeLocationProvider() {
  11. result_ = device::mojom::GeopositionResult::NewError(
  12. device::mojom::GeopositionError::New(
  13. device::mojom::GeopositionErrorCode::kPositionUnavailable,
  14. "Position unavailable.", ""));
  15. }
  16. FakeLocationProvider::~FakeLocationProvider() = default;
  17. void FakeLocationProvider::FillDiagnostics(
  18. device::mojom::GeolocationDiagnostics& diagnostics) {
  19. diagnostics.provider_state = state_;
  20. }
  21. void FakeLocationProvider::SetUpdateCallback(
  22. const LocationProviderUpdateCallback& callback) {
  23. callback_ = callback;
  24. }
  25. void FakeLocationProvider::StartProvider(bool high_accuracy) {
  26. state_ =
  27. high_accuracy
  28. ? device::mojom::GeolocationDiagnostics::ProviderState::kHighAccuracy
  29. : device::mojom::GeolocationDiagnostics::ProviderState::kLowAccuracy;
  30. }
  31. void FakeLocationProvider::StopProvider() {
  32. state_ = device::mojom::GeolocationDiagnostics::ProviderState::kStopped;
  33. }
  34. const device::mojom::GeopositionResult* FakeLocationProvider::GetPosition() {
  35. return result_.get();
  36. }
  37. void FakeLocationProvider::OnPermissionGranted() {
  38. if (!callback_.is_null()) {
  39. callback_.Run(this, result_.Clone());
  40. }
  41. }
  42. } // namespace electron