diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-01 13:30:01 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-01 13:30:01 +0000 |
commit | 221e544540fc33994373a8e88ba68300f840da75 (patch) | |
tree | 9ac704647f1ddd6a7268a8a90403ed9ab54d4109 /chrome/browser/geolocation/location_arbitrator.h | |
parent | 191b4a057b46e49da447c3c08754485f5d8be58b (diff) | |
download | chromium_src-221e544540fc33994373a8e88ba68300f840da75.zip chromium_src-221e544540fc33994373a8e88ba68300f840da75.tar.gz chromium_src-221e544540fc33994373a8e88ba68300f840da75.tar.bz2 |
Implement location arbitration (kudos to previous internal projects this is lifted from)
BUG=38509
TEST=GeolocationLocationArbitratorTest.Arbitration
Review URL: http://codereview.chromium.org/2376001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48631 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/geolocation/location_arbitrator.h')
-rw-r--r-- | chrome/browser/geolocation/location_arbitrator.h | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/chrome/browser/geolocation/location_arbitrator.h b/chrome/browser/geolocation/location_arbitrator.h index 4742e56..085e320 100644 --- a/chrome/browser/geolocation/location_arbitrator.h +++ b/chrome/browser/geolocation/location_arbitrator.h @@ -5,6 +5,8 @@ #ifndef CHROME_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_H_ #define CHROME_BROWSER_GEOLOCATION_LOCATION_ARBITRATOR_H_ +#include "base/string16.h" +#include "base/time.h" #include "base/ref_counted.h" class AccessTokenStore; @@ -23,11 +25,37 @@ struct Geoposition; // moment. class GeolocationArbitrator : public base::RefCounted<GeolocationArbitrator> { public: + // Number of milliseconds newer a location provider has to be that it's worth + // switching to this location provider on the basis of it being fresher + // (regardles of relative accuracy). Public for tests. + static const int64 kFixStaleTimeoutMilliseconds; + + // Defines a function that returns the current time. + typedef base::Time (*GetTimeNow)(); + + // Allows injection of factory methods for creating the location providers. + // RefCounted for simplicity of writing tests. + class ProviderFactory : public base::RefCounted<ProviderFactory> { + public: + virtual LocationProviderBase* NewNetworkLocationProvider( + AccessTokenStore* access_token_store, + URLRequestContextGetter* context, + const GURL& url, + const string16& access_token) = 0; + virtual LocationProviderBase* NewGpsLocationProvider() = 0; + + protected: + friend class base::RefCounted<ProviderFactory>; + virtual ~ProviderFactory(); + }; + // Creates and returns a new instance of the location arbitrator. Allows - // injection of the access token store and url getter context, for testing. + // injection of dependencies, for testing. static GeolocationArbitrator* Create( AccessTokenStore* access_token_store, - URLRequestContextGetter* context_getter); + URLRequestContextGetter* context_getter, + GetTimeNow get_time_now, + ProviderFactory* provider_factory); // Gets a pointer to the singleton instance of the location arbitrator, which // is in turn bound to the browser's global context objects. Ownership is NOT @@ -55,7 +83,7 @@ class GeolocationArbitrator : public base::RefCounted<GeolocationArbitrator> { // The update options passed are used as a 'hint' for the provider preferences // for this particular observer, however the delegate could receive callbacks // for best available locations from any active provider whilst it is - // registerd. + // registered. // If an existing delegate is added a second time it's options are updated // but only a single call to RemoveObserver() is required to remove it. virtual void AddObserver(Delegate* delegate, @@ -64,6 +92,11 @@ class GeolocationArbitrator : public base::RefCounted<GeolocationArbitrator> { // via AddObserver(). Returns true if the observer was removed. virtual bool RemoveObserver(Delegate* delegate) = 0; + // Returns the current position estimate, or an uninitialized position + // if none is yet available. Once initialized, this will always match + // the most recent observer notification (via Delegate::OnLocationUpdate()). + virtual Geoposition GetCurrentPosition() = 0; + // Called everytime permission is granted to a page for using geolocation. // This may either be through explicit user action (e.g. responding to the // infobar prompt) or inferred from a persisted site permission. @@ -75,8 +108,10 @@ class GeolocationArbitrator : public base::RefCounted<GeolocationArbitrator> { // OnPermissionGranted(). virtual bool HasPermissionBeenGranted() const = 0; - // For testing, a factory functino can be set which will be used to create + // For testing, a factory function can be set which will be used to create // a specified test provider. Pass NULL to reset to the default behavior. + // For finer grained control, use class ProviderFactory instead. + // TODO(joth): Move all tests to use ProviderFactory and remove this. typedef LocationProviderBase* (*LocationProviderFactoryFunction)(void); static void SetProviderFactoryForTest( LocationProviderFactoryFunction factory_function); |