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

Side by Side Diff: device/geolocation/network_location_provider.cc

Issue 2298013002: Gets rid of LocationProviderBase. (Closed)
Patch Set: Created 4 years, 3 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 "device/geolocation/network_location_provider.h" 5 #include "device/geolocation/network_location_provider.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 *key += separator; 86 *key += separator;
87 *key += access_point_data.mac_address; 87 *key += access_point_data.mac_address;
88 *key += separator; 88 *key += separator;
89 } 89 }
90 // If the key is the empty string, return false, as we don't want to cache a 90 // If the key is the empty string, return false, as we don't want to cache a
91 // position for such data. 91 // position for such data.
92 return !key->empty(); 92 return !key->empty();
93 } 93 }
94 94
95 // NetworkLocationProvider factory function 95 // NetworkLocationProvider factory function
96 LocationProviderBase* NewNetworkLocationProvider( 96 LocationProvider* NewNetworkLocationProvider(
97 const scoped_refptr<AccessTokenStore>& access_token_store, 97 const scoped_refptr<AccessTokenStore>& access_token_store,
98 const scoped_refptr<net::URLRequestContextGetter>& context, 98 const scoped_refptr<net::URLRequestContextGetter>& context,
99 const GURL& url, 99 const GURL& url,
100 const base::string16& access_token) { 100 const base::string16& access_token) {
101 return new NetworkLocationProvider(access_token_store, context, url, 101 return new NetworkLocationProvider(access_token_store, context, url,
102 access_token); 102 access_token);
103 } 103 }
104 104
105 // NetworkLocationProvider 105 // NetworkLocationProvider
106 NetworkLocationProvider::NetworkLocationProvider( 106 NetworkLocationProvider::NetworkLocationProvider(
(...skipping 20 matching lines...) Expand all
127 127
128 NetworkLocationProvider::~NetworkLocationProvider() { 128 NetworkLocationProvider::~NetworkLocationProvider() {
129 StopProvider(); 129 StopProvider();
130 } 130 }
131 131
132 // LocationProvider implementation 132 // LocationProvider implementation
133 const Geoposition& NetworkLocationProvider::GetPosition() { 133 const Geoposition& NetworkLocationProvider::GetPosition() {
134 return position_; 134 return position_;
135 } 135 }
136 136
137 void NetworkLocationProvider::SetUpdateCallback(
138 const LocationProvider::LocationProviderUpdateCallback& callback) {
139 callback_ = callback;
140 }
141
137 void NetworkLocationProvider::OnPermissionGranted() { 142 void NetworkLocationProvider::OnPermissionGranted() {
138 const bool was_permission_granted = is_permission_granted_; 143 const bool was_permission_granted = is_permission_granted_;
139 is_permission_granted_ = true; 144 is_permission_granted_ = true;
140 if (!was_permission_granted && IsStarted()) { 145 if (!was_permission_granted && IsStarted()) {
141 RequestPosition(); 146 RequestPosition();
142 } 147 }
143 } 148 }
144 149
145 void NetworkLocationProvider::OnWifiDataUpdate() { 150 void NetworkLocationProvider::OnWifiDataUpdate() {
146 DCHECK(wifi_data_provider_manager_); 151 DCHECK(wifi_data_provider_manager_);
(...skipping 13 matching lines...) Expand all
160 position_cache_->CachePosition(wifi_data, position); 165 position_cache_->CachePosition(wifi_data, position);
161 } 166 }
162 167
163 // Record access_token if it's set. 168 // Record access_token if it's set.
164 if (!access_token.empty() && access_token_ != access_token) { 169 if (!access_token.empty() && access_token_ != access_token) {
165 access_token_ = access_token; 170 access_token_ = access_token;
166 access_token_store_->SaveAccessToken(request_->url(), access_token); 171 access_token_store_->SaveAccessToken(request_->url(), access_token);
167 } 172 }
168 173
169 // Let listeners know that we now have a position available. 174 // Let listeners know that we now have a position available.
170 NotifyCallback(position_); 175 if (!callback_.is_null()) {
Michael van Ouwerkerk 2016/08/31 09:44:37 nit: no curly braces
CJ 2016/08/31 17:22:11 Done.
176 callback_.Run(this, position_);
177 }
171 } 178 }
172 179
173 bool NetworkLocationProvider::StartProvider(bool high_accuracy) { 180 bool NetworkLocationProvider::StartProvider(bool high_accuracy) {
174 DCHECK(CalledOnValidThread()); 181 DCHECK(CalledOnValidThread());
175 if (IsStarted()) 182 if (IsStarted())
176 return true; 183 return true;
177 DCHECK(!wifi_data_provider_manager_); 184 DCHECK(!wifi_data_provider_manager_);
178 if (!request_->url().is_valid()) { 185 if (!request_->url().is_valid()) {
179 LOG(WARNING) << "StartProvider() : Failed, Bad URL: " 186 LOG(WARNING) << "StartProvider() : Failed, Bad URL: "
180 << request_->url().possibly_invalid_spec(); 187 << request_->url().possibly_invalid_spec();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // Record the position and update its timestamp. 241 // Record the position and update its timestamp.
235 position_ = *cached_position; 242 position_ = *cached_position;
236 243
237 // The timestamp of a position fix is determined by the timestamp 244 // The timestamp of a position fix is determined by the timestamp
238 // of the source data update. (The value of position_.timestamp from 245 // of the source data update. (The value of position_.timestamp from
239 // the cache could be from weeks ago!) 246 // the cache could be from weeks ago!)
240 position_.timestamp = wifi_timestamp_; 247 position_.timestamp = wifi_timestamp_;
241 is_new_data_available_ = false; 248 is_new_data_available_ = false;
242 249
243 // Let listeners know that we now have a position available. 250 // Let listeners know that we now have a position available.
244 NotifyCallback(position_); 251 if (!callback_.is_null()) {
Michael van Ouwerkerk 2016/08/31 09:44:37 nit: no curly braces
CJ 2016/08/31 17:22:11 Done.
252 callback_.Run(this, position_);
253 }
245 return; 254 return;
246 } 255 }
247 // Don't send network requests until authorized. http://crbug.com/39171 256 // Don't send network requests until authorized. http://crbug.com/39171
248 if (!is_permission_granted_) 257 if (!is_permission_granted_)
249 return; 258 return;
250 259
251 weak_factory_.InvalidateWeakPtrs(); 260 weak_factory_.InvalidateWeakPtrs();
252 is_new_data_available_ = false; 261 is_new_data_available_ = false;
253 262
254 // TODO(joth): Rather than cancel pending requests, we should create a new 263 // TODO(joth): Rather than cancel pending requests, we should create a new
255 // NetworkLocationRequest for each and hold a set of pending requests. 264 // NetworkLocationRequest for each and hold a set of pending requests.
256 if (request_->is_request_pending()) { 265 if (request_->is_request_pending()) {
257 DVLOG(1) << "NetworkLocationProvider - pre-empting pending network request " 266 DVLOG(1) << "NetworkLocationProvider - pre-empting pending network request "
258 "with new data. Wifi APs: " 267 "with new data. Wifi APs: "
259 << wifi_data_.access_point_data.size(); 268 << wifi_data_.access_point_data.size();
260 } 269 }
261 request_->MakeRequest(access_token_, wifi_data_, wifi_timestamp_); 270 request_->MakeRequest(access_token_, wifi_data_, wifi_timestamp_);
262 } 271 }
263 272
264 bool NetworkLocationProvider::IsStarted() const { 273 bool NetworkLocationProvider::IsStarted() const {
265 return wifi_data_provider_manager_ != nullptr; 274 return wifi_data_provider_manager_ != nullptr;
266 } 275 }
267 276
268 } // namespace device 277 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698