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..69f889a6ac480694600eb313fe7d6be3206c75f0 100644 |
| --- a/chromeos/geolocation/simple_geolocation_provider.cc |
| +++ b/chromeos/geolocation/simple_geolocation_provider.cc |
| @@ -17,23 +17,10 @@ |
| namespace chromeos { |
| namespace { |
| + |
| 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; |
| - } |
| - return result; |
| -} |
| - |
| } // namespace |
| SimpleGeolocationProvider::SimpleGeolocationProvider( |
| @@ -49,12 +36,32 @@ SimpleGeolocationProvider::~SimpleGeolocationProvider() { |
| void SimpleGeolocationProvider::RequestGeolocation( |
| base::TimeDelta timeout, |
| bool send_wifi_access_points, |
| + bool send_cell_towers, |
| SimpleGeolocationRequest::ResponseCallback callback) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| + auto cell_vector = base::MakeUnique<chromeos::CellTowerVector>(); |
| + auto wifi_vector = base::MakeUnique<chromeos::WifiAccessPointVector>(); |
| + |
| + // Mostly necessary for testing and rare cases where NetworkHandler is not |
| + // initialized: in that case, calls to Get() will fail. |
| + if (!send_wifi_access_points && !send_cell_towers) { |
| + wifi_vector = nullptr; |
| + cell_vector = nullptr; |
|
stevenjb (google-dont-use)
2017/02/09 00:13:28
No need to do this explicitly, just only make the
can Skylar cook
2017/02/09 19:44:30
Ah, clever. Done.
|
| + } else { |
| + NetworkHandler::Get()->geolocation_handler()->GetNetworkInformation( |
| + wifi_vector.get(), cell_vector.get()); |
| + |
| + if (!send_wifi_access_points || (wifi_vector->size() == 0)) |
| + wifi_vector = nullptr; |
| + |
| + if (!send_cell_towers || (cell_vector->size() == 0)) |
| + cell_vector = nullptr; |
| + } |
| + |
| SimpleGeolocationRequest* request(new SimpleGeolocationRequest( |
| - url_context_getter_.get(), url_, timeout, |
| - send_wifi_access_points ? GetAccessPointData() : nullptr)); |
| + url_context_getter_.get(), url_, timeout, std::move(wifi_vector), |
| + std::move(cell_vector))); |
| requests_.push_back(base::WrapUnique(request)); |
| // SimpleGeolocationProvider owns all requests. It is safe to pass unretained |