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