Infer appropriate GNU_STACK alignment for a shared library.
[chromium-blink-merge.git] / remoting / host / chromoting_host.h
bloba6b18115d819ae952974dee190099517a76b4fb4
1 // Copyright (c) 2012 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.
5 #ifndef REMOTING_HOST_CHROMOTING_HOST_H_
6 #define REMOTING_HOST_CHROMOTING_HOST_H_
8 #include <list>
9 #include <string>
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h"
16 #include "base/threading/non_thread_safe.h"
17 #include "base/threading/thread.h"
18 #include "net/base/backoff_entry.h"
19 #include "remoting/host/client_session.h"
20 #include "remoting/host/host_extension.h"
21 #include "remoting/host/host_status_monitor.h"
22 #include "remoting/host/host_status_observer.h"
23 #include "remoting/protocol/authenticator.h"
24 #include "remoting/protocol/connection_to_client.h"
25 #include "remoting/protocol/pairing_registry.h"
26 #include "remoting/protocol/session_manager.h"
28 namespace base {
29 class SingleThreadTaskRunner;
30 } // namespace base
32 namespace remoting {
34 namespace protocol {
35 class InputStub;
36 class SessionConfig;
37 class CandidateSessionConfig;
38 } // namespace protocol
40 class DesktopEnvironmentFactory;
42 // A class to implement the functionality of a host process.
44 // Here's the work flow of this class:
45 // 1. We should load the saved GAIA ID token or if this is the first
46 // time the host process runs we should prompt user for the
47 // credential. We will use this token or credentials to authenicate
48 // and register the host.
50 // 2. We listen for incoming connection using libjingle. We will create
51 // a ConnectionToClient object that wraps around linjingle for transport.
52 // A VideoFramePump is created with an Encoder and a webrtc::DesktopCapturer.
53 // A ConnectionToClient is added to the ScreenRecorder for transporting
54 // the screen captures. An InputStub is created and registered with the
55 // ConnectionToClient to receive mouse / keyboard events from the remote
56 // client.
57 // After we have done all the initialization we'll start the ScreenRecorder.
58 // We'll then enter the running state of the host process.
60 // 3. When the user is disconnected, we will pause the ScreenRecorder
61 // and try to terminate the threads we have created. This will allow
62 // all pending tasks to complete. After all of that completed we
63 // return to the idle state. We then go to step (2) if there a new
64 // incoming connection.
65 class ChromotingHost : public base::NonThreadSafe,
66 public ClientSession::EventHandler,
67 public protocol::SessionManager::Listener,
68 public HostStatusMonitor {
69 public:
70 // Both |signal_strategy| and |desktop_environment_factory| should outlive
71 // this object.
72 ChromotingHost(
73 SignalStrategy* signal_strategy,
74 DesktopEnvironmentFactory* desktop_environment_factory,
75 scoped_ptr<protocol::SessionManager> session_manager,
76 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
77 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
78 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner,
79 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner,
80 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
81 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
82 ~ChromotingHost() override;
84 // Asynchronously starts the host.
86 // After this is invoked, the host process will connect to the talk
87 // network and start listening for incoming connections.
89 // This method can only be called once during the lifetime of this object.
90 void Start(const std::string& host_owner);
92 // HostStatusMonitor interface.
93 void AddStatusObserver(HostStatusObserver* observer) override;
94 void RemoveStatusObserver(HostStatusObserver* observer) override;
96 // Registers a host extension.
97 void AddExtension(scoped_ptr<HostExtension> extension);
99 // This method may be called only from
100 // HostStatusObserver::OnClientAuthenticated() to reject the new
101 // client.
102 void RejectAuthenticatingClient();
104 // Sets the authenticator factory to use for incoming
105 // connections. Incoming connections are rejected until
106 // authenticator factory is set. Must be called on the network
107 // thread after the host is started. Must not be called more than
108 // once per host instance because it may not be safe to delete
109 // factory before all authenticators it created are deleted.
110 void SetAuthenticatorFactory(
111 scoped_ptr<protocol::AuthenticatorFactory> authenticator_factory);
113 // Enables/disables curtaining when one or more clients are connected.
114 // Takes immediate effect if clients are already connected.
115 void SetEnableCurtaining(bool enable);
117 // Sets the maximum duration of any session. By default, a session has no
118 // maximum duration.
119 void SetMaximumSessionDuration(const base::TimeDelta& max_session_duration);
121 ////////////////////////////////////////////////////////////////////////////
122 // ClientSession::EventHandler implementation.
123 void OnSessionAuthenticating(ClientSession* client) override;
124 bool OnSessionAuthenticated(ClientSession* client) override;
125 void OnSessionChannelsConnected(ClientSession* client) override;
126 void OnSessionAuthenticationFailed(ClientSession* client) override;
127 void OnSessionClosed(ClientSession* session) override;
128 void OnSessionRouteChange(ClientSession* session,
129 const std::string& channel_name,
130 const protocol::TransportRoute& route) override;
132 // SessionManager::Listener implementation.
133 void OnSessionManagerReady() override;
134 void OnIncomingSession(
135 protocol::Session* session,
136 protocol::SessionManager::IncomingSessionResponse* response) override;
138 // Gets the candidate configuration for the protocol.
139 const protocol::CandidateSessionConfig* protocol_config() const {
140 return protocol_config_.get();
143 // Sets desired configuration for the protocol. Must be called before Start().
144 void set_protocol_config(scoped_ptr<protocol::CandidateSessionConfig> config);
146 // The host uses a pairing registry to generate and store pairing information
147 // for clients for PIN-less authentication.
148 scoped_refptr<protocol::PairingRegistry> pairing_registry() const {
149 return pairing_registry_;
151 void set_pairing_registry(
152 scoped_refptr<protocol::PairingRegistry> pairing_registry) {
153 pairing_registry_ = pairing_registry;
156 base::WeakPtr<ChromotingHost> AsWeakPtr() {
157 return weak_factory_.GetWeakPtr();
160 private:
161 friend class ChromotingHostTest;
163 typedef std::list<ClientSession*> ClientList;
164 typedef ScopedVector<HostExtension> HostExtensionList;
166 // Immediately disconnects all active clients. Host-internal components may
167 // shutdown asynchronously, but the caller is guaranteed not to receive
168 // callbacks for disconnected clients after this call returns.
169 void DisconnectAllClients();
171 // Unless specified otherwise all members of this class must be
172 // used on the network thread only.
174 // Parameters specified when the host was created.
175 DesktopEnvironmentFactory* desktop_environment_factory_;
176 scoped_ptr<protocol::SessionManager> session_manager_;
177 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
178 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner_;
179 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner_;
180 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner_;
181 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
182 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
184 // Connection objects.
185 SignalStrategy* signal_strategy_;
187 // Must be used on the network thread only.
188 ObserverList<HostStatusObserver> status_observers_;
190 // The connections to remote clients.
191 ClientList clients_;
193 // True if the host has been started.
194 bool started_;
196 // Configuration of the protocol.
197 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_;
199 // Login backoff state.
200 net::BackoffEntry login_backoff_;
202 // Flags used for RejectAuthenticatingClient().
203 bool authenticating_client_;
204 bool reject_authenticating_client_;
206 // True if the curtain mode is enabled.
207 bool enable_curtaining_;
209 // The maximum duration of any session.
210 base::TimeDelta max_session_duration_;
212 // The pairing registry for PIN-less authentication.
213 scoped_refptr<protocol::PairingRegistry> pairing_registry_;
215 // List of host extensions.
216 HostExtensionList extensions_;
218 base::WeakPtrFactory<ChromotingHost> weak_factory_;
220 DISALLOW_COPY_AND_ASSIGN(ChromotingHost);
223 } // namespace remoting
225 #endif // REMOTING_HOST_CHROMOTING_HOST_H_