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

Side by Side Diff: base/test/sequenced_worker_pool_owner.cc

Issue 1417353006: Tests: Simplify SequencedWorkerPoolOwner, call Shutdown on destructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adjust formatting and rebase Created 5 years 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/test/sequenced_worker_pool_owner.h" 5 #include "base/test/sequenced_worker_pool_owner.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 10
11 namespace base { 11 namespace base {
12 12
13 SequencedWorkerPoolOwner::SequencedWorkerPoolOwner( 13 SequencedWorkerPoolOwner::SequencedWorkerPoolOwner(
14 size_t max_threads, 14 size_t max_threads,
15 const std::string& thread_name_prefix) 15 const std::string& thread_name_prefix)
16 : constructor_message_loop_(MessageLoop::current()), 16 : constructor_message_loop_(MessageLoop::current()),
17 pool_(new SequencedWorkerPool(max_threads, thread_name_prefix, this)), 17 pool_(new SequencedWorkerPool(max_threads, thread_name_prefix, this)),
18 has_work_call_count_(0) {} 18 has_work_call_count_(0) {}
19 19
20 SequencedWorkerPoolOwner::~SequencedWorkerPoolOwner() { 20 SequencedWorkerPoolOwner::~SequencedWorkerPoolOwner() {
21 pool_->Shutdown();
21 pool_ = NULL; 22 pool_ = NULL;
22 MessageLoop::current()->Run(); 23
24 // Spin the current message loop until SWP destruction verified in OnDestruct.
25 exit_loop_.Run();
23 } 26 }
24 27
25 const scoped_refptr<SequencedWorkerPool>& SequencedWorkerPoolOwner::pool() { 28 const scoped_refptr<SequencedWorkerPool>& SequencedWorkerPoolOwner::pool() {
26 return pool_; 29 return pool_;
27 } 30 }
28 31
29 void SequencedWorkerPoolOwner::SetWillWaitForShutdownCallback( 32 void SequencedWorkerPoolOwner::SetWillWaitForShutdownCallback(
30 const Closure& callback) { 33 const Closure& callback) {
31 will_wait_for_shutdown_callback_ = callback; 34 will_wait_for_shutdown_callback_ = callback;
32 } 35 }
(...skipping 11 matching lines...) Expand all
44 void SequencedWorkerPoolOwner::WillWaitForShutdown() { 47 void SequencedWorkerPoolOwner::WillWaitForShutdown() {
45 if (!will_wait_for_shutdown_callback_.is_null()) { 48 if (!will_wait_for_shutdown_callback_.is_null()) {
46 will_wait_for_shutdown_callback_.Run(); 49 will_wait_for_shutdown_callback_.Run();
47 50
48 // Release the reference to the callback to prevent retain cycles. 51 // Release the reference to the callback to prevent retain cycles.
49 will_wait_for_shutdown_callback_ = Closure(); 52 will_wait_for_shutdown_callback_ = Closure();
50 } 53 }
51 } 54 }
52 55
53 void SequencedWorkerPoolOwner::OnDestruct() { 56 void SequencedWorkerPoolOwner::OnDestruct() {
54 constructor_message_loop_->task_runner()->PostTask( 57 constructor_message_loop_->PostTask(FROM_HERE, exit_loop_.QuitClosure());
55 FROM_HERE, constructor_message_loop_->QuitWhenIdleClosure());
56 } 58 }
57 59
58 } // namespace base 60 } // namespace base
OLDNEW
« no previous file with comments | « base/test/sequenced_worker_pool_owner.h ('k') | base/threading/sequenced_task_runner_handle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698