Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3115)

Unified Diff: base/threading/sequenced_worker_pool_unittest.cc

Issue 9663075: Implementation of SequencedTaskRunner based on SequencedWorkerPool. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/threading/sequenced_worker_pool_unittest.cc
===================================================================
--- base/threading/sequenced_worker_pool_unittest.cc (revision 127368)
+++ 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,56 @@
#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(
akalin 2012/03/20 22:16:08 move this in the corresponding file base/test/sequ
Francois 2012/03/26 09:33:21 Done.
+ 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) {}
+
+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;
+}
+
+int SequencedWorkerPoolOwner::has_work_call_count() const {
+ AutoLock lock(has_work_lock_);
+ return has_work_call_count_;
+}
+
+void SequencedWorkerPoolOwner::OnHasWork() {
+ AutoLock lock(has_work_lock_);
+ ++has_work_call_count_;
+}
+
+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,72 +191,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()

Powered by Google App Engine
This is Rietveld 408576698