summaryrefslogtreecommitdiffstats
path: root/base/threading/sequenced_worker_pool_unittest.cc
diff options
context:
space:
mode:
authorfrancoisk777@gmail.com <francoisk777@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-02 10:16:55 +0000
committerfrancoisk777@gmail.com <francoisk777@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-02 10:16:55 +0000
commitce5d047544f7e28cdc7693b86ffc78e3cfd01a2a (patch)
tree1a6cc4b3cd2dae37cfec2b1099be4610862c17f6 /base/threading/sequenced_worker_pool_unittest.cc
parent6fe6965e2d0e4ac248d6825a88b5e53a77ac5ffe (diff)
downloadchromium_src-ce5d047544f7e28cdc7693b86ffc78e3cfd01a2a.zip
chromium_src-ce5d047544f7e28cdc7693b86ffc78e3cfd01a2a.tar.gz
chromium_src-ce5d047544f7e28cdc7693b86ffc78e3cfd01a2a.tar.bz2
Implementation of SequencedTaskRunner based on SequencedWorkerPool.
Also includes specification tests for SequencedTaskRunner. BUG=114330,114327 TEST=--gtest_filter=SequencedWorkerPoolTaskRunner* Review URL: http://codereview.chromium.org/9663075 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130113 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/threading/sequenced_worker_pool_unittest.cc')
-rw-r--r--base/threading/sequenced_worker_pool_unittest.cc67
1 files changed, 1 insertions, 66 deletions
diff --git a/base/threading/sequenced_worker_pool_unittest.cc b/base/threading/sequenced_worker_pool_unittest.cc
index 8a3508d..1c29c34 100644
--- a/base/threading/sequenced_worker_pool_unittest.cc
+++ b/base/threading/sequenced_worker_pool_unittest.cc
@@ -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 @@ class TestTracker : public base::RefCountedThreadSafe<TestTracker> {
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()