geolocation_impl.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_DEVICE_GEOLOCATION_GEOLOCATION_IMPL_H_
  5. #define SERVICES_DEVICE_GEOLOCATION_GEOLOCATION_IMPL_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "mojo/public/cpp/bindings/receiver.h"
  8. #include "services/device/geolocation/geolocation_provider_impl.h"
  9. #include "services/device/public/mojom/geolocation.mojom.h"
  10. namespace device {
  11. class GeolocationProvider;
  12. class GeolocationContext;
  13. // Implements the Geolocation Mojo interface.
  14. class GeolocationImpl : public mojom::Geolocation {
  15. public:
  16. // |context| must outlive this object.
  17. GeolocationImpl(mojo::PendingReceiver<mojom::Geolocation> receiver,
  18. GeolocationContext* context);
  19. GeolocationImpl(const GeolocationImpl&) = delete;
  20. GeolocationImpl& operator=(const GeolocationImpl&) = delete;
  21. ~GeolocationImpl() override;
  22. // Starts listening for updates.
  23. void StartListeningForUpdates();
  24. // Pauses and resumes sending updates to the client of this instance.
  25. void PauseUpdates();
  26. void ResumeUpdates();
  27. // Enables and disables geolocation override.
  28. void SetOverride(const mojom::Geoposition& position);
  29. void ClearOverride();
  30. private:
  31. // mojom::Geolocation:
  32. void SetHighAccuracy(bool high_accuracy) override;
  33. void QueryNextPosition(QueryNextPositionCallback callback) override;
  34. void OnConnectionError();
  35. void OnLocationUpdate(const mojom::Geoposition& position);
  36. void ReportCurrentPosition();
  37. // The binding between this object and the other end of the pipe.
  38. mojo::Receiver<mojom::Geolocation> receiver_;
  39. // Owns this object.
  40. raw_ptr<GeolocationContext> context_;
  41. // Token that unsubscribes from GeolocationProvider updates when destroyed.
  42. base::CallbackListSubscription geolocation_subscription_;
  43. // The callback passed to QueryNextPosition.
  44. QueryNextPositionCallback position_callback_;
  45. // Valid if SetOverride() has been called and ClearOverride() has not
  46. // subsequently been called.
  47. mojom::Geoposition position_override_;
  48. mojom::Geoposition current_position_;
  49. // Whether this instance is currently observing location updates with high
  50. // accuracy.
  51. bool high_accuracy_;
  52. bool has_position_to_report_;
  53. };
  54. } // namespace device
  55. #endif // SERVICES_DEVICE_GEOLOCATION_GEOLOCATION_IMPL_H_