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

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

Issue 841773005: Cleanup channel dispatchers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « remoting/protocol/connection_to_client.h ('k') | remoting/protocol/connection_to_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/connection_to_client.h" 5 #include "remoting/protocol/connection_to_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 case Session::ACCEPTING: 112 case Session::ACCEPTING:
113 case Session::CONNECTED: 113 case Session::CONNECTED:
114 // Don't care about these events. 114 // Don't care about these events.
115 break; 115 break;
116 case Session::AUTHENTICATING: 116 case Session::AUTHENTICATING:
117 handler_->OnConnectionAuthenticating(this); 117 handler_->OnConnectionAuthenticating(this);
118 break; 118 break;
119 case Session::AUTHENTICATED: 119 case Session::AUTHENTICATED:
120 // Initialize channels. 120 // Initialize channels.
121 control_dispatcher_.reset(new HostControlDispatcher()); 121 control_dispatcher_.reset(new HostControlDispatcher());
122 control_dispatcher_->Init( 122 control_dispatcher_->Init(session_.get(),
123 session_.get(), session_->config().control_config(), 123 session_->config().control_config(), this);
124 base::Bind(&ConnectionToClient::OnChannelInitialized,
125 base::Unretained(this)));
126 control_dispatcher_->set_clipboard_stub(clipboard_stub_); 124 control_dispatcher_->set_clipboard_stub(clipboard_stub_);
127 control_dispatcher_->set_host_stub(host_stub_); 125 control_dispatcher_->set_host_stub(host_stub_);
128 126
129 event_dispatcher_.reset(new HostEventDispatcher()); 127 event_dispatcher_.reset(new HostEventDispatcher());
130 event_dispatcher_->Init( 128 event_dispatcher_->Init(session_.get(), session_->config().event_config(),
131 session_.get(), session_->config().event_config(), 129 this);
132 base::Bind(&ConnectionToClient::OnChannelInitialized,
133 base::Unretained(this)));
134 event_dispatcher_->set_input_stub(input_stub_); 130 event_dispatcher_->set_input_stub(input_stub_);
135 event_dispatcher_->set_event_timestamp_callback(base::Bind( 131 event_dispatcher_->set_event_timestamp_callback(base::Bind(
136 &ConnectionToClient::OnEventTimestamp, base::Unretained(this))); 132 &ConnectionToClient::OnEventTimestamp, base::Unretained(this)));
137 133
138 video_dispatcher_.reset(new HostVideoDispatcher()); 134 video_dispatcher_.reset(new HostVideoDispatcher());
139 video_dispatcher_->Init( 135 video_dispatcher_->Init(session_.get(), session_->config().video_config(),
140 session_.get(), session_->config().video_config(), 136 this);
141 base::Bind(&ConnectionToClient::OnChannelInitialized,
142 base::Unretained(this)));
143 137
144 audio_writer_ = AudioWriter::Create(session_->config()); 138 audio_writer_ = AudioWriter::Create(session_->config());
145 if (audio_writer_.get()) { 139 if (audio_writer_.get()) {
146 audio_writer_->Init( 140 audio_writer_->Init(session_.get(), session_->config().audio_config(),
147 session_.get(), session_->config().audio_config(), 141 this);
148 base::Bind(&ConnectionToClient::OnChannelInitialized,
149 base::Unretained(this)));
150 } 142 }
151 143
152 // Notify the handler after initializing the channels, so that 144 // Notify the handler after initializing the channels, so that
153 // ClientSession can get a client clipboard stub. 145 // ClientSession can get a client clipboard stub.
154 handler_->OnConnectionAuthenticated(this); 146 handler_->OnConnectionAuthenticated(this);
155 break; 147 break;
156 148
157 case Session::CLOSED: 149 case Session::CLOSED:
158 Close(OK); 150 Close(OK);
159 break; 151 break;
160 152
161 case Session::FAILED: 153 case Session::FAILED:
162 Close(session_->error()); 154 Close(session_->error());
163 break; 155 break;
164 } 156 }
165 } 157 }
166 158
167 void ConnectionToClient::OnSessionRouteChange( 159 void ConnectionToClient::OnSessionRouteChange(
168 const std::string& channel_name, 160 const std::string& channel_name,
169 const TransportRoute& route) { 161 const TransportRoute& route) {
170 handler_->OnRouteChange(this, channel_name, route); 162 handler_->OnRouteChange(this, channel_name, route);
171 } 163 }
172 164
173 void ConnectionToClient::OnChannelInitialized(bool successful) { 165 void ConnectionToClient::OnChannelInitialized(
166 ChannelDispatcherBase* channel_dispatcher) {
174 DCHECK(CalledOnValidThread()); 167 DCHECK(CalledOnValidThread());
175 168
176 if (!successful) { 169 NotifyIfChannelsReady();
177 LOG(ERROR) << "Failed to connect a channel"; 170 }
178 Close(CHANNEL_CONNECTION_ERROR);
179 return;
180 }
181 171
182 NotifyIfChannelsReady(); 172 void ConnectionToClient::OnChannelError(
173 ChannelDispatcherBase* channel_dispatcher,
174 ErrorCode error) {
175 DCHECK(CalledOnValidThread());
176
177 LOG(ERROR) << "Failed to connect channel "
178 << channel_dispatcher->channel_name();
179 Close(CHANNEL_CONNECTION_ERROR);
183 } 180 }
184 181
185 void ConnectionToClient::NotifyIfChannelsReady() { 182 void ConnectionToClient::NotifyIfChannelsReady() {
186 DCHECK(CalledOnValidThread()); 183 DCHECK(CalledOnValidThread());
187 184
188 if (!control_dispatcher_.get() || !control_dispatcher_->is_connected()) 185 if (!control_dispatcher_ || !control_dispatcher_->is_connected())
189 return; 186 return;
190 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) 187 if (!event_dispatcher_ || !event_dispatcher_->is_connected())
191 return; 188 return;
192 if (!video_dispatcher_.get() || !video_dispatcher_->is_connected()) 189 if (!video_dispatcher_ || !video_dispatcher_->is_connected())
193 return; 190 return;
194 if ((!audio_writer_.get() || !audio_writer_->is_connected()) && 191 if ((!audio_writer_ || !audio_writer_->is_connected()) &&
195 session_->config().is_audio_enabled()) { 192 session_->config().is_audio_enabled()) {
196 return; 193 return;
197 } 194 }
198 handler_->OnConnectionChannelsConnected(this); 195 handler_->OnConnectionChannelsConnected(this);
199 } 196 }
200 197
201 void ConnectionToClient::Close(ErrorCode error) { 198 void ConnectionToClient::Close(ErrorCode error) {
202 CloseChannels(); 199 CloseChannels();
203 handler_->OnConnectionClosed(this, error); 200 handler_->OnConnectionClosed(this, error);
204 } 201 }
205 202
206 void ConnectionToClient::CloseChannels() { 203 void ConnectionToClient::CloseChannels() {
207 control_dispatcher_.reset(); 204 control_dispatcher_.reset();
208 event_dispatcher_.reset(); 205 event_dispatcher_.reset();
209 video_dispatcher_.reset(); 206 video_dispatcher_.reset();
210 audio_writer_.reset(); 207 audio_writer_.reset();
211 } 208 }
212 209
213 } // namespace protocol 210 } // namespace protocol
214 } // namespace remoting 211 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/connection_to_client.h ('k') | remoting/protocol/connection_to_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698