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