Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1003)

Unified Diff: content/browser/geolocation/location_arbitrator_impl.cc

Issue 2028823002: Refactor to make BlimpLocationProvider accessible to content layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses kmarshall's #63 comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/geolocation/location_arbitrator_impl.cc
diff --git a/content/browser/geolocation/location_arbitrator_impl.cc b/content/browser/geolocation/location_arbitrator_impl.cc
index d6cb78b1657aa34b3567a864563d71f8477ceffb..75a27973e229ba2bee67bacdbc4cc64bc720f672 100644
--- a/content/browser/geolocation/location_arbitrator_impl.cc
+++ b/content/browser/geolocation/location_arbitrator_impl.cc
@@ -52,31 +52,37 @@ void LocationArbitratorImpl::OnPermissionGranted() {
}
void LocationArbitratorImpl::StartProviders(bool enable_high_accuracy) {
- // GetAccessTokenStore() will return NULL for embedders not implementing
- // the AccessTokenStore class, so we report an error to avoid JavaScript
- // requests of location to wait eternally for a reply.
- AccessTokenStore* access_token_store = GetAccessTokenStore();
- if (!access_token_store) {
- Geoposition position;
- position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED;
- arbitrator_update_callback_.Run(position);
- return;
- }
-
// Stash options as OnAccessTokenStoresLoaded has not yet been called.
is_running_ = true;
enable_high_accuracy_ = enable_high_accuracy;
+
if (providers_.empty()) {
- DCHECK(DefaultNetworkProviderURL().is_valid());
- access_token_store->LoadAccessTokens(
- base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded,
- base::Unretained(this)));
- } else {
- DoStartProviders();
+ RegisterSystemProvider();
+
+ AccessTokenStore* access_token_store = GetAccessTokenStore();
+ if (access_token_store &&
+ GetContentClient()->browser()->UseNetworkLocationProviders()) {
+ DCHECK(DefaultNetworkProviderURL().is_valid());
+ token_store_callback_.Reset(
+ base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded,
+ base::Unretained(this)));
+ access_token_store->LoadAccessTokens(token_store_callback_.callback());
+ return;
+ }
}
+ DoStartProviders();
}
void LocationArbitratorImpl::DoStartProviders() {
+ if (providers_.empty()) {
+ // GetAccessTokenStore() will return NULL for embedders not implementing
+ // the AccessTokenStore class, so we report an error to avoid JavaScript
+ // requests of location to wait eternally for a reply.
+ Geoposition position;
+ position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED;
+ arbitrator_update_callback_.Run(position);
+ return;
+ }
for (const auto& provider : providers_)
provider->StartProvider(enable_high_accuracy_);
}
@@ -95,11 +101,6 @@ void LocationArbitratorImpl::StopProviders() {
void LocationArbitratorImpl::OnAccessTokenStoresLoaded(
AccessTokenStore::AccessTokenMap access_token_map,
net::URLRequestContextGetter* context_getter) {
- if (!is_running_ || !providers_.empty()) {
- // A second StartProviders() call may have arrived before the first
- // completed.
- return;
- }
// If there are no access tokens, boot strap it with the default server URL.
if (access_token_map.empty())
access_token_map[DefaultNetworkProviderURL()];
@@ -107,12 +108,6 @@ void LocationArbitratorImpl::OnAccessTokenStoresLoaded(
RegisterProvider(NewNetworkLocationProvider(
GetAccessTokenStore(), context_getter, entry.first, entry.second));
}
-
- LocationProvider* provider =
- GetContentClient()->browser()->OverrideSystemLocationProvider();
- if (!provider)
- provider = NewSystemLocationProvider();
- RegisterProvider(provider);
DoStartProviders();
}
@@ -126,6 +121,14 @@ void LocationArbitratorImpl::RegisterProvider(
providers_.push_back(provider);
}
+void LocationArbitratorImpl::RegisterSystemProvider() {
+ LocationProvider* provider =
+ GetContentClient()->browser()->OverrideSystemLocationProvider();
+ if (!provider)
+ provider = NewSystemLocationProvider();
+ RegisterProvider(provider);
+}
+
void LocationArbitratorImpl::OnLocationUpdate(const LocationProvider* provider,
const Geoposition& new_position) {
DCHECK(new_position.Validate() ||

Powered by Google App Engine
This is Rietveld 408576698