Chromium Code Reviews| Index: chromeos/geolocation/simple_geolocation_request.cc |
| diff --git a/chromeos/geolocation/simple_geolocation_request.cc b/chromeos/geolocation/simple_geolocation_request.cc |
| index 1369458218cb3d21772ad81e43723fc673fe6409..b36c58a85cd0854823d202811a7ee913012f80b4 100644 |
| --- a/chromeos/geolocation/simple_geolocation_request.cc |
| +++ b/chromeos/geolocation/simple_geolocation_request.cc |
| @@ -44,17 +44,28 @@ namespace { |
| // The full request text. (no parameters are supported by now) |
| const char kSimpleGeolocationRequestBody[] = "{\"considerIp\": \"true\"}"; |
| -// Request data |
| +// TODO(skylarc): kill these and use dbus-constants instead? |
| +// Top-level request data fields |
| const char kConsiderIp[] = "considerIp"; |
| const char kWifiAccessPoints[] = "wifiAccessPoints"; |
| +const char kCellTowers[] = "cellTowers"; |
| + |
| +// Shared Wifi and Cell Tower objects |
| +const char kAge[] = "age"; |
| +const char kSignalStrength[] = "signalStrength"; |
| // WiFi access point objects. |
| const char kMacAddress[] = "macAddress"; |
| -const char kSignalStrength[] = "signalStrength"; |
| -const char kAge[] = "age"; |
| const char kChannel[] = "channel"; |
| const char kSignalToNoiseRatio[] = "signalToNoiseRatio"; |
| +// Cell tower objects |
| +const char kCellId[] = "cellId"; |
| +const char kLocationAreaCode[] = "locationAreaCode"; |
| +const char kMobileCountryCode[] = "mobileCountryCode"; |
| +const char kMobileNetworkCode[] = "mobileNetworkCode"; |
| +// const char kTimingAdvance[] = "timingAdvance"; |
|
Ben Chan
2017/02/02 20:49:24
either drop this line, or add a TODO for it
comme
can Skylar cook
2017/02/03 00:15:17
Done.
|
| + |
| // Response data. |
| const char kLocationString[] = "location"; |
| const char kLatString[] = "lat"; |
| @@ -291,6 +302,9 @@ bool GetGeolocationFromResponse(bool http_success, |
| void ReportUmaHasWiFiAccessPoints(bool value) { |
| UMA_HISTOGRAM_BOOLEAN("SimpleGeolocation.Request.HasWiFiAccessPoints", value); |
| } |
| +void ReportUmaHasCellTowers(bool value) { |
| + UMA_HISTOGRAM_BOOLEAN("SimpleGeolocation.Request.HasCellTowers", value); |
| +} |
| } // namespace |
| @@ -298,7 +312,8 @@ SimpleGeolocationRequest::SimpleGeolocationRequest( |
| net::URLRequestContextGetter* url_context_getter, |
| const GURL& service_url, |
| base::TimeDelta timeout, |
| - std::unique_ptr<WifiAccessPointVector> wifi_data) |
| + std::unique_ptr<WifiAccessPointVector> wifi_data, |
| + std::unique_ptr<CellTowerVector> cell_tower_data) |
| : url_context_getter_(url_context_getter), |
| service_url_(service_url), |
| retry_sleep_on_server_error_(base::TimeDelta::FromSeconds( |
| @@ -307,7 +322,8 @@ SimpleGeolocationRequest::SimpleGeolocationRequest( |
| kResolveGeolocationRetrySleepBadResponseSeconds)), |
| timeout_(timeout), |
| retries_(0), |
| - wifi_data_(wifi_data.release()) {} |
| + wifi_data_(wifi_data.release()), |
| + cell_tower_data_(cell_tower_data.release()) {} |
| SimpleGeolocationRequest::~SimpleGeolocationRequest() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| @@ -323,44 +339,85 @@ SimpleGeolocationRequest::~SimpleGeolocationRequest() { |
| } |
| std::string SimpleGeolocationRequest::FormatRequestBody() const { |
| - if (!wifi_data_) { |
| + if (!wifi_data_) |
| ReportUmaHasWiFiAccessPoints(false); |
| + |
| + if (!cell_tower_data_) |
| + ReportUmaHasCellTowers(false); |
| + |
| + if (!cell_tower_data_ && !wifi_data_) |
| return std::string(kSimpleGeolocationRequestBody); |
| - } |
| std::unique_ptr<base::DictionaryValue> request(new base::DictionaryValue); |
| request->SetBooleanWithoutPathExpansion(kConsiderIp, true); |
| - base::ListValue* wifi_access_points(new base::ListValue); |
| - request->SetWithoutPathExpansion(kWifiAccessPoints, wifi_access_points); |
| - |
| - for (const WifiAccessPoint& access_point : *wifi_data_) { |
| - auto access_point_dictionary = base::MakeUnique<base::DictionaryValue>(); |
| + if (wifi_data_) { |
| + base::ListValue* wifi_access_points(new base::ListValue); |
| + request->SetWithoutPathExpansion(kWifiAccessPoints, wifi_access_points); |
| + for (const WifiAccessPoint& access_point : *wifi_data_) { |
| + auto access_point_dictionary = base::MakeUnique<base::DictionaryValue>(); |
| - access_point_dictionary->SetStringWithoutPathExpansion( |
| - kMacAddress, access_point.mac_address); |
| - access_point_dictionary->SetIntegerWithoutPathExpansion( |
| - kSignalStrength, access_point.signal_strength); |
| - if (!access_point.timestamp.is_null()) { |
| access_point_dictionary->SetStringWithoutPathExpansion( |
| - kAge, |
| - base::Int64ToString( |
| - (base::Time::Now() - access_point.timestamp).InMilliseconds())); |
| + kMacAddress, access_point.mac_address); |
| + access_point_dictionary->SetIntegerWithoutPathExpansion( |
| + kSignalStrength, access_point.signal_strength); |
| + if (!access_point.timestamp.is_null()) { |
| + access_point_dictionary->SetStringWithoutPathExpansion( |
| + kAge, |
| + base::Int64ToString( |
| + (base::Time::Now() - access_point.timestamp).InMilliseconds())); |
| + } |
| + |
| + access_point_dictionary->SetIntegerWithoutPathExpansion( |
| + kChannel, access_point.channel); |
| + access_point_dictionary->SetIntegerWithoutPathExpansion( |
| + kSignalToNoiseRatio, access_point.signal_to_noise); |
| + |
| + wifi_access_points->Append(std::move(access_point_dictionary)); |
| } |
| + } |
| - access_point_dictionary->SetIntegerWithoutPathExpansion( |
| - kChannel, access_point.channel); |
| - access_point_dictionary->SetIntegerWithoutPathExpansion( |
| - kSignalToNoiseRatio, access_point.signal_to_noise); |
| - |
| - wifi_access_points->Append(std::move(access_point_dictionary)); |
| + if (cell_tower_data_) { |
| + base::ListValue* cell_towers(new base::ListValue); |
|
Ben Chan
2017/02/02 20:49:24
keep it in unique_ptr
auto cell_towers = base::Ma
can Skylar cook
2017/02/03 00:15:18
Done.
|
| + request->SetWithoutPathExpansion(kCellTowers, cell_towers); |
| + |
| + for (const CellTower& cell_tower : *cell_tower_data_) { |
| + auto cell_tower_dictionary = base::MakeUnique<base::DictionaryValue>(); |
| + cell_tower_dictionary->SetStringWithoutPathExpansion(kCellId, |
| + cell_tower.ci); |
| + cell_tower_dictionary->SetStringWithoutPathExpansion(kLocationAreaCode, |
| + cell_tower.lac); |
| + cell_tower_dictionary->SetStringWithoutPathExpansion(kMobileCountryCode, |
| + cell_tower.mcc); |
| + cell_tower_dictionary->SetStringWithoutPathExpansion(kMobileNetworkCode, |
| + cell_tower.mnc); |
| + |
| + if (!cell_tower.timestamp.is_null()) { |
| + cell_tower_dictionary->SetStringWithoutPathExpansion( |
| + kAge, |
| + base::Int64ToString( |
| + (base::Time::Now() - cell_tower.timestamp).InMilliseconds())); |
| + } |
| + cell_towers->Append(std::move(cell_tower_dictionary)); |
| + } |
| } |
| + |
| std::string result; |
| if (!base::JSONWriter::Write(*request, &result)) { |
| - ReportUmaHasWiFiAccessPoints(false); |
| + // If there's no data for a network type, we will have already reported |
| + // false above |
| + if (wifi_data_) |
| + ReportUmaHasWiFiAccessPoints(false); |
| + if (cell_tower_data_) |
| + ReportUmaHasCellTowers(false); |
| + |
| return std::string(kSimpleGeolocationRequestBody); |
| } |
| - ReportUmaHasWiFiAccessPoints(wifi_data_->size()); |
| + |
| + if (wifi_data_) |
| + ReportUmaHasWiFiAccessPoints(wifi_data_->size()); |
| + if (cell_tower_data_) |
| + ReportUmaHasCellTowers(cell_tower_data_->size()); |
| return result; |
| } |