| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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 // A location provider provides position information from a particular source | |
| 6 // (GPS, network etc). The GearsGeolocation object uses a set of location | |
| 7 // providers to obtain a position fix. | |
| 8 // | |
| 9 // This file declares a base class to be used by all location providers. | |
| 10 // Primarily, this class declares interface methods to be implemented by | |
| 11 // derived classes. | |
| 12 | |
| 13 #ifndef CHROME_BROWSER_GEOLOCATION_LOCATION_PROVIDER_H_ | |
| 14 #define CHROME_BROWSER_GEOLOCATION_LOCATION_PROVIDER_H_ | |
| 15 #pragma once | |
| 16 | |
| 17 #include <map> | |
| 18 #include "base/string16.h" | |
| 19 #include "base/threading/non_thread_safe.h" | |
| 20 | |
| 21 class AccessTokenStore; | |
| 22 struct Geoposition; | |
| 23 class GURL; | |
| 24 class URLRequestContextGetter; | |
| 25 | |
| 26 // The base class used by all location providers. | |
| 27 class LocationProviderBase : public base::NonThreadSafe { | |
| 28 public: | |
| 29 // Clients of the location provider must implement this interface. All call- | |
| 30 // backs to this interface will happen in the context of the thread on which | |
| 31 // the location provider was created. | |
| 32 class ListenerInterface { | |
| 33 public: | |
| 34 // Used to inform listener that a new position fix is available or that a | |
| 35 // fatal error has occurred. Providers should call this for new listeners | |
| 36 // as soon as a position is available. | |
| 37 virtual void LocationUpdateAvailable(LocationProviderBase* provider) = 0; | |
| 38 | |
| 39 protected: | |
| 40 virtual ~ListenerInterface() {} | |
| 41 }; | |
| 42 | |
| 43 virtual ~LocationProviderBase(); | |
| 44 | |
| 45 // Registers a listener, which will be called back on | |
| 46 // ListenerInterface::LocationUpdateAvailable as soon as a position is | |
| 47 // available and again whenever a new position is available. Ref counts the | |
| 48 // listener to handle multiple calls to this method. | |
| 49 void RegisterListener(ListenerInterface* listener); | |
| 50 // Unregisters a listener. Unrefs the listener to handle multiple calls to | |
| 51 // this method. Once the ref count reaches zero, the listener is removed and | |
| 52 // once this method returns, no further calls to | |
| 53 // ListenerInterface::LocationUpdateAvailable will be made for this listener. | |
| 54 // It may block if a callback is in progress. | |
| 55 void UnregisterListener(ListenerInterface* listener); | |
| 56 | |
| 57 // Interface methods | |
| 58 // StartProvider maybe called multiple times, e.g. to alter the | |
| 59 // |high_accuracy| setting. Returns false if a fatal error was encountered | |
| 60 // which prevented the provider from starting. | |
| 61 virtual bool StartProvider(bool high_accuracy) = 0; | |
| 62 virtual void StopProvider() = 0; | |
| 63 // Gets the current best position estimate. | |
| 64 virtual void GetPosition(Geoposition* position) = 0; | |
| 65 // Provides a hint to the provider that new location data is needed as soon | |
| 66 // as possible. Default implementation does nothing. | |
| 67 virtual void UpdatePosition() {} | |
| 68 // Delegated to the provider by GeolocationArbitrator. See the corresponding | |
| 69 // method on that class for more details. | |
| 70 virtual void OnPermissionGranted(const GURL& requesting_frame) {} | |
| 71 | |
| 72 bool has_listeners() const; | |
| 73 | |
| 74 protected: | |
| 75 LocationProviderBase(); | |
| 76 | |
| 77 // Inform listeners that a new position or error is available, using | |
| 78 // LocationUpdateAvailable. | |
| 79 void UpdateListeners(); | |
| 80 | |
| 81 private: | |
| 82 // The listeners registered to this provider. For each listener, we store a | |
| 83 // ref count. | |
| 84 typedef std::map<ListenerInterface*, int> ListenerMap; | |
| 85 ListenerMap listeners_; | |
| 86 }; | |
| 87 | |
| 88 // Factory functions for the various types of location provider to abstract | |
| 89 // over the platform-dependent implementations. | |
| 90 LocationProviderBase* NewNetworkLocationProvider( | |
| 91 AccessTokenStore* access_token_store, | |
| 92 URLRequestContextGetter* context, | |
| 93 const GURL& url, | |
| 94 const string16& access_token); | |
| 95 LocationProviderBase* NewSystemLocationProvider(); | |
| 96 | |
| 97 #endif // CHROME_BROWSER_GEOLOCATION_LOCATION_PROVIDER_H_ | |
| OLD | NEW |