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 101
|
// Copyright 2020 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_DIRECTORY_SERVICE_CLIENT_H_
#define REMOTING_BASE_DIRECTORY_SERVICE_CLIENT_H_
#include <memory>
#include <string>
#include "base/functional/callback_forward.h"
#include "remoting/base/protobuf_http_client.h"
namespace google::protobuf {
class MessageLite;
} // namespace google::protobuf
namespace net {
struct NetworkTrafficAnnotationTag;
} // namespace net
namespace remoting {
namespace apis::v1 {
class DeleteHostResponse;
class GetManagedChromeOsHostResponse;
class GetHostListResponse;
class HeartbeatResponse;
class RegisterHostResponse;
class SendHeartbeatResponse;
} // namespace apis::v1
class HttpStatus;
class OAuthTokenGetter;
// A service client that communicates with the directory service.
class DirectoryServiceClient {
public:
using DeleteHostCallback =
base::OnceCallback<void(const HttpStatus&,
std::unique_ptr<apis::v1::DeleteHostResponse>)>;
using GetManagedChromeOsHostCallback = base::OnceCallback<void(
const HttpStatus&,
std::unique_ptr<apis::v1::GetManagedChromeOsHostResponse>)>;
using GetHostListCallback =
base::OnceCallback<void(const HttpStatus&,
std::unique_ptr<apis::v1::GetHostListResponse>)>;
using LegacyHeartbeatCallback =
base::OnceCallback<void(const HttpStatus&,
std::unique_ptr<apis::v1::HeartbeatResponse>)>;
using RegisterHostCallback =
base::OnceCallback<void(const HttpStatus&,
std::unique_ptr<apis::v1::RegisterHostResponse>)>;
using SendHeartbeatCallback = base::OnceCallback<void(
const HttpStatus&,
std::unique_ptr<apis::v1::SendHeartbeatResponse>)>;
DirectoryServiceClient(
OAuthTokenGetter* token_getter,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
virtual ~DirectoryServiceClient();
DirectoryServiceClient(const DirectoryServiceClient&) = delete;
DirectoryServiceClient& operator=(const DirectoryServiceClient&) = delete;
void DeleteHost(const std::string& host_id, DeleteHostCallback callback);
void GetManagedChromeOsHost(const std::string& support_id,
GetManagedChromeOsHostCallback callback);
void GetHostList(GetHostListCallback callback);
void LegacyHeartbeat(const std::string& directory_id,
std::optional<std::string> signaling_id,
std::optional<std::string> offline_reason,
bool is_initial_heartbeat,
bool set_fqdn,
const std::string& os_name,
const std::string& os_version,
LegacyHeartbeatCallback callback);
void RegisterHost(const std::string& host_id,
const std::string& host_name,
const std::string& public_key,
const std::string& host_client_id,
RegisterHostCallback callback);
void SendHeartbeat(const std::string& directory_id,
SendHeartbeatCallback callback);
void CancelPendingRequests();
private:
template <typename CallbackType>
void ExecuteRequest(
const net::NetworkTrafficAnnotationTag& traffic_annotation,
const std::string& path,
std::unique_ptr<google::protobuf::MessageLite> request_message,
CallbackType callback);
ProtobufHttpClient http_client_;
};
} // namespace remoting
#endif // REMOTING_BASE_DIRECTORY_SERVICE_CLIENT_H_
|