| 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 #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 | 13 |
| 14 namespace { | 14 namespace { |
| 15 // The maximum period of time we'll wait for a complete set of device data | 15 // The maximum period of time we'll wait for a complete set of device data |
| 16 // before sending the request. | 16 // before sending the request. |
| 17 const int kDataCompleteWaitPeriod = 1000 * 2; // 2 seconds | 17 const int kDataCompleteWaitSeconds = 2; |
| 18 } // namespace | 18 } // namespace |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 const size_t NetworkLocationProvider::PositionCache::kMaximumSize = 10; | 21 const size_t NetworkLocationProvider::PositionCache::kMaximumSize = 10; |
| 22 | 22 |
| 23 NetworkLocationProvider::PositionCache::PositionCache() {} | 23 NetworkLocationProvider::PositionCache::PositionCache() {} |
| 24 | 24 |
| 25 NetworkLocationProvider::PositionCache::~PositionCache() {} | 25 NetworkLocationProvider::PositionCache::~PositionCache() {} |
| 26 | 26 |
| 27 bool NetworkLocationProvider::PositionCache::CachePosition( | 27 bool NetworkLocationProvider::PositionCache::CachePosition( |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 206 |
| 207 // Get the device data providers. The first call to Register will create the | 207 // Get the device data providers. The first call to Register will create the |
| 208 // provider and it will be deleted by ref counting. | 208 // provider and it will be deleted by ref counting. |
| 209 radio_data_provider_ = RadioDataProvider::Register(this); | 209 radio_data_provider_ = RadioDataProvider::Register(this); |
| 210 wifi_data_provider_ = WifiDataProvider::Register(this); | 210 wifi_data_provider_ = WifiDataProvider::Register(this); |
| 211 | 211 |
| 212 MessageLoop::current()->PostDelayedTask( | 212 MessageLoop::current()->PostDelayedTask( |
| 213 FROM_HERE, | 213 FROM_HERE, |
| 214 base::Bind(&NetworkLocationProvider::RequestPosition, | 214 base::Bind(&NetworkLocationProvider::RequestPosition, |
| 215 weak_factory_.GetWeakPtr()), | 215 weak_factory_.GetWeakPtr()), |
| 216 kDataCompleteWaitPeriod); | 216 base::TimeDelta::FromSeconds(kDataCompleteWaitSeconds)); |
| 217 // Get the device data. | 217 // Get the device data. |
| 218 is_radio_data_complete_ = radio_data_provider_->GetData(&radio_data_); | 218 is_radio_data_complete_ = radio_data_provider_->GetData(&radio_data_); |
| 219 is_wifi_data_complete_ = wifi_data_provider_->GetData(&wifi_data_); | 219 is_wifi_data_complete_ = wifi_data_provider_->GetData(&wifi_data_); |
| 220 if (is_radio_data_complete_ || is_wifi_data_complete_) | 220 if (is_radio_data_complete_ || is_wifi_data_complete_) |
| 221 OnDeviceDataUpdated(); | 221 OnDeviceDataUpdated(); |
| 222 return true; | 222 return true; |
| 223 } | 223 } |
| 224 | 224 |
| 225 void NetworkLocationProvider::StopProvider() { | 225 void NetworkLocationProvider::StopProvider() { |
| 226 DCHECK(CalledOnValidThread()); | 226 DCHECK(CalledOnValidThread()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 device_data_updated_timestamp_ = base::Time::Now(); | 283 device_data_updated_timestamp_ = base::Time::Now(); |
| 284 | 284 |
| 285 is_new_data_available_ = is_radio_data_complete_ || is_wifi_data_complete_; | 285 is_new_data_available_ = is_radio_data_complete_ || is_wifi_data_complete_; |
| 286 UpdatePosition(); | 286 UpdatePosition(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 bool NetworkLocationProvider::IsStarted() const { | 289 bool NetworkLocationProvider::IsStarted() const { |
| 290 DCHECK_EQ(!!radio_data_provider_, !!wifi_data_provider_); | 290 DCHECK_EQ(!!radio_data_provider_, !!wifi_data_provider_); |
| 291 return wifi_data_provider_ != NULL; | 291 return wifi_data_provider_ != NULL; |
| 292 } | 292 } |
| OLD | NEW |