Roll WebGL conformance tests and update test expectations.
[chromium-blink-merge.git] / remoting / protocol / connection_to_client.h
blob11f4a3404a350792ec0f401fa5ddf0d55bb79a09
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_PROTOCOL_CONNECTION_TO_CLIENT_H_
6 #define REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_
8 #include <deque>
9 #include <string>
10 #include <vector>
12 #include "base/memory/scoped_ptr.h"
13 #include "base/synchronization/lock.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "remoting/protocol/audio_writer.h"
16 #include "remoting/protocol/session.h"
18 namespace remoting {
19 namespace protocol {
21 class ClientStub;
22 class ClipboardStub;
23 class HostControlDispatcher;
24 class HostEventDispatcher;
25 class HostStub;
26 class HostVideoDispatcher;
27 class InputStub;
28 class VideoStub;
30 // This class represents a remote viewer connection to the chromoting
31 // host. It sets up all protocol channels and connects them to the
32 // stubs.
33 class ConnectionToClient : public base::NonThreadSafe,
34 public Session::EventHandler,
35 public ChannelDispatcherBase::EventHandler {
36 public:
37 class EventHandler {
38 public:
39 // Called when the network connection is authenticating
40 virtual void OnConnectionAuthenticating(ConnectionToClient* connection) = 0;
42 // Called when the network connection is authenticated.
43 virtual void OnConnectionAuthenticated(ConnectionToClient* connection) = 0;
45 // Called when the network connection is authenticated and all
46 // channels are connected.
47 virtual void OnConnectionChannelsConnected(
48 ConnectionToClient* connection) = 0;
50 // Called when the network connection is closed or failed.
51 virtual void OnConnectionClosed(ConnectionToClient* connection,
52 ErrorCode error) = 0;
54 // Called when sequence number is updated.
55 virtual void OnEventTimestamp(ConnectionToClient* connection,
56 int64 timestamp) = 0;
58 // Called on notification of a route change event, which happens when a
59 // channel is connected.
60 virtual void OnRouteChange(ConnectionToClient* connection,
61 const std::string& channel_name,
62 const TransportRoute& route) = 0;
64 protected:
65 virtual ~EventHandler() {}
68 // Constructs a ConnectionToClient object for the |session|. Takes
69 // ownership of |session|.
70 explicit ConnectionToClient(Session* session);
71 ~ConnectionToClient() override;
73 // Set |event_handler| for connection events. Must be called once when this
74 // object is created.
75 void SetEventHandler(EventHandler* event_handler);
77 // Returns the connection in use.
78 virtual Session* session();
80 // Disconnect the client connection.
81 virtual void Disconnect();
83 // Callback for HostEventDispatcher to be called with a timestamp for each
84 // received event.
85 virtual void OnEventTimestamp(int64 timestamp);
87 // Get the stubs used by the host to transmit messages to the client.
88 // The stubs must not be accessed before OnConnectionAuthenticated(), or
89 // after OnConnectionClosed().
90 // Note that the audio stub will be nullptr if audio is not enabled.
91 virtual VideoStub* video_stub();
92 virtual AudioStub* audio_stub();
93 virtual ClientStub* client_stub();
95 // Set/get the stubs which will handle messages we receive from the client.
96 // All stubs MUST be set before the session's channels become connected.
97 virtual void set_clipboard_stub(ClipboardStub* clipboard_stub);
98 virtual ClipboardStub* clipboard_stub();
99 virtual void set_host_stub(HostStub* host_stub);
100 virtual HostStub* host_stub();
101 virtual void set_input_stub(InputStub* input_stub);
102 virtual InputStub* input_stub();
104 // Session::EventHandler interface.
105 void OnSessionStateChange(Session::State state) override;
106 void OnSessionRouteChange(const std::string& channel_name,
107 const TransportRoute& route) override;
109 // ChannelDispatcherBase::EventHandler interface.
110 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override;
111 void OnChannelError(ChannelDispatcherBase* channel_dispatcher,
112 ErrorCode error) override;
114 private:
115 void NotifyIfChannelsReady();
117 void Close(ErrorCode error);
119 // Stops writing in the channels.
120 void CloseChannels();
122 // Event handler for handling events sent from this object.
123 EventHandler* handler_;
125 // Stubs that are called for incoming messages.
126 ClipboardStub* clipboard_stub_;
127 HostStub* host_stub_;
128 InputStub* input_stub_;
130 // The libjingle channel used to send and receive data from the remote client.
131 scoped_ptr<Session> session_;
133 scoped_ptr<HostControlDispatcher> control_dispatcher_;
134 scoped_ptr<HostEventDispatcher> event_dispatcher_;
135 scoped_ptr<HostVideoDispatcher> video_dispatcher_;
136 scoped_ptr<AudioWriter> audio_writer_;
138 DISALLOW_COPY_AND_ASSIGN(ConnectionToClient);
141 } // namespace protocol
142 } // namespace remoting
144 #endif // REMOTING_PROTOCOL_CONNECTION_TO_CLIENT_H_