| OLD | NEW |
| 1 // Copyright 2008, Google Inc. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // Redistribution and use in source and binary forms, with or without | 3 // found in the LICENSE file. |
| 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 | 4 |
| 26 #ifndef GEARS_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H__ | 5 #ifndef CHROME_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ |
| 27 #define GEARS_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H__ | 6 #define CHROME_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ |
| 28 | 7 |
| 29 // TODO(joth): port to chromium | 8 #include <string> |
| 30 #if 0 | |
| 31 | 9 |
| 32 #include "gears/base/common/common.h" | 10 #include "base/basictypes.h" |
| 33 #include "gears/base/common/mutex.h" | 11 #include "base/lock.h" |
| 34 #include "gears/base/common/string16.h" | 12 #include "base/string16.h" |
| 35 #include "gears/base/common/thread.h" | 13 #include "base/thread.h" |
| 36 #include "gears/geolocation/device_data_provider.h" | 14 #include "chrome/browser/geolocation/device_data_provider.h" |
| 37 #include "gears/geolocation/location_provider.h" | 15 #include "chrome/browser/geolocation/geoposition.h" |
| 38 #include "gears/geolocation/network_location_request.h" | 16 #include "chrome/browser/geolocation/location_provider.h" |
| 17 #include "chrome/browser/geolocation/network_location_request.h" |
| 39 | 18 |
| 40 // PositionCache is an implementation detail of NetworkLocationProvider. | 19 class URLFetcherProtectEntry; |
| 41 class PositionCache; | |
| 42 | 20 |
| 43 class NetworkLocationProvider | 21 class NetworkLocationProvider |
| 44 : public LocationProviderBase, | 22 : public LocationProviderBase, |
| 45 public RadioDataProvider::ListenerInterface, | 23 public RadioDataProvider::ListenerInterface, |
| 46 public WifiDataProvider::ListenerInterface, | 24 public WifiDataProvider::ListenerInterface, |
| 47 public NetworkLocationRequest::ListenerInterface, | 25 public NetworkLocationRequest::ListenerInterface { |
| 48 public Thread { | |
| 49 public: | 26 public: |
| 50 NetworkLocationProvider(BrowsingContext *browsing_context, | 27 NetworkLocationProvider(AccessTokenStore* access_token_store, |
| 51 const std::string16 &url, | 28 URLRequestContextGetter* context, |
| 52 const std::string16 &host_name, | 29 const GURL& url, |
| 53 const std::string16 &language); | 30 const string16& host_name); |
| 54 virtual ~NetworkLocationProvider(); | 31 virtual ~NetworkLocationProvider(); |
| 55 | 32 |
| 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 | 33 // LocationProviderBase implementation |
| 34 virtual bool StartProvider(); |
| 64 virtual void GetPosition(Position *position); | 35 virtual void GetPosition(Position *position); |
| 36 virtual void UpdatePosition(); |
| 65 | 37 |
| 66 private: | 38 private: |
| 39 // PositionCache is an implementation detail of NetworkLocationProvider. |
| 40 class PositionCache; |
| 41 |
| 42 // Satisfies a position request from cache or network. |
| 43 void RequestPosition(); |
| 44 |
| 45 // Internal helper used by DeviceDataUpdateAvailable |
| 46 void OnDeviceDataUpdated(); |
| 47 |
| 67 // DeviceDataProvider::ListenerInterface implementation. | 48 // DeviceDataProvider::ListenerInterface implementation. |
| 68 virtual void DeviceDataUpdateAvailable(RadioDataProvider *provider); | 49 virtual void DeviceDataUpdateAvailable(RadioDataProvider* provider); |
| 69 virtual void DeviceDataUpdateAvailable(WifiDataProvider *provider); | 50 virtual void DeviceDataUpdateAvailable(WifiDataProvider* provider); |
| 70 | 51 |
| 71 // NetworkLocationRequest::ListenerInterface implementation. | 52 // NetworkLocationRequest::ListenerInterface implementation. |
| 72 virtual void LocationResponseAvailable(const Position &position, | 53 virtual void LocationResponseAvailable(const Position& position, |
| 73 bool server_error, | 54 bool server_error, |
| 74 const std::string16 &access_token); | 55 const string16& access_token); |
| 75 | 56 |
| 76 // Thread implementation | 57 AccessTokenStore* access_token_store_; |
| 77 virtual void Run(); | |
| 78 | 58 |
| 79 // Internal helper used by worker thread to make a network request | 59 // The device data providers, acquired via global factories. |
| 80 bool MakeRequest(); | 60 RadioDataProvider* radio_data_provider_; |
| 81 | 61 WifiDataProvider* wifi_data_provider_; |
| 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 | 62 |
| 94 // The radio and wifi data, flags to indicate if each data set is complete, | 63 // The radio and wifi data, flags to indicate if each data set is complete, |
| 95 // and their guarding mutex. | 64 // and their guarding mutex. |
| 96 RadioData radio_data_; | 65 RadioData radio_data_; |
| 97 WifiData wifi_data_; | 66 WifiData wifi_data_; |
| 98 bool is_radio_data_complete_; | 67 bool is_radio_data_complete_; |
| 99 bool is_wifi_data_complete_; | 68 bool is_wifi_data_complete_; |
| 100 Mutex data_mutex_; | 69 Lock data_mutex_; |
| 101 | 70 |
| 102 // The timestamp for the latest device data update. | 71 // The timestamp for the latest device data update. |
| 103 int64 timestamp_; | 72 int64 device_data_updated_timestamp_; |
| 104 | 73 |
| 105 // Parameters for the network request | 74 string16 access_token_; |
| 106 bool request_address_; | |
| 107 bool request_address_from_last_request_; | |
| 108 std::string16 address_language_; | |
| 109 | 75 |
| 110 // The current best position estimate and its guarding mutex | 76 // The current best position estimate and its guarding mutex |
| 111 Position position_; | 77 Position position_; |
| 112 Mutex position_mutex_; | 78 Lock position_mutex_; |
| 113 | 79 |
| 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_; | 80 bool is_new_data_available_; |
| 121 bool is_last_request_complete_; | |
| 122 bool is_new_listener_waiting_; | |
| 123 | 81 |
| 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 | 82 |
| 130 // The earliest timestamp at which the next request can be made, in | 83 // The network location request object, and the url it uses. |
| 131 // milliseconds. | 84 scoped_ptr<NetworkLocationRequest> request_; |
| 132 int64 earliest_next_request_time_; | |
| 133 | 85 |
| 134 BrowsingContext *browsing_context_; | 86 ScopedRunnableMethodFactory<NetworkLocationProvider> delayed_start_task_; |
| 135 | |
| 136 // The cache of positions. | 87 // The cache of positions. |
| 137 scoped_ptr<PositionCache> position_cache_; | 88 scoped_ptr<PositionCache> position_cache_; |
| 138 | 89 |
| 139 DISALLOW_EVIL_CONSTRUCTORS(NetworkLocationProvider); | 90 DISALLOW_COPY_AND_ASSIGN(NetworkLocationProvider); |
| 140 }; | 91 }; |
| 141 | 92 |
| 142 #endif // if 0 | 93 #endif // CHROME_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ |
| 143 | |
| 144 #endif // GEARS_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H__ | |
| OLD | NEW |