| 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/win/worker_process_launcher.h" | 5 #include "remoting/host/win/worker_process_launcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" |
| 11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
| 14 #include "remoting/host/chromoting_messages.h" | 15 #include "remoting/host/chromoting_messages.h" |
| 15 #include "remoting/host/host_exit_codes.h" | 16 #include "remoting/host/host_exit_codes.h" |
| 17 #include "remoting/host/switches.h" |
| 16 #include "remoting/host/worker_process_ipc_delegate.h" | 18 #include "remoting/host/worker_process_ipc_delegate.h" |
| 17 | 19 |
| 18 using base::TimeDelta; | 20 using base::TimeDelta; |
| 19 using base::win::ScopedHandle; | 21 using base::win::ScopedHandle; |
| 20 | 22 |
| 21 const net::BackoffEntry::Policy kDefaultBackoffPolicy = { | 23 const net::BackoffEntry::Policy kDefaultBackoffPolicy = { |
| 22 // Number of initial errors (in sequence) to ignore before applying | 24 // Number of initial errors (in sequence) to ignore before applying |
| 23 // exponential back-off rules. | 25 // exponential back-off rules. |
| 24 0, | 26 0, |
| 25 | 27 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // disconnected when the worker process is about to exit. Waiting a little bit | 158 // disconnected when the worker process is about to exit. Waiting a little bit |
| 157 // here allows the worker to exit completely and so, notify | 159 // here allows the worker to exit completely and so, notify |
| 158 // |process_watcher_|. As the result KillProcess() will not be called and | 160 // |process_watcher_|. As the result KillProcess() will not be called and |
| 159 // the original exit code reported by the worker process will be retrieved. | 161 // the original exit code reported by the worker process will be retrieved. |
| 160 if (!kill_process_timer_.IsRunning()) { | 162 if (!kill_process_timer_.IsRunning()) { |
| 161 kill_process_timer_.Start(FROM_HERE, kill_process_timeout_, this, | 163 kill_process_timer_.Start(FROM_HERE, kill_process_timeout_, this, |
| 162 &WorkerProcessLauncher::StopWorker); | 164 &WorkerProcessLauncher::StopWorker); |
| 163 } | 165 } |
| 164 } | 166 } |
| 165 | 167 |
| 168 void WorkerProcessLauncher::AppendSwitches( |
| 169 base::CommandLine* command_line) const { |
| 170 DCHECK(command_line); |
| 171 if (start_counter_ == 1) { |
| 172 return; |
| 173 } |
| 174 |
| 175 command_line->AppendSwitch(kSafeMode); |
| 176 } |
| 177 |
| 166 void WorkerProcessLauncher::OnObjectSignaled(HANDLE object) { | 178 void WorkerProcessLauncher::OnObjectSignaled(HANDLE object) { |
| 167 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 179 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 168 DCHECK(!process_watcher_.GetWatchedObject()); | 180 DCHECK(!process_watcher_.GetWatchedObject()); |
| 169 DCHECK_EQ(exit_code_, CONTROL_C_EXIT); | 181 DCHECK_EQ(exit_code_, CONTROL_C_EXIT); |
| 170 DCHECK_EQ(worker_process_.Get(), object); | 182 DCHECK_EQ(worker_process_.Get(), object); |
| 171 | 183 |
| 172 // Get exit code of the worker process if it is available. | 184 // Get exit code of the worker process if it is available. |
| 173 if (!::GetExitCodeProcess(worker_process_.Get(), &exit_code_)) { | 185 if (!::GetExitCodeProcess(worker_process_.Get(), &exit_code_)) { |
| 174 PLOG(INFO) << "Failed to query the exit code of the worker process"; | 186 PLOG(INFO) << "Failed to query the exit code of the worker process"; |
| 175 exit_code_ = CONTROL_C_EXIT; | 187 exit_code_ = CONTROL_C_EXIT; |
| 176 } | 188 } |
| 177 | 189 |
| 178 worker_process_.Close(); | 190 worker_process_.Close(); |
| 179 StopWorker(); | 191 StopWorker(); |
| 180 } | 192 } |
| 181 | 193 |
| 182 void WorkerProcessLauncher::LaunchWorker() { | 194 void WorkerProcessLauncher::LaunchWorker() { |
| 183 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 195 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 184 DCHECK(!ipc_enabled_); | 196 DCHECK(!ipc_enabled_); |
| 185 DCHECK(!kill_process_timer_.IsRunning()); | 197 DCHECK(!kill_process_timer_.IsRunning()); |
| 186 DCHECK(!launch_timer_.IsRunning()); | 198 DCHECK(!launch_timer_.IsRunning()); |
| 187 DCHECK(!process_watcher_.GetWatchedObject()); | 199 DCHECK(!process_watcher_.GetWatchedObject()); |
| 188 DCHECK(!launch_result_timer_.IsRunning()); | 200 DCHECK(!launch_result_timer_.IsRunning()); |
| 189 | 201 |
| 190 exit_code_ = CONTROL_C_EXIT; | 202 exit_code_ = CONTROL_C_EXIT; |
| 191 | 203 |
| 204 start_counter_++; |
| 192 // Make sure launching a process will not take forever. | 205 // Make sure launching a process will not take forever. |
| 193 launch_result_timer_.Start( | 206 launch_result_timer_.Start( |
| 194 FROM_HERE, base::TimeDelta::FromSeconds(kLaunchResultTimeoutSeconds), | 207 FROM_HERE, base::TimeDelta::FromSeconds(kLaunchResultTimeoutSeconds), |
| 195 this, &WorkerProcessLauncher::RecordLaunchResult); | 208 this, &WorkerProcessLauncher::RecordLaunchResult); |
| 196 | 209 |
| 197 launcher_delegate_->LaunchProcess(this); | 210 launcher_delegate_->LaunchProcess(this); |
| 198 } | 211 } |
| 199 | 212 |
| 200 void WorkerProcessLauncher::RecordLaunchResult() { | 213 void WorkerProcessLauncher::RecordLaunchResult() { |
| 201 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 214 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 ipc_handler_->OnPermanentError(exit_code_); | 272 ipc_handler_->OnPermanentError(exit_code_); |
| 260 return; | 273 return; |
| 261 } | 274 } |
| 262 | 275 |
| 263 // Schedule the next attempt to launch the worker process. | 276 // Schedule the next attempt to launch the worker process. |
| 264 launch_timer_.Start(FROM_HERE, launch_backoff_.GetTimeUntilRelease(), this, | 277 launch_timer_.Start(FROM_HERE, launch_backoff_.GetTimeUntilRelease(), this, |
| 265 &WorkerProcessLauncher::LaunchWorker); | 278 &WorkerProcessLauncher::LaunchWorker); |
| 266 } | 279 } |
| 267 | 280 |
| 268 } // namespace remoting | 281 } // namespace remoting |
| OLD | NEW |