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_HOST_H_
6 #define REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_
11 #include "base/callback_forward.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "remoting/jingle_glue/signal_strategy.h"
16 #include "remoting/proto/internal.pb.h"
17 #include "remoting/protocol/clipboard_filter.h"
18 #include "remoting/protocol/errors.h"
19 #include "remoting/protocol/input_filter.h"
20 #include "remoting/protocol/message_reader.h"
21 #include "remoting/protocol/session.h"
22 #include "remoting/protocol/session_manager.h"
38 class ClientControlDispatcher
;
39 class ClientEventDispatcher
;
45 class TransportFactory
;
49 class ConnectionToHost
: public SignalStrategy::Listener
,
50 public SessionManager::Listener
,
51 public Session::EventHandler
,
52 public base::NonThreadSafe
{
54 // The UI implementations maintain corresponding definitions of this
55 // enumeration in webapp/client_session.js,
56 // android/java/res/values/strings.xml and
57 // android/java/src/org/chromium/chromoting/jni/JniInterface.java. Be sure to
58 // update these locations if you make any changes to the ordering.
68 class HostEventCallback
{
70 virtual ~HostEventCallback() {}
72 // Called when state of the connection changes.
73 virtual void OnConnectionState(State state
, ErrorCode error
) = 0;
75 // Called when ready state of the connection changes. When |ready|
76 // is set to false some data sent by the peers may be
77 // delayed. This is used to indicate in the UI when connection is
78 // temporarily broken.
79 virtual void OnConnectionReady(bool ready
) = 0;
81 // Called when the route type (direct vs. STUN vs. proxied) changes.
82 virtual void OnRouteChanged(const std::string
& channel_name
,
83 const protocol::TransportRoute
& route
) = 0;
86 ConnectionToHost(bool allow_nat_traversal
);
87 virtual ~ConnectionToHost();
89 // |signal_strategy| must outlive connection. |audio_stub| may be
90 // null, in which case audio will not be requested.
91 virtual void Connect(SignalStrategy
* signal_strategy
,
92 const std::string
& host_jid
,
93 const std::string
& host_public_key
,
94 scoped_ptr
<TransportFactory
> transport_factory
,
95 scoped_ptr
<Authenticator
> authenticator
,
96 HostEventCallback
* event_callback
,
97 ClientStub
* client_stub
,
98 ClipboardStub
* clipboard_stub
,
99 VideoStub
* video_stub
,
100 AudioStub
* audio_stub
);
102 virtual const SessionConfig
& config();
104 // Stubs for sending data to the host.
105 virtual ClipboardStub
* clipboard_stub();
106 virtual HostStub
* host_stub();
107 virtual InputStub
* input_stub();
109 // SignalStrategy::StatusObserver interface.
110 virtual void OnSignalStrategyStateChange(
111 SignalStrategy::State state
) OVERRIDE
;
112 virtual bool OnSignalStrategyIncomingStanza(
113 const buzz::XmlElement
* stanza
) OVERRIDE
;
115 // SessionManager::Listener interface.
116 virtual void OnSessionManagerReady() OVERRIDE
;
117 virtual void OnIncomingSession(
119 SessionManager::IncomingSessionResponse
* response
) OVERRIDE
;
121 // Session::EventHandler interface.
122 virtual void OnSessionStateChange(Session::State state
) OVERRIDE
;
123 virtual void OnSessionRouteChange(const std::string
& channel_name
,
124 const TransportRoute
& route
) OVERRIDE
;
125 virtual void OnSessionChannelReady(const std::string
& channel_name
,
126 bool ready
) OVERRIDE
;
128 // Return the current state of ConnectionToHost.
132 // Callbacks for channel initialization
133 void OnChannelInitialized(bool successful
);
135 void NotifyIfChannelsReady();
137 void CloseOnError(ErrorCode error
);
139 // Stops writing in the channels.
140 void CloseChannels();
142 void SetState(State state
, ErrorCode error
);
144 bool allow_nat_traversal_
;
146 std::string host_jid_
;
147 std::string host_public_key_
;
148 scoped_ptr
<Authenticator
> authenticator_
;
150 HostEventCallback
* event_callback_
;
152 // Stub for incoming messages.
153 ClientStub
* client_stub_
;
154 ClipboardStub
* clipboard_stub_
;
155 VideoStub
* video_stub_
;
156 AudioStub
* audio_stub_
;
158 SignalStrategy
* signal_strategy_
;
159 scoped_ptr
<SessionManager
> session_manager_
;
160 scoped_ptr
<Session
> session_
;
162 scoped_ptr
<VideoReader
> video_reader_
;
163 scoped_ptr
<AudioReader
> audio_reader_
;
164 scoped_ptr
<ClientControlDispatcher
> control_dispatcher_
;
165 scoped_ptr
<ClientEventDispatcher
> event_dispatcher_
;
166 ClipboardFilter clipboard_forwarder_
;
167 InputFilter event_forwarder_
;
169 // Internal state of the connection.
173 // List of channels that are not currently ready.
174 std::set
<std::string
> not_ready_channels_
;
177 DISALLOW_COPY_AND_ASSIGN(ConnectionToHost
);
180 } // namespace protocol
181 } // namespace remoting
183 #endif // REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_