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

Side by Side Diff: content/browser/geolocation/network_location_provider.cc

Issue 10107017: Remove requesting_frame parameters from Geolocation stack (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 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/network_location_provider.h" 5 #include "content/browser/geolocation/network_location_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "content/public/browser/access_token_store.h" 10 #include "content/public/browser/access_token_store.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 AccessTokenStore* access_token_store, 109 AccessTokenStore* access_token_store,
110 net::URLRequestContextGetter* url_context_getter, 110 net::URLRequestContextGetter* url_context_getter,
111 const GURL& url, 111 const GURL& url,
112 const string16& access_token) 112 const string16& access_token)
113 : access_token_store_(access_token_store), 113 : access_token_store_(access_token_store),
114 radio_data_provider_(NULL), 114 radio_data_provider_(NULL),
115 wifi_data_provider_(NULL), 115 wifi_data_provider_(NULL),
116 is_radio_data_complete_(false), 116 is_radio_data_complete_(false),
117 is_wifi_data_complete_(false), 117 is_wifi_data_complete_(false),
118 access_token_(access_token), 118 access_token_(access_token),
119 is_permission_granted_(false),
119 is_new_data_available_(false), 120 is_new_data_available_(false),
120 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 121 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
121 // Create the position cache. 122 // Create the position cache.
122 position_cache_.reset(new PositionCache()); 123 position_cache_.reset(new PositionCache());
123 124
124 request_.reset(new NetworkLocationRequest(url_context_getter, url, this)); 125 request_.reset(new NetworkLocationRequest(url_context_getter, url, this));
125 } 126 }
126 127
127 NetworkLocationProvider::~NetworkLocationProvider() { 128 NetworkLocationProvider::~NetworkLocationProvider() {
128 StopProvider(); 129 StopProvider();
129 } 130 }
130 131
131 // LocationProviderBase implementation 132 // LocationProviderBase implementation
132 void NetworkLocationProvider::GetPosition(Geoposition *position) { 133 void NetworkLocationProvider::GetPosition(Geoposition *position) {
133 DCHECK(position); 134 DCHECK(position);
134 *position = position_; 135 *position = position_;
135 } 136 }
136 137
137 void NetworkLocationProvider::UpdatePosition() { 138 void NetworkLocationProvider::UpdatePosition() {
138 // TODO(joth): When called via the public (base class) interface, this should 139 // TODO(joth): When called via the public (base class) interface, this should
139 // poke each data provider to get them to expedite their next scan. 140 // poke each data provider to get them to expedite their next scan.
140 // Whilst in the delayed start, only send request if all data is ready. 141 // Whilst in the delayed start, only send request if all data is ready.
141 if (!weak_factory_.HasWeakPtrs() || 142 if (!weak_factory_.HasWeakPtrs() ||
142 (is_radio_data_complete_ && is_wifi_data_complete_)) { 143 (is_radio_data_complete_ && is_wifi_data_complete_)) {
143 RequestPosition(); 144 RequestPosition();
144 } 145 }
145 } 146 }
146 147
147 void NetworkLocationProvider::OnPermissionGranted( 148 void NetworkLocationProvider::OnPermissionGranted() {
148 const GURL& requesting_frame) { 149 const bool was_permission_granted = is_permission_granted_;
149 const bool host_was_empty = most_recent_authorized_host_.empty(); 150 is_permission_granted_ = true;
150 most_recent_authorized_host_ = requesting_frame.host(); 151 if (!was_permission_granted && IsStarted()) {
151 if (host_was_empty && !most_recent_authorized_host_.empty()
152 && IsStarted()) {
153 UpdatePosition(); 152 UpdatePosition();
154 } 153 }
155 } 154 }
156 155
157 // DeviceDataProviderInterface::ListenerInterface implementation. 156 // DeviceDataProviderInterface::ListenerInterface implementation.
158 void NetworkLocationProvider::DeviceDataUpdateAvailable( 157 void NetworkLocationProvider::DeviceDataUpdateAvailable(
159 RadioDataProvider* provider) { 158 RadioDataProvider* provider) {
160 DCHECK(provider == radio_data_provider_); 159 DCHECK(provider == radio_data_provider_);
161 is_radio_data_complete_ = radio_data_provider_->GetData(&radio_data_); 160 is_radio_data_complete_ = radio_data_provider_->GetData(&radio_data_);
162 OnDeviceDataUpdated(); 161 OnDeviceDataUpdated();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 // The timestamp of a position fix is determined by the timestamp 249 // The timestamp of a position fix is determined by the timestamp
251 // of the source data update. (The value of position_.timestamp from 250 // of the source data update. (The value of position_.timestamp from
252 // the cache could be from weeks ago!) 251 // the cache could be from weeks ago!)
253 position_.timestamp = device_data_updated_timestamp_; 252 position_.timestamp = device_data_updated_timestamp_;
254 is_new_data_available_ = false; 253 is_new_data_available_ = false;
255 // Let listeners know that we now have a position available. 254 // Let listeners know that we now have a position available.
256 UpdateListeners(); 255 UpdateListeners();
257 return; 256 return;
258 } 257 }
259 // Don't send network requests until authorized. http://crbug.com/39171 258 // Don't send network requests until authorized. http://crbug.com/39171
260 if (most_recent_authorized_host_.empty()) 259 if (!is_permission_granted_)
261 return; 260 return;
262 261
263 weak_factory_.InvalidateWeakPtrs(); 262 weak_factory_.InvalidateWeakPtrs();
264 is_new_data_available_ = false; 263 is_new_data_available_ = false;
265 264
266 // TODO(joth): Rather than cancel pending requests, we should create a new 265 // TODO(joth): Rather than cancel pending requests, we should create a new
267 // NetworkLocationRequest for each and hold a set of pending requests. 266 // NetworkLocationRequest for each and hold a set of pending requests.
268 if (request_->is_request_pending()) { 267 if (request_->is_request_pending()) {
269 DVLOG(1) << "NetworkLocationProvider - pre-empting pending network request " 268 DVLOG(1) << "NetworkLocationProvider - pre-empting pending network request "
270 "with new data. Wifi APs: " 269 "with new data. Wifi APs: "
271 << wifi_data_.access_point_data.size(); 270 << wifi_data_.access_point_data.size();
272 } 271 }
273 // The hostname sent in the request is just to give a first-order 272 request_->MakeRequest(access_token_,
274 // approximation of usage. We do not need to guarantee that this network
275 // request was triggered by an API call from this specific host.
276 request_->MakeRequest(most_recent_authorized_host_, access_token_,
277 radio_data_, wifi_data_, 273 radio_data_, wifi_data_,
278 device_data_updated_timestamp_); 274 device_data_updated_timestamp_);
279 } 275 }
280 276
281 void NetworkLocationProvider::OnDeviceDataUpdated() { 277 void NetworkLocationProvider::OnDeviceDataUpdated() {
282 DCHECK(CalledOnValidThread()); 278 DCHECK(CalledOnValidThread());
283 device_data_updated_timestamp_ = base::Time::Now(); 279 device_data_updated_timestamp_ = base::Time::Now();
284 280
285 is_new_data_available_ = is_radio_data_complete_ || is_wifi_data_complete_; 281 is_new_data_available_ = is_radio_data_complete_ || is_wifi_data_complete_;
286 UpdatePosition(); 282 UpdatePosition();
287 } 283 }
288 284
289 bool NetworkLocationProvider::IsStarted() const { 285 bool NetworkLocationProvider::IsStarted() const {
290 DCHECK_EQ(!!radio_data_provider_, !!wifi_data_provider_); 286 DCHECK_EQ(!!radio_data_provider_, !!wifi_data_provider_);
291 return wifi_data_provider_ != NULL; 287 return wifi_data_provider_ != NULL;
292 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698