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 "content/child/child_process.h" | 7 #include "content/child/child_process.h" |
8 #include "content/utility/utility_thread_impl.h" | 8 #include "content/utility/utility_thread_impl.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 | 11 |
12 // 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 |
13 // are many globals used in the utility process. | 13 // are many globals used in the utility process. |
14 static base::LazyInstance<base::Lock> g_one_utility_thread_lock; | 14 static base::LazyInstance<base::Lock> g_one_utility_thread_lock; |
15 | 15 |
16 InProcessUtilityThread::InProcessUtilityThread(const std::string& channel_id) | 16 InProcessUtilityThread::InProcessUtilityThread(const std::string& channel_id) |
17 : Thread("Chrome_InProcUtilityThread"), channel_id_(channel_id) { | 17 : Thread("Chrome_InProcUtilityThread"), channel_id_(channel_id) { |
18 } | 18 } |
19 | 19 |
20 InProcessUtilityThread::~InProcessUtilityThread() { | 20 InProcessUtilityThread::~InProcessUtilityThread() { |
| 21 // Wait till in-process utility thread finishes clean up. |
| 22 bool previous_value = base::ThreadRestrictions::SetIOAllowed(true); |
21 Stop(); | 23 Stop(); |
| 24 base::ThreadRestrictions::SetIOAllowed(previous_value); |
22 } | 25 } |
23 | 26 |
24 void InProcessUtilityThread::Init() { | 27 void InProcessUtilityThread::Init() { |
25 // We need to return right away or else the main thread that started us will | 28 // We need to return right away or else the main thread that started us will |
26 // hang. | 29 // hang. |
27 base::MessageLoop::current()->PostTask( | 30 base::MessageLoop::current()->PostTask( |
28 FROM_HERE, | 31 FROM_HERE, |
29 base::Bind(&InProcessUtilityThread::InitInternal, | 32 base::Bind(&InProcessUtilityThread::InitInternal, |
30 base::Unretained(this))); | 33 base::Unretained(this))); |
31 } | 34 } |
(...skipping 10 matching lines...) Expand all Loading... |
42 g_one_utility_thread_lock.Get().Acquire(); | 45 g_one_utility_thread_lock.Get().Acquire(); |
43 child_process_.reset(new ChildProcess()); | 46 child_process_.reset(new ChildProcess()); |
44 child_process_->set_main_thread(new UtilityThreadImpl(channel_id_)); | 47 child_process_->set_main_thread(new UtilityThreadImpl(channel_id_)); |
45 } | 48 } |
46 | 49 |
47 base::Thread* CreateInProcessUtilityThread(const std::string& channel_id) { | 50 base::Thread* CreateInProcessUtilityThread(const std::string& channel_id) { |
48 return new InProcessUtilityThread(channel_id); | 51 return new InProcessUtilityThread(channel_id); |
49 } | 52 } |
50 | 53 |
51 } // namespace content | 54 } // namespace content |
OLD | NEW |