Reduce the scope of CGL current contexts
[chromium-blink-merge.git] / content / utility / in_process_utility_thread.cc
blob8859e518216264fbb9c1b46f9e732caa55e63b2b
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 "content/child/child_process.h"
8 #include "content/utility/utility_thread_impl.h"
10 namespace content {
12 // We want to ensure there's only one utility thread running at a time, as there
13 // are many globals used in the utility process.
14 static base::LazyInstance<base::Lock> g_one_utility_thread_lock;
16 InProcessUtilityThread::InProcessUtilityThread(const std::string& channel_id)
17 : Thread("Chrome_InProcUtilityThread"), channel_id_(channel_id) {
20 InProcessUtilityThread::~InProcessUtilityThread() {
21 Stop();
24 void InProcessUtilityThread::Init() {
25 // We need to return right away or else the main thread that started us will
26 // hang.
27 base::MessageLoop::current()->PostTask(
28 FROM_HERE,
29 base::Bind(&InProcessUtilityThread::InitInternal,
30 base::Unretained(this)));
33 void InProcessUtilityThread::CleanUp() {
34 child_process_.reset();
36 // See comment in RendererMainThread.
37 SetThreadWasQuitProperly(true);
38 g_one_utility_thread_lock.Get().Release();
41 void InProcessUtilityThread::InitInternal() {
42 g_one_utility_thread_lock.Get().Acquire();
43 child_process_.reset(new ChildProcess());
44 child_process_->set_main_thread(new UtilityThreadImpl(channel_id_));
47 base::Thread* CreateInProcessUtilityThread(const std::string& channel_id) {
48 return new InProcessUtilityThread(channel_id);
51 } // namespace content