directory_service_client.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef REMOTING_BASE_DIRECTORY_SERVICE_CLIENT_H_
  5. #define REMOTING_BASE_DIRECTORY_SERVICE_CLIENT_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/callback_forward.h"
  9. #include "remoting/base/protobuf_http_client.h"
  10. namespace google {
  11. namespace protobuf {
  12. class MessageLite;
  13. } // namespace protobuf
  14. } // namespace google
  15. namespace net {
  16. struct NetworkTrafficAnnotationTag;
  17. } // namespace net
  18. namespace remoting {
  19. namespace apis {
  20. namespace v1 {
  21. class DeleteHostResponse;
  22. class GetHostListResponse;
  23. class RegisterHostResponse;
  24. } // namespace v1
  25. } // namespace apis
  26. class OAuthTokenGetter;
  27. class ProtobufHttpStatus;
  28. // A service client that communicates with the directory service.
  29. class DirectoryServiceClient {
  30. public:
  31. using DeleteHostCallback =
  32. base::OnceCallback<void(const ProtobufHttpStatus&,
  33. std::unique_ptr<apis::v1::DeleteHostResponse>)>;
  34. using GetHostListCallback =
  35. base::OnceCallback<void(const ProtobufHttpStatus&,
  36. std::unique_ptr<apis::v1::GetHostListResponse>)>;
  37. using RegisterHostCallback =
  38. base::OnceCallback<void(const ProtobufHttpStatus&,
  39. std::unique_ptr<apis::v1::RegisterHostResponse>)>;
  40. DirectoryServiceClient(
  41. OAuthTokenGetter* token_getter,
  42. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
  43. virtual ~DirectoryServiceClient();
  44. DirectoryServiceClient(const DirectoryServiceClient&) = delete;
  45. DirectoryServiceClient& operator=(const DirectoryServiceClient&) = delete;
  46. void DeleteHost(const std::string& host_id, DeleteHostCallback callback);
  47. void GetHostList(GetHostListCallback callback);
  48. void RegisterHost(const std::string& host_id,
  49. const std::string& host_name,
  50. const std::string& public_key,
  51. const std::string& host_client_id,
  52. RegisterHostCallback callback);
  53. void CancelPendingRequests();
  54. private:
  55. template <typename CallbackType>
  56. void ExecuteRequest(
  57. const net::NetworkTrafficAnnotationTag& traffic_annotation,
  58. const std::string& path,
  59. std::unique_ptr<google::protobuf::MessageLite> request_message,
  60. CallbackType callback);
  61. ProtobufHttpClient http_client_;
  62. };
  63. } // namespace remoting
  64. #endif // REMOTING_BASE_DIRECTORY_SERVICE_CLIENT_H_