OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "remoting/protocol/webrtc_connection_to_host.h" | 5 #include "remoting/protocol/webrtc_connection_to_host.h" |
6 | 6 |
| 7 #include "jingle/glue/thread_wrapper.h" |
7 #include "remoting/protocol/client_control_dispatcher.h" | 8 #include "remoting/protocol/client_control_dispatcher.h" |
8 #include "remoting/protocol/client_event_dispatcher.h" | 9 #include "remoting/protocol/client_event_dispatcher.h" |
9 #include "remoting/protocol/client_stub.h" | 10 #include "remoting/protocol/client_stub.h" |
10 #include "remoting/protocol/clipboard_stub.h" | 11 #include "remoting/protocol/clipboard_stub.h" |
| 12 #include "remoting/protocol/transport_context.h" |
11 #include "remoting/protocol/webrtc_transport.h" | 13 #include "remoting/protocol/webrtc_transport.h" |
12 | 14 |
13 namespace remoting { | 15 namespace remoting { |
14 namespace protocol { | 16 namespace protocol { |
15 | 17 |
16 WebrtcConnectionToHost::WebrtcConnectionToHost() {} | 18 WebrtcConnectionToHost::WebrtcConnectionToHost() {} |
17 WebrtcConnectionToHost::~WebrtcConnectionToHost() {} | 19 WebrtcConnectionToHost::~WebrtcConnectionToHost() {} |
18 | 20 |
19 void WebrtcConnectionToHost::Connect(scoped_ptr<Session> session, | 21 void WebrtcConnectionToHost::Connect( |
20 HostEventCallback* event_callback) { | 22 scoped_ptr<Session> session, |
| 23 scoped_refptr<TransportContext> transport_context, |
| 24 HostEventCallback* event_callback) { |
21 DCHECK(client_stub_); | 25 DCHECK(client_stub_); |
22 DCHECK(clipboard_stub_); | 26 DCHECK(clipboard_stub_); |
23 | 27 |
| 28 transport_.reset(new WebrtcTransport( |
| 29 jingle_glue::JingleThreadWrapper::current(), transport_context, this)); |
| 30 |
24 session_ = std::move(session); | 31 session_ = std::move(session); |
25 session_->SetEventHandler(this); | 32 session_->SetEventHandler(this); |
| 33 session_->SetTransport(transport_.get()); |
26 | 34 |
27 event_callback_ = event_callback; | 35 event_callback_ = event_callback; |
28 | 36 |
29 SetState(CONNECTING, OK); | 37 SetState(CONNECTING, OK); |
30 } | 38 } |
31 | 39 |
32 const SessionConfig& WebrtcConnectionToHost::config() { | 40 const SessionConfig& WebrtcConnectionToHost::config() { |
33 return session_->config(); | 41 return session_->config(); |
34 } | 42 } |
35 | 43 |
(...skipping 27 matching lines...) Expand all Loading... |
63 | 71 |
64 void WebrtcConnectionToHost::OnSessionStateChange(Session::State state) { | 72 void WebrtcConnectionToHost::OnSessionStateChange(Session::State state) { |
65 DCHECK(event_callback_); | 73 DCHECK(event_callback_); |
66 | 74 |
67 switch (state) { | 75 switch (state) { |
68 case Session::INITIALIZING: | 76 case Session::INITIALIZING: |
69 case Session::CONNECTING: | 77 case Session::CONNECTING: |
70 case Session::ACCEPTING: | 78 case Session::ACCEPTING: |
71 case Session::ACCEPTED: | 79 case Session::ACCEPTED: |
72 case Session::AUTHENTICATING: | 80 case Session::AUTHENTICATING: |
73 case Session::CONNECTED: | |
74 // Don't care about these events. | 81 // Don't care about these events. |
75 break; | 82 break; |
76 | 83 |
77 case Session::AUTHENTICATED: | 84 case Session::AUTHENTICATED: |
78 SetState(AUTHENTICATED, OK); | 85 SetState(AUTHENTICATED, OK); |
79 | 86 |
80 control_dispatcher_.reset(new ClientControlDispatcher()); | 87 control_dispatcher_.reset(new ClientControlDispatcher()); |
81 control_dispatcher_->Init( | 88 control_dispatcher_->Init(transport_->GetStreamChannelFactory(), this); |
82 session_->GetTransport()->GetStreamChannelFactory(), this); | |
83 control_dispatcher_->set_client_stub(client_stub_); | 89 control_dispatcher_->set_client_stub(client_stub_); |
84 control_dispatcher_->set_clipboard_stub(clipboard_stub_); | 90 control_dispatcher_->set_clipboard_stub(clipboard_stub_); |
85 | 91 |
86 event_dispatcher_.reset(new ClientEventDispatcher()); | 92 event_dispatcher_.reset(new ClientEventDispatcher()); |
87 event_dispatcher_->Init( | 93 event_dispatcher_->Init(transport_->GetStreamChannelFactory(), this); |
88 session_->GetTransport()->GetStreamChannelFactory(), this); | |
89 break; | 94 break; |
90 | 95 |
91 case Session::CLOSED: | 96 case Session::CLOSED: |
92 case Session::FAILED: | 97 case Session::FAILED: |
93 CloseChannels(); | 98 CloseChannels(); |
94 SetState(CLOSED, state == Session::FAILED ? session_->error() : OK); | 99 SetState(CLOSED, state == Session::FAILED ? session_->error() : OK); |
95 break; | 100 break; |
96 } | 101 } |
97 } | 102 } |
98 | 103 |
99 void WebrtcConnectionToHost::OnSessionRouteChange( | 104 void WebrtcConnectionToHost::OnWebrtcTransportConnected() {} |
100 const std::string& channel_name, | 105 |
101 const TransportRoute& route) { | 106 void WebrtcConnectionToHost::OnWebrtcTransportError(ErrorCode error) { |
102 event_callback_->OnRouteChanged(channel_name, route); | 107 CloseChannels(); |
| 108 SetState(FAILED, error); |
103 } | 109 } |
104 | 110 |
105 void WebrtcConnectionToHost::OnChannelInitialized( | 111 void WebrtcConnectionToHost::OnChannelInitialized( |
106 ChannelDispatcherBase* channel_dispatcher) { | 112 ChannelDispatcherBase* channel_dispatcher) { |
107 NotifyIfChannelsReady(); | 113 NotifyIfChannelsReady(); |
108 } | 114 } |
109 | 115 |
110 void WebrtcConnectionToHost::OnChannelError( | 116 void WebrtcConnectionToHost::OnChannelError( |
111 ChannelDispatcherBase* channel_dispatcher, | 117 ChannelDispatcherBase* channel_dispatcher, |
112 ErrorCode error) { | 118 ErrorCode error) { |
113 LOG(ERROR) << "Failed to connect channel " << channel_dispatcher; | 119 LOG(ERROR) << "Failed to connect channel " << channel_dispatcher; |
114 CloseChannels(); | 120 CloseChannels(); |
115 SetState(FAILED, CHANNEL_CONNECTION_ERROR); | 121 SetState(FAILED, CHANNEL_CONNECTION_ERROR); |
116 return; | |
117 } | 122 } |
118 | 123 |
119 ConnectionToHost::State WebrtcConnectionToHost::state() const { | 124 ConnectionToHost::State WebrtcConnectionToHost::state() const { |
120 return state_; | 125 return state_; |
121 } | 126 } |
122 | 127 |
123 void WebrtcConnectionToHost::NotifyIfChannelsReady() { | 128 void WebrtcConnectionToHost::NotifyIfChannelsReady() { |
124 if (!control_dispatcher_.get() || !control_dispatcher_->is_connected()) | 129 if (!control_dispatcher_.get() || !control_dispatcher_->is_connected()) |
125 return; | 130 return; |
126 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) | 131 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) |
(...skipping 18 matching lines...) Expand all Loading... |
145 | 150 |
146 if (state != state_) { | 151 if (state != state_) { |
147 state_ = state; | 152 state_ = state; |
148 error_ = error; | 153 error_ = error; |
149 event_callback_->OnConnectionState(state_, error_); | 154 event_callback_->OnConnectionState(state_, error_); |
150 } | 155 } |
151 } | 156 } |
152 | 157 |
153 } // namespace protocol | 158 } // namespace protocol |
154 } // namespace remoting | 159 } // namespace remoting |
OLD | NEW |