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.
5 #ifndef CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_
6 #define CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_
8 #include "base/callback_forward.h"
9 #include "content/common/content_export.h"
14 class CONTENT_EXPORT GeolocationProvider
{
16 // This method, and all below, can only be called on the IO thread unless
17 // otherwise specified.
18 static GeolocationProvider
* GetInstance();
20 typedef base::Callback
<void(const Geoposition
&)> LocationUpdateCallback
;
22 // |use_high_accuracy| is used as a 'hint' for the provider preferences for
23 // this particular observer, however the observer could receive updates for
24 // best available locations from any active provider whilst it is registered.
25 // If an existing observer is added a second time, its options are updated
26 // but only a single call to RemoveLocationUpdateCallback() is required to
28 virtual void AddLocationUpdateCallback(const LocationUpdateCallback
& callback
,
29 bool use_high_accuracy
) = 0;
31 // Remove a previously registered observer. No-op if not previously registered
32 // via AddLocationUpdateCallback(). Returns true if the observer was removed.
33 virtual bool RemoveLocationUpdateCallback(
34 const LocationUpdateCallback
& callback
) = 0;
36 // Calling this method indicates the user has opted into using location
37 // services, including sending network requests to [Google servers to] resolve
38 // the user's location. Use this method carefully, in line with the rules in
39 // go/chrome-privacy-doc.
40 virtual void UserDidOptIntoLocationServices() = 0;
42 // Overrides the current location for testing. This function may be called on
43 // any thread. The completion callback will be invoked asynchronously on the
44 // calling thread when the override operation is completed.
46 // This function allows the current location to be faked without having to
47 // manually instantiate a GeolocationProvider backed by a MockLocationProvider
48 // that serves a fake location.
50 // Do not use this function in unit tests. The function instantiates the
51 // singleton geolocation stack in the background and manipulates it to report
52 // a fake location. Neither step can be undone, breaking unit test isolation
53 // (crbug.com/125931).
54 static void OverrideLocationForTesting(
55 const Geoposition
& position
,
56 const base::Closure
& completion_callback
);
59 virtual~GeolocationProvider() {}
62 } // namespace content
64 #endif // CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_