OLD | NEW |
| (Empty) |
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 <memory> | |
9 | |
10 #include "base/callback_list.h" | |
11 #include "content/common/content_export.h" | |
12 | |
13 namespace content { | |
14 class GeolocationDelegate; | |
15 struct Geoposition; | |
16 | |
17 // This is the main API to the geolocation subsystem. The application will hold | |
18 // a single instance of this class and can register multiple clients to be | |
19 // notified of location changes: | |
20 // * Callbacks are registered by AddLocationUpdateCallback() and will keep | |
21 // receiving updates until the returned subscription object is destructed. | |
22 // The application must instantiate the GeolocationProvider on the UI thread and | |
23 // must communicate with it on the same thread. | |
24 // The underlying location arbitrator will only be enabled whilst there is at | |
25 // least one registered observer or pending callback (and only after | |
26 // UserDidOptIntoLocationServices). The arbitrator and the location providers it | |
27 // uses run on a separate Geolocation thread. | |
28 class GeolocationProvider { | |
29 public: | |
30 CONTENT_EXPORT static GeolocationProvider* GetInstance(); | |
31 | |
32 // Optional: provide a Delegate to override typical services. | |
33 CONTENT_EXPORT static void SetGeolocationDelegate( | |
34 GeolocationDelegate* delegate); | |
35 | |
36 typedef base::Callback<void(const Geoposition&)> LocationUpdateCallback; | |
37 typedef base::CallbackList<void(const Geoposition&)>::Subscription | |
38 Subscription; | |
39 | |
40 // |enable_high_accuracy| is used as a 'hint' for the provider preferences for | |
41 // this particular observer, however the observer could receive updates for | |
42 // best available locations from any active provider whilst it is registered. | |
43 virtual std::unique_ptr<Subscription> AddLocationUpdateCallback( | |
44 const LocationUpdateCallback& callback, | |
45 bool enable_high_accuracy) = 0; | |
46 | |
47 // Calling this method indicates the user has opted into using location | |
48 // services, including sending network requests to [Google servers to] resolve | |
49 // the user's location. Use this method carefully, in line with the rules in | |
50 // go/chrome-privacy-doc. | |
51 virtual void UserDidOptIntoLocationServices() = 0; | |
52 | |
53 // Overrides the current location for testing. | |
54 // | |
55 // Overrides the location for automation/testing. Suppresses any further | |
56 // updates from the actual providers and sends an update with the overridden | |
57 // position to all registered clients. | |
58 // | |
59 // Do not use this function in unit tests. The function instantiates the | |
60 // singleton geolocation stack in the background and manipulates it to report | |
61 // a fake location. Neither step can be undone, breaking unit test isolation | |
62 // (crbug.com/125931). | |
63 virtual void OverrideLocationForTesting(const Geoposition& position) = 0; | |
64 | |
65 protected: | |
66 virtual~GeolocationProvider() {} | |
67 }; | |
68 | |
69 } // namespace content | |
70 | |
71 #endif // CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_ | |
OLD | NEW |