| Index: base/threading/sequenced_worker_pool_unittest.cc
|
| ===================================================================
|
| --- base/threading/sequenced_worker_pool_unittest.cc (revision 130053)
|
| +++ base/threading/sequenced_worker_pool_unittest.cc (working copy)
|
| @@ -12,6 +12,7 @@
|
| #include "base/message_loop_proxy.h"
|
| #include "base/synchronization/condition_variable.h"
|
| #include "base/synchronization/lock.h"
|
| +#include "base/test/sequenced_worker_pool_owner.h"
|
| #include "base/test/task_runner_test_template.h"
|
| #include "base/threading/platform_thread.h"
|
| #include "base/threading/sequenced_worker_pool.h"
|
| @@ -145,72 +146,6 @@
|
| size_t started_events_;
|
| };
|
|
|
| -// Wrapper around SequencedWorkerPool that blocks destruction until
|
| -// the pool is actually destroyed. This is so that a
|
| -// SequencedWorkerPool from one test doesn't outlive its test and
|
| -// cause strange races with other tests that touch global stuff (like
|
| -// histograms and logging). However, this requires that nothing else
|
| -// on this thread holds a ref to the pool when the
|
| -// SequencedWorkerPoolOwner is destroyed.
|
| -class SequencedWorkerPoolOwner : public SequencedWorkerPool::TestingObserver {
|
| - public:
|
| - SequencedWorkerPoolOwner(size_t max_threads,
|
| - const std::string& thread_name_prefix)
|
| - : constructor_message_loop_(MessageLoop::current()),
|
| - pool_(new SequencedWorkerPool(
|
| - max_threads, thread_name_prefix,
|
| - ALLOW_THIS_IN_INITIALIZER_LIST(this))),
|
| - has_work_call_count_(0) {}
|
| -
|
| - virtual ~SequencedWorkerPoolOwner() {
|
| - pool_ = NULL;
|
| - MessageLoop::current()->Run();
|
| - }
|
| -
|
| - // Don't change the return pool's testing observer.
|
| - const scoped_refptr<SequencedWorkerPool>& pool() {
|
| - return pool_;
|
| - }
|
| -
|
| - // The given callback will be called on WillWaitForShutdown().
|
| - void SetWillWaitForShutdownCallback(const Closure& callback) {
|
| - will_wait_for_shutdown_callback_ = callback;
|
| - }
|
| -
|
| - int has_work_call_count() const {
|
| - AutoLock lock(has_work_lock_);
|
| - return has_work_call_count_;
|
| - }
|
| -
|
| - private:
|
| - // SequencedWorkerPool::TestingObserver implementation.
|
| - virtual void OnHasWork() OVERRIDE {
|
| - AutoLock lock(has_work_lock_);
|
| - ++has_work_call_count_;
|
| - }
|
| -
|
| - virtual void WillWaitForShutdown() OVERRIDE {
|
| - if (!will_wait_for_shutdown_callback_.is_null()) {
|
| - will_wait_for_shutdown_callback_.Run();
|
| - }
|
| - }
|
| -
|
| - virtual void OnDestruct() OVERRIDE {
|
| - constructor_message_loop_->PostTask(
|
| - FROM_HERE,
|
| - constructor_message_loop_->QuitClosure());
|
| - }
|
| -
|
| - MessageLoop* const constructor_message_loop_;
|
| - scoped_refptr<SequencedWorkerPool> pool_;
|
| - Closure will_wait_for_shutdown_callback_;
|
| -
|
| - mutable Lock has_work_lock_;
|
| - int has_work_call_count_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPoolOwner);
|
| -};
|
| -
|
| class SequencedWorkerPoolTest : public testing::Test {
|
| public:
|
| SequencedWorkerPoolTest()
|
|
|