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.
5 #include "base/test/sequenced_worker_pool_owner.h"
7 #include "base/location.h"
8 #include "base/message_loop/message_loop.h"
12 SequencedWorkerPoolOwner::SequencedWorkerPoolOwner(
14 const std::string
& thread_name_prefix
)
15 : constructor_message_loop_(MessageLoop::current()),
16 pool_(new SequencedWorkerPool(max_threads
, thread_name_prefix
, this)),
17 has_work_call_count_(0) {}
19 SequencedWorkerPoolOwner::~SequencedWorkerPoolOwner() {
21 MessageLoop::current()->Run();
24 const scoped_refptr
<SequencedWorkerPool
>& SequencedWorkerPoolOwner::pool() {
28 void SequencedWorkerPoolOwner::SetWillWaitForShutdownCallback(
29 const Closure
& callback
) {
30 will_wait_for_shutdown_callback_
= callback
;
33 int SequencedWorkerPoolOwner::has_work_call_count() const {
34 AutoLock
lock(has_work_lock_
);
35 return has_work_call_count_
;
38 void SequencedWorkerPoolOwner::OnHasWork() {
39 AutoLock
lock(has_work_lock_
);
40 ++has_work_call_count_
;
43 void SequencedWorkerPoolOwner::WillWaitForShutdown() {
44 if (!will_wait_for_shutdown_callback_
.is_null()) {
45 will_wait_for_shutdown_callback_
.Run();
49 void SequencedWorkerPoolOwner::OnDestruct() {
50 constructor_message_loop_
->PostTask(
52 constructor_message_loop_
->QuitWhenIdleClosure());