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

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

Issue 940813003: Use a utility process for the Mojo v8 proxy resolver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v8-pac-in-process-enable
Patch Set: Address some review comments. Created 5 years, 9 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
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/utility_process_host_impl.h" 5 #include "content/browser/utility_process_host_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/process/process_handle.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
13 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
16 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
17 #include "content/browser/browser_child_process_host_impl.h" 18 #include "content/browser/browser_child_process_host_impl.h"
19 #include "content/browser/mojo/mojo_application_host.h"
18 #include "content/browser/renderer_host/render_process_host_impl.h" 20 #include "content/browser/renderer_host/render_process_host_impl.h"
19 #include "content/common/child_process_host_impl.h" 21 #include "content/common/child_process_host_impl.h"
20 #include "content/common/utility_messages.h" 22 #include "content/common/utility_messages.h"
21 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/content_browser_client.h" 24 #include "content/public/browser/content_browser_client.h"
23 #include "content/public/browser/utility_process_host_client.h" 25 #include "content/public/browser/utility_process_host_client.h"
24 #include "content/public/common/content_switches.h" 26 #include "content/public/common/content_switches.h"
25 #include "content/public/common/process_type.h" 27 #include "content/public/common/process_type.h"
26 #include "content/public/common/sandboxed_process_launcher_delegate.h" 28 #include "content/public/common/sandboxed_process_launcher_delegate.h"
27 #include "ipc/ipc_switches.h" 29 #include "ipc/ipc_switches.h"
28 #include "ui/base/ui_base_switches.h" 30 #include "ui/base/ui_base_switches.h"
29 31
30 namespace content { 32 namespace content {
31 33
32 // NOTE: changes to this class need to be reviewed by the security team. 34 // NOTE: changes to this class need to be reviewed by the security team.
33 class UtilitySandboxedProcessLauncherDelegate 35 class UtilitySandboxedProcessLauncherDelegate
34 : public SandboxedProcessLauncherDelegate { 36 : public SandboxedProcessLauncherDelegate {
35 public: 37 public:
36 UtilitySandboxedProcessLauncherDelegate(const base::FilePath& exposed_dir, 38 UtilitySandboxedProcessLauncherDelegate(const base::FilePath& exposed_dir,
37 bool launch_elevated, bool no_sandbox, 39 bool launch_elevated,
40 bool no_sandbox,
38 const base::EnvironmentMap& env, 41 const base::EnvironmentMap& env,
39 ChildProcessHost* host) 42 ChildProcessHost* host)
40 : exposed_dir_(exposed_dir), 43 : exposed_dir_(exposed_dir),
41 #if defined(OS_WIN) 44 #if defined(OS_WIN)
42 launch_elevated_(launch_elevated) 45 launch_elevated_(launch_elevated)
43 #elif defined(OS_POSIX) 46 #elif defined(OS_POSIX)
44 env_(env), 47 env_(env),
45 no_sandbox_(no_sandbox), 48 no_sandbox_(no_sandbox),
46 ipc_fd_(host->TakeClientFileDescriptor()) 49 ipc_fd_(host->TakeClientFileDescriptor())
47 #endif // OS_WIN 50 #endif // OS_WIN
48 {} 51 {}
49 52
50 ~UtilitySandboxedProcessLauncherDelegate() override {} 53 ~UtilitySandboxedProcessLauncherDelegate() override {}
51 54
52 #if defined(OS_WIN) 55 #if defined(OS_WIN)
53 bool ShouldLaunchElevated() override { 56 bool ShouldLaunchElevated() override { return launch_elevated_; }
54 return launch_elevated_;
55 }
56 void PreSandbox(bool* disable_default_policy, 57 void PreSandbox(bool* disable_default_policy,
57 base::FilePath* exposed_dir) override { 58 base::FilePath* exposed_dir) override {
58 *exposed_dir = exposed_dir_; 59 *exposed_dir = exposed_dir_;
59 } 60 }
60 #elif defined(OS_POSIX) 61 #elif defined(OS_POSIX)
61 62
62 bool ShouldUseZygote() override { 63 bool ShouldUseZygote() override {
63 return !no_sandbox_ && exposed_dir_.empty(); 64 return !no_sandbox_ && exposed_dir_.empty();
64 } 65 }
65 base::EnvironmentMap GetEnvironment() override { return env_; } 66 base::EnvironmentMap GetEnvironment() override { return env_; }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 #else 106 #else
106 child_flags_(ChildProcessHost::CHILD_NORMAL), 107 child_flags_(ChildProcessHost::CHILD_NORMAL),
107 #endif 108 #endif
108 started_(false) { 109 started_(false) {
109 } 110 }
110 111
111 UtilityProcessHostImpl::~UtilityProcessHostImpl() { 112 UtilityProcessHostImpl::~UtilityProcessHostImpl() {
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
113 if (is_batch_mode_) 114 if (is_batch_mode_)
114 EndBatchMode(); 115 EndBatchMode();
116
117 // We could be destroyed as a result of Chrome shutdown. When that happens,
118 // the Mojo channel doesn't get the oppertunity to shut down cleanly becuase
eroman 2015/03/11 18:48:36 oppertunity --> opportunity becuase --> because
Anand Mistry (off Chromium) 2015/03/12 05:10:22 Maybe aspell should be part of the PRESUBMIT check
119 // it posts to the IO thread (the current thread) which is being destroyed.
120 // To guarantee proper shutdown of the Mojo channel, we do it explicitly here.
eroman 2015/03/11 18:48:36 Note: Use of "we" is something chromium tries to a
Anand Mistry (off Chromium) 2015/03/12 05:10:22 Done. And noted for the future.
121 if (mojo_application_host_)
122 mojo_application_host_->ShutdownOnIOThread();
115 } 123 }
116 124
117 bool UtilityProcessHostImpl::Send(IPC::Message* message) { 125 bool UtilityProcessHostImpl::Send(IPC::Message* message) {
118 if (!StartProcess()) 126 if (!StartProcess())
119 return false; 127 return false;
120 128
121 return process_->Send(message); 129 return process_->Send(message);
122 } 130 }
123 131
124 bool UtilityProcessHostImpl::StartBatchMode() { 132 bool UtilityProcessHostImpl::StartBatchMode() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 166 }
159 167
160 #if defined(OS_POSIX) 168 #if defined(OS_POSIX)
161 169
162 void UtilityProcessHostImpl::SetEnv(const base::EnvironmentMap& env) { 170 void UtilityProcessHostImpl::SetEnv(const base::EnvironmentMap& env) {
163 env_ = env; 171 env_ = env;
164 } 172 }
165 173
166 #endif // OS_POSIX 174 #endif // OS_POSIX
167 175
176 bool UtilityProcessHostImpl::StartMojoMode() {
177 CHECK(!mojo_application_host_);
178 mojo_application_host_.reset(new MojoApplicationHost);
179
180 bool mojo_result = mojo_application_host_->Init();
181 if (!mojo_result)
182 return false;
183
184 return StartProcess();
185 }
186
187 ServiceRegistry* UtilityProcessHostImpl::GetServiceRegistry() {
188 DCHECK(mojo_application_host_);
189 return mojo_application_host_->service_registry();
190 }
191
168 bool UtilityProcessHostImpl::StartProcess() { 192 bool UtilityProcessHostImpl::StartProcess() {
169 if (started_) 193 if (started_)
170 return true; 194 return true;
171 started_ = true; 195 started_ = true;
172 196
173 if (is_batch_mode_) 197 if (is_batch_mode_)
174 return true; 198 return true;
175 199
176 // Name must be set or metrics_service will crash in any test which 200 // Name must be set or metrics_service will crash in any test which
177 // launches a UtilityProcessHost. 201 // launches a UtilityProcessHost.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { 309 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) {
286 if (!client_.get()) 310 if (!client_.get())
287 return; 311 return;
288 312
289 client_task_runner_->PostTask( 313 client_task_runner_->PostTask(
290 FROM_HERE, 314 FROM_HERE,
291 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), 315 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(),
292 exit_code)); 316 exit_code));
293 } 317 }
294 318
319 void UtilityProcessHostImpl::OnProcessLaunched() {
320 if (mojo_application_host_) {
321 base::ProcessHandle handle;
322 if (RenderProcessHost::run_renderer_in_process())
323 handle = base::GetCurrentProcessHandle();
324 else
325 handle = process_->GetData().handle;
326
327 mojo_application_host_->Activate(this, handle);
328 }
329 }
330
295 } // namespace content 331 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698