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