| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 // Searches for a cached position response for the current set of data. | 48 // Searches for a cached position response for the current set of data. |
| 49 // Returns NULL if the position is not in the cache, or the cached | 49 // Returns NULL if the position is not in the cache, or the cached |
| 50 // position if available. Ownership remains with the cache. | 50 // position if available. Ownership remains with the cache. |
| 51 const Geoposition* FindPosition(const WifiData& wifi_data); | 51 const Geoposition* FindPosition(const WifiData& wifi_data); |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 // Makes the key for the map of cached positions, using a set of | 54 // Makes the key for the map of cached positions, using a set of |
| 55 // data. Returns true if a good key was generated, false otherwise. | 55 // data. Returns true if a good key was generated, false otherwise. |
| 56 static bool MakeKey(const WifiData& wifi_data, | 56 static bool MakeKey(const WifiData& wifi_data, |
| 57 string16* key); | 57 base::string16* key); |
| 58 | 58 |
| 59 // The cache of positions. This is stored as a map keyed on a string that | 59 // The cache of positions. This is stored as a map keyed on a string that |
| 60 // represents a set of data, and a list to provide | 60 // represents a set of data, and a list to provide |
| 61 // least-recently-added eviction. | 61 // least-recently-added eviction. |
| 62 typedef std::map<string16, Geoposition> CacheMap; | 62 typedef std::map<base::string16, Geoposition> CacheMap; |
| 63 CacheMap cache_; | 63 CacheMap cache_; |
| 64 typedef std::list<CacheMap::iterator> CacheAgeList; | 64 typedef std::list<CacheMap::iterator> CacheAgeList; |
| 65 CacheAgeList cache_age_list_; // Oldest first. | 65 CacheAgeList cache_age_list_; // Oldest first. |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 NetworkLocationProvider(AccessTokenStore* access_token_store, | 68 NetworkLocationProvider(AccessTokenStore* access_token_store, |
| 69 net::URLRequestContextGetter* context, | 69 net::URLRequestContextGetter* context, |
| 70 const GURL& url, | 70 const GURL& url, |
| 71 const string16& access_token); | 71 const base::string16& access_token); |
| 72 virtual ~NetworkLocationProvider(); | 72 virtual ~NetworkLocationProvider(); |
| 73 | 73 |
| 74 // LocationProvider implementation | 74 // LocationProvider implementation |
| 75 virtual bool StartProvider(bool high_accuracy) OVERRIDE; | 75 virtual bool StartProvider(bool high_accuracy) OVERRIDE; |
| 76 virtual void StopProvider() OVERRIDE; | 76 virtual void StopProvider() OVERRIDE; |
| 77 virtual void GetPosition(Geoposition *position) OVERRIDE; | 77 virtual void GetPosition(Geoposition *position) OVERRIDE; |
| 78 virtual void RequestRefresh() OVERRIDE; | 78 virtual void RequestRefresh() OVERRIDE; |
| 79 virtual void OnPermissionGranted() OVERRIDE; | 79 virtual void OnPermissionGranted() OVERRIDE; |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 // Satisfies a position request from cache or network. | 82 // Satisfies a position request from cache or network. |
| 83 void RequestPosition(); | 83 void RequestPosition(); |
| 84 | 84 |
| 85 // Called from a callback when new wifi data is available. | 85 // Called from a callback when new wifi data is available. |
| 86 void WifiDataUpdateAvailable(WifiDataProvider* provider); | 86 void WifiDataUpdateAvailable(WifiDataProvider* provider); |
| 87 | 87 |
| 88 // Internal helper used by WifiDataUpdateAvailable. | 88 // Internal helper used by WifiDataUpdateAvailable. |
| 89 void OnWifiDataUpdated(); | 89 void OnWifiDataUpdated(); |
| 90 | 90 |
| 91 bool IsStarted() const; | 91 bool IsStarted() const; |
| 92 | 92 |
| 93 void LocationResponseAvailable(const Geoposition& position, | 93 void LocationResponseAvailable(const Geoposition& position, |
| 94 bool server_error, | 94 bool server_error, |
| 95 const string16& access_token, | 95 const base::string16& access_token, |
| 96 const WifiData& wifi_data); | 96 const WifiData& wifi_data); |
| 97 | 97 |
| 98 scoped_refptr<AccessTokenStore> access_token_store_; | 98 scoped_refptr<AccessTokenStore> access_token_store_; |
| 99 | 99 |
| 100 // The wifi data provider, acquired via global factories. | 100 // The wifi data provider, acquired via global factories. |
| 101 WifiDataProvider* wifi_data_provider_; | 101 WifiDataProvider* wifi_data_provider_; |
| 102 | 102 |
| 103 WifiDataProvider::WifiDataUpdateCallback wifi_data_update_callback_; | 103 WifiDataProvider::WifiDataUpdateCallback wifi_data_update_callback_; |
| 104 | 104 |
| 105 // The wifi data and a flag to indicate if the data set is complete. | 105 // The wifi data and a flag to indicate if the data set is complete. |
| 106 WifiData wifi_data_; | 106 WifiData wifi_data_; |
| 107 bool is_wifi_data_complete_; | 107 bool is_wifi_data_complete_; |
| 108 | 108 |
| 109 // The timestamp for the latest wifi data update. | 109 // The timestamp for the latest wifi data update. |
| 110 base::Time wifi_data_updated_timestamp_; | 110 base::Time wifi_data_updated_timestamp_; |
| 111 | 111 |
| 112 // Cached value loaded from the token store or set by a previous server | 112 // Cached value loaded from the token store or set by a previous server |
| 113 // response, and sent in each subsequent network request. | 113 // response, and sent in each subsequent network request. |
| 114 string16 access_token_; | 114 base::string16 access_token_; |
| 115 | 115 |
| 116 // The current best position estimate. | 116 // The current best position estimate. |
| 117 Geoposition position_; | 117 Geoposition position_; |
| 118 | 118 |
| 119 // Whether permission has been granted for the provider to operate. | 119 // Whether permission has been granted for the provider to operate. |
| 120 bool is_permission_granted_; | 120 bool is_permission_granted_; |
| 121 | 121 |
| 122 bool is_new_data_available_; | 122 bool is_new_data_available_; |
| 123 | 123 |
| 124 // The network location request object, and the url it uses. | 124 // The network location request object, and the url it uses. |
| 125 scoped_ptr<NetworkLocationRequest> request_; | 125 scoped_ptr<NetworkLocationRequest> request_; |
| 126 | 126 |
| 127 // The cache of positions. | 127 // The cache of positions. |
| 128 scoped_ptr<PositionCache> position_cache_; | 128 scoped_ptr<PositionCache> position_cache_; |
| 129 | 129 |
| 130 base::WeakPtrFactory<NetworkLocationProvider> weak_factory_; | 130 base::WeakPtrFactory<NetworkLocationProvider> weak_factory_; |
| 131 | 131 |
| 132 DISALLOW_COPY_AND_ASSIGN(NetworkLocationProvider); | 132 DISALLOW_COPY_AND_ASSIGN(NetworkLocationProvider); |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 // Factory functions for the various types of location provider to abstract | 135 // Factory functions for the various types of location provider to abstract |
| 136 // over the platform-dependent implementations. | 136 // over the platform-dependent implementations. |
| 137 CONTENT_EXPORT LocationProviderBase* NewNetworkLocationProvider( | 137 CONTENT_EXPORT LocationProviderBase* NewNetworkLocationProvider( |
| 138 AccessTokenStore* access_token_store, | 138 AccessTokenStore* access_token_store, |
| 139 net::URLRequestContextGetter* context, | 139 net::URLRequestContextGetter* context, |
| 140 const GURL& url, | 140 const GURL& url, |
| 141 const string16& access_token); | 141 const base::string16& access_token); |
| 142 | 142 |
| 143 } // namespace content | 143 } // namespace content |
| 144 | 144 |
| 145 #endif // CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ | 145 #endif // CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ |
| OLD | NEW |