| 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 "device/geolocation/network_location_request.h" | 5 #include "device/geolocation/network_location_request.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> |
| 12 | 13 |
| 13 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
| 14 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
| 16 #include "base/memory/ptr_util.h" |
| 15 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 16 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/values.h" | 21 #include "base/values.h" |
| 20 #include "device/geolocation/geoposition.h" | 22 #include "device/geolocation/geoposition.h" |
| 21 #include "device/geolocation/location_arbitrator.h" | 23 #include "device/geolocation/location_arbitrator.h" |
| 22 #include "google_apis/google_api_keys.h" | 24 #include "google_apis/google_api_keys.h" |
| 23 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
| 24 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 269 |
| 268 if (wifi_data.access_point_data.empty()) | 270 if (wifi_data.access_point_data.empty()) |
| 269 return; | 271 return; |
| 270 | 272 |
| 271 typedef std::multiset<const AccessPointData*, AccessPointLess> AccessPointSet; | 273 typedef std::multiset<const AccessPointData*, AccessPointLess> AccessPointSet; |
| 272 AccessPointSet access_points_by_signal_strength; | 274 AccessPointSet access_points_by_signal_strength; |
| 273 | 275 |
| 274 for (const auto& ap_data : wifi_data.access_point_data) | 276 for (const auto& ap_data : wifi_data.access_point_data) |
| 275 access_points_by_signal_strength.insert(&ap_data); | 277 access_points_by_signal_strength.insert(&ap_data); |
| 276 | 278 |
| 277 base::ListValue* wifi_access_point_list = new base::ListValue(); | 279 auto wifi_access_point_list = base::MakeUnique<base::ListValue>(); |
| 278 for (auto* ap_data : access_points_by_signal_strength) { | 280 for (auto* ap_data : access_points_by_signal_strength) { |
| 279 std::unique_ptr<base::DictionaryValue> wifi_dict( | 281 auto wifi_dict = base::MakeUnique<base::DictionaryValue>(); |
| 280 new base::DictionaryValue()); | |
| 281 AddString("macAddress", base::UTF16ToUTF8(ap_data->mac_address), | 282 AddString("macAddress", base::UTF16ToUTF8(ap_data->mac_address), |
| 282 wifi_dict.get()); | 283 wifi_dict.get()); |
| 283 AddInteger("signalStrength", ap_data->radio_signal_strength, | 284 AddInteger("signalStrength", ap_data->radio_signal_strength, |
| 284 wifi_dict.get()); | 285 wifi_dict.get()); |
| 285 AddInteger("age", age_milliseconds, wifi_dict.get()); | 286 AddInteger("age", age_milliseconds, wifi_dict.get()); |
| 286 AddInteger("channel", ap_data->channel, wifi_dict.get()); | 287 AddInteger("channel", ap_data->channel, wifi_dict.get()); |
| 287 AddInteger("signalToNoiseRatio", ap_data->signal_to_noise, wifi_dict.get()); | 288 AddInteger("signalToNoiseRatio", ap_data->signal_to_noise, wifi_dict.get()); |
| 288 wifi_access_point_list->Append(std::move(wifi_dict)); | 289 wifi_access_point_list->Append(std::move(wifi_dict)); |
| 289 } | 290 } |
| 290 request->Set("wifiAccessPoints", wifi_access_point_list); | 291 request->Set("wifiAccessPoints", std::move(wifi_access_point_list)); |
| 291 } | 292 } |
| 292 | 293 |
| 293 void FormatPositionError(const GURL& server_url, | 294 void FormatPositionError(const GURL& server_url, |
| 294 const std::string& message, | 295 const std::string& message, |
| 295 Geoposition* position) { | 296 Geoposition* position) { |
| 296 position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; | 297 position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; |
| 297 position->error_message = "Network location provider at '"; | 298 position->error_message = "Network location provider at '"; |
| 298 position->error_message += server_url.GetOrigin().spec(); | 299 position->error_message += server_url.GetOrigin().spec(); |
| 299 position->error_message += "' : "; | 300 position->error_message += "' : "; |
| 300 position->error_message += message; | 301 position->error_message += message; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 443 |
| 443 // Other fields are optional. | 444 // Other fields are optional. |
| 444 GetAsDouble(*response_object, kAccuracyString, &position->accuracy); | 445 GetAsDouble(*response_object, kAccuracyString, &position->accuracy); |
| 445 | 446 |
| 446 return true; | 447 return true; |
| 447 } | 448 } |
| 448 | 449 |
| 449 } // namespace | 450 } // namespace |
| 450 | 451 |
| 451 } // namespace device | 452 } // namespace device |
| OLD | NEW |