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

Unified Diff: chromeos/geolocation/simple_geolocation_provider.cc

Issue 2624843003: Add support for cellular geolocation (Closed)
Patch Set: Update device tests to use correct dict key Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
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..06ce1f263c1cdc685cd82cbf3aad2a3349e1faa1 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,29 @@ 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) {
+ 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
« no previous file with comments | « chromeos/geolocation/simple_geolocation_provider.h ('k') | chromeos/geolocation/simple_geolocation_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698