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

Side by Side Diff: content/browser/child_process_launcher.cc

Issue 98603007: Launches a privileged utility process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Actually works now. Removes unnecessary logging. Created 7 years 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
OLDNEW
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 "content/browser/child_process_launcher.h" 5 #include "content/browser/child_process_launcher.h"
6 6
7 #include <utility> // For std::pair. 7 #include <utility> // For std::pair.
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #endif 61 #endif
62 { 62 {
63 #if defined(OS_POSIX) 63 #if defined(OS_POSIX)
64 terminate_child_on_shutdown_ = !CommandLine::ForCurrentProcess()-> 64 terminate_child_on_shutdown_ = !CommandLine::ForCurrentProcess()->
65 HasSwitch(switches::kChildCleanExit); 65 HasSwitch(switches::kChildCleanExit);
66 #else 66 #else
67 terminate_child_on_shutdown_ = true; 67 terminate_child_on_shutdown_ = true;
68 #endif 68 #endif
69 } 69 }
70 70
71 #if defined(OS_WIN)
72 void Launch(
73 SandboxedProcessLauncherDelegate* delegate,
74 CommandLine* cmd_line,
75 int child_process_id,
76 Client* client) {
77 Launch(delegate, false, cmd_line, child_process_id, client);
78 }
79 #endif
80
71 void Launch( 81 void Launch(
72 #if defined(OS_WIN) 82 #if defined(OS_WIN)
73 SandboxedProcessLauncherDelegate* delegate, 83 SandboxedProcessLauncherDelegate* delegate,
84 bool run_elevated,
74 #elif defined(OS_ANDROID) 85 #elif defined(OS_ANDROID)
75 int ipcfd, 86 int ipcfd,
76 #elif defined(OS_POSIX) 87 #elif defined(OS_POSIX)
77 bool use_zygote, 88 bool use_zygote,
78 const base::EnvironmentMap& environ, 89 const base::EnvironmentMap& environ,
79 int ipcfd, 90 int ipcfd,
80 #endif 91 #endif
81 CommandLine* cmd_line, 92 CommandLine* cmd_line,
82 int child_process_id, 93 int child_process_id,
83 Client* client) { 94 Client* client) {
84 client_ = client; 95 client_ = client;
85 96
86 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); 97 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_));
87 98
88 #if defined(OS_ANDROID) 99 #if defined(OS_ANDROID)
89 // We need to close the client end of the IPC channel to reliably detect 100 // We need to close the client end of the IPC channel to reliably detect
90 // child termination. We will close this fd after we create the child 101 // child termination. We will close this fd after we create the child
91 // process which is asynchronous on Android. 102 // process which is asynchronous on Android.
92 ipcfd_ = ipcfd; 103 ipcfd_ = ipcfd;
93 #endif 104 #endif
94 BrowserThread::PostTask( 105 BrowserThread::PostTask(
95 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 106 BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
96 base::Bind( 107 base::Bind(
97 &Context::LaunchInternal, 108 &Context::LaunchInternal,
98 make_scoped_refptr(this), 109 make_scoped_refptr(this),
99 client_thread_id_, 110 client_thread_id_,
100 child_process_id, 111 child_process_id,
101 #if defined(OS_WIN) 112 #if defined(OS_WIN)
102 delegate, 113 delegate,
114 run_elevated,
103 #elif defined(OS_ANDROID) 115 #elif defined(OS_ANDROID)
104 ipcfd, 116 ipcfd,
105 #elif defined(OS_POSIX) 117 #elif defined(OS_POSIX)
106 use_zygote, 118 use_zygote,
107 environ, 119 environ,
108 ipcfd, 120 ipcfd,
109 #endif 121 #endif
110 cmd_line)); 122 cmd_line));
111 } 123 }
112 124
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 188 }
177 } 189 }
178 190
179 static void LaunchInternal( 191 static void LaunchInternal(
180 // |this_object| is NOT thread safe. Only use it to post a task back. 192 // |this_object| is NOT thread safe. Only use it to post a task back.
181 scoped_refptr<Context> this_object, 193 scoped_refptr<Context> this_object,
182 BrowserThread::ID client_thread_id, 194 BrowserThread::ID client_thread_id,
183 int child_process_id, 195 int child_process_id,
184 #if defined(OS_WIN) 196 #if defined(OS_WIN)
185 SandboxedProcessLauncherDelegate* delegate, 197 SandboxedProcessLauncherDelegate* delegate,
198 bool run_elevated,
186 #elif defined(OS_ANDROID) 199 #elif defined(OS_ANDROID)
187 int ipcfd, 200 int ipcfd,
188 #elif defined(OS_POSIX) 201 #elif defined(OS_POSIX)
189 bool use_zygote, 202 bool use_zygote,
190 const base::EnvironmentMap& env, 203 const base::EnvironmentMap& env,
191 int ipcfd, 204 int ipcfd,
192 #endif 205 #endif
193 CommandLine* cmd_line) { 206 CommandLine* cmd_line) {
194 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); 207 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line);
195 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); 208 base::TimeTicks begin_launch_time = base::TimeTicks::Now();
196 209
210
197 #if defined(OS_WIN) 211 #if defined(OS_WIN)
198 scoped_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); 212 scoped_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate);
199 base::ProcessHandle handle = StartSandboxedProcess(delegate, cmd_line); 213 base::ProcessHandle handle;
214 if (run_elevated) {
215 base::LaunchOptions options;
216 options.run_elevated = run_elevated;
217 base::LaunchProcess(*cmd_line, options, &handle);
218 } else {
219 handle = StartSandboxedProcess(delegate, cmd_line);
220 }
200 #elif defined(OS_ANDROID) 221 #elif defined(OS_ANDROID)
201 // Android WebView runs in single process, ensure that we never get here 222 // Android WebView runs in single process, ensure that we never get here
202 // when running in single process mode. 223 // when running in single process mode.
203 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); 224 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess));
204 225
205 std::string process_type = 226 std::string process_type =
206 cmd_line->GetSwitchValueASCII(switches::kProcessType); 227 cmd_line->GetSwitchValueASCII(switches::kProcessType);
207 std::vector<FileDescriptorInfo> files_to_register; 228 std::vector<FileDescriptorInfo> files_to_register;
208 files_to_register.push_back( 229 files_to_register.push_back(
209 FileDescriptorInfo(kPrimaryIPCChannel, 230 FileDescriptorInfo(kPrimaryIPCChannel,
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 #elif defined(OS_POSIX) 451 #elif defined(OS_POSIX)
431 use_zygote, 452 use_zygote,
432 environ, 453 environ,
433 ipcfd, 454 ipcfd,
434 #endif 455 #endif
435 cmd_line, 456 cmd_line,
436 child_process_id, 457 child_process_id,
437 client); 458 client);
438 } 459 }
439 460
461 #if defined(OS_WIN)
462 ChildProcessLauncher::ChildProcessLauncher(
463 SandboxedProcessLauncherDelegate* delegate,
464 bool run_elevated,
465 CommandLine* cmd_line,
466 int child_process_id,
467 Client* client) {
468 context_ = new Context();
469 context_->Launch(
470 delegate,
471 run_elevated,
472 cmd_line,
473 child_process_id,
474 client);
475 }
476 #endif
477
440 ChildProcessLauncher::~ChildProcessLauncher() { 478 ChildProcessLauncher::~ChildProcessLauncher() {
441 context_->ResetClient(); 479 context_->ResetClient();
442 } 480 }
443 481
444 bool ChildProcessLauncher::IsStarting() { 482 bool ChildProcessLauncher::IsStarting() {
445 return context_->starting_; 483 return context_->starting_;
446 } 484 }
447 485
448 base::ProcessHandle ChildProcessLauncher::GetHandle() { 486 base::ProcessHandle ChildProcessLauncher::GetHandle() {
449 DCHECK(!context_->starting_); 487 DCHECK(!context_->starting_);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 GetHandle(), background)); 537 GetHandle(), background));
500 } 538 }
501 539
502 void ChildProcessLauncher::SetTerminateChildOnShutdown( 540 void ChildProcessLauncher::SetTerminateChildOnShutdown(
503 bool terminate_on_shutdown) { 541 bool terminate_on_shutdown) {
504 if (context_.get()) 542 if (context_.get())
505 context_->set_terminate_child_on_shutdown(terminate_on_shutdown); 543 context_->set_terminate_child_on_shutdown(terminate_on_shutdown);
506 } 544 }
507 545
508 } // namespace content 546 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698