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/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/location.h" |
| 9 #include "base/single_thread_task_runner.h" |
8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/thread_task_runner_handle.h" |
9 #include "base/time/time.h" | 12 #include "base/time/time.h" |
10 #include "content/public/browser/access_token_store.h" | 13 #include "content/public/browser/access_token_store.h" |
11 | 14 |
12 namespace content { | 15 namespace content { |
13 namespace { | 16 namespace { |
14 // The maximum period of time we'll wait for a complete set of wifi data | 17 // The maximum period of time we'll wait for a complete set of wifi data |
15 // before sending the request. | 18 // before sending the request. |
16 const int kDataCompleteWaitSeconds = 2; | 19 const int kDataCompleteWaitSeconds = 2; |
17 } // namespace | 20 } // namespace |
18 | 21 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 << request_->url().possibly_invalid_spec(); | 195 << request_->url().possibly_invalid_spec(); |
193 return false; | 196 return false; |
194 } | 197 } |
195 | 198 |
196 // Registers a callback with the data provider. The first call to Register | 199 // Registers a callback with the data provider. The first call to Register |
197 // will create a singleton data provider and it will be deleted when the last | 200 // will create a singleton data provider and it will be deleted when the last |
198 // callback is removed with Unregister. | 201 // callback is removed with Unregister. |
199 wifi_data_provider_manager_ = | 202 wifi_data_provider_manager_ = |
200 WifiDataProviderManager::Register(&wifi_data_update_callback_); | 203 WifiDataProviderManager::Register(&wifi_data_update_callback_); |
201 | 204 |
202 base::MessageLoop::current()->PostDelayedTask( | 205 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
203 FROM_HERE, | 206 FROM_HERE, base::Bind(&NetworkLocationProvider::RequestPosition, |
204 base::Bind(&NetworkLocationProvider::RequestPosition, | 207 weak_factory_.GetWeakPtr()), |
205 weak_factory_.GetWeakPtr()), | |
206 base::TimeDelta::FromSeconds(kDataCompleteWaitSeconds)); | 208 base::TimeDelta::FromSeconds(kDataCompleteWaitSeconds)); |
207 // Get the wifi data. | 209 // Get the wifi data. |
208 is_wifi_data_complete_ = wifi_data_provider_manager_->GetData(&wifi_data_); | 210 is_wifi_data_complete_ = wifi_data_provider_manager_->GetData(&wifi_data_); |
209 if (is_wifi_data_complete_) | 211 if (is_wifi_data_complete_) |
210 OnWifiDataUpdated(); | 212 OnWifiDataUpdated(); |
211 return true; | 213 return true; |
212 } | 214 } |
213 | 215 |
214 void NetworkLocationProvider::OnWifiDataUpdated() { | 216 void NetworkLocationProvider::OnWifiDataUpdated() { |
215 DCHECK(CalledOnValidThread()); | 217 DCHECK(CalledOnValidThread()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 } | 269 } |
268 request_->MakeRequest(access_token_, wifi_data_, | 270 request_->MakeRequest(access_token_, wifi_data_, |
269 wifi_data_updated_timestamp_); | 271 wifi_data_updated_timestamp_); |
270 } | 272 } |
271 | 273 |
272 bool NetworkLocationProvider::IsStarted() const { | 274 bool NetworkLocationProvider::IsStarted() const { |
273 return wifi_data_provider_manager_ != NULL; | 275 return wifi_data_provider_manager_ != NULL; |
274 } | 276 } |
275 | 277 |
276 } // namespace content | 278 } // namespace content |
OLD | NEW |