| 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(); | |
| 22 pool_ = NULL; | 21 pool_ = NULL; |
| 23 | 22 MessageLoop::current()->Run(); |
| 24 // Spin the current message loop until SWP destruction verified in OnDestruct. | |
| 25 exit_loop_.Run(); | |
| 26 } | 23 } |
| 27 | 24 |
| 28 const scoped_refptr<SequencedWorkerPool>& SequencedWorkerPoolOwner::pool() { | 25 const scoped_refptr<SequencedWorkerPool>& SequencedWorkerPoolOwner::pool() { |
| 29 return pool_; | 26 return pool_; |
| 30 } | 27 } |
| 31 | 28 |
| 32 void SequencedWorkerPoolOwner::SetWillWaitForShutdownCallback( | 29 void SequencedWorkerPoolOwner::SetWillWaitForShutdownCallback( |
| 33 const Closure& callback) { | 30 const Closure& callback) { |
| 34 will_wait_for_shutdown_callback_ = callback; | 31 will_wait_for_shutdown_callback_ = callback; |
| 35 } | 32 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 47 void SequencedWorkerPoolOwner::WillWaitForShutdown() { | 44 void SequencedWorkerPoolOwner::WillWaitForShutdown() { |
| 48 if (!will_wait_for_shutdown_callback_.is_null()) { | 45 if (!will_wait_for_shutdown_callback_.is_null()) { |
| 49 will_wait_for_shutdown_callback_.Run(); | 46 will_wait_for_shutdown_callback_.Run(); |
| 50 | 47 |
| 51 // Release the reference to the callback to prevent retain cycles. | 48 // Release the reference to the callback to prevent retain cycles. |
| 52 will_wait_for_shutdown_callback_ = Closure(); | 49 will_wait_for_shutdown_callback_ = Closure(); |
| 53 } | 50 } |
| 54 } | 51 } |
| 55 | 52 |
| 56 void SequencedWorkerPoolOwner::OnDestruct() { | 53 void SequencedWorkerPoolOwner::OnDestruct() { |
| 57 constructor_message_loop_->PostTask(FROM_HERE, exit_loop_.QuitClosure()); | 54 constructor_message_loop_->task_runner()->PostTask( |
| 55 FROM_HERE, constructor_message_loop_->QuitWhenIdleClosure()); |
| 58 } | 56 } |
| 59 | 57 |
| 60 } // namespace base | 58 } // namespace base |
| OLD | NEW |