| 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/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/process.h" | 14 #include "base/process.h" |
| 15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "base/timer.h" | 18 #include "base/timer.h" |
| 19 #include "base/win/scoped_handle.h" | 19 #include "base/win/scoped_handle.h" |
| 20 #include "ipc/ipc_message.h" | 20 #include "ipc/ipc_message.h" |
| 21 #include "ipc/ipc_message_macros.h" | 21 #include "ipc/ipc_message_macros.h" |
| 22 #include "remoting/base/auto_thread_task_runner.h" | 22 #include "remoting/base/auto_thread_task_runner.h" |
| 23 #include "remoting/base/scoped_sc_handle_win.h" |
| 24 #include "remoting/host/branding.h" |
| 23 #include "remoting/host/chromoting_messages.h" | 25 #include "remoting/host/chromoting_messages.h" |
| 24 #include "remoting/host/desktop_session_win.h" | 26 #include "remoting/host/desktop_session_win.h" |
| 25 #include "remoting/host/host_exit_codes.h" | 27 #include "remoting/host/host_exit_codes.h" |
| 26 #include "remoting/host/host_main.h" | 28 #include "remoting/host/host_main.h" |
| 27 #include "remoting/host/ipc_constants.h" | 29 #include "remoting/host/ipc_constants.h" |
| 28 #include "remoting/host/screen_resolution.h" | 30 #include "remoting/host/screen_resolution.h" |
| 29 #include "remoting/host/win/launch_process_with_token.h" | 31 #include "remoting/host/win/launch_process_with_token.h" |
| 30 #include "remoting/host/win/unprivileged_process_delegate.h" | 32 #include "remoting/host/win/unprivileged_process_delegate.h" |
| 31 #include "remoting/host/win/worker_process_launcher.h" | 33 #include "remoting/host/win/worker_process_launcher.h" |
| 32 | 34 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 44 class DaemonProcessWin : public DaemonProcess { | 46 class DaemonProcessWin : public DaemonProcess { |
| 45 public: | 47 public: |
| 46 DaemonProcessWin( | 48 DaemonProcessWin( |
| 47 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 49 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 48 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 50 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 49 const base::Closure& stopped_callback); | 51 const base::Closure& stopped_callback); |
| 50 virtual ~DaemonProcessWin(); | 52 virtual ~DaemonProcessWin(); |
| 51 | 53 |
| 52 // WorkerProcessIpcDelegate implementation. | 54 // WorkerProcessIpcDelegate implementation. |
| 53 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 55 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| 56 virtual void OnPermanentError(int exit_code) OVERRIDE; |
| 54 | 57 |
| 55 // DaemonProcess overrides. | 58 // DaemonProcess overrides. |
| 56 virtual void SendToNetwork(IPC::Message* message) OVERRIDE; | 59 virtual void SendToNetwork(IPC::Message* message) OVERRIDE; |
| 57 virtual bool OnDesktopSessionAgentAttached( | 60 virtual bool OnDesktopSessionAgentAttached( |
| 58 int terminal_id, | 61 int terminal_id, |
| 59 base::ProcessHandle desktop_process, | 62 base::ProcessHandle desktop_process, |
| 60 IPC::PlatformFileForTransit desktop_pipe) OVERRIDE; | 63 IPC::PlatformFileForTransit desktop_pipe) OVERRIDE; |
| 61 | 64 |
| 62 protected: | 65 protected: |
| 63 // DaemonProcess implementation. | 66 // DaemonProcess implementation. |
| 64 virtual scoped_ptr<DesktopSession> DoCreateDesktopSession( | 67 virtual scoped_ptr<DesktopSession> DoCreateDesktopSession( |
| 65 int terminal_id, | 68 int terminal_id, |
| 66 const ScreenResolution& resolution, | 69 const ScreenResolution& resolution, |
| 67 bool virtual_terminal) OVERRIDE; | 70 bool virtual_terminal) OVERRIDE; |
| 68 virtual void DoCrashNetworkProcess( | 71 virtual void DoCrashNetworkProcess( |
| 69 const tracked_objects::Location& location) OVERRIDE; | 72 const tracked_objects::Location& location) OVERRIDE; |
| 70 virtual void LaunchNetworkProcess() OVERRIDE; | 73 virtual void LaunchNetworkProcess() OVERRIDE; |
| 71 | 74 |
| 75 // Changes the service start type to 'manual'. |
| 76 void DisableAutoStart(); |
| 77 |
| 72 private: | 78 private: |
| 73 scoped_ptr<WorkerProcessLauncher> network_launcher_; | 79 scoped_ptr<WorkerProcessLauncher> network_launcher_; |
| 74 | 80 |
| 75 // Handle of the network process. | 81 // Handle of the network process. |
| 76 ScopedHandle network_process_; | 82 ScopedHandle network_process_; |
| 77 | 83 |
| 78 DISALLOW_COPY_AND_ASSIGN(DaemonProcessWin); | 84 DISALLOW_COPY_AND_ASSIGN(DaemonProcessWin); |
| 79 }; | 85 }; |
| 80 | 86 |
| 81 DaemonProcessWin::DaemonProcessWin( | 87 DaemonProcessWin::DaemonProcessWin( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 92 // Obtain the handle of the network process. | 98 // Obtain the handle of the network process. |
| 93 network_process_.Set(OpenProcess(PROCESS_DUP_HANDLE, false, peer_pid)); | 99 network_process_.Set(OpenProcess(PROCESS_DUP_HANDLE, false, peer_pid)); |
| 94 if (!network_process_.IsValid()) { | 100 if (!network_process_.IsValid()) { |
| 95 CrashNetworkProcess(FROM_HERE); | 101 CrashNetworkProcess(FROM_HERE); |
| 96 return; | 102 return; |
| 97 } | 103 } |
| 98 | 104 |
| 99 DaemonProcess::OnChannelConnected(peer_pid); | 105 DaemonProcess::OnChannelConnected(peer_pid); |
| 100 } | 106 } |
| 101 | 107 |
| 108 void DaemonProcessWin::OnPermanentError(int exit_code) { |
| 109 // Change the service start type to 'manual' if the host has been deleted |
| 110 // remotely. This way the host will not be started every time the machine |
| 111 // boots until the user re-enable it again. |
| 112 if (exit_code == kInvalidHostIdExitCode) |
| 113 DisableAutoStart(); |
| 114 |
| 115 DaemonProcess::OnPermanentError(exit_code); |
| 116 } |
| 117 |
| 102 void DaemonProcessWin::SendToNetwork(IPC::Message* message) { | 118 void DaemonProcessWin::SendToNetwork(IPC::Message* message) { |
| 103 if (network_launcher_) { | 119 if (network_launcher_) { |
| 104 network_launcher_->Send(message); | 120 network_launcher_->Send(message); |
| 105 } else { | 121 } else { |
| 106 delete message; | 122 delete message; |
| 107 } | 123 } |
| 108 } | 124 } |
| 109 | 125 |
| 110 bool DaemonProcessWin::OnDesktopSessionAgentAttached( | 126 bool DaemonProcessWin::OnDesktopSessionAgentAttached( |
| 111 int terminal_id, | 127 int terminal_id, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 195 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 180 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 196 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 181 const base::Closure& stopped_callback) { | 197 const base::Closure& stopped_callback) { |
| 182 scoped_ptr<DaemonProcessWin> daemon_process( | 198 scoped_ptr<DaemonProcessWin> daemon_process( |
| 183 new DaemonProcessWin(caller_task_runner, io_task_runner, | 199 new DaemonProcessWin(caller_task_runner, io_task_runner, |
| 184 stopped_callback)); | 200 stopped_callback)); |
| 185 daemon_process->Initialize(); | 201 daemon_process->Initialize(); |
| 186 return daemon_process.PassAs<DaemonProcess>(); | 202 return daemon_process.PassAs<DaemonProcess>(); |
| 187 } | 203 } |
| 188 | 204 |
| 205 void DaemonProcessWin::DisableAutoStart() { |
| 206 ScopedScHandle scmanager( |
| 207 OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, |
| 208 SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE)); |
| 209 if (!scmanager.IsValid()) { |
| 210 LOG_GETLASTERROR(INFO) |
| 211 << "Failed to connect to the service control manager"; |
| 212 return; |
| 213 } |
| 214 |
| 215 DWORD desired_access = SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS; |
| 216 ScopedScHandle service( |
| 217 OpenService(scmanager, kWindowsServiceName, desired_access)); |
| 218 if (!service.IsValid()) { |
| 219 LOG_GETLASTERROR(INFO) |
| 220 << "Failed to open to the '" << kWindowsServiceName << "' service"; |
| 221 return; |
| 222 } |
| 223 |
| 224 // Change the service start type to 'manual'. All |NULL| parameters below mean |
| 225 // that there is no change to the corresponding service parameter. |
| 226 if (!ChangeServiceConfig(service, |
| 227 SERVICE_NO_CHANGE, |
| 228 SERVICE_DEMAND_START, |
| 229 SERVICE_NO_CHANGE, |
| 230 NULL, |
| 231 NULL, |
| 232 NULL, |
| 233 NULL, |
| 234 NULL, |
| 235 NULL, |
| 236 NULL)) { |
| 237 LOG_GETLASTERROR(INFO) |
| 238 << "Failed to change the '" << kWindowsServiceName |
| 239 << "'service start type to 'manual'"; |
| 240 } |
| 241 } |
| 242 |
| 189 } // namespace remoting | 243 } // namespace remoting |
| OLD | NEW |