Update V8 to version 4.7.42.
[chromium-blink-merge.git] / content / utility / in_process_utility_thread.cc
blob444b81df5c35313c743202d21d78153cd0e3930d
1 // Copyright 2013 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.
5 #include "content/utility/in_process_utility_thread.h"
7 #include "base/location.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "content/child/child_process.h"
11 #include "content/utility/utility_thread_impl.h"
13 namespace content {
15 // We want to ensure there's only one utility thread running at a time, as there
16 // are many globals used in the utility process.
17 static base::LazyInstance<base::Lock> g_one_utility_thread_lock;
19 InProcessUtilityThread::InProcessUtilityThread(
20 const InProcessChildThreadParams& params)
21 : Thread("Chrome_InProcUtilityThread"), params_(params) {
24 InProcessUtilityThread::~InProcessUtilityThread() {
25 // Wait till in-process utility thread finishes clean up.
26 bool previous_value = base::ThreadRestrictions::SetIOAllowed(true);
27 Stop();
28 base::ThreadRestrictions::SetIOAllowed(previous_value);
31 void InProcessUtilityThread::Init() {
32 // We need to return right away or else the main thread that started us will
33 // hang.
34 base::ThreadTaskRunnerHandle::Get()->PostTask(
35 FROM_HERE, base::Bind(&InProcessUtilityThread::InitInternal,
36 base::Unretained(this)));
39 void InProcessUtilityThread::CleanUp() {
40 child_process_.reset();
42 // See comment in RendererMainThread.
43 SetThreadWasQuitProperly(true);
44 g_one_utility_thread_lock.Get().Release();
47 void InProcessUtilityThread::InitInternal() {
48 g_one_utility_thread_lock.Get().Acquire();
49 child_process_.reset(new ChildProcess());
50 child_process_->set_main_thread(new UtilityThreadImpl(params_));
53 base::Thread* CreateInProcessUtilityThread(
54 const InProcessChildThreadParams& params) {
55 return new InProcessUtilityThread(params);
58 } // namespace content