#include "services/device/geolocation/network_location_request.h"
#include <stdint.h>
#include <iterator>
#include <limits>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/strings/escape.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/types/expected_macros.h"
#include "base/values.h"
#include "components/device_event_log/device_event_log.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/device/public/cpp/device_features.h"
#include "services/device/public/cpp/geolocation/geoposition.h"
#include "services/device/public/mojom/geolocation_internals.mojom.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace device {
namespace {
const char kNetworkLocationBaseUrl[] = …;
const char kLocationString[] = …;
const char kLatitudeString[] = …;
const char kLongitudeString[] = …;
const char kAccuracyString[] = …;
constexpr std::string_view kAgeKey = …;
constexpr std::string_view kChannelKey = …;
constexpr std::string_view kMacAddressKey = …;
constexpr std::string_view kSignalStrengthKey = …;
constexpr std::string_view kSignalToNoiseRatioKey = …;
constexpr std::string_view kWifiAccessPointsKey = …;
enum NetworkLocationRequestEvent { … };
void RecordUmaEvent(NetworkLocationRequestEvent event) { … }
void RecordUmaResponseCode(int code) { … }
void RecordUmaRequestInterval(base::TimeDelta time_delta) { … }
void RecordUmaNetworkLocationRequestSource(
NetworkLocationRequestSource network_location_request_source) { … }
GURL FormRequestURL(const std::string& api_key);
base::Value::Dict FormUploadData(const WifiData& wifi_data,
const base::Time& wifi_timestamp);
mojom::GeopositionResultPtr CreateGeopositionResultFromResponse(
const base::Value::Dict& response_body,
const base::Time& wifi_timestamp,
const GURL& server_url);
mojom::GeopositionResultPtr CreateGeopositionErrorResult(
const GURL& server_url,
const std::string& error_message,
const std::string& error_technical);
mojom::GeopositionPtr CreateGeoposition(const base::Value::Dict& response_body,
const base::Time& wifi_timestamp);
void AddWifiData(const WifiData& wifi_data,
int age_milliseconds,
base::Value::Dict& request);
std::vector<mojom::AccessPointDataPtr> RequestToMojom(
const base::Value::Dict& request_dict,
const base::Time& wifi_timestamp) { … }
mojom::NetworkLocationResponsePtr ResponseToMojom(
const base::Value::Dict& response_dict) { … }
}
NetworkLocationRequest::NetworkLocationRequest(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::string& api_key,
LocationResponseCallback callback)
: … { … }
NetworkLocationRequest::~NetworkLocationRequest() = default;
void NetworkLocationRequest::MakeRequest(
const WifiData& wifi_data,
const base::Time& wifi_timestamp,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation,
NetworkLocationRequestSource network_location_request_source) { … }
void NetworkLocationRequest::OnRequestComplete(
std::unique_ptr<std::string> data) { … }
std::vector<mojom::AccessPointDataPtr>
NetworkLocationRequest::GetRequestDataForDiagnostics() const { … }
namespace {
struct AccessPointLess { … };
GURL FormRequestURL(const std::string& api_key) { … }
base::Value::Dict FormUploadData(const WifiData& wifi_data,
const base::Time& wifi_timestamp) { … }
void AddString(std::string_view property_name,
const std::string& value,
base::Value::Dict& dict) { … }
void AddInteger(std::string_view property_name,
int value,
base::Value::Dict& dict) { … }
void AddWifiData(const WifiData& wifi_data,
int age_milliseconds,
base::Value::Dict& request) { … }
mojom::GeopositionResultPtr CreateGeopositionErrorResult(
const GURL& server_url,
const std::string& error_message,
const std::string& error_technical) { … }
mojom::GeopositionResultPtr CreateGeopositionResultFromResponse(
const base::Value::Dict& response_body,
const base::Time& wifi_timestamp,
const GURL& server_url) { … }
mojom::GeopositionPtr CreateGeoposition(const base::Value::Dict& response_body,
const base::Time& wifi_timestamp) { … }
}
}