fake_location_provider.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 "atom/browser/fake_location_provider.h"
  5. #include "base/callback.h"
  6. #include "base/time/time.h"
  7. namespace atom {
  8. FakeLocationProvider::FakeLocationProvider() {
  9. position_.latitude = 10;
  10. position_.longitude = -10;
  11. position_.accuracy = 1;
  12. position_.error_code =
  13. device::mojom::Geoposition::ErrorCode::POSITION_UNAVAILABLE;
  14. }
  15. FakeLocationProvider::~FakeLocationProvider() = default;
  16. void FakeLocationProvider::SetUpdateCallback(
  17. const LocationProviderUpdateCallback& callback) {
  18. callback_ = callback;
  19. }
  20. void FakeLocationProvider::StartProvider(bool high_accuracy) {}
  21. void FakeLocationProvider::StopProvider() {}
  22. const device::mojom::Geoposition& FakeLocationProvider::GetPosition() {
  23. return position_;
  24. }
  25. void FakeLocationProvider::OnPermissionGranted() {
  26. if (!callback_.is_null()) {
  27. // Check device::ValidateGeoPosition for range of values.
  28. position_.error_code = device::mojom::Geoposition::ErrorCode::NONE;
  29. position_.timestamp = base::Time::Now();
  30. callback_.Run(this, position_);
  31. }
  32. }
  33. } // namespace atom