Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/host/client_session.h" | 5 #include "remoting/host/client_session.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "remoting/base/capabilities.h" | 10 #include "remoting/base/capabilities.h" |
| 11 #include "remoting/base/logging.h" | 11 #include "remoting/base/logging.h" |
| 12 #include "remoting/codec/audio_encoder.h" | 12 #include "remoting/codec/audio_encoder.h" |
| 13 #include "remoting/codec/audio_encoder_opus.h" | 13 #include "remoting/codec/audio_encoder_opus.h" |
| 14 #include "remoting/codec/audio_encoder_verbatim.h" | 14 #include "remoting/codec/audio_encoder_verbatim.h" |
| 15 #include "remoting/codec/video_encoder.h" | 15 #include "remoting/codec/video_encoder.h" |
| 16 #include "remoting/codec/video_encoder_verbatim.h" | 16 #include "remoting/codec/video_encoder_verbatim.h" |
| 17 #include "remoting/codec/video_encoder_vpx.h" | 17 #include "remoting/codec/video_encoder_vpx.h" |
| 18 #include "remoting/host/audio_capturer.h" | 18 #include "remoting/host/audio_capturer.h" |
| 19 #include "remoting/host/audio_scheduler.h" | 19 #include "remoting/host/audio_scheduler.h" |
| 20 #include "remoting/host/desktop_environment.h" | 20 #include "remoting/host/desktop_environment.h" |
| 21 #include "remoting/host/host_extension_session.h" | |
| 21 #include "remoting/host/input_injector.h" | 22 #include "remoting/host/input_injector.h" |
| 22 #include "remoting/host/screen_controls.h" | 23 #include "remoting/host/screen_controls.h" |
| 23 #include "remoting/host/screen_resolution.h" | 24 #include "remoting/host/screen_resolution.h" |
| 24 #include "remoting/host/video_scheduler.h" | 25 #include "remoting/host/video_scheduler.h" |
| 25 #include "remoting/proto/control.pb.h" | 26 #include "remoting/proto/control.pb.h" |
| 26 #include "remoting/proto/event.pb.h" | 27 #include "remoting/proto/event.pb.h" |
| 27 #include "remoting/protocol/client_stub.h" | 28 #include "remoting/protocol/client_stub.h" |
| 28 #include "remoting/protocol/clipboard_thread_proxy.h" | 29 #include "remoting/protocol/clipboard_thread_proxy.h" |
| 29 #include "remoting/protocol/pairing_registry.h" | 30 #include "remoting/protocol/pairing_registry.h" |
| 30 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" | 31 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 DCHECK(CalledOnValidThread()); | 92 DCHECK(CalledOnValidThread()); |
| 92 DCHECK(!audio_scheduler_.get()); | 93 DCHECK(!audio_scheduler_.get()); |
| 93 DCHECK(!desktop_environment_); | 94 DCHECK(!desktop_environment_); |
| 94 DCHECK(!input_injector_); | 95 DCHECK(!input_injector_); |
| 95 DCHECK(!screen_controls_); | 96 DCHECK(!screen_controls_); |
| 96 DCHECK(!video_scheduler_.get()); | 97 DCHECK(!video_scheduler_.get()); |
| 97 | 98 |
| 98 connection_.reset(); | 99 connection_.reset(); |
| 99 } | 100 } |
| 100 | 101 |
| 102 void ClientSession::AddExtensionSession( | |
| 103 scoped_ptr<HostExtensionSession> extension_session) { | |
| 104 DCHECK(CalledOnValidThread()); | |
| 105 | |
| 106 extension_sessions_.push_back(extension_session.release()); | |
| 107 } | |
| 108 | |
| 109 void ClientSession::AddHostCapabilities(const std::string& capabilities) { | |
| 110 DCHECK(CalledOnValidThread()); | |
| 111 | |
| 112 if (capabilities.empty()) | |
| 113 return; | |
| 114 | |
| 115 if (!host_capabilities_.empty()) | |
| 116 host_capabilities_.append(" "); | |
|
Wez
2014/05/28 23:03:41
See comment in ChromotingHost re doing this accumu
dcaiafa
2014/05/29 00:03:16
As you mentioned in the comment's message, AddHost
| |
| 117 | |
| 118 host_capabilities_.append(capabilities); | |
| 119 } | |
| 120 | |
| 101 void ClientSession::NotifyClientResolution( | 121 void ClientSession::NotifyClientResolution( |
| 102 const protocol::ClientResolution& resolution) { | 122 const protocol::ClientResolution& resolution) { |
| 103 DCHECK(CalledOnValidThread()); | 123 DCHECK(CalledOnValidThread()); |
| 104 | 124 |
| 105 // TODO(sergeyu): Move these checks to protocol layer. | 125 // TODO(sergeyu): Move these checks to protocol layer. |
| 106 if (!resolution.has_dips_width() || !resolution.has_dips_height() || | 126 if (!resolution.has_dips_width() || !resolution.has_dips_height() || |
| 107 resolution.dips_width() < 0 || resolution.dips_height() < 0 || | 127 resolution.dips_width() < 0 || resolution.dips_height() < 0 || |
| 108 resolution.width() <= 0 || resolution.height() <= 0) { | 128 resolution.width() <= 0 || resolution.height() <= 0) { |
| 109 LOG(ERROR) << "Received invalid ClientResolution message."; | 129 LOG(ERROR) << "Received invalid ClientResolution message."; |
| 110 return; | 130 return; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 if (client_capabilities_) { | 181 if (client_capabilities_) { |
| 162 LOG(WARNING) << "protocol::Capabilities has been received already."; | 182 LOG(WARNING) << "protocol::Capabilities has been received already."; |
| 163 return; | 183 return; |
| 164 } | 184 } |
| 165 | 185 |
| 166 client_capabilities_ = make_scoped_ptr(new std::string()); | 186 client_capabilities_ = make_scoped_ptr(new std::string()); |
| 167 if (capabilities.has_capabilities()) | 187 if (capabilities.has_capabilities()) |
| 168 *client_capabilities_ = capabilities.capabilities(); | 188 *client_capabilities_ = capabilities.capabilities(); |
| 169 | 189 |
| 170 VLOG(1) << "Client capabilities: " << *client_capabilities_; | 190 VLOG(1) << "Client capabilities: " << *client_capabilities_; |
| 191 event_handler_->OnClientCapabilities(this); | |
| 171 | 192 |
| 172 // Calculate the set of capabilities enabled by both client and host and | 193 // Calculate the set of capabilities enabled by both client and host and |
| 173 // pass it to the desktop environment if it is available. | 194 // pass it to the desktop environment if it is available. |
| 174 desktop_environment_->SetCapabilities( | 195 desktop_environment_->SetCapabilities( |
| 175 IntersectCapabilities(*client_capabilities_, host_capabilities_)); | 196 IntersectCapabilities(*client_capabilities_, host_capabilities_)); |
| 176 } | 197 } |
| 177 | 198 |
| 178 void ClientSession::RequestPairing( | 199 void ClientSession::RequestPairing( |
| 179 const protocol::PairingRequest& pairing_request) { | 200 const protocol::PairingRequest& pairing_request) { |
| 180 if (pairing_registry_ && pairing_request.has_client_name()) { | 201 if (pairing_registry_ && pairing_request.has_client_name()) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 197 reply.set_data(message.data().substr(0, 16)); | 218 reply.set_data(message.data().substr(0, 16)); |
| 198 connection_->client_stub()->DeliverHostMessage(reply); | 219 connection_->client_stub()->DeliverHostMessage(reply); |
| 199 return; | 220 return; |
| 200 } else if (message.type() == "gnubby-auth") { | 221 } else if (message.type() == "gnubby-auth") { |
| 201 if (gnubby_auth_handler_) { | 222 if (gnubby_auth_handler_) { |
| 202 gnubby_auth_handler_->DeliverClientMessage(message.data()); | 223 gnubby_auth_handler_->DeliverClientMessage(message.data()); |
| 203 } else { | 224 } else { |
| 204 HOST_LOG << "gnubby auth is not enabled"; | 225 HOST_LOG << "gnubby auth is not enabled"; |
| 205 } | 226 } |
| 206 return; | 227 return; |
| 228 } else { | |
| 229 for(HostExtensionSessionList::iterator it = extension_sessions_.begin(); | |
| 230 it != extension_sessions_.end(); ++it) { | |
| 231 // Extension returns |true| to indicate that the message was handled. | |
| 232 if ((*it)->OnExtensionMessage(this, message)) | |
| 233 return; | |
| 234 } | |
| 207 } | 235 } |
| 208 } | 236 } |
| 209 HOST_LOG << "Unexpected message received: " | 237 HOST_LOG << "Unexpected message received: " |
| 210 << message.type() << ": " << message.data(); | 238 << message.type() << ": " << message.data(); |
| 211 } | 239 } |
| 212 | 240 |
| 213 void ClientSession::OnConnectionAuthenticating( | 241 void ClientSession::OnConnectionAuthenticating( |
| 214 protocol::ConnectionToClient* connection) { | 242 protocol::ConnectionToClient* connection) { |
| 215 event_handler_->OnSessionAuthenticating(this); | 243 event_handler_->OnSessionAuthenticating(this); |
| 216 } | 244 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 246 | 274 |
| 247 // Create the desktop environment. Drop the connection if it could not be | 275 // Create the desktop environment. Drop the connection if it could not be |
| 248 // created for any reason (for instance the curtain could not initialize). | 276 // created for any reason (for instance the curtain could not initialize). |
| 249 desktop_environment_ = | 277 desktop_environment_ = |
| 250 desktop_environment_factory_->Create(control_factory_.GetWeakPtr()); | 278 desktop_environment_factory_->Create(control_factory_.GetWeakPtr()); |
| 251 if (!desktop_environment_) { | 279 if (!desktop_environment_) { |
| 252 DisconnectSession(); | 280 DisconnectSession(); |
| 253 return; | 281 return; |
| 254 } | 282 } |
| 255 | 283 |
| 256 host_capabilities_ = desktop_environment_->GetCapabilities(); | 284 AddHostCapabilities(desktop_environment_->GetCapabilities()); |
| 257 | 285 |
| 258 // Ignore protocol::Capabilities messages from the client if it does not | 286 // Ignore protocol::Capabilities messages from the client if it does not |
| 259 // support any capabilities. | 287 // support any capabilities. |
| 260 if (!connection_->session()->config().SupportsCapabilities()) { | 288 if (!connection_->session()->config().SupportsCapabilities()) { |
| 261 VLOG(1) << "The client does not support any capabilities."; | 289 VLOG(1) << "The client does not support any capabilities."; |
| 262 | 290 |
| 263 client_capabilities_ = make_scoped_ptr(new std::string()); | 291 client_capabilities_ = make_scoped_ptr(new std::string()); |
| 292 event_handler_->OnClientCapabilities(this); | |
| 293 | |
| 264 desktop_environment_->SetCapabilities(*client_capabilities_); | 294 desktop_environment_->SetCapabilities(*client_capabilities_); |
| 265 } | 295 } |
| 266 | 296 |
| 267 // Create the object that controls the screen resolution. | 297 // Create the object that controls the screen resolution. |
| 268 screen_controls_ = desktop_environment_->CreateScreenControls(); | 298 screen_controls_ = desktop_environment_->CreateScreenControls(); |
| 269 | 299 |
| 270 // Create the event executor. | 300 // Create the event executor. |
| 271 input_injector_ = desktop_environment_->CreateInputInjector(); | 301 input_injector_ = desktop_environment_->CreateInputInjector(); |
| 272 | 302 |
| 273 // Connect the host clipboard and input stubs. | 303 // Connect the host clipboard and input stubs. |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 return scoped_ptr<AudioEncoder>(new AudioEncoderVerbatim()); | 496 return scoped_ptr<AudioEncoder>(new AudioEncoderVerbatim()); |
| 467 } else if (audio_config.codec == protocol::ChannelConfig::CODEC_OPUS) { | 497 } else if (audio_config.codec == protocol::ChannelConfig::CODEC_OPUS) { |
| 468 return scoped_ptr<AudioEncoder>(new AudioEncoderOpus()); | 498 return scoped_ptr<AudioEncoder>(new AudioEncoderOpus()); |
| 469 } | 499 } |
| 470 | 500 |
| 471 NOTREACHED(); | 501 NOTREACHED(); |
| 472 return scoped_ptr<AudioEncoder>(); | 502 return scoped_ptr<AudioEncoder>(); |
| 473 } | 503 } |
| 474 | 504 |
| 475 } // namespace remoting | 505 } // namespace remoting |
| OLD | NEW |