| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ | 5 #ifndef CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ |
| 6 #define CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ | 6 #define CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "content/browser/geolocation/device_data_provider.h" | 18 #include "content/browser/geolocation/device_data_provider.h" |
| 19 #include "content/browser/geolocation/location_provider.h" | 19 #include "content/browser/geolocation/location_provider.h" |
| 20 #include "content/browser/geolocation/network_location_request.h" | 20 #include "content/browser/geolocation/network_location_request.h" |
| 21 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
| 22 #include "content/common/geoposition.h" | 22 #include "content/common/geoposition.h" |
| 23 | 23 |
| 24 namespace content { |
| 25 class AccessTokenStore; |
| 26 } |
| 27 |
| 24 class NetworkLocationProvider | 28 class NetworkLocationProvider |
| 25 : public LocationProviderBase, | 29 : public LocationProviderBase, |
| 26 public RadioDataProvider::ListenerInterface, | 30 public RadioDataProvider::ListenerInterface, |
| 27 public WifiDataProvider::ListenerInterface, | 31 public WifiDataProvider::ListenerInterface, |
| 28 public NetworkLocationRequest::ListenerInterface { | 32 public NetworkLocationRequest::ListenerInterface { |
| 29 public: | 33 public: |
| 30 // Cache of recently resolved locations. Public for tests. | 34 // Cache of recently resolved locations. Public for tests. |
| 31 class CONTENT_EXPORT PositionCache { | 35 class CONTENT_EXPORT PositionCache { |
| 32 public: | 36 public: |
| 33 // The maximum size of the cache of positions for previously requested | 37 // The maximum size of the cache of positions for previously requested |
| (...skipping 23 matching lines...) Expand all Loading... |
| 57 | 61 |
| 58 // The cache of positions. This is stored as a map keyed on a string that | 62 // The cache of positions. This is stored as a map keyed on a string that |
| 59 // represents a set of device data, and a list to provide | 63 // represents a set of device data, and a list to provide |
| 60 // least-recently-added eviction. | 64 // least-recently-added eviction. |
| 61 typedef std::map<string16, Geoposition> CacheMap; | 65 typedef std::map<string16, Geoposition> CacheMap; |
| 62 CacheMap cache_; | 66 CacheMap cache_; |
| 63 typedef std::list<CacheMap::iterator> CacheAgeList; | 67 typedef std::list<CacheMap::iterator> CacheAgeList; |
| 64 CacheAgeList cache_age_list_; // Oldest first. | 68 CacheAgeList cache_age_list_; // Oldest first. |
| 65 }; | 69 }; |
| 66 | 70 |
| 67 NetworkLocationProvider(AccessTokenStore* access_token_store, | 71 NetworkLocationProvider(content::AccessTokenStore* access_token_store, |
| 68 net::URLRequestContextGetter* context, | 72 net::URLRequestContextGetter* context, |
| 69 const GURL& url, | 73 const GURL& url, |
| 70 const string16& access_token); | 74 const string16& access_token); |
| 71 virtual ~NetworkLocationProvider(); | 75 virtual ~NetworkLocationProvider(); |
| 72 | 76 |
| 73 // LocationProviderBase implementation | 77 // LocationProviderBase implementation |
| 74 virtual bool StartProvider(bool high_accuracy) OVERRIDE; | 78 virtual bool StartProvider(bool high_accuracy) OVERRIDE; |
| 75 virtual void StopProvider() OVERRIDE; | 79 virtual void StopProvider() OVERRIDE; |
| 76 virtual void GetPosition(Geoposition *position) OVERRIDE; | 80 virtual void GetPosition(Geoposition *position) OVERRIDE; |
| 77 virtual void UpdatePosition() OVERRIDE; | 81 virtual void UpdatePosition() OVERRIDE; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 90 virtual void DeviceDataUpdateAvailable(RadioDataProvider* provider) OVERRIDE; | 94 virtual void DeviceDataUpdateAvailable(RadioDataProvider* provider) OVERRIDE; |
| 91 virtual void DeviceDataUpdateAvailable(WifiDataProvider* provider) OVERRIDE; | 95 virtual void DeviceDataUpdateAvailable(WifiDataProvider* provider) OVERRIDE; |
| 92 | 96 |
| 93 // NetworkLocationRequest::ListenerInterface implementation. | 97 // NetworkLocationRequest::ListenerInterface implementation. |
| 94 virtual void LocationResponseAvailable(const Geoposition& position, | 98 virtual void LocationResponseAvailable(const Geoposition& position, |
| 95 bool server_error, | 99 bool server_error, |
| 96 const string16& access_token, | 100 const string16& access_token, |
| 97 const RadioData& radio_data, | 101 const RadioData& radio_data, |
| 98 const WifiData& wifi_data) OVERRIDE; | 102 const WifiData& wifi_data) OVERRIDE; |
| 99 | 103 |
| 100 scoped_refptr<AccessTokenStore> access_token_store_; | 104 scoped_refptr<content::AccessTokenStore> access_token_store_; |
| 101 | 105 |
| 102 // The device data providers, acquired via global factories. | 106 // The device data providers, acquired via global factories. |
| 103 RadioDataProvider* radio_data_provider_; | 107 RadioDataProvider* radio_data_provider_; |
| 104 WifiDataProvider* wifi_data_provider_; | 108 WifiDataProvider* wifi_data_provider_; |
| 105 | 109 |
| 106 // The radio and wifi data, flags to indicate if each data set is complete. | 110 // The radio and wifi data, flags to indicate if each data set is complete. |
| 107 RadioData radio_data_; | 111 RadioData radio_data_; |
| 108 WifiData wifi_data_; | 112 WifiData wifi_data_; |
| 109 bool is_radio_data_complete_; | 113 bool is_radio_data_complete_; |
| 110 bool is_wifi_data_complete_; | 114 bool is_wifi_data_complete_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 127 scoped_ptr<NetworkLocationRequest> request_; | 131 scoped_ptr<NetworkLocationRequest> request_; |
| 128 | 132 |
| 129 base::WeakPtrFactory<NetworkLocationProvider> weak_factory_; | 133 base::WeakPtrFactory<NetworkLocationProvider> weak_factory_; |
| 130 // The cache of positions. | 134 // The cache of positions. |
| 131 scoped_ptr<PositionCache> position_cache_; | 135 scoped_ptr<PositionCache> position_cache_; |
| 132 | 136 |
| 133 DISALLOW_COPY_AND_ASSIGN(NetworkLocationProvider); | 137 DISALLOW_COPY_AND_ASSIGN(NetworkLocationProvider); |
| 134 }; | 138 }; |
| 135 | 139 |
| 136 #endif // CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ | 140 #endif // CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ |
| OLD | NEW |