OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/test/sequenced_worker_pool_owner.h" | 5 #include "base/test/sequenced_worker_pool_owner.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 | 12 |
13 SequencedWorkerPoolOwner::SequencedWorkerPoolOwner( | 13 SequencedWorkerPoolOwner::SequencedWorkerPoolOwner( |
14 size_t max_threads, | 14 size_t max_threads, |
15 const std::string& thread_name_prefix) | 15 const std::string& thread_name_prefix) |
16 : constructor_message_loop_(MessageLoop::current()), | 16 : constructor_message_loop_(MessageLoop::current()), |
17 pool_(new SequencedWorkerPool(max_threads, thread_name_prefix, this)), | 17 pool_(new SequencedWorkerPool(max_threads, thread_name_prefix, this)), |
18 has_work_call_count_(0) {} | 18 has_work_call_count_(0) {} |
19 | 19 |
20 SequencedWorkerPoolOwner::~SequencedWorkerPoolOwner() { | 20 SequencedWorkerPoolOwner::~SequencedWorkerPoolOwner() { |
| 21 pool_->Shutdown(); |
21 pool_ = NULL; | 22 pool_ = NULL; |
22 MessageLoop::current()->Run(); | 23 |
| 24 // Spin the current message loop until SWP destruction verified in OnDestruct. |
| 25 exit_loop_.Run(); |
23 } | 26 } |
24 | 27 |
25 const scoped_refptr<SequencedWorkerPool>& SequencedWorkerPoolOwner::pool() { | 28 const scoped_refptr<SequencedWorkerPool>& SequencedWorkerPoolOwner::pool() { |
26 return pool_; | 29 return pool_; |
27 } | 30 } |
28 | 31 |
29 void SequencedWorkerPoolOwner::SetWillWaitForShutdownCallback( | 32 void SequencedWorkerPoolOwner::SetWillWaitForShutdownCallback( |
30 const Closure& callback) { | 33 const Closure& callback) { |
31 will_wait_for_shutdown_callback_ = callback; | 34 will_wait_for_shutdown_callback_ = callback; |
32 } | 35 } |
(...skipping 11 matching lines...) Expand all Loading... |
44 void SequencedWorkerPoolOwner::WillWaitForShutdown() { | 47 void SequencedWorkerPoolOwner::WillWaitForShutdown() { |
45 if (!will_wait_for_shutdown_callback_.is_null()) { | 48 if (!will_wait_for_shutdown_callback_.is_null()) { |
46 will_wait_for_shutdown_callback_.Run(); | 49 will_wait_for_shutdown_callback_.Run(); |
47 | 50 |
48 // Release the reference to the callback to prevent retain cycles. | 51 // Release the reference to the callback to prevent retain cycles. |
49 will_wait_for_shutdown_callback_ = Closure(); | 52 will_wait_for_shutdown_callback_ = Closure(); |
50 } | 53 } |
51 } | 54 } |
52 | 55 |
53 void SequencedWorkerPoolOwner::OnDestruct() { | 56 void SequencedWorkerPoolOwner::OnDestruct() { |
54 constructor_message_loop_->task_runner()->PostTask( | 57 constructor_message_loop_->PostTask(FROM_HERE, exit_loop_.QuitClosure()); |
55 FROM_HERE, constructor_message_loop_->QuitWhenIdleClosure()); | |
56 } | 58 } |
57 | 59 |
58 } // namespace base | 60 } // namespace base |
OLD | NEW |