#ifndef REMOTING_BASE_COMPUTE_ENGINE_SERVICE_CLIENT_H_
#define REMOTING_BASE_COMPUTE_ENGINE_SERVICE_CLIENT_H_
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include "base/functional/callback_forward.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "base/values.h"
#include "net/http/http_status_code.h"
#include "remoting/base/http_status.h"
namespace net {
struct NetworkTrafficAnnotationTag;
}
namespace network {
class SimpleURLLoader;
class SharedURLLoaderFactory;
}
namespace remoting {
class ComputeEngineServiceClient {
public:
using ResponseCallback = base::OnceCallback<void(const HttpStatus&)>;
explicit ComputeEngineServiceClient(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
ComputeEngineServiceClient(const ComputeEngineServiceClient&) = delete;
ComputeEngineServiceClient& operator=(const ComputeEngineServiceClient&) =
delete;
~ComputeEngineServiceClient();
void GetInstanceIdentityToken(std::string_view audience,
ResponseCallback callback);
void GetServiceAccountAccessToken(ResponseCallback callback);
void GetServiceAccountScopes(ResponseCallback callback);
void CancelPendingRequests();
private:
void ExecuteRequest(
std::string_view url,
const net::NetworkTrafficAnnotationTag& network_annotation,
ResponseCallback callback);
void OnRequestComplete(ResponseCallback callback,
std::optional<std::string> response_body);
std::string metadata_server_base_url_;
std::unique_ptr<network::SimpleURLLoader> url_loader_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
THREAD_CHECKER(thread_checker_);
base::WeakPtrFactory<ComputeEngineServiceClient> weak_ptr_factory_{this};
};
}
#endif