Chromium Code Reviews| Index: remoting/host/win/wts_console_session_process_driver.cc |
| diff --git a/remoting/host/win/wts_console_session_process_driver.cc b/remoting/host/win/wts_console_session_process_driver.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a838391756a2e4ce20f126db8be0bb9245107a07 |
| --- /dev/null |
| +++ b/remoting/host/win/wts_console_session_process_driver.cc |
| @@ -0,0 +1,132 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +// |
| +// This file implements the Windows service controlling Me2Me host processes |
| +// running within user sessions. |
|
Wez
2012/10/09 03:40:39
nit: Remove this comment.
alexeypa (please no reviews)
2012/10/09 19:42:04
Done.
|
| + |
| +#include "remoting/host/win/wts_console_session_process_driver.h" |
| + |
| +#include <sddl.h> |
| +#include <limits> |
| + |
| +#include "base/base_switches.h" |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/file_path.h" |
| +#include "base/logging.h" |
| +#include "base/single_thread_task_runner.h" |
| +#include "base/path_service.h" |
| +#include "ipc/ipc_message.h" |
| +#include "remoting/host/win/worker_process_launcher.h" |
| +#include "remoting/host/win/wts_console_monitor.h" |
| +#include "remoting/host/win/wts_session_process_delegate.h" |
| + |
| +namespace { |
| + |
| +const FilePath::CharType kMe2meHostBinaryName[] = |
| + FILE_PATH_LITERAL("remoting_host.exe"); |
| + |
| +// The security descriptor of the daemon IPC endpoint. It gives full access |
| +// to LocalSystem and denies access by anyone else. |
| +const char kDaemonIpcSecurityDescriptor[] = "O:SYG:SYD:(A;;GA;;;SY)"; |
| + |
| +} // namespace |
| + |
| +namespace remoting { |
| + |
| +WtsConsoleSessionProcessDriver::WtsConsoleSessionProcessDriver( |
| + const base::Closure& stopped_callback, |
| + WtsConsoleMonitor* monitor, |
| + scoped_refptr<base::SingleThreadTaskRunner> main_message_loop, |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| + : Stoppable(main_message_loop, stopped_callback), |
| + main_task_runner_(main_message_loop), |
| + io_task_runner_(io_task_runner), |
| + monitor_(monitor) { |
| + monitor_->AddWtsConsoleObserver(this); |
| +} |
| + |
| +WtsConsoleSessionProcessDriver::~WtsConsoleSessionProcessDriver() { |
|
Wez
2012/10/09 03:40:39
nit: Thread check
alexeypa (please no reviews)
2012/10/09 19:42:04
Done.
|
| + // Make sure that the object is completely stopped. The same check exists |
| + // in Stoppable::~Stoppable() but this one helps us to fail early and |
| + // predictably. |
| + CHECK_EQ(stoppable_state(), Stoppable::kStopped); |
| + |
| + monitor_->RemoveWtsConsoleObserver(this); |
| + |
| + CHECK(launcher_.get() == NULL); |
| +} |
| + |
| +void WtsConsoleSessionProcessDriver::OnChannelConnected() { |
| + DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| +} |
| + |
| +bool WtsConsoleSessionProcessDriver::OnMessageReceived( |
| + const IPC::Message& message) { |
| + DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| + |
| + return false; |
| +} |
| + |
| +void WtsConsoleSessionProcessDriver::OnPermanentError() { |
| + DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| + |
| + Stop(); |
| +} |
| + |
| +void WtsConsoleSessionProcessDriver::OnSessionAttached(uint32 session_id) { |
| + DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| + |
| + if (stoppable_state() != Stoppable::kRunning) { |
| + return; |
| + } |
| + |
| + DCHECK(launcher_.get() == NULL); |
| + |
| + // Construct the host binary name. |
| + FilePath dir_path; |
| + if (!PathService::Get(base::DIR_EXE, &dir_path)) { |
| + LOG(ERROR) << "Failed to get the executable file name."; |
| + Stop(); |
| + return; |
| + } |
| + FilePath host_binary = dir_path.Append(kMe2meHostBinaryName); |
| + |
| + // Create the delegate knowing how to launch a process in a session. |
|
Wez
2012/10/09 03:40:39
nit: Create a Delegate capable of launching an ele
alexeypa (please no reviews)
2012/10/09 19:42:04
Done.
|
| + scoped_ptr<WtsSessionProcessDelegate> delegate( |
| + new WtsSessionProcessDelegate(main_task_runner_, |
| + io_task_runner_, |
| + host_binary, |
| + session_id, |
| + true)); |
| + |
| + // Create a per-session launcher that will start the host process. |
|
Wez
2012/10/09 03:40:39
nit: Use the Delegate to launch the host process.
alexeypa (please no reviews)
2012/10/09 19:42:04
Done.
|
| + launcher_ = new WorkerProcessLauncher(main_task_runner_, |
| + io_task_runner_, |
| + delegate.Pass(), |
| + this, |
| + kDaemonIpcSecurityDescriptor); |
| + launcher_->Start(); |
| +} |
| + |
| +void WtsConsoleSessionProcessDriver::OnSessionDetached() { |
| + DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| + DCHECK(launcher_.get() != NULL); |
| + |
| + launcher_->Stop(); |
| + launcher_ = NULL; |
| +} |
| + |
| +void WtsConsoleSessionProcessDriver::DoStop() { |
| + DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| + |
| + if (launcher_.get() != NULL) { |
| + launcher_->Stop(); |
| + launcher_ = NULL; |
| + } |
| + |
| + CompleteStopping(); |
| +} |
| + |
| +} // namespace remoting |