OLD | NEW |
1 | 1 |
2 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 // | 5 // |
6 // This file implements the Windows service controlling Me2Me host processes | 6 // This file implements the Windows service controlling Me2Me host processes |
7 // running within user sessions. | 7 // running within user sessions. |
8 | 8 |
9 #include "remoting/host/win/unprivileged_process_delegate.h" | 9 #include "remoting/host/win/unprivileged_process_delegate.h" |
10 | 10 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 handles.Swap(*handles_out); | 230 handles.Swap(*handles_out); |
231 return true; | 231 return true; |
232 } | 232 } |
233 | 233 |
234 } // namespace | 234 } // namespace |
235 | 235 |
236 UnprivilegedProcessDelegate::UnprivilegedProcessDelegate( | 236 UnprivilegedProcessDelegate::UnprivilegedProcessDelegate( |
237 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 237 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
238 scoped_ptr<base::CommandLine> target_command) | 238 scoped_ptr<base::CommandLine> target_command) |
239 : io_task_runner_(io_task_runner), | 239 : io_task_runner_(io_task_runner), |
240 target_command_(target_command.Pass()), | 240 target_command_(std::move(target_command)), |
241 event_handler_(nullptr) { | 241 event_handler_(nullptr) {} |
242 } | |
243 | 242 |
244 UnprivilegedProcessDelegate::~UnprivilegedProcessDelegate() { | 243 UnprivilegedProcessDelegate::~UnprivilegedProcessDelegate() { |
245 DCHECK(CalledOnValidThread()); | 244 DCHECK(CalledOnValidThread()); |
246 DCHECK(!channel_); | 245 DCHECK(!channel_); |
247 DCHECK(!worker_process_.IsValid()); | 246 DCHECK(!worker_process_.IsValid()); |
248 } | 247 } |
249 | 248 |
250 void UnprivilegedProcessDelegate::LaunchProcess( | 249 void UnprivilegedProcessDelegate::LaunchProcess( |
251 WorkerProcessLauncher* event_handler) { | 250 WorkerProcessLauncher* event_handler) { |
252 DCHECK(CalledOnValidThread()); | 251 DCHECK(CalledOnValidThread()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 // even on 64bit platforms. | 308 // even on 64bit platforms. |
310 std::string pipe_handle = base::StringPrintf( | 309 std::string pipe_handle = base::StringPrintf( |
311 "%d", reinterpret_cast<ULONG_PTR>(client.GetPlatformFile())); | 310 "%d", reinterpret_cast<ULONG_PTR>(client.GetPlatformFile())); |
312 | 311 |
313 // Pass the IPC channel via the command line. | 312 // Pass the IPC channel via the command line. |
314 base::CommandLine command_line(target_command_->argv()); | 313 base::CommandLine command_line(target_command_->argv()); |
315 command_line.AppendSwitchASCII(kDaemonPipeSwitchName, pipe_handle); | 314 command_line.AppendSwitchASCII(kDaemonPipeSwitchName, pipe_handle); |
316 | 315 |
317 // Create our own window station and desktop accessible by |logon_sid|. | 316 // Create our own window station and desktop accessible by |logon_sid|. |
318 WindowStationAndDesktop handles; | 317 WindowStationAndDesktop handles; |
319 if (!CreateWindowStationAndDesktop(logon_sid.Pass(), &handles)) { | 318 if (!CreateWindowStationAndDesktop(std::move(logon_sid), &handles)) { |
320 PLOG(ERROR) << "Failed to create a window station and desktop"; | 319 PLOG(ERROR) << "Failed to create a window station and desktop"; |
321 ReportFatalError(); | 320 ReportFatalError(); |
322 return; | 321 return; |
323 } | 322 } |
324 | 323 |
325 // Try to launch the worker process. The launched process inherits | 324 // Try to launch the worker process. The launched process inherits |
326 // the window station, desktop and pipe handles, created above. | 325 // the window station, desktop and pipe handles, created above. |
327 ScopedHandle worker_thread; | 326 ScopedHandle worker_thread; |
328 if (!LaunchProcessWithToken(command_line.GetProgram(), | 327 if (!LaunchProcessWithToken( |
329 command_line.GetCommandLineString(), | 328 command_line.GetProgram(), command_line.GetCommandLineString(), |
330 token.Get(), | 329 token.Get(), &process_attributes, &thread_attributes, true, 0, |
331 &process_attributes, | 330 nullptr, &worker_process, &worker_thread)) { |
332 &thread_attributes, | |
333 true, | |
334 0, | |
335 nullptr, | |
336 &worker_process, | |
337 &worker_thread)) { | |
338 ReportFatalError(); | 331 ReportFatalError(); |
339 return; | 332 return; |
340 } | 333 } |
341 } | 334 } |
342 | 335 |
343 channel_ = server.Pass(); | 336 channel_ = std::move(server); |
344 ReportProcessLaunched(worker_process.Pass()); | 337 ReportProcessLaunched(std::move(worker_process)); |
345 } | 338 } |
346 | 339 |
347 void UnprivilegedProcessDelegate::Send(IPC::Message* message) { | 340 void UnprivilegedProcessDelegate::Send(IPC::Message* message) { |
348 DCHECK(CalledOnValidThread()); | 341 DCHECK(CalledOnValidThread()); |
349 | 342 |
350 if (channel_) { | 343 if (channel_) { |
351 channel_->Send(message); | 344 channel_->Send(message); |
352 } else { | 345 } else { |
353 delete message; | 346 delete message; |
354 } | 347 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 WorkerProcessLauncher* event_handler = event_handler_; | 401 WorkerProcessLauncher* event_handler = event_handler_; |
409 event_handler_ = nullptr; | 402 event_handler_ = nullptr; |
410 event_handler->OnFatalError(); | 403 event_handler->OnFatalError(); |
411 } | 404 } |
412 | 405 |
413 void UnprivilegedProcessDelegate::ReportProcessLaunched( | 406 void UnprivilegedProcessDelegate::ReportProcessLaunched( |
414 base::win::ScopedHandle worker_process) { | 407 base::win::ScopedHandle worker_process) { |
415 DCHECK(CalledOnValidThread()); | 408 DCHECK(CalledOnValidThread()); |
416 DCHECK(!worker_process_.IsValid()); | 409 DCHECK(!worker_process_.IsValid()); |
417 | 410 |
418 worker_process_ = worker_process.Pass(); | 411 worker_process_ = std::move(worker_process); |
419 | 412 |
420 // Report a handle that can be used to wait for the worker process completion, | 413 // Report a handle that can be used to wait for the worker process completion, |
421 // query information about the process and duplicate handles. | 414 // query information about the process and duplicate handles. |
422 DWORD desired_access = | 415 DWORD desired_access = |
423 SYNCHRONIZE | PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION; | 416 SYNCHRONIZE | PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION; |
424 HANDLE temp_handle; | 417 HANDLE temp_handle; |
425 if (!DuplicateHandle(GetCurrentProcess(), | 418 if (!DuplicateHandle(GetCurrentProcess(), worker_process_.Get(), |
426 worker_process_.Get(), | 419 GetCurrentProcess(), &temp_handle, desired_access, FALSE, |
427 GetCurrentProcess(), | |
428 &temp_handle, | |
429 desired_access, | |
430 FALSE, | |
431 0)) { | 420 0)) { |
432 PLOG(ERROR) << "Failed to duplicate a handle"; | 421 PLOG(ERROR) << "Failed to duplicate a handle"; |
433 ReportFatalError(); | 422 ReportFatalError(); |
434 return; | 423 return; |
435 } | 424 } |
436 ScopedHandle limited_handle(temp_handle); | 425 ScopedHandle limited_handle(temp_handle); |
437 | 426 |
438 event_handler_->OnProcessLaunched(limited_handle.Pass()); | 427 event_handler_->OnProcessLaunched(std::move(limited_handle)); |
439 } | 428 } |
440 | 429 |
441 } // namespace remoting | 430 } // namespace remoting |
OLD | NEW |