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"
9 #include "base/single_thread_task_runner.h"
13 SequencedWorkerPoolOwner::SequencedWorkerPoolOwner(
15 const std::string
& thread_name_prefix
)
16 : constructor_message_loop_(MessageLoop::current()),
17 pool_(new SequencedWorkerPool(max_threads
, thread_name_prefix
, this)),
18 has_work_call_count_(0) {}
20 SequencedWorkerPoolOwner::~SequencedWorkerPoolOwner() {
22 MessageLoop::current()->Run();
25 const scoped_refptr
<SequencedWorkerPool
>& SequencedWorkerPoolOwner::pool() {
29 void SequencedWorkerPoolOwner::SetWillWaitForShutdownCallback(
30 const Closure
& callback
) {
31 will_wait_for_shutdown_callback_
= callback
;
34 int SequencedWorkerPoolOwner::has_work_call_count() const {
35 AutoLock
lock(has_work_lock_
);
36 return has_work_call_count_
;
39 void SequencedWorkerPoolOwner::OnHasWork() {
40 AutoLock
lock(has_work_lock_
);
41 ++has_work_call_count_
;
44 void SequencedWorkerPoolOwner::WillWaitForShutdown() {
45 if (!will_wait_for_shutdown_callback_
.is_null()) {
46 will_wait_for_shutdown_callback_
.Run();
48 // Release the reference to the callback to prevent retain cycles.
49 will_wait_for_shutdown_callback_
= Closure();
53 void SequencedWorkerPoolOwner::OnDestruct() {
54 constructor_message_loop_
->task_runner()->PostTask(
55 FROM_HERE
, constructor_message_loop_
->QuitWhenIdleClosure());