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 "content/browser/geolocation/location_arbitrator_impl.h" | 5 #include "content/browser/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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 return GURL(kDefaultNetworkProviderUrl); | 45 return GURL(kDefaultNetworkProviderUrl); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void LocationArbitratorImpl::OnPermissionGranted() { | 48 void LocationArbitratorImpl::OnPermissionGranted() { |
| 49 is_permission_granted_ = true; | 49 is_permission_granted_ = true; |
| 50 for (const auto& provider : providers_) | 50 for (const auto& provider : providers_) |
| 51 provider->OnPermissionGranted(); | 51 provider->OnPermissionGranted(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void LocationArbitratorImpl::StartProviders(bool enable_high_accuracy) { | 54 void LocationArbitratorImpl::StartProviders(bool enable_high_accuracy) { |
| 55 // GetAccessTokenStore() will return NULL for embedders not implementing | 55 // GetAccessTokenStore() will return NULL for embedders not implementing |
|
Michael van Ouwerkerk
2016/06/02 10:04:32
Keep this comment with the code it documents.
CJ
2016/06/02 22:12:05
Done.
| |
| 56 // the AccessTokenStore class, so we report an error to avoid JavaScript | 56 // the AccessTokenStore class, so we report an error to avoid JavaScript |
| 57 // requests of location to wait eternally for a reply. | 57 // requests of location to wait eternally for a reply. |
| 58 AccessTokenStore* access_token_store = GetAccessTokenStore(); | |
| 59 if (!access_token_store) { | |
| 60 Geoposition position; | |
| 61 position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED; | |
| 62 arbitrator_update_callback_.Run(position); | |
| 63 return; | |
| 64 } | |
| 65 | 58 |
| 66 // Stash options as OnAccessTokenStoresLoaded has not yet been called. | 59 // Stash options as OnAccessTokenStoresLoaded has not yet been called. |
| 67 is_running_ = true; | 60 is_running_ = true; |
| 68 enable_high_accuracy_ = enable_high_accuracy; | 61 enable_high_accuracy_ = enable_high_accuracy; |
| 62 | |
| 69 if (providers_.empty()) { | 63 if (providers_.empty()) { |
| 70 DCHECK(DefaultNetworkProviderURL().is_valid()); | 64 if (GetContentClient()->browser()->UseNetworkLocationProviders()) { |
| 71 access_token_store->LoadAccessTokens( | 65 AccessTokenStore* access_token_store = GetAccessTokenStore(); |
| 72 base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded, | 66 if (!access_token_store) { |
| 73 base::Unretained(this))); | 67 Geoposition position; |
| 68 position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED; | |
| 69 arbitrator_update_callback_.Run(position); | |
| 70 return; | |
| 71 } | |
| 72 DCHECK(DefaultNetworkProviderURL().is_valid()); | |
| 73 access_token_store->LoadAccessTokens( | |
| 74 base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded, | |
| 75 base::Unretained(this))); | |
| 76 } else { | |
| 77 RegisterSystemProvider(); | |
| 78 } | |
| 74 } else { | 79 } else { |
| 75 DoStartProviders(); | 80 DoStartProviders(); |
| 76 } | 81 } |
| 77 } | 82 } |
| 78 | 83 |
| 79 void LocationArbitratorImpl::DoStartProviders() { | 84 void LocationArbitratorImpl::DoStartProviders() { |
| 80 for (const auto& provider : providers_) | 85 for (const auto& provider : providers_) |
| 81 provider->StartProvider(enable_high_accuracy_); | 86 provider->StartProvider(enable_high_accuracy_); |
| 82 } | 87 } |
| 83 | 88 |
| 84 void LocationArbitratorImpl::StopProviders() { | 89 void LocationArbitratorImpl::StopProviders() { |
| 85 // Reset the reference location state (provider+position) | 90 // Reset the reference location state (provider+position) |
| 86 // so that future starts use fresh locations from | 91 // so that future starts use fresh locations from |
| 87 // the newly constructed providers. | 92 // the newly constructed providers. |
| 88 position_provider_ = NULL; | 93 position_provider_ = NULL; |
| 89 position_ = Geoposition(); | 94 position_ = Geoposition(); |
| 90 | 95 |
| 91 providers_.clear(); | 96 providers_.clear(); |
| 92 is_running_ = false; | 97 is_running_ = false; |
| 93 } | 98 } |
| 94 | 99 |
| 100 void LocationArbitratorImpl::RegisterSystemProvider() { | |
| 101 LocationProvider* provider = | |
| 102 GetContentClient()->browser()->OverrideSystemLocationProvider(); | |
| 103 if (!provider) | |
| 104 provider = NewSystemLocationProvider(); | |
| 105 RegisterProvider(provider); | |
| 106 DoStartProviders(); | |
| 107 } | |
| 108 | |
| 95 void LocationArbitratorImpl::OnAccessTokenStoresLoaded( | 109 void LocationArbitratorImpl::OnAccessTokenStoresLoaded( |
| 96 AccessTokenStore::AccessTokenMap access_token_map, | 110 AccessTokenStore::AccessTokenMap access_token_map, |
| 97 net::URLRequestContextGetter* context_getter) { | 111 net::URLRequestContextGetter* context_getter) { |
| 98 if (!is_running_ || !providers_.empty()) { | 112 if (!is_running_ || !providers_.empty()) { |
| 99 // A second StartProviders() call may have arrived before the first | 113 // A second StartProviders() call may have arrived before the first |
| 100 // completed. | 114 // completed. |
| 101 return; | 115 return; |
| 102 } | 116 } |
| 103 // If there are no access tokens, boot strap it with the default server URL. | 117 if (GetContentClient()->browser()->UseNetworkLocationProviders()) { |
| 104 if (access_token_map.empty()) | 118 // If there are no access tokens, boot strap it with the default server URL. |
| 105 access_token_map[DefaultNetworkProviderURL()]; | 119 if (access_token_map.empty()) |
| 106 for (const auto& entry : access_token_map) { | 120 access_token_map[DefaultNetworkProviderURL()]; |
| 107 RegisterProvider(NewNetworkLocationProvider( | 121 for (const auto& entry : access_token_map) { |
| 108 GetAccessTokenStore(), context_getter, entry.first, entry.second)); | 122 RegisterProvider(NewNetworkLocationProvider( |
| 123 GetAccessTokenStore(), context_getter, entry.first, entry.second)); | |
| 124 } | |
| 109 } | 125 } |
| 110 | 126 RegisterSystemProvider(); |
| 111 LocationProvider* provider = | |
| 112 GetContentClient()->browser()->OverrideSystemLocationProvider(); | |
| 113 if (!provider) | |
| 114 provider = NewSystemLocationProvider(); | |
| 115 RegisterProvider(provider); | |
| 116 DoStartProviders(); | |
| 117 } | 127 } |
| 118 | 128 |
| 119 void LocationArbitratorImpl::RegisterProvider( | 129 void LocationArbitratorImpl::RegisterProvider( |
| 120 LocationProvider* provider) { | 130 LocationProvider* provider) { |
| 121 if (!provider) | 131 if (!provider) |
| 122 return; | 132 return; |
| 123 provider->SetUpdateCallback(provider_update_callback_); | 133 provider->SetUpdateCallback(provider_update_callback_); |
| 124 if (is_permission_granted_) | 134 if (is_permission_granted_) |
| 125 provider->OnPermissionGranted(); | 135 provider->OnPermissionGranted(); |
| 126 providers_.push_back(provider); | 136 providers_.push_back(provider); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 } | 208 } |
| 199 } | 209 } |
| 200 return false; | 210 return false; |
| 201 } | 211 } |
| 202 | 212 |
| 203 bool LocationArbitratorImpl::HasPermissionBeenGranted() const { | 213 bool LocationArbitratorImpl::HasPermissionBeenGranted() const { |
| 204 return is_permission_granted_; | 214 return is_permission_granted_; |
| 205 } | 215 } |
| 206 | 216 |
| 207 } // namespace content | 217 } // namespace content |
| OLD | NEW |