| Index: base/threading/sequenced_worker_pool_unittest.cc
|
| ===================================================================
|
| --- base/threading/sequenced_worker_pool_unittest.cc (revision 126348)
|
| +++ base/threading/sequenced_worker_pool_unittest.cc (working copy)
|
| @@ -2,6 +2,8 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "base/threading/sequenced_worker_pool_unittest.h"
|
| +
|
| #include <algorithm>
|
|
|
| #include "base/bind.h"
|
| @@ -14,12 +16,45 @@
|
| #include "base/synchronization/lock.h"
|
| #include "base/test/task_runner_test_template.h"
|
| #include "base/threading/platform_thread.h"
|
| -#include "base/threading/sequenced_worker_pool.h"
|
| #include "base/tracked_objects.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace base {
|
|
|
| +SequencedWorkerPoolOwner::SequencedWorkerPoolOwner(
|
| + size_t max_threads,
|
| + const std::string& thread_name_prefix)
|
| + : constructor_message_loop_(MessageLoop::current()),
|
| + pool_(new SequencedWorkerPool(max_threads, thread_name_prefix)) {
|
| + pool_->SetTestingObserver(this);
|
| +}
|
| +
|
| +SequencedWorkerPoolOwner::~SequencedWorkerPoolOwner() {
|
| + pool_ = NULL;
|
| + MessageLoop::current()->Run();
|
| +}
|
| +
|
| +const scoped_refptr<SequencedWorkerPool>& SequencedWorkerPoolOwner::pool() {
|
| + return pool_;
|
| +}
|
| +
|
| +void SequencedWorkerPoolOwner::SetWillWaitForShutdownCallback(
|
| + const Closure& callback) {
|
| + will_wait_for_shutdown_callback_ = callback;
|
| +}
|
| +
|
| +void SequencedWorkerPoolOwner::WillWaitForShutdown() {
|
| + if (!will_wait_for_shutdown_callback_.is_null()) {
|
| + will_wait_for_shutdown_callback_.Run();
|
| + }
|
| +}
|
| +
|
| +void SequencedWorkerPoolOwner::OnDestruct() {
|
| + constructor_message_loop_->PostTask(
|
| + FROM_HERE,
|
| + constructor_message_loop_->QuitClosure());
|
| +}
|
| +
|
| // IMPORTANT NOTE:
|
| //
|
| // Many of these tests have failure modes where they'll hang forever. These
|
| @@ -145,58 +180,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)) {
|
| - pool_->SetTestingObserver(this);
|
| - }
|
| -
|
| - 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;
|
| - }
|
| -
|
| - private:
|
| - // SequencedWorkerPool::TestingObserver implementation.
|
| - 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_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPoolOwner);
|
| -};
|
| -
|
| class SequencedWorkerPoolTest : public testing::Test {
|
| public:
|
| SequencedWorkerPoolTest()
|
|
|