#ifndef SERVICES_DEVICE_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_
#define SERVICES_DEVICE_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_
#include <memory>
#include <string>
#include "base/functional/callback.h"
#include "base/memory/scoped_refptr.h"
#include "base/time/time.h"
#include "services/device/geolocation/wifi_data_provider.h"
#include "services/device/public/mojom/geoposition.mojom.h"
#include "url/gurl.h"
namespace net {
struct PartialNetworkTrafficAnnotationTag;
}
namespace network {
class SharedURLLoaderFactory;
class SimpleURLLoader;
}
namespace device {
class NetworkLocationRequest {
public:
using LocationResponseCallback =
base::RepeatingCallback<void(mojom::GeopositionResultPtr ,
bool ,
const WifiData& )>;
NetworkLocationRequest(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::string& api_key,
LocationResponseCallback callback);
NetworkLocationRequest(const NetworkLocationRequest&) = delete;
NetworkLocationRequest& operator=(const NetworkLocationRequest&) = delete;
~NetworkLocationRequest();
bool MakeRequest(const WifiData& wifi_data,
const base::Time& wifi_timestamp,
const net::PartialNetworkTrafficAnnotationTag&
partial_traffic_annotation);
bool is_request_pending() const { return bool(url_loader_); }
private:
void OnRequestComplete(std::unique_ptr<std::string> data);
const scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
const std::string api_key_;
const LocationResponseCallback location_response_callback_;
std::unique_ptr<network::SimpleURLLoader> url_loader_;
WifiData wifi_data_;
base::Time wifi_timestamp_;
};
}
#endif