- add sources.
[platform/framework/web/crosswalk.git] / src / content / public / browser / geolocation_provider.h
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
5 #ifndef CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_
6 #define CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_
7
8 #include "base/callback_forward.h"
9 #include "content/common/content_export.h"
10
11 namespace content {
12 struct Geoposition;
13
14 class CONTENT_EXPORT GeolocationProvider {
15  public:
16   // This method, and all below, can only be called on the IO thread unless
17   // otherwise specified.
18   static GeolocationProvider* GetInstance();
19
20   typedef base::Callback<void(const Geoposition&)> LocationUpdateCallback;
21
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
27   // remove it.
28   virtual void AddLocationUpdateCallback(const LocationUpdateCallback& callback,
29                                          bool use_high_accuracy) = 0;
30
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;
35
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;
41
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.
45   //
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.
49   //
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);
57
58  protected:
59   virtual~GeolocationProvider() {}
60 };
61
62 }  // namespace content
63
64 #endif  // CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_