OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
vandebo (ex-Chrome)
2013/06/28 21:00:06
nit: current policy is to not update copyright not
tommycli
2013/06/28 22:37:07
Done.
| |
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. |
11 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) | 11 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) |
(...skipping 12 matching lines...) Expand all Loading... | |
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 CalledOnValidSequence() const { | 31 bool CalledOnValidSequence() const { |
32 return true; | 32 return true; |
33 } | 33 } |
34 | |
35 void ChangeSequence( | |
36 const scoped_refptr<SequencedTaskRunner>& sequenced_task_runner) {} | |
37 }; | 34 }; |
38 | 35 |
vandebo (ex-Chrome)
2013/06/28 21:00:06
DetachFromSequence() missing?
tommycli
2013/06/28 22:37:07
Done.
| |
39 // SequenceChecker is a helper class used to help verify that some | 36 // SequenceChecker is a helper class used to help verify that some |
40 // methods of a class are called in sequence -- that is, called from | 37 // methods of a class are called in sequence -- that is, called from |
41 // the same SequencedTaskRunner. It is a generalization of | 38 // the same SequencedTaskRunner. It is a generalization of |
42 // ThreadChecker; see comments in sequence_checker_impl.h for details. | 39 // ThreadChecker; see comments in sequence_checker_impl.h for details. |
43 // | 40 // |
44 // Example: | 41 // Example: |
45 // class MyClass { | 42 // class MyClass { |
46 // public: | 43 // public: |
47 // explicit MyClass( | |
48 // const scoped_refptr<SequencedTaskRunner>& sequenced_task_runner) | |
49 // : sequence_checker_(sequenced_task_runner) {} | |
50 // | |
51 // void Foo() { | 44 // void Foo() { |
52 // DCHECK(sequence_checker_.CalledOnValidSequence()); | 45 // DCHECK(sequence_checker_.CalledOnValidSequence()); |
53 // ... (do stuff) ... | 46 // ... (do stuff) ... |
54 // } | 47 // } |
55 // | 48 // |
56 // private: | 49 // private: |
57 // SequenceChecker sequence_checker_; | 50 // SequenceChecker sequence_checker_; |
58 // } | 51 // } |
59 // | 52 // |
60 // In Release mode, CalledOnValidSequence will always return true. | 53 // In Release mode, CalledOnValidSequence will always return true. |
61 #if ENABLE_SEQUENCE_CHECKER | 54 #if ENABLE_SEQUENCE_CHECKER |
62 class SequenceChecker : public SequenceCheckerImpl { | 55 class SequenceChecker : public SequenceCheckerImpl { |
63 public: | |
64 explicit SequenceChecker( | |
65 const scoped_refptr<SequencedTaskRunner>& sequenced_task_runner) | |
66 : SequenceCheckerImpl(sequenced_task_runner) {} | |
67 }; | 56 }; |
68 #else | 57 #else |
69 class SequenceChecker : public SequenceCheckerDoNothing { | 58 class SequenceChecker : public SequenceCheckerDoNothing { |
70 public: | |
71 explicit SequenceChecker( | |
72 const scoped_refptr<SequencedTaskRunner>& sequenced_task_runner) {} | |
73 }; | 59 }; |
74 #endif // ENABLE_SEQUENCE_CHECKER | 60 #endif // ENABLE_SEQUENCE_CHECKER |
75 | 61 |
76 #undef ENABLE_SEQUENCE_CHECKER | 62 #undef ENABLE_SEQUENCE_CHECKER |
77 | 63 |
78 } // namespace base | 64 } // namespace base |
79 | 65 |
80 #endif // BASE_SEQUENCE_CHECKER_H_ | 66 #endif // BASE_SEQUENCE_CHECKER_H_ |
OLD | NEW |