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 #ifndef BASE_THREADING_SEQUENCED_WORKER_POOL_UNITTEST_H_ |
| 6 #define BASE_THREADING_SEQUENCED_WORKER_POOL_UNITTEST_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" |
| 12 |
| 13 class MessageLoop; |
| 14 |
| 15 namespace base { |
| 16 |
| 17 // Wrapper around SequencedWorkerPool that blocks destruction until |
| 18 // the pool is actually destroyed. This is so that a |
| 19 // SequencedWorkerPool from one test doesn't outlive its test and |
| 20 // cause strange races with other tests that touch global stuff (like |
| 21 // histograms and logging). However, this requires that nothing else |
| 22 // on this thread holds a ref to the pool when the |
| 23 // SequencedWorkerPoolOwner is destroyed. |
| 24 class SequencedWorkerPoolOwner : public SequencedWorkerPool::TestingObserver { |
| 25 public: |
| 26 SequencedWorkerPoolOwner(size_t max_threads, |
| 27 const std::string& thread_name_prefix); |
| 28 |
| 29 virtual ~SequencedWorkerPoolOwner(); |
| 30 |
| 31 // Don't change the return pool's testing observer. |
| 32 const scoped_refptr<SequencedWorkerPool>& pool(); |
| 33 |
| 34 // The given callback will be called on WillWaitForShutdown(). |
| 35 void SetWillWaitForShutdownCallback(const Closure& callback); |
| 36 |
| 37 private: |
| 38 // SequencedWorkerPool::TestingObserver implementation. |
| 39 virtual void WillWaitForShutdown() OVERRIDE; |
| 40 virtual void OnDestruct() OVERRIDE; |
| 41 |
| 42 MessageLoop* const constructor_message_loop_; |
| 43 scoped_refptr<SequencedWorkerPool> pool_; |
| 44 Closure will_wait_for_shutdown_callback_; |
| 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPoolOwner); |
| 47 }; |
| 48 |
| 49 } // namespace base |
| 50 |
| 51 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_UNITTEST_H_ |
OLD | NEW |