1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_BASE_CORP_SERVICE_CLIENT_H_
#define REMOTING_BASE_CORP_SERVICE_CLIENT_H_
#include <memory>
#include <optional>
#include <string>
#include "base/functional/callback_forward.h"
#include "base/memory/scoped_refptr.h"
#include "remoting/base/buildflags.h"
#include "remoting/base/internal_headers.h"
#include "remoting/base/protobuf_http_client.h"
#include "remoting/proto/empty.pb.h"
namespace google::protobuf {
class MessageLite;
} // namespace google::protobuf
namespace net {
struct NetworkTrafficAnnotationTag;
} // namespace net
namespace remoting {
class HttpStatus;
class OAuthTokenGetter;
// A helper class that communicates with backend services using the Corp API.
class CorpServiceClient {
public:
using ProvisionCorpMachineCallback = base::OnceCallback<void(
const HttpStatus&,
std::unique_ptr<internal::ProvisionCorpMachineResponse>)>;
using ReportProvisioningErrorCallback =
base::OnceCallback<void(const HttpStatus&, std::unique_ptr<Empty>)>;
using SendHeartbeatCallback =
base::OnceCallback<void(const HttpStatus&, std::unique_ptr<Empty>)>;
using UpdateRemoteAccessHostCallback = base::OnceCallback<void(
const HttpStatus&,
std::unique_ptr<internal::RemoteAccessHostV1Proto>)>;
// C'tor to use for unauthenticated service requests.
CorpServiceClient(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<net::ClientCertStore> client_cert_store);
// C'tor to use for authenticated requests using the device robot account.
CorpServiceClient(
const std::string& refresh_token,
const std::string& service_account_email,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<net::ClientCertStore> client_cert_store);
~CorpServiceClient();
CorpServiceClient(const CorpServiceClient&) = delete;
CorpServiceClient& operator=(const CorpServiceClient&) = delete;
void ProvisionCorpMachine(const std::string& owner_email,
const std::string& fqdn,
const std::string& public_key,
const std::optional<std::string>& existing_host_id,
ProvisionCorpMachineCallback callback);
void ReportProvisioningError(const std::string& host_id,
const std::string& error_message,
ReportProvisioningErrorCallback callback);
void SendHeartbeat(const std::string& directory_id,
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,
UpdateRemoteAccessHostCallback callback);
void CancelPendingRequests();
private:
template <typename CallbackType>
void ExecuteRequest(
const net::NetworkTrafficAnnotationTag& traffic_annotation,
const std::string& path,
const std::string& method,
bool unauthenticated,
std::unique_ptr<google::protobuf::MessageLite> request_message,
CallbackType callback);
std::unique_ptr<OAuthTokenGetter> oauth_token_getter_;
ProtobufHttpClient http_client_;
};
} // namespace remoting
#endif // REMOTING_BASE_CORP_SERVICE_CLIENT_H_
|