summaryrefslogtreecommitdiffstats
path: root/chromium/content/public/browser/geolocation_provider.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/content/public/browser/geolocation_provider.h')
-rw-r--r--chromium/content/public/browser/geolocation_provider.h47
1 files changed, 23 insertions, 24 deletions
diff --git a/chromium/content/public/browser/geolocation_provider.h b/chromium/content/public/browser/geolocation_provider.h
index 5e27db48880..dea3c7ee3f4 100644
--- a/chromium/content/public/browser/geolocation_provider.h
+++ b/chromium/content/public/browser/geolocation_provider.h
@@ -5,33 +5,36 @@
#ifndef CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_
#define CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_
-#include "base/callback_forward.h"
+#include "base/callback_list.h"
#include "content/common/content_export.h"
namespace content {
struct Geoposition;
-class CONTENT_EXPORT GeolocationProvider {
+// This is the main API to the geolocation subsystem. The application will hold
+// a single instance of this class and can register multiple clients to be
+// notified of location changes:
+// * Callbacks are registered by AddLocationUpdateCallback() and will keep
+// receiving updates until the returned subscription object is destructed.
+// The application must instantiate the GeolocationProvider on the UI thread and
+// must communicate with it on the same thread.
+// The underlying location arbitrator will only be enabled whilst there is at
+// least one registered observer or pending callback (and only after
+// UserDidOptIntoLocationServices). The arbitrator and the location providers it
+// uses run on a separate Geolocation thread.
+class GeolocationProvider {
public:
- // This method, and all below, can only be called on the IO thread unless
- // otherwise specified.
- static GeolocationProvider* GetInstance();
+ CONTENT_EXPORT static GeolocationProvider* GetInstance();
typedef base::Callback<void(const Geoposition&)> LocationUpdateCallback;
+ typedef base::CallbackList<void(const Geoposition&)>::Subscription
+ Subscription;
// |use_high_accuracy| is used as a 'hint' for the provider preferences for
// this particular observer, however the observer could receive updates for
// best available locations from any active provider whilst it is registered.
- // If an existing observer is added a second time, its options are updated
- // but only a single call to RemoveLocationUpdateCallback() is required to
- // remove it.
- virtual void AddLocationUpdateCallback(const LocationUpdateCallback& callback,
- bool use_high_accuracy) = 0;
-
- // Remove a previously registered observer. No-op if not previously registered
- // via AddLocationUpdateCallback(). Returns true if the observer was removed.
- virtual bool RemoveLocationUpdateCallback(
- const LocationUpdateCallback& callback) = 0;
+ virtual scoped_ptr<Subscription> AddLocationUpdateCallback(
+ const LocationUpdateCallback& callback, bool use_high_accuracy) = 0;
// Calling this method indicates the user has opted into using location
// services, including sending network requests to [Google servers to] resolve
@@ -39,21 +42,17 @@ class CONTENT_EXPORT GeolocationProvider {
// go/chrome-privacy-doc.
virtual void UserDidOptIntoLocationServices() = 0;
- // Overrides the current location for testing. This function may be called on
- // any thread. The completion callback will be invoked asynchronously on the
- // calling thread when the override operation is completed.
+ // Overrides the current location for testing.
//
- // This function allows the current location to be faked without having to
- // manually instantiate a GeolocationProvider backed by a MockLocationProvider
- // that serves a fake location.
+ // Overrides the location for automation/testing. Suppresses any further
+ // updates from the actual providers and sends an update with the overridden
+ // position to all registered clients.
//
// Do not use this function in unit tests. The function instantiates the
// singleton geolocation stack in the background and manipulates it to report
// a fake location. Neither step can be undone, breaking unit test isolation
// (crbug.com/125931).
- static void OverrideLocationForTesting(
- const Geoposition& position,
- const base::Closure& completion_callback);
+ virtual void OverrideLocationForTesting(const Geoposition& position) = 0;
protected:
virtual~GeolocationProvider() {}