| 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/daemon_process.h" | 5 #include "remoting/host/daemon_process.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/path_service.h" | |
| 14 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 15 #include "base/time.h" | 14 #include "base/time.h" |
| 16 #include "base/timer.h" | 15 #include "base/timer.h" |
| 17 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 18 #include "base/win/scoped_handle.h" | 17 #include "base/win/scoped_handle.h" |
| 19 #include "remoting/host/host_exit_codes.h" | 18 #include "remoting/host/host_exit_codes.h" |
| 19 #include "remoting/host/ipc_consts.h" |
| 20 #include "remoting/host/win/launch_process_with_token.h" | 20 #include "remoting/host/win/launch_process_with_token.h" |
| 21 #include "remoting/host/win/unprivileged_process_delegate.h" | 21 #include "remoting/host/win/unprivileged_process_delegate.h" |
| 22 #include "remoting/host/win/worker_process_launcher.h" | 22 #include "remoting/host/win/worker_process_launcher.h" |
| 23 | 23 |
| 24 using base::win::ScopedHandle; | 24 using base::win::ScopedHandle; |
| 25 using base::TimeDelta; | 25 using base::TimeDelta; |
| 26 | 26 |
| 27 namespace { | |
| 28 | |
| 29 const FilePath::CharType kMe2meHostBinaryName[] = | |
| 30 FILE_PATH_LITERAL("remoting_host.exe"); | |
| 31 | |
| 32 // The security descriptor of the daemon IPC endpoint. It gives full access | |
| 33 // to LocalSystem and denies access by anyone else. | |
| 34 const char kDaemonPipeSecurityDescriptor[] = "O:SYG:SYD:(A;;GA;;;SY)"; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 namespace remoting { | 27 namespace remoting { |
| 39 | 28 |
| 40 class DaemonProcessWin : public DaemonProcess { | 29 class DaemonProcessWin : public DaemonProcess { |
| 41 public: | 30 public: |
| 42 DaemonProcessWin(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 31 DaemonProcessWin(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 43 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 32 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 44 const base::Closure& stopped_callback); | 33 const base::Closure& stopped_callback); |
| 45 virtual ~DaemonProcessWin(); | 34 virtual ~DaemonProcessWin(); |
| 46 | 35 |
| 47 // Sends an IPC message to the worker process. This method can be called only | 36 // Sends an IPC message to the worker process. This method can be called only |
| (...skipping 25 matching lines...) Expand all Loading... |
| 73 // in Stoppable::~Stoppable() but this one helps us to fail early and | 62 // in Stoppable::~Stoppable() but this one helps us to fail early and |
| 74 // predictably. | 63 // predictably. |
| 75 CHECK_EQ(stoppable_state(), Stoppable::kStopped); | 64 CHECK_EQ(stoppable_state(), Stoppable::kStopped); |
| 76 } | 65 } |
| 77 | 66 |
| 78 void DaemonProcessWin::LaunchNetworkProcess() { | 67 void DaemonProcessWin::LaunchNetworkProcess() { |
| 79 DCHECK(main_task_runner()->BelongsToCurrentThread()); | 68 DCHECK(main_task_runner()->BelongsToCurrentThread()); |
| 80 DCHECK(launcher_.get() == NULL); | 69 DCHECK(launcher_.get() == NULL); |
| 81 | 70 |
| 82 // Construct the host binary name. | 71 // Construct the host binary name. |
| 83 FilePath dir_path; | 72 FilePath host_binary; |
| 84 if (!PathService::Get(base::DIR_EXE, &dir_path)) { | 73 if (!GetInstalledBinaryPath(kHostBinaryName, &host_binary)) { |
| 85 LOG(ERROR) << "Failed to get the executable file name."; | |
| 86 Stop(); | 74 Stop(); |
| 87 return; | 75 return; |
| 88 } | 76 } |
| 89 | 77 |
| 90 scoped_ptr<UnprivilegedProcessDelegate> delegate( | 78 scoped_ptr<UnprivilegedProcessDelegate> delegate( |
| 91 new UnprivilegedProcessDelegate(main_task_runner(), io_task_runner(), | 79 new UnprivilegedProcessDelegate(main_task_runner(), io_task_runner(), |
| 92 dir_path.Append(kMe2meHostBinaryName))); | 80 host_binary)); |
| 93 launcher_.reset(new WorkerProcessLauncher(main_task_runner(), | 81 launcher_.reset(new WorkerProcessLauncher( |
| 94 io_task_runner(), | 82 main_task_runner(), delegate.Pass(), this)); |
| 95 delegate.Pass(), | |
| 96 this, | |
| 97 kDaemonPipeSecurityDescriptor)); | |
| 98 } | 83 } |
| 99 | 84 |
| 100 void DaemonProcessWin::Send(IPC::Message* message) { | 85 void DaemonProcessWin::Send(IPC::Message* message) { |
| 101 if (launcher_.get() != NULL) { | 86 if (launcher_.get() != NULL) { |
| 102 launcher_->Send(message); | 87 launcher_->Send(message); |
| 103 } else { | 88 } else { |
| 104 delete message; | 89 delete message; |
| 105 } | 90 } |
| 106 } | 91 } |
| 107 | 92 |
| 108 void DaemonProcessWin::DoStop() { | 93 void DaemonProcessWin::DoStop() { |
| 109 DCHECK(main_task_runner()->BelongsToCurrentThread()); | 94 DCHECK(main_task_runner()->BelongsToCurrentThread()); |
| 110 | 95 |
| 111 launcher_.reset(); | 96 launcher_.reset(); |
| 112 DaemonProcess::DoStop(); | 97 DaemonProcess::DoStop(); |
| 113 } | 98 } |
| 114 | 99 |
| 115 scoped_ptr<DaemonProcess> DaemonProcess::Create( | 100 scoped_ptr<DaemonProcess> DaemonProcess::Create( |
| 116 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 101 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 117 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 102 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 118 const base::Closure& stopped_callback) { | 103 const base::Closure& stopped_callback) { |
| 119 scoped_ptr<DaemonProcessWin> daemon_process( | 104 scoped_ptr<DaemonProcessWin> daemon_process( |
| 120 new DaemonProcessWin(main_task_runner, io_task_runner, stopped_callback)); | 105 new DaemonProcessWin(main_task_runner, io_task_runner, stopped_callback)); |
| 121 return daemon_process.PassAs<DaemonProcess>(); | 106 return daemon_process.PassAs<DaemonProcess>(); |
| 122 } | 107 } |
| 123 | 108 |
| 124 } // namespace remoting | 109 } // namespace remoting |
| OLD | NEW |