OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/test/sequenced_worker_pool_owner.h" |
| 6 |
| 7 #include "base/location.h" |
| 8 #include "base/message_loop.h" |
| 9 |
| 10 namespace base { |
| 11 |
| 12 SequencedWorkerPoolOwner::SequencedWorkerPoolOwner( |
| 13 size_t max_threads, |
| 14 const std::string& thread_name_prefix) |
| 15 : constructor_message_loop_(MessageLoop::current()), |
| 16 pool_(new SequencedWorkerPool( |
| 17 max_threads, thread_name_prefix, |
| 18 ALLOW_THIS_IN_INITIALIZER_LIST(this))), |
| 19 has_work_call_count_(0) {} |
| 20 |
| 21 SequencedWorkerPoolOwner::~SequencedWorkerPoolOwner() { |
| 22 pool_ = NULL; |
| 23 MessageLoop::current()->Run(); |
| 24 } |
| 25 |
| 26 const scoped_refptr<SequencedWorkerPool>& SequencedWorkerPoolOwner::pool() { |
| 27 return pool_; |
| 28 } |
| 29 |
| 30 void SequencedWorkerPoolOwner::SetWillWaitForShutdownCallback( |
| 31 const Closure& callback) { |
| 32 will_wait_for_shutdown_callback_ = callback; |
| 33 } |
| 34 |
| 35 int SequencedWorkerPoolOwner::has_work_call_count() const { |
| 36 AutoLock lock(has_work_lock_); |
| 37 return has_work_call_count_; |
| 38 } |
| 39 |
| 40 void SequencedWorkerPoolOwner::OnHasWork() { |
| 41 AutoLock lock(has_work_lock_); |
| 42 ++has_work_call_count_; |
| 43 } |
| 44 |
| 45 void SequencedWorkerPoolOwner::WillWaitForShutdown() { |
| 46 if (!will_wait_for_shutdown_callback_.is_null()) { |
| 47 will_wait_for_shutdown_callback_.Run(); |
| 48 } |
| 49 } |
| 50 |
| 51 void SequencedWorkerPoolOwner::OnDestruct() { |
| 52 constructor_message_loop_->PostTask( |
| 53 FROM_HERE, |
| 54 constructor_message_loop_->QuitClosure()); |
| 55 } |
| 56 |
| 57 } // namespace base |
OLD | NEW |