| 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 "device/geolocation/location_arbitrator_impl.h" | 5 #include "device/geolocation/location_arbitrator_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 GeolocationDelegate* delegate) | 32 GeolocationDelegate* delegate) |
| 33 : delegate_(delegate), | 33 : delegate_(delegate), |
| 34 arbitrator_update_callback_(callback), | 34 arbitrator_update_callback_(callback), |
| 35 provider_update_callback_( | 35 provider_update_callback_( |
| 36 base::Bind(&LocationArbitratorImpl::OnLocationUpdate, | 36 base::Bind(&LocationArbitratorImpl::OnLocationUpdate, |
| 37 base::Unretained(this))), | 37 base::Unretained(this))), |
| 38 position_provider_(nullptr), | 38 position_provider_(nullptr), |
| 39 is_permission_granted_(false), | 39 is_permission_granted_(false), |
| 40 is_running_(false) {} | 40 is_running_(false) {} |
| 41 | 41 |
| 42 LocationArbitratorImpl::~LocationArbitratorImpl() { | 42 LocationArbitratorImpl::~LocationArbitratorImpl() {} |
| 43 } | |
| 44 | 43 |
| 45 GURL LocationArbitratorImpl::DefaultNetworkProviderURL() { | 44 GURL LocationArbitratorImpl::DefaultNetworkProviderURL() { |
| 46 return GURL(kDefaultNetworkProviderUrl); | 45 return GURL(kDefaultNetworkProviderUrl); |
| 47 } | 46 } |
| 48 | 47 |
| 49 void LocationArbitratorImpl::OnPermissionGranted() { | 48 void LocationArbitratorImpl::OnPermissionGranted() { |
| 50 is_permission_granted_ = true; | 49 is_permission_granted_ = true; |
| 51 for (const auto& provider : providers_) | 50 for (const auto& provider : providers_) |
| 52 provider->OnPermissionGranted(); | 51 provider->OnPermissionGranted(); |
| 53 } | 52 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 #else | 172 #else |
| 174 return device::NewSystemLocationProvider(); | 173 return device::NewSystemLocationProvider(); |
| 175 #endif | 174 #endif |
| 176 } | 175 } |
| 177 | 176 |
| 178 base::Time LocationArbitratorImpl::GetTimeNow() const { | 177 base::Time LocationArbitratorImpl::GetTimeNow() const { |
| 179 return base::Time::Now(); | 178 return base::Time::Now(); |
| 180 } | 179 } |
| 181 | 180 |
| 182 bool LocationArbitratorImpl::IsNewPositionBetter( | 181 bool LocationArbitratorImpl::IsNewPositionBetter( |
| 183 const Geoposition& old_position, const Geoposition& new_position, | 182 const Geoposition& old_position, |
| 183 const Geoposition& new_position, |
| 184 bool from_same_provider) const { | 184 bool from_same_provider) const { |
| 185 // Updates location_info if it's better than what we currently have, | 185 // Updates location_info if it's better than what we currently have, |
| 186 // or if it's a newer update from the same provider. | 186 // or if it's a newer update from the same provider. |
| 187 if (!old_position.Validate()) { | 187 if (!old_position.Validate()) { |
| 188 // Older location wasn't locked. | 188 // Older location wasn't locked. |
| 189 return true; | 189 return true; |
| 190 } | 190 } |
| 191 if (new_position.Validate()) { | 191 if (new_position.Validate()) { |
| 192 // New location is locked, let's check if it's any better. | 192 // New location is locked, let's check if it's any better. |
| 193 if (old_position.accuracy >= new_position.accuracy) { | 193 if (old_position.accuracy >= new_position.accuracy) { |
| 194 // Accuracy is better. | 194 // Accuracy is better. |
| 195 return true; | 195 return true; |
| 196 } else if (from_same_provider) { | 196 } else if (from_same_provider) { |
| 197 // Same provider, fresher location. | 197 // Same provider, fresher location. |
| 198 return true; | 198 return true; |
| 199 } else if ((GetTimeNow() - old_position.timestamp).InMilliseconds() > | 199 } else if ((GetTimeNow() - old_position.timestamp).InMilliseconds() > |
| 200 kFixStaleTimeoutMilliseconds) { | 200 kFixStaleTimeoutMilliseconds) { |
| 201 // Existing fix is stale. | 201 // Existing fix is stale. |
| 202 return true; | 202 return true; |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 return false; | 205 return false; |
| 206 } | 206 } |
| 207 | 207 |
| 208 bool LocationArbitratorImpl::HasPermissionBeenGranted() const { | 208 bool LocationArbitratorImpl::HasPermissionBeenGranted() const { |
| 209 return is_permission_granted_; | 209 return is_permission_granted_; |
| 210 } | 210 } |
| 211 | 211 |
| 212 } // namespace device | 212 } // namespace device |
| OLD | NEW |