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

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

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
« no previous file with comments | « base/test/launcher/test_launcher.cc ('k') | base/test/sequenced_worker_pool_owner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef BASE_TEST_SEQUENCED_WORKER_POOL_OWNER_H_ 5 #ifndef BASE_TEST_SEQUENCED_WORKER_POOL_OWNER_H_
6 #define BASE_TEST_SEQUENCED_WORKER_POOL_OWNER_H_ 6 #define BASE_TEST_SEQUENCED_WORKER_POOL_OWNER_H_
7 7
8 #include <cstddef> 8 #include <cstddef>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/run_loop.h"
15 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
16 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
17 18
18 namespace base { 19 namespace base {
19 20
20 class MessageLoop; 21 class MessageLoop;
21 22
22 // Wrapper around SequencedWorkerPool for testing that blocks destruction 23 // Wrapper around SequencedWorkerPool for testing that blocks destruction
23 // until the pool is actually destroyed. This is so that a 24 // until the pool is actually destroyed. This is so that a
24 // SequencedWorkerPool from one test doesn't outlive its test and cause 25 // SequencedWorkerPool from one test doesn't outlive its test and cause
25 // strange races with other tests that touch global stuff (like histograms and 26 // strange races with other tests that touch global stuff (like histograms and
26 // logging). However, this requires that nothing else on this thread holds a 27 // logging). However, this requires that nothing else on this thread holds a
27 // ref to the pool when the SequencedWorkerPoolOwner is destroyed. 28 // ref to the pool when the SequencedWorkerPoolOwner is destroyed.
29 //
30 // This class calls Shutdown on the owned SequencedWorkerPool in the destructor.
31 // Tests may themselves call Shutdown earlier to test shutdown behavior.
28 class SequencedWorkerPoolOwner : public SequencedWorkerPool::TestingObserver { 32 class SequencedWorkerPoolOwner : public SequencedWorkerPool::TestingObserver {
29 public: 33 public:
30 SequencedWorkerPoolOwner(size_t max_threads, 34 SequencedWorkerPoolOwner(size_t max_threads,
31 const std::string& thread_name_prefix); 35 const std::string& thread_name_prefix);
32 36
33 ~SequencedWorkerPoolOwner() override; 37 ~SequencedWorkerPoolOwner() override;
34 38
35 // Don't change the returned pool's testing observer. 39 // Don't change the returned pool's testing observer.
36 const scoped_refptr<SequencedWorkerPool>& pool(); 40 const scoped_refptr<SequencedWorkerPool>& pool();
37 41
38 // The given callback will be called on WillWaitForShutdown(). 42 // The given callback will be called on WillWaitForShutdown().
39 void SetWillWaitForShutdownCallback(const Closure& callback); 43 void SetWillWaitForShutdownCallback(const Closure& callback);
40 44
41 int has_work_call_count() const; 45 int has_work_call_count() const;
42 46
43 private: 47 private:
44 // SequencedWorkerPool::TestingObserver implementation. 48 // SequencedWorkerPool::TestingObserver implementation.
45 void OnHasWork() override; 49 void OnHasWork() override;
46 void WillWaitForShutdown() override; 50 void WillWaitForShutdown() override;
47 void OnDestruct() override; 51 void OnDestruct() override;
48 52
53 // Used to run the current thread's message loop until the
54 // SequencedWorkerPool's destruction has been verified.
55 base::RunLoop exit_loop_;
49 MessageLoop* const constructor_message_loop_; 56 MessageLoop* const constructor_message_loop_;
57
50 scoped_refptr<SequencedWorkerPool> pool_; 58 scoped_refptr<SequencedWorkerPool> pool_;
51 Closure will_wait_for_shutdown_callback_; 59 Closure will_wait_for_shutdown_callback_;
52 60
53 mutable Lock has_work_lock_; 61 mutable Lock has_work_lock_;
54 int has_work_call_count_; 62 int has_work_call_count_;
55 63
56 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPoolOwner); 64 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPoolOwner);
57 }; 65 };
58 66
59 } // namespace base 67 } // namespace base
60 68
61 #endif // BASE_TEST_SEQUENCED_WORKER_POOL_OWNER_H_ 69 #endif // BASE_TEST_SEQUENCED_WORKER_POOL_OWNER_H_
OLDNEW
« no previous file with comments | « base/test/launcher/test_launcher.cc ('k') | base/test/sequenced_worker_pool_owner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698