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

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

Issue 1844233003: Always allow ServiceRegistry to be used with UtilityProcessHosts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove scoped_ptr usage. Created 4 years, 8 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 <utility> 7 #include <utility>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 is_batch_mode_(false), 150 is_batch_mode_(false),
151 no_sandbox_(false), 151 no_sandbox_(false),
152 run_elevated_(false), 152 run_elevated_(false),
153 #if defined(OS_LINUX) 153 #if defined(OS_LINUX)
154 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), 154 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF),
155 #else 155 #else
156 child_flags_(ChildProcessHost::CHILD_NORMAL), 156 child_flags_(ChildProcessHost::CHILD_NORMAL),
157 #endif 157 #endif
158 started_(false), 158 started_(false),
159 name_(base::ASCIIToUTF16("utility process")), 159 name_(base::ASCIIToUTF16("utility process")),
160 mojo_application_host_(new MojoApplicationHost),
160 weak_ptr_factory_(this) { 161 weak_ptr_factory_(this) {
161 } 162 }
162 163
163 UtilityProcessHostImpl::~UtilityProcessHostImpl() { 164 UtilityProcessHostImpl::~UtilityProcessHostImpl() {
164 DCHECK_CURRENTLY_ON(BrowserThread::IO); 165 DCHECK_CURRENTLY_ON(BrowserThread::IO);
165 if (is_batch_mode_) 166 if (is_batch_mode_)
166 EndBatchMode(); 167 EndBatchMode();
167 } 168 }
168 169
169 base::WeakPtr<UtilityProcessHost> UtilityProcessHostImpl::AsWeakPtr() { 170 base::WeakPtr<UtilityProcessHost> UtilityProcessHostImpl::AsWeakPtr() {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 211 }
211 212
212 #if defined(OS_POSIX) 213 #if defined(OS_POSIX)
213 214
214 void UtilityProcessHostImpl::SetEnv(const base::EnvironmentMap& env) { 215 void UtilityProcessHostImpl::SetEnv(const base::EnvironmentMap& env) {
215 env_ = env; 216 env_ = env;
216 } 217 }
217 218
218 #endif // OS_POSIX 219 #endif // OS_POSIX
219 220
220 bool UtilityProcessHostImpl::StartMojoMode() { 221 bool UtilityProcessHostImpl::Start() {
221 CHECK(!mojo_application_host_);
222 mojo_application_host_.reset(new MojoApplicationHost);
223
224 bool mojo_result = mojo_application_host_->Init();
225 if (!mojo_result)
226 return false;
227
228 return StartProcess(); 222 return StartProcess();
229 } 223 }
230 224
231 ServiceRegistry* UtilityProcessHostImpl::GetServiceRegistry() { 225 ServiceRegistry* UtilityProcessHostImpl::GetServiceRegistry() {
232 if (mojo_application_host_) 226 DCHECK(mojo_application_host_);
233 return mojo_application_host_->service_registry(); 227 return mojo_application_host_->service_registry();
234 return nullptr;
235 } 228 }
236 229
237 void UtilityProcessHostImpl::SetName(const base::string16& name) { 230 void UtilityProcessHostImpl::SetName(const base::string16& name) {
238 name_ = name; 231 name_ = name;
239 } 232 }
240 233
241 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) 234 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
242 // static 235 // static
243 void UtilityProcessHostImpl::EarlyZygoteLaunch() { 236 void UtilityProcessHostImpl::EarlyZygoteLaunch() {
244 DCHECK(!g_utility_zygote); 237 DCHECK(!g_utility_zygote);
245 g_utility_zygote = CreateZygote(); 238 g_utility_zygote = CreateZygote();
246 } 239 }
247 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) 240 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
248 241
249 bool UtilityProcessHostImpl::StartProcess() { 242 bool UtilityProcessHostImpl::StartProcess() {
250 if (started_) 243 if (started_)
251 return true; 244 return true;
252 started_ = true; 245 started_ = true;
253 246
254 if (is_batch_mode_) 247 if (is_batch_mode_)
255 return true; 248 return true;
256 249
250 bool mojo_result = mojo_application_host_->Init();
251 if (!mojo_result)
252 return false;
253
257 // Name must be set or metrics_service will crash in any test which 254 // Name must be set or metrics_service will crash in any test which
258 // launches a UtilityProcessHost. 255 // launches a UtilityProcessHost.
259 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); 256 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this));
260 process_->SetName(name_); 257 process_->SetName(name_);
261 258
262 std::string channel_id = process_->GetHost()->CreateChannel(); 259 std::string channel_id = process_->GetHost()->CreateChannel();
263 if (channel_id.empty()) 260 if (channel_id.empty())
264 return false; 261 return false;
265 262
266 if (RenderProcessHost::run_renderer_in_process()) { 263 if (RenderProcessHost::run_renderer_in_process()) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 if (!client_.get()) 387 if (!client_.get())
391 return; 388 return;
392 389
393 client_task_runner_->PostTask( 390 client_task_runner_->PostTask(
394 FROM_HERE, 391 FROM_HERE,
395 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), 392 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(),
396 exit_code)); 393 exit_code));
397 } 394 }
398 395
399 void UtilityProcessHostImpl::OnProcessLaunched() { 396 void UtilityProcessHostImpl::OnProcessLaunched() {
400 if (mojo_application_host_) { 397 DCHECK(mojo_application_host_);
401 base::ProcessHandle handle; 398 base::ProcessHandle handle;
402 if (RenderProcessHost::run_renderer_in_process()) 399 if (RenderProcessHost::run_renderer_in_process())
403 handle = base::GetCurrentProcessHandle(); 400 handle = base::GetCurrentProcessHandle();
404 else 401 else
405 handle = process_->GetData().handle; 402 handle = process_->GetData().handle;
406 403
407 mojo_application_host_->Activate(this, handle); 404 mojo_application_host_->Activate(this, handle);
408 }
409 } 405 }
410 406
411 } // namespace content 407 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698