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 // This file implements the Windows service controlling Me2Me host processes | 5 // This file implements the Windows service controlling Me2Me host processes |
| 6 // running within user sessions. | 6 // running within user sessions. |
| 7 | 7 |
| 8 #include "remoting/host/desktop_process.h" | 8 #include "remoting/host/desktop_process.h" |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "ipc/ipc_channel_proxy.h" | 15 #include "ipc/ipc_channel_proxy.h" |
| 16 #include "remoting/base/auto_thread.h" | 16 #include "remoting/base/auto_thread.h" |
| 17 #include "remoting/base/auto_thread_task_runner.h" | 17 #include "remoting/base/auto_thread_task_runner.h" |
| 18 #include "remoting/host/chromoting_messages.h" | 18 #include "remoting/host/chromoting_messages.h" |
| 19 #include "remoting/host/desktop_session_agent.h" | 19 #include "remoting/host/desktop_session_agent.h" |
| 20 | 20 |
| 21 const char kIoThreadName[] = "I/O thread"; | |
| 22 | |
| 23 namespace remoting { | 21 namespace remoting { |
| 24 | 22 |
| 25 DesktopProcess::DesktopProcess( | 23 DesktopProcess::DesktopProcess( |
| 26 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 24 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 27 const std::string& daemon_channel_name) | 25 const std::string& daemon_channel_name) |
| 28 : caller_task_runner_(caller_task_runner), | 26 : caller_task_runner_(caller_task_runner), |
| 29 daemon_channel_name_(daemon_channel_name) { | 27 daemon_channel_name_(daemon_channel_name) { |
| 30 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 28 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 31 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); | 29 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); |
| 32 } | 30 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 53 VLOG(1) << "IPC: desktop <- daemon (" << peer_pid << ")"; | 51 VLOG(1) << "IPC: desktop <- daemon (" << peer_pid << ")"; |
| 54 | 52 |
| 55 NOTIMPLEMENTED(); | 53 NOTIMPLEMENTED(); |
| 56 } | 54 } |
| 57 | 55 |
| 58 void DesktopProcess::OnChannelError() { | 56 void DesktopProcess::OnChannelError() { |
| 59 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 57 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 60 | 58 |
| 61 // Shutdown the desktop process. | 59 // Shutdown the desktop process. |
| 62 daemon_channel_.reset(); | 60 daemon_channel_.reset(); |
| 63 desktop_agent_.reset(); | 61 desktop_agent_->Stop(); |
| 62 desktop_agent_ = NULL; | |
| 64 caller_task_runner_ = NULL; | 63 caller_task_runner_ = NULL; |
|
Wez
2012/11/16 23:37:31
Do you really need to NULL |caller_task_runner_| h
alexeypa (please no reviews)
2012/11/19 21:46:25
Yes. This is the way to stop the process.
Wez
2012/11/20 07:05:39
But if you NULL it then caller_task_runner_->Belon
| |
| 65 } | 64 } |
| 66 | 65 |
| 67 bool DesktopProcess::Start() { | 66 bool DesktopProcess::Start() { |
| 68 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 67 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 69 | 68 |
| 70 // Launch the I/O thread. | 69 // Launch the I/O thread. |
| 71 scoped_refptr<AutoThreadTaskRunner> io_task_runner = | 70 scoped_refptr<AutoThreadTaskRunner> io_task_runner = |
| 72 AutoThread::CreateWithType(kIoThreadName, caller_task_runner_, | 71 AutoThread::CreateWithType("I/O thread", caller_task_runner_, |
| 73 MessageLoop::TYPE_IO); | 72 MessageLoop::TYPE_IO); |
| 74 | 73 |
| 74 // Launch the video capture thread. | |
| 75 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner = | |
| 76 AutoThread::Create("Video capture thread", caller_task_runner_); | |
| 77 | |
| 75 // Create a desktop agent. | 78 // Create a desktop agent. |
| 76 desktop_agent_ = DesktopSessionAgent::Create(caller_task_runner_, | 79 desktop_agent_ = DesktopSessionAgent::Create(caller_task_runner_, |
| 77 io_task_runner); | 80 io_task_runner, |
| 81 video_capture_task_runner); | |
| 78 | 82 |
| 79 // Start the agent and create an IPC channel to talk to it. It is safe to | 83 // Start the agent and create an IPC channel to talk to it. It is safe to |
| 80 // use base::Unretained(this) here because the message loop below will run | 84 // use base::Unretained(this) here because the message loop below will run |
| 81 // until |desktop_agent_| is completely destroyed. | 85 // until |desktop_agent_| is completely destroyed. |
| 82 IPC::PlatformFileForTransit desktop_pipe; | 86 IPC::PlatformFileForTransit desktop_pipe; |
| 83 if (!desktop_agent_->Start(base::Bind(&DesktopProcess::OnChannelError, | 87 if (!desktop_agent_->Start(base::Bind(&DesktopProcess::OnChannelError, |
| 84 base::Unretained(this)), | 88 base::Unretained(this)), |
| 85 &desktop_pipe)) { | 89 &desktop_pipe)) { |
| 86 desktop_agent_.reset(); | 90 desktop_agent_ = NULL; |
|
Wez
2012/11/16 23:37:31
Is there definitely nothing in Stop() that needs d
alexeypa (please no reviews)
2012/11/19 21:46:25
It is all done by DesktopProcess::OnChannelError()
Wez
2012/11/20 07:05:39
Could you do without NULLing |desktop_agent_| here
alexeypa (please no reviews)
2012/11/20 20:15:17
No, I can't. DesktopProcess::OnChannelError may no
| |
| 87 return false; | 91 return false; |
| 88 } | 92 } |
| 89 | 93 |
| 90 // Connect to the daemon. | 94 // Connect to the daemon. |
| 91 daemon_channel_.reset(new IPC::ChannelProxy(daemon_channel_name_, | 95 daemon_channel_.reset(new IPC::ChannelProxy(daemon_channel_name_, |
| 92 IPC::Channel::MODE_CLIENT, | 96 IPC::Channel::MODE_CLIENT, |
| 93 this, | 97 this, |
| 94 io_task_runner)); | 98 io_task_runner)); |
| 95 | 99 |
| 96 // Pass |desktop_pipe| to the daemon. | 100 // Pass |desktop_pipe| to the daemon. |
| 97 daemon_channel_->Send( | 101 daemon_channel_->Send( |
| 98 new ChromotingDesktopDaemonMsg_DesktopAttached(desktop_pipe)); | 102 new ChromotingDesktopDaemonMsg_DesktopAttached(desktop_pipe)); |
| 99 | 103 |
| 100 return true; | 104 return true; |
| 101 } | 105 } |
| 102 | 106 |
| 103 void DesktopProcess::OnCrash(const std::string& function_name, | 107 void DesktopProcess::OnCrash(const std::string& function_name, |
| 104 const std::string& file_name, | 108 const std::string& file_name, |
| 105 const int& line_number) { | 109 const int& line_number) { |
| 106 // The daemon requested us to crash the process. | 110 // The daemon requested us to crash the process. |
| 107 CHECK(false); | 111 CHECK(false); |
| 108 } | 112 } |
| 109 | 113 |
| 110 } // namespace remoting | 114 } // namespace remoting |
| OLD | NEW |