| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // This file implements the Windows service controlling Me2Me host processes |
| 6 // running within user sessions. |
| 7 |
| 8 #include "remoting/host/win/wts_console_session_process_driver.h" |
| 9 |
| 10 #include <sddl.h> |
| 11 #include <limits> |
| 12 |
| 13 #include "base/base_switches.h" |
| 14 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" |
| 16 #include "base/file_path.h" |
| 17 #include "base/logging.h" |
| 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/path_service.h" |
| 20 #include "ipc/ipc_message.h" |
| 21 #include "remoting/host/win/worker_process_launcher.h" |
| 22 #include "remoting/host/win/wts_console_monitor.h" |
| 23 #include "remoting/host/win/wts_session_process_delegate.h" |
| 24 |
| 25 namespace { |
| 26 |
| 27 const FilePath::CharType kMe2meHostBinaryName[] = |
| 28 FILE_PATH_LITERAL("remoting_host.exe"); |
| 29 |
| 30 // The security descriptor of the daemon IPC endpoint. It gives full access |
| 31 // to LocalSystem and denies access by anyone else. |
| 32 const char kDaemonIpcSecurityDescriptor[] = "O:SYG:SYD:(A;;GA;;;SY)"; |
| 33 |
| 34 } // namespace |
| 35 |
| 36 namespace remoting { |
| 37 |
| 38 WtsConsoleSessionProcessDriver::WtsConsoleSessionProcessDriver( |
| 39 const base::Closure& stopped_callback, |
| 40 WtsConsoleMonitor* monitor, |
| 41 scoped_refptr<base::SingleThreadTaskRunner> main_message_loop, |
| 42 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| 43 : Stoppable(main_message_loop, stopped_callback), |
| 44 main_task_runner_(main_message_loop), |
| 45 io_task_runner_(io_task_runner), |
| 46 monitor_(monitor) { |
| 47 monitor_->AddWtsConsoleObserver(this); |
| 48 } |
| 49 |
| 50 WtsConsoleSessionProcessDriver::~WtsConsoleSessionProcessDriver() { |
| 51 // Make sure that the object is completely stopped. The same check exists |
| 52 // in Stoppable::~Stoppable() but this one helps us to fail early and |
| 53 // predictably. |
| 54 CHECK_EQ(stoppable_state(), Stoppable::kStopped); |
| 55 |
| 56 monitor_->RemoveWtsConsoleObserver(this); |
| 57 |
| 58 CHECK(launcher_.get() == NULL); |
| 59 } |
| 60 |
| 61 void WtsConsoleSessionProcessDriver::OnChannelConnected() { |
| 62 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 63 } |
| 64 |
| 65 bool WtsConsoleSessionProcessDriver::OnMessageReceived( |
| 66 const IPC::Message& message) { |
| 67 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 68 |
| 69 return false; |
| 70 } |
| 71 |
| 72 void WtsConsoleSessionProcessDriver::OnPermanentError() { |
| 73 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 74 |
| 75 Stop(); |
| 76 } |
| 77 |
| 78 void WtsConsoleSessionProcessDriver::OnSessionAttached(uint32 session_id) { |
| 79 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 80 |
| 81 if (stoppable_state() != Stoppable::kRunning) { |
| 82 return; |
| 83 } |
| 84 |
| 85 DCHECK(launcher_.get() == NULL); |
| 86 |
| 87 // Construct the host binary name. |
| 88 FilePath dir_path; |
| 89 if (!PathService::Get(base::DIR_EXE, &dir_path)) { |
| 90 LOG(ERROR) << "Failed to get the executable file name."; |
| 91 Stop(); |
| 92 return; |
| 93 } |
| 94 FilePath host_binary = dir_path.Append(kMe2meHostBinaryName); |
| 95 |
| 96 // Create the delegate knowing how to launch a process in a session. |
| 97 scoped_ptr<WtsSessionProcessDelegate> delegate( |
| 98 new WtsSessionProcessDelegate(main_task_runner_, |
| 99 io_task_runner_, |
| 100 host_binary, |
| 101 session_id, |
| 102 true)); |
| 103 |
| 104 // Create a per-session launcher that will start the host process. |
| 105 launcher_ = new WorkerProcessLauncher(main_task_runner_, |
| 106 io_task_runner_, |
| 107 delegate.Pass(), |
| 108 this, |
| 109 kDaemonIpcSecurityDescriptor); |
| 110 } |
| 111 |
| 112 void WtsConsoleSessionProcessDriver::OnSessionDetached() { |
| 113 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 114 DCHECK(launcher_.get() != NULL); |
| 115 |
| 116 launcher_->Stop(); |
| 117 launcher_ = NULL; |
| 118 } |
| 119 |
| 120 void WtsConsoleSessionProcessDriver::DoStop() { |
| 121 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 122 |
| 123 if (launcher_.get() != NULL) { |
| 124 launcher_->Stop(); |
| 125 launcher_ = NULL; |
| 126 } |
| 127 |
| 128 CompleteStopping(); |
| 129 } |
| 130 |
| 131 } // namespace remoting |
| OLD | NEW |