#ifndef SERVICES_DEVICE_PUBLIC_CPP_GEOLOCATION_SYSTEM_GEOLOCATION_SOURCE_WIN_H_
#define SERVICES_DEVICE_PUBLIC_CPP_GEOLOCATION_SYSTEM_GEOLOCATION_SOURCE_WIN_H_
#include <windows.devices.geolocation.h>
#include <windows.security.authorization.appcapabilityaccess.h>
#include <wrl/client.h>
#include <memory>
#include <optional>
#include <string_view>
#include "base/memory/weak_ptr.h"
#include "base/threading/sequence_bound.h"
#include "services/device/public/cpp/geolocation/geolocation_system_permission_manager.h"
#include "services/device/public/cpp/geolocation/location_system_permission_status.h"
#include "services/device/public/cpp/geolocation/system_geolocation_source.h"
namespace device {
class COMPONENT_EXPORT(GEOLOCATION) SystemGeolocationSourceWin
: public SystemGeolocationSource {
public:
static std::unique_ptr<GeolocationSystemPermissionManager>
CreateGeolocationSystemPermissionManager();
SystemGeolocationSourceWin();
SystemGeolocationSourceWin(const SystemGeolocationSourceWin&) = delete;
SystemGeolocationSourceWin& operator=(const SystemGeolocationSourceWin&) =
delete;
~SystemGeolocationSourceWin() override;
void RegisterPermissionUpdateCallback(
PermissionUpdateCallback callback) override;
void OpenSystemPermissionSetting() override;
void RequestPermission() override;
void OnPermissionStatusUpdated(LocationSystemPermissionStatus status);
private:
class AccessCheckHelper;
void OnLaunchUriSuccess(uint8_t launched);
void OnLaunchUriFailure(HRESULT result);
void OnRequestLocationAccessSuccess(
ABI::Windows::Devices::Geolocation::GeolocationAccessStatus
geolocation_access_status);
void OnRequestLocationAccessFailure(HRESULT result);
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperation<bool>>
launch_uri_op_;
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperation<
ABI::Windows::Devices::Geolocation::GeolocationAccessStatus>>
request_location_access_op_;
bool has_pending_system_prompt_ = false;
PermissionUpdateCallback permission_update_callback_;
std::optional<LocationSystemPermissionStatus> permission_status_;
base::SequenceBound<AccessCheckHelper> access_check_helper_;
base::WeakPtrFactory<SystemGeolocationSourceWin> weak_factory_{this};
};
}
#endif