| 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 #ifndef GEARS_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H__ |
| 27 #define GEARS_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H__ |
| 28 |
| 29 // TODO(joth): port to chromium |
| 30 #if 0 |
| 31 |
| 32 #include "gears/base/common/common.h" |
| 33 #include "gears/base/common/mutex.h" |
| 34 #include "gears/base/common/string16.h" |
| 35 #include "gears/base/common/thread.h" |
| 36 #include "gears/geolocation/device_data_provider.h" |
| 37 #include "gears/geolocation/location_provider.h" |
| 38 #include "gears/geolocation/network_location_request.h" |
| 39 |
| 40 // PositionCache is an implementation detail of NetworkLocationProvider. |
| 41 class PositionCache; |
| 42 |
| 43 class NetworkLocationProvider |
| 44 : public LocationProviderBase, |
| 45 public RadioDataProvider::ListenerInterface, |
| 46 public WifiDataProvider::ListenerInterface, |
| 47 public NetworkLocationRequest::ListenerInterface, |
| 48 public Thread { |
| 49 public: |
| 50 NetworkLocationProvider(BrowsingContext *browsing_context, |
| 51 const std::string16 &url, |
| 52 const std::string16 &host_name, |
| 53 const std::string16 &language); |
| 54 virtual ~NetworkLocationProvider(); |
| 55 |
| 56 // Override LocationProviderBase implementation. |
| 57 virtual void RegisterListener( |
| 58 LocationProviderBase::ListenerInterface *listener, |
| 59 bool request_address); |
| 60 virtual void UnregisterListener( |
| 61 LocationProviderBase::ListenerInterface *listener); |
| 62 |
| 63 // LocationProviderBase implementation |
| 64 virtual void GetPosition(Position *position); |
| 65 |
| 66 private: |
| 67 // DeviceDataProvider::ListenerInterface implementation. |
| 68 virtual void DeviceDataUpdateAvailable(RadioDataProvider *provider); |
| 69 virtual void DeviceDataUpdateAvailable(WifiDataProvider *provider); |
| 70 |
| 71 // NetworkLocationRequest::ListenerInterface implementation. |
| 72 virtual void LocationResponseAvailable(const Position &position, |
| 73 bool server_error, |
| 74 const std::string16 &access_token); |
| 75 |
| 76 // Thread implementation |
| 77 virtual void Run(); |
| 78 |
| 79 // Internal helper used by worker thread to make a network request |
| 80 bool MakeRequest(); |
| 81 |
| 82 // Internal helper used by DeviceDataUpdateAvailable |
| 83 void DeviceDataUpdateAvailableImpl(); |
| 84 |
| 85 // The network location request object and the url and host name it will use. |
| 86 NetworkLocationRequest *request_; |
| 87 std::string16 url_; |
| 88 std::string16 host_name_; |
| 89 |
| 90 // The device data providers |
| 91 RadioDataProvider *radio_data_provider_; |
| 92 WifiDataProvider *wifi_data_provider_; |
| 93 |
| 94 // The radio and wifi data, flags to indicate if each data set is complete, |
| 95 // and their guarding mutex. |
| 96 RadioData radio_data_; |
| 97 WifiData wifi_data_; |
| 98 bool is_radio_data_complete_; |
| 99 bool is_wifi_data_complete_; |
| 100 Mutex data_mutex_; |
| 101 |
| 102 // The timestamp for the latest device data update. |
| 103 int64 timestamp_; |
| 104 |
| 105 // Parameters for the network request |
| 106 bool request_address_; |
| 107 bool request_address_from_last_request_; |
| 108 std::string16 address_language_; |
| 109 |
| 110 // The current best position estimate and its guarding mutex |
| 111 Position position_; |
| 112 Mutex position_mutex_; |
| 113 |
| 114 // The event used to notify this object's (ie the network location provider) |
| 115 // worker thread about changes in available data, the network request status |
| 116 // and whether we're shutting down. The booleans are used to indicate what the |
| 117 // event signals. |
| 118 Event thread_notification_event_; |
| 119 bool is_shutting_down_; |
| 120 bool is_new_data_available_; |
| 121 bool is_last_request_complete_; |
| 122 bool is_new_listener_waiting_; |
| 123 |
| 124 // When the last request did not request an address, this stores any new |
| 125 // listeners which have been added and require an address to be requested. |
| 126 typedef std::set<LocationProviderBase::ListenerInterface*> ListenerSet; |
| 127 ListenerSet new_listeners_requiring_address_; |
| 128 Mutex new_listeners_requiring_address_mutex_; |
| 129 |
| 130 // The earliest timestamp at which the next request can be made, in |
| 131 // milliseconds. |
| 132 int64 earliest_next_request_time_; |
| 133 |
| 134 BrowsingContext *browsing_context_; |
| 135 |
| 136 // The cache of positions. |
| 137 scoped_ptr<PositionCache> position_cache_; |
| 138 |
| 139 DISALLOW_EVIL_CONSTRUCTORS(NetworkLocationProvider); |
| 140 }; |
| 141 |
| 142 #endif // if 0 |
| 143 |
| 144 #endif // GEARS_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H__ |
| OLD | NEW |