Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: content/public/browser/geolocation_provider.h

Issue 273523007: Dispatch geolocation IPCs on the UI thread. Aside from simplifying the code to avoid a lot of threa… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: benm comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_ 5 #ifndef CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_
6 #define CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_ 6 #define CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_
7 7
8 #include "base/callback_forward.h" 8 #include "base/callback_list.h"
9 #include "content/common/content_export.h" 9 #include "content/common/content_export.h"
10 10
11 namespace content { 11 namespace content {
12 struct Geoposition; 12 struct Geoposition;
13 13
14 class CONTENT_EXPORT GeolocationProvider { 14 // This is the main API to the geolocation subsystem. The application will hold
15 // a single instance of this class and can register multiple clients to be
16 // notified of location changes:
17 // * Callbacks are registered by AddLocationUpdateCallback() and will keep
18 // receiving updates until the returned subscription object is destructed.
19 // The application must instantiate the GeolocationProvider on the UI thread and
20 // must communicate with it on the same thread.
21 // The underlying location arbitrator will only be enabled whilst there is at
22 // least one registered observer or pending callback. The arbitrator and the
bulach 2014/05/08 17:29:26 perhaps: ...or pending callback (and only after Us
jam 2014/05/08 19:09:53 Done.
23 // location providers it uses run on a separate Geolocation thread.
24 class GeolocationProvider {
15 public: 25 public:
16 // This method, and all below, can only be called on the IO thread unless 26 CONTENT_EXPORT static GeolocationProvider* GetInstance();
17 // otherwise specified.
18 static GeolocationProvider* GetInstance();
19 27
20 typedef base::Callback<void(const Geoposition&)> LocationUpdateCallback; 28 typedef base::Callback<void(const Geoposition&)> LocationUpdateCallback;
29 typedef base::CallbackList<void(const Geoposition&)>::Subscription
30 Subscription;
21 31
22 // |use_high_accuracy| is used as a 'hint' for the provider preferences for 32 // |use_high_accuracy| is used as a 'hint' for the provider preferences for
23 // this particular observer, however the observer could receive updates for 33 // this particular observer, however the observer could receive updates for
24 // best available locations from any active provider whilst it is registered. 34 // 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 35 virtual scoped_ptr<Subscription> AddLocationUpdateCallback(
26 // but only a single call to RemoveLocationUpdateCallback() is required to 36 const LocationUpdateCallback& callback, bool use_high_accuracy) = 0;
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 37
36 // Calling this method indicates the user has opted into using location 38 // Calling this method indicates the user has opted into using location
37 // services, including sending network requests to [Google servers to] resolve 39 // 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 40 // the user's location. Use this method carefully, in line with the rules in
39 // go/chrome-privacy-doc. 41 // go/chrome-privacy-doc.
40 virtual void UserDidOptIntoLocationServices() = 0; 42 virtual void UserDidOptIntoLocationServices() = 0;
41 43
42 // Overrides the current location for testing. This function may be called on 44 // Overrides the current location for testing.
43 // any thread. The completion callback will be invoked asynchronously on the
44 // calling thread when the override operation is completed.
45 // 45 //
46 // This function allows the current location to be faked without having to 46 // Overrides the location for automation/testing. Suppresses any further
47 // manually instantiate a GeolocationProvider backed by a MockLocationProvider 47 // updates from the actual providers and sends an update with the overridden
48 // that serves a fake location. 48 // position to all registered clients.
49 // 49 //
50 // Do not use this function in unit tests. The function instantiates the 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 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 52 // a fake location. Neither step can be undone, breaking unit test isolation
53 // (crbug.com/125931). 53 // (crbug.com/125931).
54 static void OverrideLocationForTesting( 54 virtual void OverrideLocationForTesting(const Geoposition& position) = 0;
55 const Geoposition& position,
56 const base::Closure& completion_callback);
57 55
58 protected: 56 protected:
59 virtual~GeolocationProvider() {} 57 virtual~GeolocationProvider() {}
60 }; 58 };
61 59
62 } // namespace content 60 } // namespace content
63 61
64 #endif // CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_ 62 #endif // CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698