#ifndef REMOTING_BASE_CLOUD_SERVICE_CLIENT_H_
#define REMOTING_BASE_CLOUD_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 "remoting/base/protobuf_http_client.h"
#include "remoting/base/protobuf_http_request_config.h"
namespace google::internal::remoting::cloud::v1alpha {
class Empty;
class GenerateHostTokenResponse;
class GenerateIceConfigResponse;
class ReauthorizeHostResponse;
class RemoteAccessHost;
class VerifySessionTokenResponse;
}
namespace google::remoting::cloud::v1 {
class ProvisionGceInstanceResponse;
}
namespace google::protobuf {
class MessageLite;
}
namespace net {
struct NetworkTrafficAnnotationTag;
}
namespace remoting {
class HttpStatus;
class CloudServiceClient {
public:
using GenerateHostTokenCallback = base::OnceCallback<void(
const HttpStatus&,
std::unique_ptr<::google::internal::remoting::cloud::v1alpha::
GenerateHostTokenResponse>)>;
using GenerateIceConfigCallback = base::OnceCallback<void(
const HttpStatus&,
std::unique_ptr<::google::internal::remoting::cloud::v1alpha::
GenerateIceConfigResponse>)>;
using ProvisionGceInstanceCallback = base::OnceCallback<void(
const HttpStatus&,
std::unique_ptr<
::google::remoting::cloud::v1::ProvisionGceInstanceResponse>)>;
using ReauthorizeHostCallback = base::OnceCallback<void(
const HttpStatus&,
std::unique_ptr<::google::internal::remoting::cloud::v1alpha::
ReauthorizeHostResponse>)>;
using SendHeartbeatCallback = base::OnceCallback<void(
const HttpStatus&,
std::unique_ptr<::google::internal::remoting::cloud::v1alpha::Empty>)>;
using UpdateRemoteAccessHostCallback = base::OnceCallback<void(
const HttpStatus&,
std::unique_ptr<
::google::internal::remoting::cloud::v1alpha::RemoteAccessHost>)>;
using VerifySessionTokenCallback = base::OnceCallback<void(
const HttpStatus&,
std::unique_ptr<::google::internal::remoting::cloud::v1alpha::
VerifySessionTokenResponse>)>;
static std::unique_ptr<CloudServiceClient> CreateForChromotingRobotAccount(
OAuthTokenGetter* oauth_token_getter,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
static std::unique_ptr<CloudServiceClient> CreateForGcpProject(
const std::string& api_key,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
static std::unique_ptr<CloudServiceClient> CreateForGceDefaultServiceAccount(
OAuthTokenGetter* oauth_token_getter,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
virtual ~CloudServiceClient();
CloudServiceClient(const CloudServiceClient&) = delete;
CloudServiceClient& operator=(const CloudServiceClient&) = delete;
void ProvisionGceInstance(
const std::string& owner_email,
const std::string& display_name,
const std::string& public_key,
const std::optional<std::string>& existing_directory_id,
const std::optional<std::string>& instance_identity_token,
ProvisionGceInstanceCallback callback);
void SendHeartbeat(const std::string& directory_id,
std::string_view instance_identity_token,
SendHeartbeatCallback callback);
void UpdateRemoteAccessHost(const std::string& directory_id,
std::optional<std::string> host_version,
std::optional<std::string> signaling_id,
std::optional<std::string> offline_reason,
std::optional<std::string> os_name,
std::optional<std::string> os_version,
std::string_view instance_identity_token,
UpdateRemoteAccessHostCallback callback);
void GenerateIceConfig(std::string_view instance_identity_token,
GenerateIceConfigCallback callback);
void GenerateHostToken(std::string_view instance_identity_token,
GenerateHostTokenCallback callback);
void VerifySessionToken(const std::string& session_token,
std::string_view instance_identity_token,
VerifySessionTokenCallback callback);
void ReauthorizeHost(
const std::string& session_reauth_token,
const std::string& session_id,
std::string_view instance_identity_token,
scoped_refptr<const ProtobufHttpRequestConfig::RetryPolicy> retry_policy,
ReauthorizeHostCallback callback);
void CancelPendingRequests();
private:
CloudServiceClient(
const std::string& api_key,
OAuthTokenGetter* oauth_token_getter,
const std::string& base_service_url,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
template <typename CallbackType>
void ExecuteRequest(
const net::NetworkTrafficAnnotationTag& traffic_annotation,
const std::string& path,
const std::string& api_key,
const std::string& method,
std::unique_ptr<google::protobuf::MessageLite> request_message,
CallbackType callback,
scoped_refptr<const ProtobufHttpRequestConfig::RetryPolicy> retry_policy =
ProtobufHttpRequestConfig::GetSimpleRetryPolicy());
std::string api_key_;
ProtobufHttpClient http_client_;
};
}
#endif