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
{
62 class HostEventCallback
{
64 virtual ~HostEventCallback() {}
66 // Called when state of the connection changes.
67 virtual void OnConnectionState(State state
, ErrorCode error
) = 0;
69 // Called when ready state of the connection changes. When |ready|
70 // is set to false some data sent by the peers may be
71 // delayed. This is used to indicate in the UI when connection is
72 // temporarily broken.
73 virtual void OnConnectionReady(bool ready
) = 0;
76 ConnectionToHost(bool allow_nat_traversal
);
77 virtual ~ConnectionToHost();
79 virtual void Connect(scoped_refptr
<XmppProxy
> xmpp_proxy
,
80 const std::string
& local_jid
,
81 const std::string
& host_jid
,
82 const std::string
& host_public_key
,
83 scoped_ptr
<TransportFactory
> transport_factory
,
84 scoped_ptr
<Authenticator
> authenticator
,
85 HostEventCallback
* event_callback
,
86 ClientStub
* client_stub
,
87 ClipboardStub
* clipboard_stub
,
88 VideoStub
* video_stub
,
89 AudioStub
* audio_stub
);
91 virtual void Disconnect(const base::Closure
& shutdown_task
);
93 virtual const SessionConfig
& config();
95 // Stubs for sending data to the host.
96 virtual ClipboardStub
* clipboard_stub();
97 virtual HostStub
* host_stub();
98 virtual InputStub
* input_stub();
100 // SignalStrategy::StatusObserver interface.
101 virtual void OnSignalStrategyStateChange(
102 SignalStrategy::State state
) OVERRIDE
;
103 virtual bool OnSignalStrategyIncomingStanza(
104 const buzz::XmlElement
* stanza
) OVERRIDE
;
106 // SessionManager::Listener interface.
107 virtual void OnSessionManagerReady() OVERRIDE
;
108 virtual void OnIncomingSession(
110 SessionManager::IncomingSessionResponse
* response
) OVERRIDE
;
112 // Session::EventHandler interface.
113 virtual void OnSessionStateChange(Session::State state
) OVERRIDE
;
114 virtual void OnSessionRouteChange(const std::string
& channel_name
,
115 const TransportRoute
& route
) OVERRIDE
;
116 virtual void OnSessionChannelReady(const std::string
& channel_name
,
117 bool ready
) OVERRIDE
;
119 // Return the current state of ConnectionToHost.
123 // Callbacks for channel initialization
124 void OnChannelInitialized(bool successful
);
126 void NotifyIfChannelsReady();
128 void CloseOnError(ErrorCode error
);
130 // Stops writing in the channels.
131 void CloseChannels();
133 void SetState(State state
, ErrorCode error
);
135 bool allow_nat_traversal_
;
137 std::string host_jid_
;
138 std::string host_public_key_
;
139 scoped_ptr
<Authenticator
> authenticator_
;
141 HostEventCallback
* event_callback_
;
143 // Stub for incoming messages.
144 ClientStub
* client_stub_
;
145 ClipboardStub
* clipboard_stub_
;
146 VideoStub
* video_stub_
;
147 AudioStub
* audio_stub_
;
149 scoped_ptr
<SignalStrategy
> signal_strategy_
;
150 scoped_ptr
<SessionManager
> session_manager_
;
151 scoped_ptr
<Session
> session_
;
153 scoped_ptr
<VideoReader
> video_reader_
;
154 scoped_ptr
<AudioReader
> audio_reader_
;
155 scoped_ptr
<ClientControlDispatcher
> control_dispatcher_
;
156 scoped_ptr
<ClientEventDispatcher
> event_dispatcher_
;
157 ClipboardFilter clipboard_forwarder_
;
158 InputFilter event_forwarder_
;
160 // Internal state of the connection.
164 // List of channels that are not currently ready.
165 std::set
<std::string
> not_ready_channels_
;
168 DISALLOW_COPY_AND_ASSIGN(ConnectionToHost
);
171 } // namespace protocol
172 } // namespace remoting
174 #endif // REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_