| 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 #include "content/browser/geolocation/network_location_provider.h" | 5 #include "content/browser/geolocation/network_location_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "content/public/browser/access_token_store.h" | 10 #include "content/public/browser/access_token_store.h" |
| 11 | 11 |
| 12 using content::AccessTokenStore; | 12 using content::AccessTokenStore; |
| 13 using content::Geoposition; |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 // The maximum period of time we'll wait for a complete set of device data | 16 // The maximum period of time we'll wait for a complete set of device data |
| 16 // before sending the request. | 17 // before sending the request. |
| 17 const int kDataCompleteWaitSeconds = 2; | 18 const int kDataCompleteWaitSeconds = 2; |
| 18 } // namespace | 19 } // namespace |
| 19 | 20 |
| 20 // static | 21 // static |
| 21 const size_t NetworkLocationProvider::PositionCache::kMaximumSize = 10; | 22 const size_t NetworkLocationProvider::PositionCache::kMaximumSize = 10; |
| 22 | 23 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // NetworkLocationRequest::ListenerInterface implementation. | 172 // NetworkLocationRequest::ListenerInterface implementation. |
| 172 void NetworkLocationProvider::LocationResponseAvailable( | 173 void NetworkLocationProvider::LocationResponseAvailable( |
| 173 const Geoposition& position, | 174 const Geoposition& position, |
| 174 bool server_error, | 175 bool server_error, |
| 175 const string16& access_token, | 176 const string16& access_token, |
| 176 const RadioData& radio_data, | 177 const RadioData& radio_data, |
| 177 const WifiData& wifi_data) { | 178 const WifiData& wifi_data) { |
| 178 DCHECK(CalledOnValidThread()); | 179 DCHECK(CalledOnValidThread()); |
| 179 // Record the position and update our cache. | 180 // Record the position and update our cache. |
| 180 position_ = position; | 181 position_ = position; |
| 181 if (position.IsValidFix()) { | 182 if (position.Validate()) { |
| 182 position_cache_->CachePosition(wifi_data, position); | 183 position_cache_->CachePosition(wifi_data, position); |
| 183 } | 184 } |
| 184 | 185 |
| 185 // Record access_token if it's set. | 186 // Record access_token if it's set. |
| 186 if (!access_token.empty() && access_token_ != access_token) { | 187 if (!access_token.empty() && access_token_ != access_token) { |
| 187 access_token_ = access_token; | 188 access_token_ = access_token; |
| 188 access_token_store_->SaveAccessToken(request_->url(), access_token); | 189 access_token_store_->SaveAccessToken(request_->url(), access_token); |
| 189 } | 190 } |
| 190 | 191 |
| 191 // Let listeners know that we now have a position available. | 192 // Let listeners know that we now have a position available. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 void NetworkLocationProvider::RequestPosition() { | 237 void NetworkLocationProvider::RequestPosition() { |
| 237 DCHECK(CalledOnValidThread()); | 238 DCHECK(CalledOnValidThread()); |
| 238 if (!is_new_data_available_) | 239 if (!is_new_data_available_) |
| 239 return; | 240 return; |
| 240 | 241 |
| 241 const Geoposition* cached_position = | 242 const Geoposition* cached_position = |
| 242 position_cache_->FindPosition(wifi_data_); | 243 position_cache_->FindPosition(wifi_data_); |
| 243 DCHECK(!device_data_updated_timestamp_.is_null()) << | 244 DCHECK(!device_data_updated_timestamp_.is_null()) << |
| 244 "Timestamp must be set before looking up position"; | 245 "Timestamp must be set before looking up position"; |
| 245 if (cached_position) { | 246 if (cached_position) { |
| 246 DCHECK(cached_position->IsValidFix()); | 247 DCHECK(cached_position->Validate()); |
| 247 // Record the position and update its timestamp. | 248 // Record the position and update its timestamp. |
| 248 position_ = *cached_position; | 249 position_ = *cached_position; |
| 249 // The timestamp of a position fix is determined by the timestamp | 250 // The timestamp of a position fix is determined by the timestamp |
| 250 // of the source data update. (The value of position_.timestamp from | 251 // of the source data update. (The value of position_.timestamp from |
| 251 // the cache could be from weeks ago!) | 252 // the cache could be from weeks ago!) |
| 252 position_.timestamp = device_data_updated_timestamp_; | 253 position_.timestamp = device_data_updated_timestamp_; |
| 253 is_new_data_available_ = false; | 254 is_new_data_available_ = false; |
| 254 // Let listeners know that we now have a position available. | 255 // Let listeners know that we now have a position available. |
| 255 UpdateListeners(); | 256 UpdateListeners(); |
| 256 return; | 257 return; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 279 device_data_updated_timestamp_ = base::Time::Now(); | 280 device_data_updated_timestamp_ = base::Time::Now(); |
| 280 | 281 |
| 281 is_new_data_available_ = is_radio_data_complete_ || is_wifi_data_complete_; | 282 is_new_data_available_ = is_radio_data_complete_ || is_wifi_data_complete_; |
| 282 UpdatePosition(); | 283 UpdatePosition(); |
| 283 } | 284 } |
| 284 | 285 |
| 285 bool NetworkLocationProvider::IsStarted() const { | 286 bool NetworkLocationProvider::IsStarted() const { |
| 286 DCHECK_EQ(!!radio_data_provider_, !!wifi_data_provider_); | 287 DCHECK_EQ(!!radio_data_provider_, !!wifi_data_provider_); |
| 287 return wifi_data_provider_ != NULL; | 288 return wifi_data_provider_ != NULL; |
| 288 } | 289 } |
| OLD | NEW |