OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/utility/in_process_utility_thread.h" | 5 #include "content/utility/in_process_utility_thread.h" |
6 | 6 |
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" | 7 #include "content/child/child_process.h" |
11 #include "content/utility/utility_thread_impl.h" | 8 #include "content/utility/utility_thread_impl.h" |
12 | 9 |
13 namespace content { | 10 namespace content { |
14 | 11 |
15 // We want to ensure there's only one utility thread running at a time, as there | 12 // 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. | 13 // are many globals used in the utility process. |
17 static base::LazyInstance<base::Lock> g_one_utility_thread_lock; | 14 static base::LazyInstance<base::Lock> g_one_utility_thread_lock; |
18 | 15 |
19 InProcessUtilityThread::InProcessUtilityThread( | 16 InProcessUtilityThread::InProcessUtilityThread( |
20 const InProcessChildThreadParams& params) | 17 const InProcessChildThreadParams& params) |
21 : Thread("Chrome_InProcUtilityThread"), params_(params) { | 18 : Thread("Chrome_InProcUtilityThread"), params_(params) { |
22 } | 19 } |
23 | 20 |
24 InProcessUtilityThread::~InProcessUtilityThread() { | 21 InProcessUtilityThread::~InProcessUtilityThread() { |
25 // Wait till in-process utility thread finishes clean up. | 22 // Wait till in-process utility thread finishes clean up. |
26 bool previous_value = base::ThreadRestrictions::SetIOAllowed(true); | 23 bool previous_value = base::ThreadRestrictions::SetIOAllowed(true); |
27 Stop(); | 24 Stop(); |
28 base::ThreadRestrictions::SetIOAllowed(previous_value); | 25 base::ThreadRestrictions::SetIOAllowed(previous_value); |
29 } | 26 } |
30 | 27 |
31 void InProcessUtilityThread::Init() { | 28 void InProcessUtilityThread::Init() { |
32 // We need to return right away or else the main thread that started us will | 29 // We need to return right away or else the main thread that started us will |
33 // hang. | 30 // hang. |
34 base::ThreadTaskRunnerHandle::Get()->PostTask( | 31 base::MessageLoop::current()->PostTask( |
35 FROM_HERE, base::Bind(&InProcessUtilityThread::InitInternal, | 32 FROM_HERE, |
36 base::Unretained(this))); | 33 base::Bind(&InProcessUtilityThread::InitInternal, |
| 34 base::Unretained(this))); |
37 } | 35 } |
38 | 36 |
39 void InProcessUtilityThread::CleanUp() { | 37 void InProcessUtilityThread::CleanUp() { |
40 child_process_.reset(); | 38 child_process_.reset(); |
41 | 39 |
42 // See comment in RendererMainThread. | 40 // See comment in RendererMainThread. |
43 SetThreadWasQuitProperly(true); | 41 SetThreadWasQuitProperly(true); |
44 g_one_utility_thread_lock.Get().Release(); | 42 g_one_utility_thread_lock.Get().Release(); |
45 } | 43 } |
46 | 44 |
47 void InProcessUtilityThread::InitInternal() { | 45 void InProcessUtilityThread::InitInternal() { |
48 g_one_utility_thread_lock.Get().Acquire(); | 46 g_one_utility_thread_lock.Get().Acquire(); |
49 child_process_.reset(new ChildProcess()); | 47 child_process_.reset(new ChildProcess()); |
50 child_process_->set_main_thread(new UtilityThreadImpl(params_)); | 48 child_process_->set_main_thread(new UtilityThreadImpl(params_)); |
51 } | 49 } |
52 | 50 |
53 base::Thread* CreateInProcessUtilityThread( | 51 base::Thread* CreateInProcessUtilityThread( |
54 const InProcessChildThreadParams& params) { | 52 const InProcessChildThreadParams& params) { |
55 return new InProcessUtilityThread(params); | 53 return new InProcessUtilityThread(params); |
56 } | 54 } |
57 | 55 |
58 } // namespace content | 56 } // namespace content |
OLD | NEW |