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

Side by Side 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 mvanouwerkerk's #81 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 unified diff | Download patch
OLDNEW
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
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 // Stash options as OnAccessTokenStoresLoaded has not yet been called.
56 // the AccessTokenStore class, so we report an error to avoid JavaScript 56 is_running_ = true;
57 // requests of location to wait eternally for a reply. 57 enable_high_accuracy_ = enable_high_accuracy;
58 AccessTokenStore* access_token_store = GetAccessTokenStore(); 58
59 if (!access_token_store) { 59 if (providers_.empty()) {
60 RegisterSystemProvider();
61
62 AccessTokenStore* access_token_store = GetAccessTokenStore();
63 if (access_token_store &&
64 GetContentClient()->browser()->UseNetworkLocationProviders()) {
65 DCHECK(DefaultNetworkProviderURL().is_valid());
66 token_store_callback_.Reset(
67 base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded,
68 base::Unretained(this)));
69 access_token_store->LoadAccessTokens(token_store_callback_.callback());
70 return;
71 }
72 }
73 DoStartProviders();
74 }
75
76 void LocationArbitratorImpl::DoStartProviders() {
77 if (providers_.empty()) {
78 // GetAccessTokenStore() will return NULL for embedders not implementing
79 // the AccessTokenStore class, so we report an error to avoid JavaScript
80 // requests of location to wait eternally for a reply.
Wez 2016/06/10 23:40:34 nit: Strange wording; I think you mean ".. to avoi
CJ 2016/06/13 23:45:20 I didn't write the comment, just have been trying
60 Geoposition position; 81 Geoposition position;
61 position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED; 82 position.error_code = Geoposition::ERROR_CODE_PERMISSION_DENIED;
62 arbitrator_update_callback_.Run(position); 83 arbitrator_update_callback_.Run(position);
63 return; 84 return;
64 } 85 }
65
66 // Stash options as OnAccessTokenStoresLoaded has not yet been called.
67 is_running_ = true;
68 enable_high_accuracy_ = enable_high_accuracy;
69 if (providers_.empty()) {
70 DCHECK(DefaultNetworkProviderURL().is_valid());
71 access_token_store->LoadAccessTokens(
72 base::Bind(&LocationArbitratorImpl::OnAccessTokenStoresLoaded,
73 base::Unretained(this)));
74 } else {
75 DoStartProviders();
76 }
77 }
78
79 void LocationArbitratorImpl::DoStartProviders() {
80 for (const auto& provider : providers_) 86 for (const auto& provider : providers_)
81 provider->StartProvider(enable_high_accuracy_); 87 provider->StartProvider(enable_high_accuracy_);
82 } 88 }
83 89
84 void LocationArbitratorImpl::StopProviders() { 90 void LocationArbitratorImpl::StopProviders() {
85 // Reset the reference location state (provider+position) 91 // Reset the reference location state (provider+position)
86 // so that future starts use fresh locations from 92 // so that future starts use fresh locations from
87 // the newly constructed providers. 93 // the newly constructed providers.
88 position_provider_ = NULL; 94 position_provider_ = NULL;
89 position_ = Geoposition(); 95 position_ = Geoposition();
90 96
91 providers_.clear(); 97 providers_.clear();
92 is_running_ = false; 98 is_running_ = false;
93 } 99 }
94 100
95 void LocationArbitratorImpl::OnAccessTokenStoresLoaded( 101 void LocationArbitratorImpl::OnAccessTokenStoresLoaded(
96 AccessTokenStore::AccessTokenMap access_token_map, 102 AccessTokenStore::AccessTokenMap access_token_map,
97 net::URLRequestContextGetter* context_getter) { 103 net::URLRequestContextGetter* context_getter) {
98 if (!is_running_ || !providers_.empty()) {
99 // A second StartProviders() call may have arrived before the first
100 // completed.
101 return;
102 }
103 // If there are no access tokens, boot strap it with the default server URL. 104 // If there are no access tokens, boot strap it with the default server URL.
104 if (access_token_map.empty()) 105 if (access_token_map.empty())
105 access_token_map[DefaultNetworkProviderURL()]; 106 access_token_map[DefaultNetworkProviderURL()];
106 for (const auto& entry : access_token_map) { 107 for (const auto& entry : access_token_map) {
107 RegisterProvider(NewNetworkLocationProvider( 108 RegisterProvider(NewNetworkLocationProvider(
108 GetAccessTokenStore(), context_getter, entry.first, entry.second)); 109 GetAccessTokenStore(), context_getter, entry.first, entry.second));
109 } 110 }
110
111 LocationProvider* provider =
112 GetContentClient()->browser()->OverrideSystemLocationProvider();
113 if (!provider)
114 provider = NewSystemLocationProvider();
115 RegisterProvider(provider);
116 DoStartProviders(); 111 DoStartProviders();
117 } 112 }
118 113
119 void LocationArbitratorImpl::RegisterProvider( 114 void LocationArbitratorImpl::RegisterProvider(
120 LocationProvider* provider) { 115 LocationProvider* provider) {
121 if (!provider) 116 if (!provider)
122 return; 117 return;
123 provider->SetUpdateCallback(provider_update_callback_); 118 provider->SetUpdateCallback(provider_update_callback_);
124 if (is_permission_granted_) 119 if (is_permission_granted_)
125 provider->OnPermissionGranted(); 120 provider->OnPermissionGranted();
126 providers_.push_back(provider); 121 providers_.push_back(provider);
127 } 122 }
128 123
124 void LocationArbitratorImpl::RegisterSystemProvider() {
125 LocationProvider* provider =
126 GetContentClient()->browser()->OverrideSystemLocationProvider();
127 if (!provider)
128 provider = NewSystemLocationProvider();
129 RegisterProvider(provider);
130 }
131
129 void LocationArbitratorImpl::OnLocationUpdate(const LocationProvider* provider, 132 void LocationArbitratorImpl::OnLocationUpdate(const LocationProvider* provider,
130 const Geoposition& new_position) { 133 const Geoposition& new_position) {
131 DCHECK(new_position.Validate() || 134 DCHECK(new_position.Validate() ||
132 new_position.error_code != Geoposition::ERROR_CODE_NONE); 135 new_position.error_code != Geoposition::ERROR_CODE_NONE);
133 if (!IsNewPositionBetter(position_, new_position, 136 if (!IsNewPositionBetter(position_, new_position,
134 provider == position_provider_)) 137 provider == position_provider_))
135 return; 138 return;
136 position_provider_ = provider; 139 position_provider_ = provider;
137 position_ = new_position; 140 position_ = new_position;
138 arbitrator_update_callback_.Run(position_); 141 arbitrator_update_callback_.Run(position_);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 201 }
199 } 202 }
200 return false; 203 return false;
201 } 204 }
202 205
203 bool LocationArbitratorImpl::HasPermissionBeenGranted() const { 206 bool LocationArbitratorImpl::HasPermissionBeenGranted() const {
204 return is_permission_granted_; 207 return is_permission_granted_;
205 } 208 }
206 209
207 } // namespace content 210 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698