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/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(ChromotingNetworkMsg_StartProcessStatsReport, | |
| 194 StartProcessStatsReport) | |
| 190 IPC_MESSAGE_UNHANDLED(handled = false) | 195 IPC_MESSAGE_UNHANDLED(handled = false) |
| 191 IPC_END_MESSAGE_MAP() | 196 IPC_END_MESSAGE_MAP() |
| 192 } else { | 197 } else { |
| 193 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) | 198 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) |
| 194 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_StartSessionAgent, | 199 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_StartSessionAgent, |
| 195 OnStartSessionAgent) | 200 OnStartSessionAgent) |
| 196 IPC_MESSAGE_UNHANDLED(handled = false) | 201 IPC_MESSAGE_UNHANDLED(handled = false) |
| 197 IPC_END_MESSAGE_MAP() | 202 IPC_END_MESSAGE_MAP() |
| 198 } | 203 } |
| 199 | 204 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 217 if (delegate_.get()) | 222 if (delegate_.get()) |
| 218 delegate_->OnNetworkProcessDisconnected(); | 223 delegate_->OnNetworkProcessDisconnected(); |
| 219 } | 224 } |
| 220 | 225 |
| 221 DesktopSessionAgent::~DesktopSessionAgent() { | 226 DesktopSessionAgent::~DesktopSessionAgent() { |
| 222 DCHECK(!audio_capturer_); | 227 DCHECK(!audio_capturer_); |
| 223 DCHECK(!desktop_environment_); | 228 DCHECK(!desktop_environment_); |
| 224 DCHECK(!network_channel_); | 229 DCHECK(!network_channel_); |
| 225 DCHECK(!screen_controls_); | 230 DCHECK(!screen_controls_); |
| 226 DCHECK(!video_capturer_); | 231 DCHECK(!video_capturer_); |
| 232 DCHECK(!stats_sender_); | |
| 227 } | 233 } |
| 228 | 234 |
| 229 const std::string& DesktopSessionAgent::client_jid() const { | 235 const std::string& DesktopSessionAgent::client_jid() const { |
| 230 return client_jid_; | 236 return client_jid_; |
| 231 } | 237 } |
| 232 | 238 |
| 233 void DesktopSessionAgent::DisconnectSession(protocol::ErrorCode error) { | 239 void DesktopSessionAgent::DisconnectSession(protocol::ErrorCode error) { |
| 234 SendToNetwork( | 240 SendToNetwork( |
| 235 base::MakeUnique<ChromotingDesktopNetworkMsg_DisconnectSession>(error)); | 241 base::MakeUnique<ChromotingDesktopNetworkMsg_DisconnectSession>(error)); |
| 236 } | 242 } |
| 237 | 243 |
| 238 void DesktopSessionAgent::OnLocalMouseMoved( | 244 void DesktopSessionAgent::OnLocalMouseMoved( |
| 239 const webrtc::DesktopVector& new_pos) { | 245 const webrtc::DesktopVector& new_pos) { |
| 240 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 246 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 241 | 247 |
| 242 remote_input_filter_->LocalMouseMoved(new_pos); | 248 remote_input_filter_->LocalMouseMoved(new_pos); |
| 243 } | 249 } |
| 244 | 250 |
| 245 void DesktopSessionAgent::SetDisableInputs(bool disable_inputs) { | 251 void DesktopSessionAgent::SetDisableInputs(bool disable_inputs) { |
| 246 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 252 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 247 | 253 |
| 248 // Do not expect this method to be called because it is only used by It2Me. | 254 // Do not expect this method to be called because it is only used by It2Me. |
| 249 NOTREACHED(); | 255 NOTREACHED(); |
| 250 } | 256 } |
| 251 | 257 |
| 258 void DesktopSessionAgent::OnProcessStats( | |
| 259 const protocol::AggregatedProcessResourceUsage& usage) { | |
| 260 SendToNetwork( | |
| 261 base::MakeUnique<ChromotingNetworkMsg_ReportProcessStats>(usage)); | |
| 262 } | |
| 263 | |
| 252 void DesktopSessionAgent::OnStartSessionAgent( | 264 void DesktopSessionAgent::OnStartSessionAgent( |
| 253 const std::string& authenticated_jid, | 265 const std::string& authenticated_jid, |
| 254 const ScreenResolution& resolution, | 266 const ScreenResolution& resolution, |
| 255 const remoting::DesktopEnvironmentOptions& options) { | 267 const remoting::DesktopEnvironmentOptions& options) { |
| 256 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 268 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 257 DCHECK(!started_); | 269 DCHECK(!started_); |
| 258 DCHECK(!audio_capturer_); | 270 DCHECK(!audio_capturer_); |
| 259 DCHECK(!desktop_environment_); | 271 DCHECK(!desktop_environment_); |
| 260 DCHECK(!input_injector_); | 272 DCHECK(!input_injector_); |
| 261 DCHECK(!screen_controls_); | 273 DCHECK(!screen_controls_); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 return; | 386 return; |
| 375 } | 387 } |
| 376 | 388 |
| 377 SendToNetwork(base::MakeUnique<ChromotingDesktopNetworkMsg_AudioPacket>( | 389 SendToNetwork(base::MakeUnique<ChromotingDesktopNetworkMsg_AudioPacket>( |
| 378 serialized_packet)); | 390 serialized_packet)); |
| 379 } | 391 } |
| 380 | 392 |
| 381 mojo::ScopedMessagePipeHandle DesktopSessionAgent::Start( | 393 mojo::ScopedMessagePipeHandle DesktopSessionAgent::Start( |
| 382 const base::WeakPtr<Delegate>& delegate) { | 394 const base::WeakPtr<Delegate>& delegate) { |
| 383 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 395 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 384 DCHECK(delegate_.get() == nullptr); | 396 DCHECK(delegate); |
| 397 DCHECK(!delegate_); | |
| 385 | 398 |
| 386 delegate_ = delegate; | 399 delegate_ = delegate; |
| 387 | 400 |
| 388 mojo::MessagePipe pipe; | 401 mojo::MessagePipe pipe; |
| 389 network_channel_ = IPC::ChannelProxy::Create( | 402 network_channel_ = IPC::ChannelProxy::Create( |
| 390 pipe.handle0.release(), IPC::Channel::MODE_SERVER, this, io_task_runner_); | 403 pipe.handle0.release(), IPC::Channel::MODE_SERVER, this, io_task_runner_); |
| 391 return std::move(pipe.handle1); | 404 return std::move(pipe.handle1); |
| 392 } | 405 } |
| 393 | 406 |
| 394 void DesktopSessionAgent::Stop() { | 407 void DesktopSessionAgent::Stop() { |
| 395 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 408 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 396 | 409 |
| 397 delegate_.reset(); | 410 delegate_.reset(); |
| 398 | 411 |
| 412 stats_sender_.reset(); | |
| 413 | |
| 399 // Make sure the channel is closed. | 414 // Make sure the channel is closed. |
| 400 network_channel_.reset(); | 415 network_channel_.reset(); |
| 401 | 416 |
| 402 if (started_) { | 417 if (started_) { |
| 403 started_ = false; | 418 started_ = false; |
| 404 | 419 |
| 405 // Ignore any further callbacks. | 420 // Ignore any further callbacks. |
| 406 weak_factory_.InvalidateWeakPtrs(); | 421 weak_factory_.InvalidateWeakPtrs(); |
| 407 client_jid_.clear(); | 422 client_jid_.clear(); |
| 408 | 423 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 this)); | 567 this)); |
| 553 } | 568 } |
| 554 } | 569 } |
| 555 | 570 |
| 556 void DesktopSessionAgent::StopAudioCapturer() { | 571 void DesktopSessionAgent::StopAudioCapturer() { |
| 557 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); | 572 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); |
| 558 | 573 |
| 559 audio_capturer_.reset(); | 574 audio_capturer_.reset(); |
| 560 } | 575 } |
| 561 | 576 |
| 577 void DesktopSessionAgent::StartProcessStatsReport(int interval_ms) { | |
| 578 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | |
| 579 | |
|
joedow
2017/06/13 20:12:12
I think it is worth a DCHECK here if you do not in
Hzj_jie
2017/06/14 23:12:23
Done.
| |
| 580 if (!stats_sender_) { | |
| 581 if (interval_ms <= 0) { | |
| 582 interval_ms = 2000; | |
| 583 } | |
| 584 | |
| 585 stats_sender_.reset(new ProcessStatsSender( | |
| 586 this, | |
| 587 base::TimeDelta::FromMilliseconds(interval_ms), | |
| 588 { ¤t_process_stats_ })); | |
| 589 } | |
| 590 } | |
| 591 | |
| 562 } // namespace remoting | 592 } // namespace remoting |
| OLD | NEW |