File: corp_service_client.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (100 lines) | stat: -rw-r--r-- 3,739 bytes parent folder | download | duplicates (3)
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_