Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: remoting/protocol/ice_connection_to_client.cc

Issue 1545743002: Move ownership of Transport out of Session. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_not_pass_client
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/ice_connection_to_client.h" 5 #include "remoting/protocol/ice_connection_to_client.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
12 #include "remoting/codec/video_encoder.h" 12 #include "remoting/codec/video_encoder.h"
13 #include "remoting/codec/video_encoder_verbatim.h" 13 #include "remoting/codec/video_encoder_verbatim.h"
14 #include "remoting/codec/video_encoder_vpx.h" 14 #include "remoting/codec/video_encoder_vpx.h"
15 #include "remoting/protocol/audio_writer.h" 15 #include "remoting/protocol/audio_writer.h"
16 #include "remoting/protocol/clipboard_stub.h" 16 #include "remoting/protocol/clipboard_stub.h"
17 #include "remoting/protocol/host_control_dispatcher.h" 17 #include "remoting/protocol/host_control_dispatcher.h"
18 #include "remoting/protocol/host_event_dispatcher.h" 18 #include "remoting/protocol/host_event_dispatcher.h"
19 #include "remoting/protocol/host_stub.h" 19 #include "remoting/protocol/host_stub.h"
20 #include "remoting/protocol/host_video_dispatcher.h" 20 #include "remoting/protocol/host_video_dispatcher.h"
21 #include "remoting/protocol/input_stub.h" 21 #include "remoting/protocol/input_stub.h"
22 #include "remoting/protocol/transport_context.h"
22 #include "remoting/protocol/video_frame_pump.h" 23 #include "remoting/protocol/video_frame_pump.h"
23 24
24 namespace remoting { 25 namespace remoting {
25 namespace protocol { 26 namespace protocol {
26 27
27 namespace { 28 namespace {
28 29
29 scoped_ptr<VideoEncoder> CreateVideoEncoder( 30 scoped_ptr<VideoEncoder> CreateVideoEncoder(
30 const protocol::SessionConfig& config) { 31 const protocol::SessionConfig& config) {
31 const protocol::ChannelConfig& video_config = config.video_config(); 32 const protocol::ChannelConfig& video_config = config.video_config();
32 33
33 if (video_config.codec == protocol::ChannelConfig::CODEC_VP8) { 34 if (video_config.codec == protocol::ChannelConfig::CODEC_VP8) {
34 return VideoEncoderVpx::CreateForVP8(); 35 return VideoEncoderVpx::CreateForVP8();
35 } else if (video_config.codec == protocol::ChannelConfig::CODEC_VP9) { 36 } else if (video_config.codec == protocol::ChannelConfig::CODEC_VP9) {
36 return VideoEncoderVpx::CreateForVP9(); 37 return VideoEncoderVpx::CreateForVP9();
37 } else if (video_config.codec == protocol::ChannelConfig::CODEC_VERBATIM) { 38 } else if (video_config.codec == protocol::ChannelConfig::CODEC_VERBATIM) {
38 return make_scoped_ptr(new VideoEncoderVerbatim()); 39 return make_scoped_ptr(new VideoEncoderVerbatim());
39 } 40 }
40 41
41 NOTREACHED(); 42 NOTREACHED();
42 return nullptr; 43 return nullptr;
43 } 44 }
44 45
45 } // namespace 46 } // namespace
46 47
47 IceConnectionToClient::IceConnectionToClient( 48 IceConnectionToClient::IceConnectionToClient(
48 scoped_ptr<protocol::Session> session, 49 scoped_ptr<protocol::Session> session,
50 scoped_refptr<TransportContext> transport_context,
49 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner) 51 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner)
50 : event_handler_(nullptr), 52 : event_handler_(nullptr),
51 session_(std::move(session)), 53 session_(std::move(session)),
52 video_encode_task_runner_(video_encode_task_runner), 54 video_encode_task_runner_(video_encode_task_runner),
55 transport_(transport_context, this),
53 control_dispatcher_(new HostControlDispatcher()), 56 control_dispatcher_(new HostControlDispatcher()),
54 event_dispatcher_(new HostEventDispatcher()), 57 event_dispatcher_(new HostEventDispatcher()),
55 video_dispatcher_(new HostVideoDispatcher()) { 58 video_dispatcher_(new HostVideoDispatcher()) {
56 session_->SetEventHandler(this); 59 session_->SetEventHandler(this);
60 session_->SetTransport(&transport_);
57 } 61 }
58 62
59 IceConnectionToClient::~IceConnectionToClient() {} 63 IceConnectionToClient::~IceConnectionToClient() {}
60 64
61 void IceConnectionToClient::SetEventHandler( 65 void IceConnectionToClient::SetEventHandler(
62 ConnectionToClient::EventHandler* event_handler) { 66 ConnectionToClient::EventHandler* event_handler) {
63 DCHECK(thread_checker_.CalledOnValidThread()); 67 DCHECK(thread_checker_.CalledOnValidThread());
64 event_handler_ = event_handler; 68 event_handler_ = event_handler;
65 } 69 }
66 70
67 protocol::Session* IceConnectionToClient::session() { 71 protocol::Session* IceConnectionToClient::session() {
68 DCHECK(thread_checker_.CalledOnValidThread()); 72 DCHECK(thread_checker_.CalledOnValidThread());
69 return session_.get(); 73 return session_.get();
70 } 74 }
71 75
72 void IceConnectionToClient::Disconnect(ErrorCode error) { 76 void IceConnectionToClient::Disconnect(ErrorCode error) {
73 DCHECK(thread_checker_.CalledOnValidThread()); 77 DCHECK(thread_checker_.CalledOnValidThread());
74 78
75 CloseChannels();
76
77 // This should trigger OnConnectionClosed() event and this object 79 // This should trigger OnConnectionClosed() event and this object
78 // may be destroyed as the result. 80 // may be destroyed as the result.
79 session_->Close(error); 81 session_->Close(error);
80 } 82 }
81 83
82 void IceConnectionToClient::OnInputEventReceived(int64_t timestamp) { 84 void IceConnectionToClient::OnInputEventReceived(int64_t timestamp) {
83 DCHECK(thread_checker_.CalledOnValidThread()); 85 DCHECK(thread_checker_.CalledOnValidThread());
84 event_handler_->OnInputEventReceived(this, timestamp); 86 event_handler_->OnInputEventReceived(this, timestamp);
85 } 87 }
86 88
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 131
130 void IceConnectionToClient::OnSessionStateChange(Session::State state) { 132 void IceConnectionToClient::OnSessionStateChange(Session::State state) {
131 DCHECK(thread_checker_.CalledOnValidThread()); 133 DCHECK(thread_checker_.CalledOnValidThread());
132 134
133 DCHECK(event_handler_); 135 DCHECK(event_handler_);
134 switch (state) { 136 switch (state) {
135 case Session::INITIALIZING: 137 case Session::INITIALIZING:
136 case Session::CONNECTING: 138 case Session::CONNECTING:
137 case Session::ACCEPTING: 139 case Session::ACCEPTING:
138 case Session::ACCEPTED: 140 case Session::ACCEPTED:
139 case Session::CONNECTED:
140 // Don't care about these events. 141 // Don't care about these events.
141 break; 142 break;
142 case Session::AUTHENTICATING: 143 case Session::AUTHENTICATING:
143 event_handler_->OnConnectionAuthenticating(this); 144 event_handler_->OnConnectionAuthenticating(this);
144 break; 145 break;
145 case Session::AUTHENTICATED: 146 case Session::AUTHENTICATED:
146 // Initialize channels. 147 // Initialize channels.
147 control_dispatcher_->Init( 148 control_dispatcher_->Init(transport_.GetMultiplexedChannelFactory(),
148 session_->GetTransport()->GetMultiplexedChannelFactory(), this); 149 this);
149 150
150 event_dispatcher_->Init( 151 event_dispatcher_->Init(transport_.GetMultiplexedChannelFactory(), this);
151 session_->GetTransport()->GetMultiplexedChannelFactory(), this);
152 event_dispatcher_->set_on_input_event_callback( 152 event_dispatcher_->set_on_input_event_callback(
153 base::Bind(&IceConnectionToClient::OnInputEventReceived, 153 base::Bind(&IceConnectionToClient::OnInputEventReceived,
154 base::Unretained(this))); 154 base::Unretained(this)));
155 155
156 video_dispatcher_->Init( 156 video_dispatcher_->Init(transport_.GetStreamChannelFactory(), this);
157 session_->GetTransport()->GetStreamChannelFactory(), this);
158 157
159 audio_writer_ = AudioWriter::Create(session_->config()); 158 audio_writer_ = AudioWriter::Create(session_->config());
160 if (audio_writer_.get()) { 159 if (audio_writer_)
161 audio_writer_->Init( 160 audio_writer_->Init(transport_.GetMultiplexedChannelFactory(), this);
162 session_->GetTransport()->GetMultiplexedChannelFactory(), this);
163 }
164 161
165 // Notify the handler after initializing the channels, so that 162 // Notify the handler after initializing the channels, so that
166 // ClientSession can get a client clipboard stub. 163 // ClientSession can get a client clipboard stub.
167 event_handler_->OnConnectionAuthenticated(this); 164 event_handler_->OnConnectionAuthenticated(this);
168 break; 165 break;
169 166
170 case Session::CLOSED: 167 case Session::CLOSED:
171 Close(OK);
172 break;
173
174 case Session::FAILED: 168 case Session::FAILED:
175 Close(session_->error()); 169 CloseChannels();
170 event_handler_->OnConnectionClosed(
171 this, state == Session::FAILED ? session_->error() : OK);
176 break; 172 break;
177 } 173 }
178 } 174 }
179 175
180 void IceConnectionToClient::OnSessionRouteChange( 176
177 void IceConnectionToClient::OnIceTransportRouteChange(
181 const std::string& channel_name, 178 const std::string& channel_name,
182 const TransportRoute& route) { 179 const TransportRoute& route) {
183 event_handler_->OnRouteChange(this, channel_name, route); 180 event_handler_->OnRouteChange(this, channel_name, route);
184 } 181 }
185 182
183 void IceConnectionToClient::OnIceTransportError(ErrorCode error) {
184 DCHECK(thread_checker_.CalledOnValidThread());
185
186 Disconnect(error);
187 }
188
186 void IceConnectionToClient::OnChannelInitialized( 189 void IceConnectionToClient::OnChannelInitialized(
187 ChannelDispatcherBase* channel_dispatcher) { 190 ChannelDispatcherBase* channel_dispatcher) {
188 DCHECK(thread_checker_.CalledOnValidThread()); 191 DCHECK(thread_checker_.CalledOnValidThread());
189 192
190 NotifyIfChannelsReady(); 193 NotifyIfChannelsReady();
191 } 194 }
192 195
193 void IceConnectionToClient::OnChannelError( 196 void IceConnectionToClient::OnChannelError(
194 ChannelDispatcherBase* channel_dispatcher, 197 ChannelDispatcherBase* channel_dispatcher,
195 ErrorCode error) { 198 ErrorCode error) {
196 DCHECK(thread_checker_.CalledOnValidThread()); 199 DCHECK(thread_checker_.CalledOnValidThread());
197 200
198 LOG(ERROR) << "Failed to connect channel " 201 LOG(ERROR) << "Failed to connect channel "
199 << channel_dispatcher->channel_name(); 202 << channel_dispatcher->channel_name();
200 Close(CHANNEL_CONNECTION_ERROR); 203 Disconnect(error);
201 } 204 }
202 205
203 void IceConnectionToClient::NotifyIfChannelsReady() { 206 void IceConnectionToClient::NotifyIfChannelsReady() {
204 DCHECK(thread_checker_.CalledOnValidThread()); 207 DCHECK(thread_checker_.CalledOnValidThread());
205 208
206 if (!control_dispatcher_ || !control_dispatcher_->is_connected()) 209 if (!control_dispatcher_ || !control_dispatcher_->is_connected())
207 return; 210 return;
208 if (!event_dispatcher_ || !event_dispatcher_->is_connected()) 211 if (!event_dispatcher_ || !event_dispatcher_->is_connected())
209 return; 212 return;
210 if (!video_dispatcher_ || !video_dispatcher_->is_connected()) 213 if (!video_dispatcher_ || !video_dispatcher_->is_connected())
211 return; 214 return;
212 if ((!audio_writer_ || !audio_writer_->is_connected()) && 215 if ((!audio_writer_ || !audio_writer_->is_connected()) &&
213 session_->config().is_audio_enabled()) { 216 session_->config().is_audio_enabled()) {
214 return; 217 return;
215 } 218 }
216 event_handler_->OnConnectionChannelsConnected(this); 219 event_handler_->OnConnectionChannelsConnected(this);
217 } 220 }
218 221
219 void IceConnectionToClient::Close(ErrorCode error) {
220 CloseChannels();
221 event_handler_->OnConnectionClosed(this, error);
222 }
223
224 void IceConnectionToClient::CloseChannels() { 222 void IceConnectionToClient::CloseChannels() {
225 control_dispatcher_.reset(); 223 control_dispatcher_.reset();
226 event_dispatcher_.reset(); 224 event_dispatcher_.reset();
227 video_dispatcher_.reset(); 225 video_dispatcher_.reset();
228 audio_writer_.reset(); 226 audio_writer_.reset();
229 } 227 }
230 228
231 } // namespace protocol 229 } // namespace protocol
232 } // namespace remoting 230 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/ice_connection_to_client.h ('k') | remoting/protocol/ice_connection_to_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698