OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_ | 5 #ifndef REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_ |
6 #define REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_ | 6 #define REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_ |
7 | 7 |
8 #include <set> | |
9 #include <string> | 8 #include <string> |
10 | 9 |
11 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
12 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
14 #include "base/threading/non_thread_safe.h" | |
15 #include "remoting/proto/internal.pb.h" | 13 #include "remoting/proto/internal.pb.h" |
Sergey Ulanov
2015/03/11 20:22:17
I don't think we need this include anymore.
| |
16 #include "remoting/protocol/channel_dispatcher_base.h" | |
17 #include "remoting/protocol/clipboard_filter.h" | 14 #include "remoting/protocol/clipboard_filter.h" |
Sergey Ulanov
2015/03/11 20:22:17
And this one
| |
18 #include "remoting/protocol/errors.h" | 15 #include "remoting/protocol/errors.h" |
19 #include "remoting/protocol/input_filter.h" | |
20 #include "remoting/protocol/message_reader.h" | |
21 #include "remoting/protocol/monitored_video_stub.h" | |
22 #include "remoting/protocol/session.h" | |
23 #include "remoting/protocol/session_config.h" | 16 #include "remoting/protocol/session_config.h" |
Sergey Ulanov
2015/03/11 20:22:17
Forward-declare CandidateSessionConfig and this in
| |
24 #include "remoting/protocol/session_manager.h" | |
25 #include "remoting/signaling/signal_strategy.h" | |
26 | 17 |
27 namespace remoting { | 18 namespace remoting { |
28 | 19 |
29 class XmppProxy; | 20 class SignalStrategy; |
30 class VideoPacket; | |
31 | 21 |
32 namespace protocol { | 22 namespace protocol { |
33 | 23 |
34 class AudioReader; | |
35 class AudioStub; | 24 class AudioStub; |
36 class Authenticator; | 25 class Authenticator; |
37 class ClientControlDispatcher; | |
38 class ClientEventDispatcher; | |
39 class ClientStub; | 26 class ClientStub; |
40 class ClipboardStub; | 27 class ClipboardStub; |
41 class HostStub; | 28 class HostStub; |
42 class InputStub; | 29 class InputStub; |
43 class SessionConfig; | 30 class SessionConfig; |
44 class TransportFactory; | 31 class TransportFactory; |
45 class ClientVideoDispatcher; | 32 struct TransportRoute; |
46 class VideoStub; | 33 class VideoStub; |
47 | 34 |
48 class ConnectionToHost : public SignalStrategy::Listener, | 35 class ConnectionToHost { |
49 public SessionManager::Listener, | |
50 public Session::EventHandler, | |
51 public ChannelDispatcherBase::EventHandler, | |
52 public base::NonThreadSafe { | |
53 public: | 36 public: |
54 // The UI implementations maintain corresponding definitions of this | 37 // The UI implementations maintain corresponding definitions of this |
55 // enumeration in webapp/client_session.js and | 38 // enumeration in webapp/client_session.js and |
56 // android/java/src/org/chromium/chromoting/jni/JniInterface.java. Be sure to | 39 // android/java/src/org/chromium/chromoting/jni/JniInterface.java. Be sure to |
57 // update these locations if you make any changes to the ordering. | 40 // update these locations if you make any changes to the ordering. |
58 enum State { | 41 enum State { |
59 INITIALIZING, | 42 INITIALIZING, |
60 CONNECTING, | 43 CONNECTING, |
61 AUTHENTICATED, | 44 AUTHENTICATED, |
62 CONNECTED, | 45 CONNECTED, |
(...skipping 12 matching lines...) Expand all Loading... | |
75 // is set to false some data sent by the peers may be | 58 // is set to false some data sent by the peers may be |
76 // delayed. This is used to indicate in the UI when connection is | 59 // delayed. This is used to indicate in the UI when connection is |
77 // temporarily broken. | 60 // temporarily broken. |
78 virtual void OnConnectionReady(bool ready) = 0; | 61 virtual void OnConnectionReady(bool ready) = 0; |
79 | 62 |
80 // Called when the route type (direct vs. STUN vs. proxied) changes. | 63 // Called when the route type (direct vs. STUN vs. proxied) changes. |
81 virtual void OnRouteChanged(const std::string& channel_name, | 64 virtual void OnRouteChanged(const std::string& channel_name, |
82 const protocol::TransportRoute& route) = 0; | 65 const protocol::TransportRoute& route) = 0; |
83 }; | 66 }; |
84 | 67 |
85 ConnectionToHost(); | 68 virtual ~ConnectionToHost() {} |
86 ~ConnectionToHost() override; | |
87 | 69 |
88 // Allows to set a custom protocol configuration (e.g. for tests). Cannot be | 70 // Allows to set a custom protocol configuration (e.g. for tests). Cannot be |
89 // called after Connect(). | 71 // called after Connect(). |
90 void set_candidate_config(scoped_ptr<CandidateSessionConfig> config); | 72 virtual void set_candidate_config( |
73 scoped_ptr<CandidateSessionConfig> config) = 0; | |
91 | 74 |
92 // Set the stubs which will handle messages from the host. | 75 // Set the stubs which will handle messages from the host. |
93 // The caller must ensure that stubs out-live the connection. | 76 // The caller must ensure that stubs out-live the connection. |
94 // Unless otherwise specified, all stubs must be set before Connect() | 77 // Unless otherwise specified, all stubs must be set before Connect() |
95 // is called. | 78 // is called. |
96 void set_client_stub(ClientStub* client_stub); | 79 virtual void set_client_stub(ClientStub* client_stub) = 0; |
97 void set_clipboard_stub(ClipboardStub* clipboard_stub); | 80 virtual void set_clipboard_stub(ClipboardStub* clipboard_stub) = 0; |
98 void set_video_stub(VideoStub* video_stub); | 81 virtual void set_video_stub(VideoStub* video_stub) = 0; |
99 // If no audio stub is specified then audio will not be requested. | 82 // If no audio stub is specified then audio will not be requested. |
100 void set_audio_stub(AudioStub* audio_stub); | 83 virtual void set_audio_stub(AudioStub* audio_stub) = 0; |
101 | 84 |
102 // Initiates a connection to the host specified by |host_jid|. | 85 // Initiates a connection to the host specified by |host_jid|. |
103 // |signal_strategy| is used to signal to the host, and must outlive the | 86 // |signal_strategy| is used to signal to the host, and must outlive the |
104 // connection. Data channels will be negotiated over |transport_factory|. | 87 // connection. Data channels will be negotiated over |transport_factory|. |
105 // |authenticator| will be used to authenticate the session and data channels. | 88 // |authenticator| will be used to authenticate the session and data channels. |
106 // |event_callback| will be notified of changes in the state of the connection | 89 // |event_callback| will be notified of changes in the state of the connection |
107 // and must outlive the ConnectionToHost. | 90 // and must outlive the ConnectionToHost. |
108 // Caller must set stubs (see below) before calling Connect. | 91 // Caller must set stubs (see below) before calling Connect. |
109 virtual void Connect(SignalStrategy* signal_strategy, | 92 virtual void Connect(SignalStrategy* signal_strategy, |
110 scoped_ptr<TransportFactory> transport_factory, | 93 scoped_ptr<TransportFactory> transport_factory, |
111 scoped_ptr<Authenticator> authenticator, | 94 scoped_ptr<Authenticator> authenticator, |
112 const std::string& host_jid, | 95 const std::string& host_jid, |
113 HostEventCallback* event_callback); | 96 HostEventCallback* event_callback) = 0; |
114 | 97 |
115 // Returns the session configuration that was negotiated with the host. | 98 // Returns the session configuration that was negotiated with the host. |
116 virtual const SessionConfig& config(); | 99 virtual const SessionConfig& config() = 0; |
117 | 100 |
118 // Stubs for sending data to the host. | 101 // Stubs for sending data to the host. |
119 virtual ClipboardStub* clipboard_forwarder(); | 102 virtual ClipboardStub* clipboard_forwarder() = 0; |
120 virtual HostStub* host_stub(); | 103 virtual HostStub* host_stub() = 0; |
121 virtual InputStub* input_stub(); | 104 virtual InputStub* input_stub() = 0; |
122 | |
123 // SignalStrategy::StatusObserver interface. | |
124 void OnSignalStrategyStateChange(SignalStrategy::State state) override; | |
125 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override; | |
126 | |
127 // SessionManager::Listener interface. | |
128 void OnSessionManagerReady() override; | |
129 void OnIncomingSession( | |
130 Session* session, | |
131 SessionManager::IncomingSessionResponse* response) override; | |
132 | |
133 // Session::EventHandler interface. | |
134 void OnSessionStateChange(Session::State state) override; | |
135 void OnSessionRouteChange(const std::string& channel_name, | |
136 const TransportRoute& route) override; | |
137 | |
138 // ChannelDispatcherBase::EventHandler interface. | |
139 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override; | |
140 void OnChannelError(ChannelDispatcherBase* channel_dispatcher, | |
141 ErrorCode error) override; | |
142 | |
143 // MonitoredVideoStub::EventHandler interface. | |
144 virtual void OnVideoChannelStatus(bool active); | |
145 | 105 |
146 // Return the current state of ConnectionToHost. | 106 // Return the current state of ConnectionToHost. |
147 State state() const; | 107 virtual State state() const = 0; |
148 | |
149 private: | |
150 void NotifyIfChannelsReady(); | |
151 | |
152 void CloseOnError(ErrorCode error); | |
153 | |
154 // Stops writing in the channels. | |
155 void CloseChannels(); | |
156 | |
157 void SetState(State state, ErrorCode error); | |
158 | |
159 std::string host_jid_; | |
160 std::string host_public_key_; | |
161 scoped_ptr<Authenticator> authenticator_; | |
162 | |
163 HostEventCallback* event_callback_; | |
164 | |
165 scoped_ptr<CandidateSessionConfig> candidate_config_; | |
166 | |
167 // Stub for incoming messages. | |
168 ClientStub* client_stub_; | |
169 ClipboardStub* clipboard_stub_; | |
170 AudioStub* audio_stub_; | |
171 | |
172 SignalStrategy* signal_strategy_; | |
173 scoped_ptr<SessionManager> session_manager_; | |
174 scoped_ptr<Session> session_; | |
175 scoped_ptr<MonitoredVideoStub> monitored_video_stub_; | |
176 | |
177 scoped_ptr<ClientVideoDispatcher> video_dispatcher_; | |
178 scoped_ptr<AudioReader> audio_reader_; | |
179 scoped_ptr<ClientControlDispatcher> control_dispatcher_; | |
180 scoped_ptr<ClientEventDispatcher> event_dispatcher_; | |
181 ClipboardFilter clipboard_forwarder_; | |
182 InputFilter event_forwarder_; | |
183 | |
184 // Internal state of the connection. | |
185 State state_; | |
186 ErrorCode error_; | |
187 | |
188 private: | |
189 DISALLOW_COPY_AND_ASSIGN(ConnectionToHost); | |
190 }; | 108 }; |
191 | 109 |
192 } // namespace protocol | 110 } // namespace protocol |
193 } // namespace remoting | 111 } // namespace remoting |
194 | 112 |
195 #endif // REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_ | 113 #endif // REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_ |
OLD | NEW |