OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "content/utility/utility_main_thread.h" |
| 6 |
| 7 #include "content/child/child_process.h" |
| 8 #include "content/utility/utility_thread_impl.h" |
| 9 |
| 10 namespace content { |
| 11 |
| 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; |
| 15 |
| 16 UtilityMainThread::UtilityMainThread(const std::string& channel_id) |
| 17 : Thread("Chrome_InProcUtilityThread"), channel_id_(channel_id) { |
| 18 } |
| 19 |
| 20 UtilityMainThread::~UtilityMainThread() { |
| 21 Stop(); |
| 22 } |
| 23 |
| 24 void UtilityMainThread::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(&UtilityMainThread::InitInternal, base::Unretained(this))); |
| 30 } |
| 31 |
| 32 void UtilityMainThread::CleanUp() { |
| 33 child_process_.reset(); |
| 34 |
| 35 // See comment in RendererMainThread. |
| 36 SetThreadWasQuitProperly(true); |
| 37 g_one_utility_thread_lock.Get().Release(); |
| 38 } |
| 39 |
| 40 void UtilityMainThread::InitInternal() { |
| 41 g_one_utility_thread_lock.Get().Acquire(); |
| 42 child_process_.reset(new ChildProcess()); |
| 43 child_process_->set_main_thread(new UtilityThreadImpl(channel_id_)); |
| 44 } |
| 45 |
| 46 base::Thread* CreateUtilityMainThread(const std::string& channel_id) { |
| 47 return new UtilityMainThread(channel_id); |
| 48 } |
| 49 |
| 50 } // namespace content |
OLD | NEW |