| 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" | |
| 16 #include "remoting/protocol/channel_dispatcher_base.h" | |
| 17 #include "remoting/protocol/clipboard_filter.h" | |
| 18 #include "remoting/protocol/errors.h" | 13 #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" | |
| 24 #include "remoting/protocol/session_manager.h" | |
| 25 #include "remoting/signaling/signal_strategy.h" | |
| 26 | 14 |
| 27 namespace remoting { | 15 namespace remoting { |
| 28 | 16 |
| 29 class XmppProxy; | 17 class SignalStrategy; |
| 30 class VideoPacket; | |
| 31 | 18 |
| 32 namespace protocol { | 19 namespace protocol { |
| 33 | 20 |
| 34 class AudioReader; | |
| 35 class AudioStub; | 21 class AudioStub; |
| 36 class Authenticator; | 22 class Authenticator; |
| 37 class ClientControlDispatcher; | 23 class CandidateSessionConfig; |
| 38 class ClientEventDispatcher; | |
| 39 class ClientStub; | 24 class ClientStub; |
| 40 class ClipboardStub; | 25 class ClipboardStub; |
| 26 class ExtensionMessage; |
| 41 class HostStub; | 27 class HostStub; |
| 42 class InputStub; | 28 class InputStub; |
| 43 class SessionConfig; | 29 class SessionConfig; |
| 44 class TransportFactory; | 30 class TransportFactory; |
| 45 class ClientVideoDispatcher; | 31 struct TransportRoute; |
| 46 class VideoStub; | 32 class VideoStub; |
| 47 | 33 |
| 48 class ConnectionToHost : public SignalStrategy::Listener, | 34 class ConnectionToHost { |
| 49 public SessionManager::Listener, | |
| 50 public Session::EventHandler, | |
| 51 public ChannelDispatcherBase::EventHandler, | |
| 52 public base::NonThreadSafe { | |
| 53 public: | 35 public: |
| 54 // The UI implementations maintain corresponding definitions of this | 36 // The UI implementations maintain corresponding definitions of this |
| 55 // enumeration in webapp/client_session.js and | 37 // enumeration in webapp/client_session.js and |
| 56 // android/java/src/org/chromium/chromoting/jni/JniInterface.java. Be sure to | 38 // android/java/src/org/chromium/chromoting/jni/JniInterface.java. Be sure to |
| 57 // update these locations if you make any changes to the ordering. | 39 // update these locations if you make any changes to the ordering. |
| 58 enum State { | 40 enum State { |
| 59 INITIALIZING, | 41 INITIALIZING, |
| 60 CONNECTING, | 42 CONNECTING, |
| 61 AUTHENTICATED, | 43 AUTHENTICATED, |
| 62 CONNECTED, | 44 CONNECTED, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 75 // is set to false some data sent by the peers may be | 57 // 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 | 58 // delayed. This is used to indicate in the UI when connection is |
| 77 // temporarily broken. | 59 // temporarily broken. |
| 78 virtual void OnConnectionReady(bool ready) = 0; | 60 virtual void OnConnectionReady(bool ready) = 0; |
| 79 | 61 |
| 80 // Called when the route type (direct vs. STUN vs. proxied) changes. | 62 // Called when the route type (direct vs. STUN vs. proxied) changes. |
| 81 virtual void OnRouteChanged(const std::string& channel_name, | 63 virtual void OnRouteChanged(const std::string& channel_name, |
| 82 const protocol::TransportRoute& route) = 0; | 64 const protocol::TransportRoute& route) = 0; |
| 83 }; | 65 }; |
| 84 | 66 |
| 85 ConnectionToHost(); | 67 virtual ~ConnectionToHost() {} |
| 86 ~ConnectionToHost() override; | |
| 87 | 68 |
| 88 // Allows to set a custom protocol configuration (e.g. for tests). Cannot be | 69 // Allows to set a custom protocol configuration (e.g. for tests). Cannot be |
| 89 // called after Connect(). | 70 // called after Connect(). |
| 90 void set_candidate_config(scoped_ptr<CandidateSessionConfig> config); | 71 virtual void set_candidate_config( |
| 72 scoped_ptr<CandidateSessionConfig> config) = 0; |
| 91 | 73 |
| 92 // Set the stubs which will handle messages from the host. | 74 // Set the stubs which will handle messages from the host. |
| 93 // The caller must ensure that stubs out-live the connection. | 75 // The caller must ensure that stubs out-live the connection. |
| 94 // Unless otherwise specified, all stubs must be set before Connect() | 76 // Unless otherwise specified, all stubs must be set before Connect() |
| 95 // is called. | 77 // is called. |
| 96 void set_client_stub(ClientStub* client_stub); | 78 virtual void set_client_stub(ClientStub* client_stub) = 0; |
| 97 void set_clipboard_stub(ClipboardStub* clipboard_stub); | 79 virtual void set_clipboard_stub(ClipboardStub* clipboard_stub) = 0; |
| 98 void set_video_stub(VideoStub* video_stub); | 80 virtual void set_video_stub(VideoStub* video_stub) = 0; |
| 99 // If no audio stub is specified then audio will not be requested. | 81 // If no audio stub is specified then audio will not be requested. |
| 100 void set_audio_stub(AudioStub* audio_stub); | 82 virtual void set_audio_stub(AudioStub* audio_stub) = 0; |
| 101 | 83 |
| 102 // Initiates a connection to the host specified by |host_jid|. | 84 // Initiates a connection to the host specified by |host_jid|. |
| 103 // |signal_strategy| is used to signal to the host, and must outlive the | 85 // |signal_strategy| is used to signal to the host, and must outlive the |
| 104 // connection. Data channels will be negotiated over |transport_factory|. | 86 // connection. Data channels will be negotiated over |transport_factory|. |
| 105 // |authenticator| will be used to authenticate the session and data channels. | 87 // |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 | 88 // |event_callback| will be notified of changes in the state of the connection |
| 107 // and must outlive the ConnectionToHost. | 89 // and must outlive the ConnectionToHost. |
| 108 // Caller must set stubs (see below) before calling Connect. | 90 // Caller must set stubs (see below) before calling Connect. |
| 109 virtual void Connect(SignalStrategy* signal_strategy, | 91 virtual void Connect(SignalStrategy* signal_strategy, |
| 110 scoped_ptr<TransportFactory> transport_factory, | 92 scoped_ptr<TransportFactory> transport_factory, |
| 111 scoped_ptr<Authenticator> authenticator, | 93 scoped_ptr<Authenticator> authenticator, |
| 112 const std::string& host_jid, | 94 const std::string& host_jid, |
| 113 HostEventCallback* event_callback); | 95 HostEventCallback* event_callback) = 0; |
| 114 | 96 |
| 115 // Returns the session configuration that was negotiated with the host. | 97 // Returns the session configuration that was negotiated with the host. |
| 116 virtual const SessionConfig& config(); | 98 virtual const SessionConfig& config() = 0; |
| 117 | 99 |
| 118 // Stubs for sending data to the host. | 100 // Stubs for sending data to the host. |
| 119 virtual ClipboardStub* clipboard_forwarder(); | 101 virtual ClipboardStub* clipboard_forwarder() = 0; |
| 120 virtual HostStub* host_stub(); | 102 virtual HostStub* host_stub() = 0; |
| 121 virtual InputStub* input_stub(); | 103 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 | 104 |
| 146 // Return the current state of ConnectionToHost. | 105 // Return the current state of ConnectionToHost. |
| 147 State state() const; | 106 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 }; | 107 }; |
| 191 | 108 |
| 192 } // namespace protocol | 109 } // namespace protocol |
| 193 } // namespace remoting | 110 } // namespace remoting |
| 194 | 111 |
| 195 #endif // REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_ | 112 #endif // REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_ |
| OLD | NEW |