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