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 and
56 // android/java/res/values/strings.xml. The Android app also includes a
57 // constant in android/java/src/org/chromium/chromoting/jni/JniInterface.java
58 // that tracks the numeric value of the CONNECTED state. Be sure to update
59 // these locations to match this one if you make any changes to the ordering.
69 class HostEventCallback
{
71 virtual ~HostEventCallback() {}
73 // Called when state of the connection changes.
74 virtual void OnConnectionState(State state
, ErrorCode error
) = 0;
76 // Called when ready state of the connection changes. When |ready|
77 // is set to false some data sent by the peers may be
78 // delayed. This is used to indicate in the UI when connection is
79 // temporarily broken.
80 virtual void OnConnectionReady(bool ready
) = 0;
83 ConnectionToHost(bool allow_nat_traversal
);
84 virtual ~ConnectionToHost();
86 // |signal_strategy| must outlive connection. |audio_stub| may be
87 // null, in which case audio will not be requested.
88 virtual void Connect(SignalStrategy
* signal_strategy
,
89 const std::string
& host_jid
,
90 const std::string
& host_public_key
,
91 scoped_ptr
<TransportFactory
> transport_factory
,
92 scoped_ptr
<Authenticator
> authenticator
,
93 HostEventCallback
* event_callback
,
94 ClientStub
* client_stub
,
95 ClipboardStub
* clipboard_stub
,
96 VideoStub
* video_stub
,
97 AudioStub
* audio_stub
);
99 virtual const SessionConfig
& config();
101 // Stubs for sending data to the host.
102 virtual ClipboardStub
* clipboard_stub();
103 virtual HostStub
* host_stub();
104 virtual InputStub
* input_stub();
106 // SignalStrategy::StatusObserver interface.
107 virtual void OnSignalStrategyStateChange(
108 SignalStrategy::State state
) OVERRIDE
;
109 virtual bool OnSignalStrategyIncomingStanza(
110 const buzz::XmlElement
* stanza
) OVERRIDE
;
112 // SessionManager::Listener interface.
113 virtual void OnSessionManagerReady() OVERRIDE
;
114 virtual void OnIncomingSession(
116 SessionManager::IncomingSessionResponse
* response
) OVERRIDE
;
118 // Session::EventHandler interface.
119 virtual void OnSessionStateChange(Session::State state
) OVERRIDE
;
120 virtual void OnSessionRouteChange(const std::string
& channel_name
,
121 const TransportRoute
& route
) OVERRIDE
;
122 virtual void OnSessionChannelReady(const std::string
& channel_name
,
123 bool ready
) OVERRIDE
;
125 // Return the current state of ConnectionToHost.
129 // Callbacks for channel initialization
130 void OnChannelInitialized(bool successful
);
132 void NotifyIfChannelsReady();
134 void CloseOnError(ErrorCode error
);
136 // Stops writing in the channels.
137 void CloseChannels();
139 void SetState(State state
, ErrorCode error
);
141 bool allow_nat_traversal_
;
143 std::string host_jid_
;
144 std::string host_public_key_
;
145 scoped_ptr
<Authenticator
> authenticator_
;
147 HostEventCallback
* event_callback_
;
149 // Stub for incoming messages.
150 ClientStub
* client_stub_
;
151 ClipboardStub
* clipboard_stub_
;
152 VideoStub
* video_stub_
;
153 AudioStub
* audio_stub_
;
155 SignalStrategy
* signal_strategy_
;
156 scoped_ptr
<SessionManager
> session_manager_
;
157 scoped_ptr
<Session
> session_
;
159 scoped_ptr
<VideoReader
> video_reader_
;
160 scoped_ptr
<AudioReader
> audio_reader_
;
161 scoped_ptr
<ClientControlDispatcher
> control_dispatcher_
;
162 scoped_ptr
<ClientEventDispatcher
> event_dispatcher_
;
163 ClipboardFilter clipboard_forwarder_
;
164 InputFilter event_forwarder_
;
166 // Internal state of the connection.
170 // List of channels that are not currently ready.
171 std::set
<std::string
> not_ready_channels_
;
174 DISALLOW_COPY_AND_ASSIGN(ConnectionToHost
);
177 } // namespace protocol
178 } // namespace remoting
180 #endif // REMOTING_PROTOCOL_CONNECTION_TO_HOST_H_