OLD | NEW |
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_SEQUENCE_CHECKER_H_ | 5 #ifndef BASE_SEQUENCE_CHECKER_H_ |
6 #define BASE_SEQUENCE_CHECKER_H_ | 6 #define BASE_SEQUENCE_CHECKER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 | 9 |
10 // See comments for the similar block in thread_checker.h. | 10 // See comments for the similar block in thread_checker.h. |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace base { | 21 namespace base { |
22 | 22 |
23 class SequencedTaskRunner; | 23 class SequencedTaskRunner; |
24 | 24 |
25 // Do nothing implementation, for use in release mode. | 25 // Do nothing implementation, for use in release mode. |
26 // | 26 // |
27 // Note: You should almost always use the SequenceChecker class to get | 27 // Note: You should almost always use the SequenceChecker class to get |
28 // the right version for your build configuration. | 28 // the right version for your build configuration. |
29 class SequenceCheckerDoNothing { | 29 class SequenceCheckerDoNothing { |
30 public: | 30 public: |
31 bool CalledOnValidSequencedThread() const { | 31 bool CalledOnValidSequence() const { |
32 return true; | 32 return true; |
33 } | 33 } |
34 | 34 |
35 void DetachFromSequence() {} | 35 void ChangeSequence( |
| 36 const scoped_refptr<SequencedTaskRunner>& sequenced_task_runner) {} |
36 }; | 37 }; |
37 | 38 |
38 // SequenceChecker is a helper class used to help verify that some | 39 // SequenceChecker is a helper class used to help verify that some |
39 // methods of a class are called in sequence -- that is, called from | 40 // methods of a class are called in sequence -- that is, called from |
40 // the same SequencedTaskRunner. It is a generalization of | 41 // the same SequencedTaskRunner. It is a generalization of |
41 // ThreadChecker; see comments in sequence_checker_impl.h for details. | 42 // ThreadChecker; see comments in sequence_checker_impl.h for details. |
42 // | 43 // |
43 // Example: | 44 // Example: |
44 // class MyClass { | 45 // class MyClass { |
45 // public: | 46 // public: |
| 47 // explicit MyClass( |
| 48 // const scoped_refptr<SequencedTaskRunner>& sequenced_task_runner) |
| 49 // : sequence_checker_(sequenced_task_runner) {} |
| 50 // |
46 // void Foo() { | 51 // void Foo() { |
47 // DCHECK(sequence_checker_.CalledOnValidSequence()); | 52 // DCHECK(sequence_checker_.CalledOnValidSequence()); |
48 // ... (do stuff) ... | 53 // ... (do stuff) ... |
49 // } | 54 // } |
50 // | 55 // |
51 // private: | 56 // private: |
52 // SequenceChecker sequence_checker_; | 57 // SequenceChecker sequence_checker_; |
53 // } | 58 // } |
54 // | 59 // |
55 // In Release mode, CalledOnValidSequence will always return true. | 60 // In Release mode, CalledOnValidSequence will always return true. |
56 #if ENABLE_SEQUENCE_CHECKER | 61 #if ENABLE_SEQUENCE_CHECKER |
57 class SequenceChecker : public SequenceCheckerImpl { | 62 class SequenceChecker : public SequenceCheckerImpl { |
| 63 public: |
| 64 explicit SequenceChecker( |
| 65 const scoped_refptr<SequencedTaskRunner>& sequenced_task_runner) |
| 66 : SequenceCheckerImpl(sequenced_task_runner) {} |
58 }; | 67 }; |
59 #else | 68 #else |
60 class SequenceChecker : public SequenceCheckerDoNothing { | 69 class SequenceChecker : public SequenceCheckerDoNothing { |
| 70 public: |
| 71 explicit SequenceChecker( |
| 72 const scoped_refptr<SequencedTaskRunner>& sequenced_task_runner) {} |
61 }; | 73 }; |
62 #endif // ENABLE_SEQUENCE_CHECKER | 74 #endif // ENABLE_SEQUENCE_CHECKER |
63 | 75 |
64 #undef ENABLE_SEQUENCE_CHECKER | 76 #undef ENABLE_SEQUENCE_CHECKER |
65 | 77 |
66 } // namespace base | 78 } // namespace base |
67 | 79 |
68 #endif // BASE_SEQUENCE_CHECKER_H_ | 80 #endif // BASE_SEQUENCE_CHECKER_H_ |
OLD | NEW |