public_ip_address_geolocator.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2017 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_PUBLIC_IP_ADDRESS_GEOLOCATOR_H_
  5. #define SERVICES_DEVICE_GEOLOCATION_PUBLIC_IP_ADDRESS_GEOLOCATOR_H_
  6. #include <string>
  7. #include "base/callback.h"
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/time/time.h"
  10. #include "net/traffic_annotation/network_traffic_annotation.h"
  11. #include "services/device/geolocation/public_ip_address_location_notifier.h"
  12. #include "services/device/public/mojom/geolocation.mojom.h"
  13. #include "services/device/public/mojom/geoposition.mojom.h"
  14. namespace device {
  15. class PublicIpAddressLocationNotifier;
  16. // An implementation of Geolocation that uses only public IP address-based
  17. // geolocation.
  18. class PublicIpAddressGeolocator : public mojom::Geolocation {
  19. public:
  20. using BadMessageCallback =
  21. base::RepeatingCallback<void(const std::string& message)>;
  22. // Creates a PublicIpAddressGeolocatorsubscribed to the specified |notifier|.
  23. // This object will unbind and destroy itself if |notifier| is destroyed.
  24. // |callback| is a callback that should be called to signify reception of a
  25. // bad Mojo message *only while processing that message*.
  26. PublicIpAddressGeolocator(const net::PartialNetworkTrafficAnnotationTag tag,
  27. PublicIpAddressLocationNotifier* notifier,
  28. BadMessageCallback callback);
  29. PublicIpAddressGeolocator(const PublicIpAddressGeolocator&) = delete;
  30. PublicIpAddressGeolocator& operator=(const PublicIpAddressGeolocator&) =
  31. delete;
  32. ~PublicIpAddressGeolocator() override;
  33. private:
  34. // mojom::Geolocation:
  35. void QueryNextPosition(QueryNextPositionCallback callback) override;
  36. void SetHighAccuracy(bool high_accuracy) override;
  37. // Callback to register with PublicIpAddressLocationNotifier.
  38. void OnPositionUpdate(const mojom::Geoposition& position);
  39. // The callback passed to QueryNextPosition.
  40. QueryNextPositionCallback query_next_position_callback_;
  41. // Timestamp of latest Geoposition this client received.
  42. base::Time last_updated_timestamp_;
  43. // Notifier to ask for IP-geolocation updates.
  44. const raw_ptr<PublicIpAddressLocationNotifier> notifier_;
  45. // The most recent PartialNetworkTrafficAnnotationTag provided by a client.
  46. std::unique_ptr<const net::PartialNetworkTrafficAnnotationTag>
  47. network_traffic_annotation_tag_;
  48. // Bad message callback.
  49. BadMessageCallback bad_message_callback_;
  50. };
  51. } // namespace device
  52. #endif // SERVICES_DEVICE_GEOLOCATION_PUBLIC_IP_ADDRESS_GEOLOCATOR_H_