OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromeos/geolocation/simple_geolocation_request.h" | 5 #include "chromeos/geolocation/simple_geolocation_request.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
| 11 #include <utility> |
11 | 12 |
12 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
13 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 15 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
15 #include "base/metrics/sparse_histogram.h" | 17 #include "base/metrics/sparse_histogram.h" |
16 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
18 #include "base/time/time.h" | 20 #include "base/time/time.h" |
19 #include "base/values.h" | 21 #include "base/values.h" |
20 #include "chromeos/geolocation/simple_geolocation_provider.h" | 22 #include "chromeos/geolocation/simple_geolocation_provider.h" |
21 #include "chromeos/geolocation/simple_geolocation_request_test_monitor.h" | 23 #include "chromeos/geolocation/simple_geolocation_request_test_monitor.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" |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 return std::string(kSimpleGeolocationRequestBody); | 327 return std::string(kSimpleGeolocationRequestBody); |
326 } | 328 } |
327 | 329 |
328 std::unique_ptr<base::DictionaryValue> request(new base::DictionaryValue); | 330 std::unique_ptr<base::DictionaryValue> request(new base::DictionaryValue); |
329 request->SetBooleanWithoutPathExpansion(kConsiderIp, true); | 331 request->SetBooleanWithoutPathExpansion(kConsiderIp, true); |
330 | 332 |
331 base::ListValue* wifi_access_points(new base::ListValue); | 333 base::ListValue* wifi_access_points(new base::ListValue); |
332 request->SetWithoutPathExpansion(kWifiAccessPoints, wifi_access_points); | 334 request->SetWithoutPathExpansion(kWifiAccessPoints, wifi_access_points); |
333 | 335 |
334 for (const WifiAccessPoint& access_point : *wifi_data_) { | 336 for (const WifiAccessPoint& access_point : *wifi_data_) { |
335 base::DictionaryValue* access_point_dictionary = new base::DictionaryValue; | 337 auto access_point_dictionary = base::MakeUnique<base::DictionaryValue>(); |
336 wifi_access_points->Append(access_point_dictionary); | |
337 | 338 |
338 access_point_dictionary->SetStringWithoutPathExpansion( | 339 access_point_dictionary->SetStringWithoutPathExpansion( |
339 kMacAddress, access_point.mac_address); | 340 kMacAddress, access_point.mac_address); |
340 access_point_dictionary->SetIntegerWithoutPathExpansion( | 341 access_point_dictionary->SetIntegerWithoutPathExpansion( |
341 kSignalStrength, access_point.signal_strength); | 342 kSignalStrength, access_point.signal_strength); |
342 if (!access_point.timestamp.is_null()) { | 343 if (!access_point.timestamp.is_null()) { |
343 access_point_dictionary->SetStringWithoutPathExpansion( | 344 access_point_dictionary->SetStringWithoutPathExpansion( |
344 kAge, | 345 kAge, |
345 base::Int64ToString( | 346 base::Int64ToString( |
346 (base::Time::Now() - access_point.timestamp).InMilliseconds())); | 347 (base::Time::Now() - access_point.timestamp).InMilliseconds())); |
347 } | 348 } |
348 | 349 |
349 access_point_dictionary->SetIntegerWithoutPathExpansion( | 350 access_point_dictionary->SetIntegerWithoutPathExpansion( |
350 kChannel, access_point.channel); | 351 kChannel, access_point.channel); |
351 access_point_dictionary->SetIntegerWithoutPathExpansion( | 352 access_point_dictionary->SetIntegerWithoutPathExpansion( |
352 kSignalToNoiseRatio, access_point.signal_to_noise); | 353 kSignalToNoiseRatio, access_point.signal_to_noise); |
| 354 |
| 355 wifi_access_points->Append(std::move(access_point_dictionary)); |
353 } | 356 } |
354 std::string result; | 357 std::string result; |
355 if (!base::JSONWriter::Write(*request, &result)) { | 358 if (!base::JSONWriter::Write(*request, &result)) { |
356 ReportUmaHasWiFiAccessPoints(false); | 359 ReportUmaHasWiFiAccessPoints(false); |
357 return std::string(kSimpleGeolocationRequestBody); | 360 return std::string(kSimpleGeolocationRequestBody); |
358 } | 361 } |
359 ReportUmaHasWiFiAccessPoints(wifi_data_->size()); | 362 ReportUmaHasWiFiAccessPoints(wifi_data_->size()); |
360 | 363 |
361 return result; | 364 return result; |
362 } | 365 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 ? SIMPLE_GEOLOCATION_REQUEST_RESULT_SERVER_ERROR | 473 ? SIMPLE_GEOLOCATION_REQUEST_RESULT_SERVER_ERROR |
471 : SIMPLE_GEOLOCATION_REQUEST_RESULT_FAILURE); | 474 : SIMPLE_GEOLOCATION_REQUEST_RESULT_FAILURE); |
472 RecordUmaResult(result, retries_); | 475 RecordUmaResult(result, retries_); |
473 position_.status = Geoposition::STATUS_TIMEOUT; | 476 position_.status = Geoposition::STATUS_TIMEOUT; |
474 const base::TimeDelta elapsed = base::Time::Now() - request_started_at_; | 477 const base::TimeDelta elapsed = base::Time::Now() - request_started_at_; |
475 ReplyAndDestroySelf(elapsed, true /* server_error */); | 478 ReplyAndDestroySelf(elapsed, true /* server_error */); |
476 // "this" is already destroyed here. | 479 // "this" is already destroyed here. |
477 } | 480 } |
478 | 481 |
479 } // namespace chromeos | 482 } // namespace chromeos |
OLD | NEW |