Chromium Code Reviews| 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 #include <memory> | |
| 9 #include <utility> | |
| 8 | 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 11 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 13 #include "device/geolocation/access_token_store.h" | 15 #include "device/geolocation/access_token_store.h" |
| 14 #include "device/geolocation/geolocation_delegate.h" | 16 #include "device/geolocation/geolocation_delegate.h" |
| 15 #include "device/geolocation/network_location_provider.h" | 17 #include "device/geolocation/network_location_provider.h" |
| 16 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 17 | 19 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 44 GURL LocationArbitratorImpl::DefaultNetworkProviderURL() { | 46 GURL LocationArbitratorImpl::DefaultNetworkProviderURL() { |
| 45 return GURL(kDefaultNetworkProviderUrl); | 47 return GURL(kDefaultNetworkProviderUrl); |
| 46 } | 48 } |
| 47 | 49 |
| 48 void LocationArbitratorImpl::OnPermissionGranted() { | 50 void LocationArbitratorImpl::OnPermissionGranted() { |
| 49 is_permission_granted_ = true; | 51 is_permission_granted_ = true; |
| 50 for (const auto& provider : providers_) | 52 for (const auto& provider : providers_) |
| 51 provider->OnPermissionGranted(); | 53 provider->OnPermissionGranted(); |
| 52 } | 54 } |
| 53 | 55 |
| 54 void LocationArbitratorImpl::StartProviders(bool enable_high_accuracy) { | 56 bool LocationArbitratorImpl::StartProvider(bool enable_high_accuracy) { |
| 55 // Stash options as OnAccessTokenStoresLoaded has not yet been called. | 57 // Stash options as OnAccessTokenStoresLoaded has not yet been called. |
| 56 is_running_ = true; | 58 is_running_ = true; |
| 57 enable_high_accuracy_ = enable_high_accuracy; | 59 enable_high_accuracy_ = enable_high_accuracy; |
| 58 | 60 |
| 59 if (providers_.empty()) { | 61 if (providers_.empty()) { |
| 60 RegisterSystemProvider(); | 62 RegisterSystemProvider(); |
| 61 | 63 |
| 62 const scoped_refptr<AccessTokenStore> access_token_store = | 64 const scoped_refptr<AccessTokenStore> access_token_store = |
| 63 GetAccessTokenStore(); | 65 GetAccessTokenStore(); |
| 64 if (access_token_store && delegate_->UseNetworkLocationProviders()) { | 66 if (access_token_store && delegate_->UseNetworkLocationProviders()) { |
| 65 DCHECK(DefaultNetworkProviderURL().is_valid()); | 67 DCHECK(DefaultNetworkProviderURL().is_valid()); |
| 66 token_store_callback_.Reset( | 68 token_store_callback_.Reset( |
| 67 base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded, | 69 base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded, |
| 68 base::Unretained(this))); | 70 base::Unretained(this))); |
| 69 access_token_store->LoadAccessTokens(token_store_callback_.callback()); | 71 access_token_store->LoadAccessTokens(token_store_callback_.callback()); |
| 70 return; | 72 return true; |
| 71 } | 73 } |
| 72 } | 74 } |
| 73 DoStartProviders(); | 75 return DoStartProviders(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 void LocationArbitratorImpl::DoStartProviders() { | 78 bool LocationArbitratorImpl::DoStartProviders() { |
| 77 if (providers_.empty()) { | 79 if (providers_.empty()) { |
| 78 // If no providers are available, we report an error to avoid | 80 // If no providers are available, we report an error to avoid |
| 79 // callers waiting indefinitely for a reply. | 81 // callers waiting indefinitely for a reply. |
| 80 Geoposition position; | 82 Geoposition position; |
| 81 position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED; | 83 position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED; |
| 82 arbitrator_update_callback_.Run(position); | 84 arbitrator_update_callback_.Run(position); |
| 83 return; | 85 return false; |
| 84 } | 86 } |
| 87 bool started = true; | |
| 85 for (const auto& provider : providers_) | 88 for (const auto& provider : providers_) |
| 86 provider->StartProvider(enable_high_accuracy_); | 89 started = true && provider->StartProvider(enable_high_accuracy_); |
|
Kevin M
2016/08/15 21:34:54
"true &&" is a no-op ;) I think you mean "started
CJ
2016/08/15 23:09:52
Done.
| |
| 90 return started; | |
| 87 } | 91 } |
| 88 | 92 |
| 89 void LocationArbitratorImpl::StopProviders() { | 93 void LocationArbitratorImpl::StopProvider() { |
| 90 // Reset the reference location state (provider+position) | 94 // Reset the reference location state (provider+position) |
| 91 // so that future starts use fresh locations from | 95 // so that future starts use fresh locations from |
| 92 // the newly constructed providers. | 96 // the newly constructed providers. |
| 93 position_provider_ = nullptr; | 97 position_provider_ = nullptr; |
| 94 position_ = Geoposition(); | 98 position_ = Geoposition(); |
| 95 | 99 |
| 96 providers_.clear(); | 100 providers_.clear(); |
| 97 is_running_ = false; | 101 is_running_ = false; |
| 98 } | 102 } |
| 99 | 103 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 DCHECK(new_position.Validate() || | 137 DCHECK(new_position.Validate() || |
| 134 new_position.error_code != Geoposition::ERROR_CODE_NONE); | 138 new_position.error_code != Geoposition::ERROR_CODE_NONE); |
| 135 if (!IsNewPositionBetter(position_, new_position, | 139 if (!IsNewPositionBetter(position_, new_position, |
| 136 provider == position_provider_)) | 140 provider == position_provider_)) |
| 137 return; | 141 return; |
| 138 position_provider_ = provider; | 142 position_provider_ = provider; |
| 139 position_ = new_position; | 143 position_ = new_position; |
| 140 arbitrator_update_callback_.Run(position_); | 144 arbitrator_update_callback_.Run(position_); |
| 141 } | 145 } |
| 142 | 146 |
| 147 const Geoposition& LocationArbitratorImpl::GetPosition() { | |
| 148 return position_; | |
| 149 } | |
| 150 | |
| 151 void LocationArbitratorImpl::SetUpdateCallback( | |
| 152 const LocationProviderUpdateCallback& callback) { | |
| 153 DCHECK(!callback.is_null()); | |
| 154 provider_update_callback_ = callback; | |
| 155 } | |
| 156 | |
| 143 scoped_refptr<AccessTokenStore> LocationArbitratorImpl::NewAccessTokenStore() { | 157 scoped_refptr<AccessTokenStore> LocationArbitratorImpl::NewAccessTokenStore() { |
| 144 return delegate_->CreateAccessTokenStore(); | 158 return delegate_->CreateAccessTokenStore(); |
| 145 } | 159 } |
| 146 | 160 |
| 147 scoped_refptr<AccessTokenStore> LocationArbitratorImpl::GetAccessTokenStore() { | 161 scoped_refptr<AccessTokenStore> LocationArbitratorImpl::GetAccessTokenStore() { |
| 148 if (!access_token_store_) | 162 if (!access_token_store_) |
| 149 access_token_store_ = NewAccessTokenStore(); | 163 access_token_store_ = NewAccessTokenStore(); |
| 150 return access_token_store_; | 164 return access_token_store_; |
| 151 } | 165 } |
| 152 | 166 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 return true; | 212 return true; |
| 199 } else if ((GetTimeNow() - old_position.timestamp).InMilliseconds() > | 213 } else if ((GetTimeNow() - old_position.timestamp).InMilliseconds() > |
| 200 kFixStaleTimeoutMilliseconds) { | 214 kFixStaleTimeoutMilliseconds) { |
| 201 // Existing fix is stale. | 215 // Existing fix is stale. |
| 202 return true; | 216 return true; |
| 203 } | 217 } |
| 204 } | 218 } |
| 205 return false; | 219 return false; |
| 206 } | 220 } |
| 207 | 221 |
| 208 bool LocationArbitratorImpl::HasPermissionBeenGranted() const { | 222 bool LocationArbitratorImpl::HasPermissionBeenGrantedForTest() const { |
| 209 return is_permission_granted_; | 223 return is_permission_granted_; |
| 210 } | 224 } |
| 211 | 225 |
| 212 } // namespace device | 226 } // namespace device |
| OLD | NEW |