| 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/desktop_session_agent.h" | 5 #include "remoting/host/desktop_session_agent.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/memory/shared_memory.h" | 13 #include "base/memory/shared_memory.h" |
| 14 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
| 15 #include "base/time/time.h" |
| 15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 #include "ipc/ipc_channel_proxy.h" | 17 #include "ipc/ipc_channel_proxy.h" |
| 17 #include "ipc/ipc_message.h" | 18 #include "ipc/ipc_message.h" |
| 18 #include "ipc/ipc_message_macros.h" | 19 #include "ipc/ipc_message_macros.h" |
| 19 #include "remoting/base/auto_thread_task_runner.h" | 20 #include "remoting/base/auto_thread_task_runner.h" |
| 20 #include "remoting/base/constants.h" | 21 #include "remoting/base/constants.h" |
| 21 #include "remoting/host/audio_capturer.h" | 22 #include "remoting/host/audio_capturer.h" |
| 22 #include "remoting/host/chromoting_messages.h" | 23 #include "remoting/host/chromoting_messages.h" |
| 23 #include "remoting/host/desktop_environment.h" | 24 #include "remoting/host/desktop_environment.h" |
| 24 #include "remoting/host/input_injector.h" | 25 #include "remoting/host/input_injector.h" |
| 26 #include "remoting/host/process_stats_sender.h" |
| 25 #include "remoting/host/remote_input_filter.h" | 27 #include "remoting/host/remote_input_filter.h" |
| 26 #include "remoting/host/screen_controls.h" | 28 #include "remoting/host/screen_controls.h" |
| 27 #include "remoting/host/screen_resolution.h" | 29 #include "remoting/host/screen_resolution.h" |
| 28 #include "remoting/proto/audio.pb.h" | 30 #include "remoting/proto/audio.pb.h" |
| 29 #include "remoting/proto/control.pb.h" | 31 #include "remoting/proto/control.pb.h" |
| 30 #include "remoting/proto/event.pb.h" | 32 #include "remoting/proto/event.pb.h" |
| 31 #include "remoting/protocol/clipboard_stub.h" | 33 #include "remoting/protocol/clipboard_stub.h" |
| 32 #include "remoting/protocol/errors.h" | 34 #include "remoting/protocol/errors.h" |
| 33 #include "remoting/protocol/input_event_tracker.h" | 35 #include "remoting/protocol/input_event_tracker.h" |
| 34 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 36 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 158 |
| 157 DesktopSessionAgent::DesktopSessionAgent( | 159 DesktopSessionAgent::DesktopSessionAgent( |
| 158 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner, | 160 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner, |
| 159 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 161 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 160 scoped_refptr<AutoThreadTaskRunner> input_task_runner, | 162 scoped_refptr<AutoThreadTaskRunner> input_task_runner, |
| 161 scoped_refptr<AutoThreadTaskRunner> io_task_runner) | 163 scoped_refptr<AutoThreadTaskRunner> io_task_runner) |
| 162 : audio_capture_task_runner_(audio_capture_task_runner), | 164 : audio_capture_task_runner_(audio_capture_task_runner), |
| 163 caller_task_runner_(caller_task_runner), | 165 caller_task_runner_(caller_task_runner), |
| 164 input_task_runner_(input_task_runner), | 166 input_task_runner_(input_task_runner), |
| 165 io_task_runner_(io_task_runner), | 167 io_task_runner_(io_task_runner), |
| 168 current_process_stats_("DesktopSessionAgent"), |
| 166 weak_factory_(this) { | 169 weak_factory_(this) { |
| 167 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 170 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 168 } | 171 } |
| 169 | 172 |
| 170 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) { | 173 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) { |
| 171 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 174 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 172 | 175 |
| 173 bool handled = true; | 176 bool handled = true; |
| 174 if (started_) { | 177 if (started_) { |
| 175 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) | 178 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) |
| 176 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_CaptureFrame, | 179 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_CaptureFrame, |
| 177 OnCaptureFrame) | 180 OnCaptureFrame) |
| 178 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectClipboardEvent, | 181 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectClipboardEvent, |
| 179 OnInjectClipboardEvent) | 182 OnInjectClipboardEvent) |
| 180 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectKeyEvent, | 183 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectKeyEvent, |
| 181 OnInjectKeyEvent) | 184 OnInjectKeyEvent) |
| 182 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectTextEvent, | 185 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectTextEvent, |
| 183 OnInjectTextEvent) | 186 OnInjectTextEvent) |
| 184 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectMouseEvent, | 187 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectMouseEvent, |
| 185 OnInjectMouseEvent) | 188 OnInjectMouseEvent) |
| 186 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectTouchEvent, | 189 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectTouchEvent, |
| 187 OnInjectTouchEvent) | 190 OnInjectTouchEvent) |
| 188 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_SetScreenResolution, | 191 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_SetScreenResolution, |
| 189 SetScreenResolution) | 192 SetScreenResolution) |
| 193 IPC_MESSAGE_HANDLER(ChromotingNetworkToAnyMsg_StartProcessStatsReport, |
| 194 StartProcessStatsReport) |
| 195 IPC_MESSAGE_HANDLER(ChromotingNetworkToAnyMsg_StopProcessStatsReport, |
| 196 StopProcessStatsReport) |
| 190 IPC_MESSAGE_UNHANDLED(handled = false) | 197 IPC_MESSAGE_UNHANDLED(handled = false) |
| 191 IPC_END_MESSAGE_MAP() | 198 IPC_END_MESSAGE_MAP() |
| 192 } else { | 199 } else { |
| 193 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) | 200 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) |
| 194 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_StartSessionAgent, | 201 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_StartSessionAgent, |
| 195 OnStartSessionAgent) | 202 OnStartSessionAgent) |
| 196 IPC_MESSAGE_UNHANDLED(handled = false) | 203 IPC_MESSAGE_UNHANDLED(handled = false) |
| 197 IPC_END_MESSAGE_MAP() | 204 IPC_END_MESSAGE_MAP() |
| 198 } | 205 } |
| 199 | 206 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 217 if (delegate_.get()) | 224 if (delegate_.get()) |
| 218 delegate_->OnNetworkProcessDisconnected(); | 225 delegate_->OnNetworkProcessDisconnected(); |
| 219 } | 226 } |
| 220 | 227 |
| 221 DesktopSessionAgent::~DesktopSessionAgent() { | 228 DesktopSessionAgent::~DesktopSessionAgent() { |
| 222 DCHECK(!audio_capturer_); | 229 DCHECK(!audio_capturer_); |
| 223 DCHECK(!desktop_environment_); | 230 DCHECK(!desktop_environment_); |
| 224 DCHECK(!network_channel_); | 231 DCHECK(!network_channel_); |
| 225 DCHECK(!screen_controls_); | 232 DCHECK(!screen_controls_); |
| 226 DCHECK(!video_capturer_); | 233 DCHECK(!video_capturer_); |
| 234 DCHECK(!stats_sender_); |
| 227 } | 235 } |
| 228 | 236 |
| 229 const std::string& DesktopSessionAgent::client_jid() const { | 237 const std::string& DesktopSessionAgent::client_jid() const { |
| 230 return client_jid_; | 238 return client_jid_; |
| 231 } | 239 } |
| 232 | 240 |
| 233 void DesktopSessionAgent::DisconnectSession(protocol::ErrorCode error) { | 241 void DesktopSessionAgent::DisconnectSession(protocol::ErrorCode error) { |
| 234 SendToNetwork( | 242 SendToNetwork( |
| 235 base::MakeUnique<ChromotingDesktopNetworkMsg_DisconnectSession>(error)); | 243 base::MakeUnique<ChromotingDesktopNetworkMsg_DisconnectSession>(error)); |
| 236 } | 244 } |
| 237 | 245 |
| 238 void DesktopSessionAgent::OnLocalMouseMoved( | 246 void DesktopSessionAgent::OnLocalMouseMoved( |
| 239 const webrtc::DesktopVector& new_pos) { | 247 const webrtc::DesktopVector& new_pos) { |
| 240 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 248 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 241 | 249 |
| 242 remote_input_filter_->LocalMouseMoved(new_pos); | 250 remote_input_filter_->LocalMouseMoved(new_pos); |
| 243 } | 251 } |
| 244 | 252 |
| 245 void DesktopSessionAgent::SetDisableInputs(bool disable_inputs) { | 253 void DesktopSessionAgent::SetDisableInputs(bool disable_inputs) { |
| 246 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 254 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 247 | 255 |
| 248 // Do not expect this method to be called because it is only used by It2Me. | 256 // Do not expect this method to be called because it is only used by It2Me. |
| 249 NOTREACHED(); | 257 NOTREACHED(); |
| 250 } | 258 } |
| 251 | 259 |
| 260 void DesktopSessionAgent::OnProcessStats( |
| 261 const protocol::AggregatedProcessResourceUsage& usage) { |
| 262 SendToNetwork( |
| 263 base::MakeUnique<ChromotingAnyToNetworkMsg_ReportProcessStats>(usage)); |
| 264 } |
| 265 |
| 252 void DesktopSessionAgent::OnStartSessionAgent( | 266 void DesktopSessionAgent::OnStartSessionAgent( |
| 253 const std::string& authenticated_jid, | 267 const std::string& authenticated_jid, |
| 254 const ScreenResolution& resolution, | 268 const ScreenResolution& resolution, |
| 255 const remoting::DesktopEnvironmentOptions& options) { | 269 const remoting::DesktopEnvironmentOptions& options) { |
| 256 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 270 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 257 DCHECK(!started_); | 271 DCHECK(!started_); |
| 258 DCHECK(!audio_capturer_); | 272 DCHECK(!audio_capturer_); |
| 259 DCHECK(!desktop_environment_); | 273 DCHECK(!desktop_environment_); |
| 260 DCHECK(!input_injector_); | 274 DCHECK(!input_injector_); |
| 261 DCHECK(!screen_controls_); | 275 DCHECK(!screen_controls_); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 return; | 388 return; |
| 375 } | 389 } |
| 376 | 390 |
| 377 SendToNetwork(base::MakeUnique<ChromotingDesktopNetworkMsg_AudioPacket>( | 391 SendToNetwork(base::MakeUnique<ChromotingDesktopNetworkMsg_AudioPacket>( |
| 378 serialized_packet)); | 392 serialized_packet)); |
| 379 } | 393 } |
| 380 | 394 |
| 381 mojo::ScopedMessagePipeHandle DesktopSessionAgent::Start( | 395 mojo::ScopedMessagePipeHandle DesktopSessionAgent::Start( |
| 382 const base::WeakPtr<Delegate>& delegate) { | 396 const base::WeakPtr<Delegate>& delegate) { |
| 383 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 397 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 384 DCHECK(delegate_.get() == nullptr); | 398 DCHECK(delegate); |
| 399 DCHECK(!delegate_); |
| 385 | 400 |
| 386 delegate_ = delegate; | 401 delegate_ = delegate; |
| 387 | 402 |
| 388 mojo::MessagePipe pipe; | 403 mojo::MessagePipe pipe; |
| 389 network_channel_ = IPC::ChannelProxy::Create( | 404 network_channel_ = IPC::ChannelProxy::Create( |
| 390 pipe.handle0.release(), IPC::Channel::MODE_SERVER, this, io_task_runner_); | 405 pipe.handle0.release(), IPC::Channel::MODE_SERVER, this, io_task_runner_); |
| 391 return std::move(pipe.handle1); | 406 return std::move(pipe.handle1); |
| 392 } | 407 } |
| 393 | 408 |
| 394 void DesktopSessionAgent::Stop() { | 409 void DesktopSessionAgent::Stop() { |
| 395 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 410 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 396 | 411 |
| 397 delegate_.reset(); | 412 delegate_.reset(); |
| 398 | 413 |
| 414 stats_sender_.reset(); |
| 415 |
| 399 // Make sure the channel is closed. | 416 // Make sure the channel is closed. |
| 400 network_channel_.reset(); | 417 network_channel_.reset(); |
| 401 | 418 |
| 402 if (started_) { | 419 if (started_) { |
| 403 started_ = false; | 420 started_ = false; |
| 404 | 421 |
| 405 // Ignore any further callbacks. | 422 // Ignore any further callbacks. |
| 406 weak_factory_.InvalidateWeakPtrs(); | 423 weak_factory_.InvalidateWeakPtrs(); |
| 407 client_jid_.clear(); | 424 client_jid_.clear(); |
| 408 | 425 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 this)); | 569 this)); |
| 553 } | 570 } |
| 554 } | 571 } |
| 555 | 572 |
| 556 void DesktopSessionAgent::StopAudioCapturer() { | 573 void DesktopSessionAgent::StopAudioCapturer() { |
| 557 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); | 574 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); |
| 558 | 575 |
| 559 audio_capturer_.reset(); | 576 audio_capturer_.reset(); |
| 560 } | 577 } |
| 561 | 578 |
| 579 void DesktopSessionAgent::StartProcessStatsReport(int interval_ms) { |
| 580 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 581 DCHECK(!stats_sender_); |
| 582 |
| 583 if (interval_ms <= 0) { |
| 584 interval_ms = kDefaultProcessStatsIntervalMs; |
| 585 } |
| 586 |
| 587 stats_sender_.reset(new ProcessStatsSender( |
| 588 this, |
| 589 base::TimeDelta::FromMilliseconds(interval_ms), |
| 590 { ¤t_process_stats_ })); |
| 591 } |
| 592 |
| 593 void DesktopSessionAgent::StopProcessStatsReport() { |
| 594 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 595 DCHECK(stats_sender_); |
| 596 stats_sender_.reset(); |
| 597 } |
| 598 |
| 562 } // namespace remoting | 599 } // namespace remoting |
| OLD | NEW |