geolocation_provider.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2012 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_PROVIDER_H_
  5. #define SERVICES_DEVICE_GEOLOCATION_GEOLOCATION_PROVIDER_H_
  6. #include "base/callback_list.h"
  7. #include "services/device/public/mojom/geoposition.mojom.h"
  8. namespace device {
  9. // This is the main API to the geolocation subsystem. The application will hold
  10. // a single instance of this class and can register multiple clients to be
  11. // notified of location changes:
  12. // * Callbacks are registered by AddLocationUpdateCallback() and will keep
  13. // receiving updates until the returned subscription object is destroyed.
  14. // The application must instantiate the GeolocationProvider on the UI thread and
  15. // must communicate with it on the same thread.
  16. // The underlying location arbitrator will only be enabled whilst there is at
  17. // least one registered observer or pending callback (and only after
  18. // mojom::UserDidOptIntoLocationServices() which is implemented by
  19. // GeolocationProviderImpl). The arbitrator and the location providers it uses
  20. // run on a separate Geolocation thread.
  21. // TODO(ke.he@intel.com): With the proceeding of the servicification of
  22. // geolocation, the geolocation core will be moved into //services/device and as
  23. // a internal part of Device Service. This geolocation_provider.h will also be
  24. // removed.
  25. class GeolocationProvider {
  26. public:
  27. static GeolocationProvider* GetInstance();
  28. typedef base::RepeatingCallback<void(const mojom::Geoposition&)>
  29. LocationUpdateCallback;
  30. // |enable_high_accuracy| is used as a 'hint' for the provider preferences for
  31. // this particular observer, however the observer could receive updates for
  32. // best available locations from any active provider whilst it is registered.
  33. virtual base::CallbackListSubscription AddLocationUpdateCallback(
  34. const LocationUpdateCallback& callback,
  35. bool enable_high_accuracy) = 0;
  36. virtual bool HighAccuracyLocationInUse() = 0;
  37. // Overrides the current location for testing.
  38. //
  39. // Overrides the location for automation/testing. Suppresses any further
  40. // updates from the actual providers and sends an update with the overridden
  41. // position to all registered clients.
  42. //
  43. // Do not use this function in unit tests. The function instantiates the
  44. // singleton geolocation stack in the background and manipulates it to report
  45. // a fake location. Neither step can be undone, breaking unit test isolation
  46. // (https://crbug.com/125931).
  47. virtual void OverrideLocationForTesting(
  48. const mojom::Geoposition& position) = 0;
  49. protected:
  50. virtual ~GeolocationProvider() {}
  51. };
  52. } // namespace device
  53. #endif // SERVICES_DEVICE_GEOLOCATION_GEOLOCATION_PROVIDER_H_