Chromium Code Reviews| Index: chromeos/geolocation/simple_geolocation_provider.cc |
| diff --git a/chromeos/geolocation/simple_geolocation_provider.cc b/chromeos/geolocation/simple_geolocation_provider.cc |
| index 45d6981dcb8b08bdf1d25cbf8ec6dc848915c429..ce9f64203ca3ad401be57d52ba20ea269cbaede4 100644 |
| --- a/chromeos/geolocation/simple_geolocation_provider.cc |
| +++ b/chromeos/geolocation/simple_geolocation_provider.cc |
| @@ -17,21 +17,39 @@ |
| namespace chromeos { |
| namespace { |
| + |
| +struct WifiCellTowerPair { |
| + std::unique_ptr<WifiAccessPointVector> wifi_vector; |
| + std::unique_ptr<CellTowerVector> cell_vector; |
| +}; |
| + |
| const char kDefaultGeolocationProviderUrl[] = |
| "https://www.googleapis.com/geolocation/v1/geolocate?"; |
| -std::unique_ptr<WifiAccessPointVector> GetAccessPointData() { |
| - if (!chromeos::NetworkHandler::Get()->geolocation_handler()->wifi_enabled()) |
| - return nullptr; |
| - |
| - std::unique_ptr<WifiAccessPointVector> result( |
| - new chromeos::WifiAccessPointVector); |
| - int64_t age_ms = 0; |
| - if (!NetworkHandler::Get()->geolocation_handler()->GetWifiAccessPoints( |
| - result.get(), &age_ms)) { |
| - return nullptr; |
| +WifiCellTowerPair GetNetworkInfo(bool get_wifi_access_points, |
| + bool get_cell_towers) { |
| + WifiCellTowerPair network_info; |
| + network_info.wifi_vector = nullptr; |
| + network_info.cell_vector = nullptr; |
| + // Mostly necessary for testing, or rare cases where NetworkHandler is not |
| + // initialized: in that case, calls to Get() will fail. |
| + if (!get_wifi_access_points && !get_cell_towers) { |
| + return network_info; |
| } |
| - return result; |
| + |
| + auto cell_vector = base::MakeUnique<chromeos::CellTowerVector>(); |
| + auto wifi_vector = base::MakeUnique<chromeos::WifiAccessPointVector>(); |
| + |
| + NetworkHandler::Get()->geolocation_handler()->GetNetworkInformation( |
| + wifi_vector.get(), cell_vector.get()); |
| + |
| + if (wifi_vector->size() > 0) |
| + network_info.wifi_vector = std::move(wifi_vector); |
| + |
| + if (cell_vector->size() > 0) |
| + network_info.cell_vector = std::move(cell_vector); |
| + |
| + return network_info; |
| } |
| } // namespace |
| @@ -49,12 +67,16 @@ SimpleGeolocationProvider::~SimpleGeolocationProvider() { |
| void SimpleGeolocationProvider::RequestGeolocation( |
| base::TimeDelta timeout, |
| bool send_wifi_access_points, |
| + bool send_cell_towers, |
| SimpleGeolocationRequest::ResponseCallback callback) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - SimpleGeolocationRequest* request(new SimpleGeolocationRequest( |
| - url_context_getter_.get(), url_, timeout, |
| - send_wifi_access_points ? GetAccessPointData() : nullptr)); |
| + auto network_info = GetNetworkInfo(send_wifi_access_points, send_cell_towers); |
|
Alexander Alekseev
2017/02/07 22:15:38
GetNetworkInfo() ignores individual values of send
can Skylar cook
2017/02/07 22:29:59
Whoops, good catch. Fixed.
|
| + |
| + SimpleGeolocationRequest* request( |
| + new SimpleGeolocationRequest(url_context_getter_.get(), url_, timeout, |
| + std::move(network_info.wifi_vector), |
| + std::move(network_info.cell_vector))); |
| requests_.push_back(base::WrapUnique(request)); |
| // SimpleGeolocationProvider owns all requests. It is safe to pass unretained |