File: remoting_client.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (137 lines) | stat: -rw-r--r-- 4,872 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2025 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_CLIENT_COMMON_REMOTING_CLIENT_H_
#define REMOTING_CLIENT_COMMON_REMOTING_CLIENT_H_

#include <memory>
#include <string>
#include <string_view>

#include "base/functional/callback.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "remoting/base/http_status.h"
#include "remoting/base/oauth_token_info.h"
#include "remoting/protocol/client_stub.h"
#include "remoting/protocol/connection_to_host.h"
#include "remoting/signaling/signal_strategy.h"

namespace network {
class SharedURLLoaderFactory;
}

namespace remoting {

namespace apis::v1 {
class GetManagedChromeOsHostResponse;
class HostInfo;
}  // namespace apis::v1

class DirectoryServiceClient;
class OAuthTokenGetter;
class ClientStatusObserver;

namespace protocol {
class ConnectionToHost;
class FrameConsumer;
class SessionManager;
class VideoRenderer;
}  // namespace protocol

// A simple, native chromoting client implementation.
class RemotingClient : public SignalStrategy::Listener,
                       public protocol::ConnectionToHost::HostEventCallback,
                       public protocol::ClientStub {
 public:
  RemotingClient(
      base::OnceClosure quit_closure,
      protocol::FrameConsumer* frame_consumer,
      scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);

  RemotingClient(const RemotingClient&) = delete;
  RemotingClient& operator=(const RemotingClient&) = delete;

  ~RemotingClient() override;

  void StartSession(std::string_view support_access_code,
                    OAuthTokenInfo oauth_token_info);

  void StopSession();

  void AddObserver(ClientStatusObserver* observer);
  void RemoveObserver(ClientStatusObserver* observer);

  base::WeakPtr<RemotingClient> GetWeakPtr();

 private:
  // ClientStub implementation.
  void SetCapabilities(const protocol::Capabilities& capabilities) override;
  void SetPairingResponse(
      const protocol::PairingResponse& pairing_response) override;
  void DeliverHostMessage(const protocol::ExtensionMessage& message) override;
  void SetVideoLayout(const protocol::VideoLayout& layout) override;
  void SetTransportInfo(const protocol::TransportInfo& transport_info) override;
  void SetActiveDisplay(const protocol::ActiveDisplay& active_display) override;
  void InjectClipboardEvent(const protocol::ClipboardEvent& event) override;
  void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override;
  void SetKeyboardLayout(const protocol::KeyboardLayout& layout) override;

  // ConnectionToHost::HostEventCallback implementation.
  void OnConnectionState(protocol::ConnectionToHost::State state,
                         protocol::ErrorCode error) override;
  void OnConnectionReady(bool ready) override;
  void OnRouteChanged(const std::string& channel_name,
                      const protocol::TransportRoute& route) override;

  // SignalStrategy::StatusObserver interface.
  void OnSignalStrategyStateChange(SignalStrategy::State state) override;
  bool OnSignalStrategyIncomingStanza(
      const jingle_xmpp::XmlElement* stanza) override;

  void OnGetManagedChromeOsHostRetrieved(
      const HttpStatus& status,
      std::unique_ptr<apis::v1::GetManagedChromeOsHostResponse> response);

  void StartConnection();
  void RunQuitClosure();

  std::string host_id_;
  std::string host_secret_;
  OAuthTokenInfo oauth_token_info_;
  base::OnceClosure quit_closure_;
  base::ObserverList<ClientStatusObserver> observers_;

  // Used to provide an OAuth access token for service requests. Since a raw *
  // is passed around, this field should be destroyed after the service clients.
  std::unique_ptr<OAuthTokenGetter> oauth_token_getter_;

  // Used to retrieve details about the remote host to connect to.
  std::unique_ptr<DirectoryServiceClient> directory_service_client_;

  // Information about the remote host being connected to.
  std::unique_ptr<apis::v1::HostInfo> chrome_os_host_;

  // TODO: joedow - |Move FtlSignalingConnector| from //remoting/host into
  // //remoting/signaling so it can be used in the client.
  std::unique_ptr<SignalStrategy> signal_strategy_;

  // |frame_consumer_| must outlive |video_renderer_|.
  const raw_ptr<protocol::FrameConsumer> frame_consumer_;

  // Session related members.
  std::unique_ptr<protocol::ConnectionToHost> connection_;
  std::unique_ptr<protocol::SessionManager> session_manager_;
  std::unique_ptr<protocol::VideoRenderer> video_renderer_;

  // Used to make service requests.
  scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;

  base::WeakPtrFactory<RemotingClient> weak_factory_{this};
};

}  // namespace remoting

#endif  // REMOTING_CLIENT_COMMON_REMOTING_CLIENT_H_