| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2008, Google Inc. |
| 2 // |
| 3 // Redistribution and use in source and binary forms, with or without |
| 4 // modification, are permitted provided that the following conditions are met: |
| 5 // |
| 6 // 1. Redistributions of source code must retain the above copyright notice, |
| 7 // this list of conditions and the following disclaimer. |
| 8 // 2. Redistributions in binary form must reproduce the above copyright notice, |
| 9 // this list of conditions and the following disclaimer in the documentation |
| 10 // and/or other materials provided with the distribution. |
| 11 // 3. Neither the name of Google Inc. nor the names of its contributors may be |
| 12 // used to endorse or promote products derived from this software without |
| 13 // specific prior written permission. |
| 14 // |
| 15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 // |
| 26 // A location provider provides position information from a particular source |
| 27 // (GPS, network etc). The GearsGeolocation object uses a set of location |
| 28 // providers to obtain a position fix. |
| 29 // |
| 30 // This file declares a base class to be used by all location providers. |
| 31 // Primarily, this class declares interface methods to be implemented by derived |
| 32 // classes. |
| 33 |
| 34 #ifndef GEARS_GEOLOCATION_LOCATION_PROVIDER_H__ |
| 35 #define GEARS_GEOLOCATION_LOCATION_PROVIDER_H__ |
| 36 |
| 37 // TODO(joth): port to chromium |
| 38 #if 0 |
| 39 |
| 40 #include <map> |
| 41 #include "gears/base/common/base_class.h" |
| 42 #include "gears/base/common/mutex.h" |
| 43 #include "gears/base/common/string16.h" |
| 44 |
| 45 struct Position; |
| 46 class RefCount; |
| 47 |
| 48 // The base class used by all location providers. |
| 49 class LocationProviderBase { |
| 50 public: |
| 51 class ListenerInterface { |
| 52 public: |
| 53 // Used to inform listener that a new position fix is available or that a |
| 54 // fatal error has occurred. Providers should call this for new listeners |
| 55 // as soon as a position is available. |
| 56 virtual bool LocationUpdateAvailable(LocationProviderBase *provider) = 0; |
| 57 // Used to inform listener that movement has been detected. If obtaining the |
| 58 // position succeeds, this will be followed by a call to |
| 59 // LocationUpdateAvailable. Some providers may not be able to detect |
| 60 // movement before a new fix is obtained, so will never call this method. |
| 61 // Note that this is not called in response to registration of a new |
| 62 // listener. |
| 63 virtual bool MovementDetected(LocationProviderBase *provider) = 0; |
| 64 virtual ~ListenerInterface() {} |
| 65 }; |
| 66 |
| 67 virtual ~LocationProviderBase() {} |
| 68 |
| 69 // Registers a listener, which will be called back on |
| 70 // ListenerInterface::LocationUpdateAvailable as soon as a position is |
| 71 // available and again whenever a new position is available. Ref counts the |
| 72 // listener to handle multiple calls to this method. |
| 73 virtual void RegisterListener(ListenerInterface *listener, |
| 74 bool request_address); |
| 75 // Unregisters a listener. Unrefs the listener to handle multiple calls to |
| 76 // this method. Once the ref count reaches zero, the listener is removed and |
| 77 // once this method returns, no further calls to |
| 78 // ListenerInterface::LocationUpdateAvailable will be made for this listener. |
| 79 // It may block if a callback is in progress. |
| 80 virtual void UnregisterListener(ListenerInterface *listener); |
| 81 |
| 82 // Interface methods |
| 83 // Gets the current best position estimate. |
| 84 virtual void GetPosition(Position *position) = 0; |
| 85 // Provides a hint to the provider that new location data is needed as soon |
| 86 // as possible. Default implementation does nothing. |
| 87 virtual void UpdatePosition() {} |
| 88 |
| 89 // Accessor methods. |
| 90 typedef std::pair<bool, RefCount*> ListenerPair; |
| 91 typedef std::map<ListenerInterface*, ListenerPair> ListenerMap; |
| 92 ListenerMap *GetListeners(); |
| 93 Mutex *GetListenersMutex(); |
| 94 |
| 95 protected: |
| 96 // Inform listeners that a new position or error is available, using |
| 97 // LocationUpdateAvailable. |
| 98 virtual void UpdateListeners(); |
| 99 // Inform listeners that movement has been detected, using MovementDetected. |
| 100 virtual void InformListenersOfMovement(); |
| 101 |
| 102 private: |
| 103 // The listeners registered to this provider. For each listener, we store a |
| 104 // ref count and whether it requires an address. |
| 105 ListenerMap listeners_; |
| 106 Mutex listeners_mutex_; |
| 107 }; |
| 108 |
| 109 // Factory functions for the various types of location provider to abstract over |
| 110 // the platform-dependent implementations. |
| 111 LocationProviderBase *NewMockLocationProvider(); |
| 112 LocationProviderBase *NewGpsLocationProvider( |
| 113 BrowsingContext *browsing_context, |
| 114 const std::string16 &reverse_geocode_url, |
| 115 const std::string16 &host_name, |
| 116 const std::string16 &address_language); |
| 117 LocationProviderBase *NewNetworkLocationProvider( |
| 118 BrowsingContext *browsing_context, |
| 119 const std::string16 &url, |
| 120 const std::string16 &host_name, |
| 121 const std::string16 &language); |
| 122 |
| 123 #endif // if 0 |
| 124 |
| 125 #endif // GEARS_GEOLOCATION_LOCATION_PROVIDER_H__ |
| OLD | NEW |