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

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: sync 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
« no previous file with comments | « content/public/browser/geolocation_permission_context.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 (and only after
23 // UserDidOptIntoLocationServices). The arbitrator and the location providers it
24 // uses run on a separate Geolocation thread.
25 class GeolocationProvider {
15 public: 26 public:
16 // This method, and all below, can only be called on the IO thread unless 27 CONTENT_EXPORT static GeolocationProvider* GetInstance();
17 // otherwise specified.
18 static GeolocationProvider* GetInstance();
19 28
20 typedef base::Callback<void(const Geoposition&)> LocationUpdateCallback; 29 typedef base::Callback<void(const Geoposition&)> LocationUpdateCallback;
30 typedef base::CallbackList<void(const Geoposition&)>::Subscription
31 Subscription;
21 32
22 // |use_high_accuracy| is used as a 'hint' for the provider preferences for 33 // |use_high_accuracy| is used as a 'hint' for the provider preferences for
23 // this particular observer, however the observer could receive updates for 34 // this particular observer, however the observer could receive updates for
24 // best available locations from any active provider whilst it is registered. 35 // 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 36 virtual scoped_ptr<Subscription> AddLocationUpdateCallback(
26 // but only a single call to RemoveLocationUpdateCallback() is required to 37 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 38
36 // Calling this method indicates the user has opted into using location 39 // Calling this method indicates the user has opted into using location
37 // services, including sending network requests to [Google servers to] resolve 40 // 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 41 // the user's location. Use this method carefully, in line with the rules in
39 // go/chrome-privacy-doc. 42 // go/chrome-privacy-doc.
40 virtual void UserDidOptIntoLocationServices() = 0; 43 virtual void UserDidOptIntoLocationServices() = 0;
41 44
42 // Overrides the current location for testing. This function may be called on 45 // 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 // 46 //
46 // This function allows the current location to be faked without having to 47 // Overrides the location for automation/testing. Suppresses any further
47 // manually instantiate a GeolocationProvider backed by a MockLocationProvider 48 // updates from the actual providers and sends an update with the overridden
48 // that serves a fake location. 49 // position to all registered clients.
49 // 50 //
50 // Do not use this function in unit tests. The function instantiates the 51 // 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 // 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 // a fake location. Neither step can be undone, breaking unit test isolation
53 // (crbug.com/125931). 54 // (crbug.com/125931).
54 static void OverrideLocationForTesting( 55 virtual void OverrideLocationForTesting(const Geoposition& position) = 0;
55 const Geoposition& position,
56 const base::Closure& completion_callback);
57 56
58 protected: 57 protected:
59 virtual~GeolocationProvider() {} 58 virtual~GeolocationProvider() {}
60 }; 59 };
61 60
62 } // namespace content 61 } // namespace content
63 62
64 #endif // CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_ 63 #endif // CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_
OLDNEW
« no previous file with comments | « content/public/browser/geolocation_permission_context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698