Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1165)

Side by Side Diff: remoting/host/win/unprivileged_process_delegate.cc

Issue 11040065: [Chromoting] Reimplemented the worker process launcher to take into account the encountered issues: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // This file implements the Windows service controlling Me2Me host processes
6 // running within user sessions.
7
8 #include "remoting/host/win/unprivileged_process_delegate.h"
9
10 #include "base/base_switches.h"
11 #include "base/command_line.h"
12 #include "base/logging.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/utf_string_conversions.h"
15 #include "base/win/scoped_handle.h"
16 #include "remoting/host/win/launch_process_with_token.h"
17
18 using base::win::ScopedHandle;
19
20 namespace {
21
22 // The command line switch specifying the name of the daemon IPC endpoint.
23 const char kDaemonIpcSwitchName[] = "daemon-pipe";
24
25 // The command line parameters that should be copied from the service's command
26 // line to the host process.
27 const char* kCopiedSwitchNames[] = {
28 "host-config", switches::kV, switches::kVModule };
29
30 } // namespace
31
32 namespace remoting {
33
34 UnprivilegedProcessDelegate::UnprivilegedProcessDelegate(
35 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
36 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
37 const FilePath& binary_path)
38 : main_task_runner_(main_task_runner),
39 io_task_runner_(io_task_runner),
40 binary_path_(binary_path) {
41 }
42
43 UnprivilegedProcessDelegate::~UnprivilegedProcessDelegate() {
44 KillProcess(CONTROL_C_EXIT);
45 }
46
47 DWORD UnprivilegedProcessDelegate::GetExitCode() {
48 DCHECK(main_task_runner_->BelongsToCurrentThread());
49
50 DWORD exit_code = CONTROL_C_EXIT;
51 if (worker_process_.IsValid()) {
52 if (!::GetExitCodeProcess(worker_process_, &exit_code)) {
53 LOG_GETLASTERROR(INFO)
54 << "Failed to query the exit code of the worker process";
55 exit_code = CONTROL_C_EXIT;
56 }
57 }
58
59 return exit_code;
60 }
61
62 void UnprivilegedProcessDelegate::KillProcess(DWORD exit_code) {
63 DCHECK(main_task_runner_->BelongsToCurrentThread());
64
65 if (worker_process_.IsValid()) {
66 TerminateProcess(worker_process_, exit_code);
67 }
68 }
69
70 bool UnprivilegedProcessDelegate::LaunchProcess(
71 const std::string& channel_name,
72 ScopedHandle* process_exit_event_out) {
73 DCHECK(main_task_runner_->BelongsToCurrentThread());
74
75 // Create the command line passing the name of the IPC channel to use and
76 // copying known switches from the caller's command line.
77 CommandLine command_line(binary_path_);
78 command_line.AppendSwitchNative(kDaemonIpcSwitchName,
79 UTF8ToWide(channel_name));
80 command_line.CopySwitchesFrom(*CommandLine::ForCurrentProcess(),
81 kCopiedSwitchNames,
82 arraysize(kCopiedSwitchNames));
83
84 // Try to launch the process.
85 // TODO(alexeypa): Pass a restricted process token.
86 // See http://crbug.com/134694.
87 ScopedHandle worker_thread;
88 worker_process_.Close();
89 if (!LaunchProcessWithToken(command_line.GetProgram(),
90 command_line.GetCommandLineString(),
91 NULL,
92 0,
93 &worker_process_,
94 &worker_thread)) {
95 return false;
96 }
97
98 // Return a handle that the caller can wait on to get notified when
99 // the process terminates.
100 ScopedHandle process_exit_event;
101 if (!DuplicateHandle(GetCurrentProcess(),
102 worker_process_,
103 GetCurrentProcess(),
104 process_exit_event.Receive(),
105 SYNCHRONIZE,
106 FALSE,
107 0)) {
108 LOG_GETLASTERROR(ERROR) << "Failed to duplicate a handle";
109 KillProcess(CONTROL_C_EXIT);
110 return false;
111 }
112
113 *process_exit_event_out = process_exit_event.Pass();
114 return true;
115 }
116
117 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/win/unprivileged_process_delegate.h ('k') | remoting/host/win/worker_process_launcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698