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

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

Issue 477633002: Rename various Geolocation bits for clarity and consistency. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more rename. Created 6 years, 4 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 | Annotate | Revision Log
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/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/public/browser/access_token_store.h" 10 #include "content/public/browser/access_token_store.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 // NetworkLocationProvider 104 // NetworkLocationProvider
105 NetworkLocationProvider::NetworkLocationProvider( 105 NetworkLocationProvider::NetworkLocationProvider(
106 AccessTokenStore* access_token_store, 106 AccessTokenStore* access_token_store,
107 net::URLRequestContextGetter* url_context_getter, 107 net::URLRequestContextGetter* url_context_getter,
108 const GURL& url, 108 const GURL& url,
109 const base::string16& access_token) 109 const base::string16& access_token)
110 : access_token_store_(access_token_store), 110 : access_token_store_(access_token_store),
111 wifi_data_provider_(NULL), 111 wifi_data_provider_(NULL),
112 wifi_data_update_callback_( 112 wifi_data_update_callback_(
113 base::Bind(&NetworkLocationProvider::WifiDataUpdateAvailable, 113 base::Bind(&NetworkLocationProvider::OnWifiDataUpdate,
114 base::Unretained(this))), 114 base::Unretained(this))),
115 is_wifi_data_complete_(false), 115 is_wifi_data_complete_(false),
116 access_token_(access_token), 116 access_token_(access_token),
117 is_permission_granted_(false), 117 is_permission_granted_(false),
118 is_new_data_available_(false), 118 is_new_data_available_(false),
119 weak_factory_(this) { 119 weak_factory_(this) {
120 // Create the position cache. 120 // Create the position cache.
121 position_cache_.reset(new PositionCache()); 121 position_cache_.reset(new PositionCache());
122 122
123 NetworkLocationRequest::LocationResponseCallback callback = 123 request_.reset(new NetworkLocationRequest(
124 base::Bind(&NetworkLocationProvider::LocationResponseAvailable, 124 url_context_getter,
125 base::Unretained(this)); 125 url,
126 request_.reset(new NetworkLocationRequest(url_context_getter, url, callback)); 126 base::Bind(&NetworkLocationProvider::OnLocationResponse,
127 base::Unretained(this))));
127 } 128 }
128 129
129 NetworkLocationProvider::~NetworkLocationProvider() { 130 NetworkLocationProvider::~NetworkLocationProvider() {
130 StopProvider(); 131 StopProvider();
131 } 132 }
132 133
133 // LocationProvider implementation 134 // LocationProvider implementation
134 void NetworkLocationProvider::GetPosition(Geoposition* position) { 135 void NetworkLocationProvider::GetPosition(Geoposition* position) {
135 DCHECK(position); 136 DCHECK(position);
136 *position = position_; 137 *position = position_;
137 } 138 }
138 139
139 void NetworkLocationProvider::RequestRefresh() { 140 void NetworkLocationProvider::RequestRefresh() {
140 // TODO(joth): When called via the public (base class) interface, this should 141 // TODO(joth): When called via the public (base class) interface, this should
141 // poke each data provider to get them to expedite their next scan. 142 // poke each data provider to get them to expedite their next scan.
142 // Whilst in the delayed start, only send request if all data is ready. 143 // Whilst in the delayed start, only send request if all data is ready.
143 if (!weak_factory_.HasWeakPtrs() || is_wifi_data_complete_) { 144 if (!weak_factory_.HasWeakPtrs() || is_wifi_data_complete_) {
144 RequestPosition(); 145 RequestPosition();
145 } 146 }
146 } 147 }
147 148
148 void NetworkLocationProvider::OnPermissionGranted() { 149 void NetworkLocationProvider::OnPermissionGranted() {
149 const bool was_permission_granted = is_permission_granted_; 150 const bool was_permission_granted = is_permission_granted_;
150 is_permission_granted_ = true; 151 is_permission_granted_ = true;
151 if (!was_permission_granted && IsStarted()) { 152 if (!was_permission_granted && IsStarted()) {
152 RequestRefresh(); 153 RequestRefresh();
153 } 154 }
154 } 155 }
155 156
156 void NetworkLocationProvider::WifiDataUpdateAvailable( 157 void NetworkLocationProvider::OnWifiDataUpdate(WifiDataProvider* provider) {
157 WifiDataProvider* provider) {
158 DCHECK(provider == wifi_data_provider_); 158 DCHECK(provider == wifi_data_provider_);
159 is_wifi_data_complete_ = wifi_data_provider_->GetData(&wifi_data_); 159 is_wifi_data_complete_ = wifi_data_provider_->GetData(&wifi_data_);
160 OnWifiDataUpdated(); 160 OnWifiDataUpdated();
161 } 161 }
162 162
163 void NetworkLocationProvider::LocationResponseAvailable( 163 void NetworkLocationProvider::OnLocationResponse(
164 const Geoposition& position, 164 const Geoposition& position,
165 bool server_error, 165 bool server_error,
166 const base::string16& access_token, 166 const base::string16& access_token,
167 const WifiData& wifi_data) { 167 const WifiData& wifi_data) {
168 DCHECK(CalledOnValidThread()); 168 DCHECK(CalledOnValidThread());
169 // Record the position and update our cache. 169 // Record the position and update our cache.
170 position_ = position; 170 position_ = position;
171 if (position.Validate()) { 171 if (position.Validate()) {
172 position_cache_->CachePosition(wifi_data, position); 172 position_cache_->CachePosition(wifi_data, position);
173 } 173 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 266 }
267 request_->MakeRequest(access_token_, wifi_data_, 267 request_->MakeRequest(access_token_, wifi_data_,
268 wifi_data_updated_timestamp_); 268 wifi_data_updated_timestamp_);
269 } 269 }
270 270
271 bool NetworkLocationProvider::IsStarted() const { 271 bool NetworkLocationProvider::IsStarted() const {
272 return wifi_data_provider_ != NULL; 272 return wifi_data_provider_ != NULL;
273 } 273 }
274 274
275 } // namespace content 275 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698