| Index: device/geolocation/network_location_provider.cc
|
| diff --git a/device/geolocation/network_location_provider.cc b/device/geolocation/network_location_provider.cc
|
| index 64bb9d9213010a65607900c99eb04b6cd6fceeaa..282a7f6c9f7ed87124fd24b08de13673f68ffe70 100644
|
| --- a/device/geolocation/network_location_provider.cc
|
| +++ b/device/geolocation/network_location_provider.cc
|
| @@ -150,6 +150,15 @@ void NetworkLocationProvider::OnPermissionGranted() {
|
| void NetworkLocationProvider::OnWifiDataUpdate() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK(IsStarted());
|
| +
|
| + if (!high_accuracy_enabled_) {
|
| + // This should never be called if this provider was started with low
|
| + // accuracy.
|
| + NOTREACHED();
|
| + wifi_data_.access_point_data.clear();
|
| + return;
|
| + }
|
| +
|
| is_wifi_data_complete_ = wifi_data_provider_manager_->GetData(&wifi_data_);
|
| if (!is_wifi_data_complete_)
|
| return;
|
| @@ -188,6 +197,14 @@ bool NetworkLocationProvider::StartProvider(bool high_accuracy) {
|
| if (!request_->url().is_valid())
|
| return false;
|
|
|
| + is_started_ = true;
|
| + high_accuracy_enabled_ = high_accuracy;
|
| +
|
| + if (!high_accuracy_enabled_) {
|
| + RequestPosition();
|
| + return true;
|
| + }
|
| +
|
| // Registers a callback with the data provider. The first call to Register()
|
| // will create a singleton data provider that will be deleted on Unregister().
|
| wifi_data_provider_manager_ =
|
| @@ -205,9 +222,12 @@ bool NetworkLocationProvider::StartProvider(bool high_accuracy) {
|
| void NetworkLocationProvider::StopProvider() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK(IsStarted());
|
| - wifi_data_provider_manager_->Unregister(&wifi_data_update_callback_);
|
| - wifi_data_provider_manager_ = nullptr;
|
| + if (high_accuracy_enabled_) {
|
| + wifi_data_provider_manager_->Unregister(&wifi_data_update_callback_);
|
| + wifi_data_provider_manager_ = nullptr;
|
| + }
|
| weak_factory_.InvalidateWeakPtrs();
|
| + is_started_ = false;
|
| }
|
|
|
| const Geoposition& NetworkLocationProvider::GetPosition() {
|
| @@ -217,10 +237,16 @@ const Geoposition& NetworkLocationProvider::GetPosition() {
|
| void NetworkLocationProvider::RequestPosition() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| - if (!is_new_data_available_ || !is_wifi_data_complete_)
|
| - return;
|
| - DCHECK(!wifi_timestamp_.is_null())
|
| - << "|wifi_timestamp_| must be set before looking up position";
|
| + if (high_accuracy_enabled_) {
|
| + if (!is_new_data_available_ || !is_wifi_data_complete_)
|
| + return;
|
| +
|
| + DCHECK(!wifi_timestamp_.is_null())
|
| + << "|wifi_timestamp_| must be set before looking up position";
|
| + } else {
|
| + wifi_timestamp_ = base::Time::Now();
|
| + wifi_data_.access_point_data.clear();
|
| + }
|
|
|
| const Geoposition* cached_position =
|
| position_cache_->FindPosition(wifi_data_);
|
| @@ -257,7 +283,7 @@ void NetworkLocationProvider::RequestPosition() {
|
| }
|
|
|
| bool NetworkLocationProvider::IsStarted() const {
|
| - return wifi_data_provider_manager_ != nullptr;
|
| + return is_started_;
|
| }
|
|
|
| } // namespace device
|
|
|