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 #ifndef BASE_SEQUENCE_CHECKER_H_
6 #define BASE_SEQUENCE_CHECKER_H_
8 #include "base/memory/ref_counted.h"
10 // See comments for the similar block in thread_checker.h.
11 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
12 #define ENABLE_SEQUENCE_CHECKER 1
14 #define ENABLE_SEQUENCE_CHECKER 0
17 #if ENABLE_SEQUENCE_CHECKER
18 #include "base/sequence_checker_impl.h"
23 class SequencedTaskRunner
;
25 // Do nothing implementation, for use in release mode.
27 // Note: You should almost always use the SequenceChecker class to get
28 // the right version for your build configuration.
29 class SequenceCheckerDoNothing
{
31 bool CalledOnValidSequence() const {
36 const scoped_refptr
<SequencedTaskRunner
>& sequenced_task_runner
) {}
39 // SequenceChecker is a helper class used to help verify that some
40 // methods of a class are called in sequence -- that is, called from
41 // the same SequencedTaskRunner. It is a generalization of
42 // ThreadChecker; see comments in sequence_checker_impl.h for details.
48 // const scoped_refptr<SequencedTaskRunner>& sequenced_task_runner)
49 // : sequence_checker_(sequenced_task_runner) {}
52 // DCHECK(sequence_checker_.CalledOnValidSequence());
57 // SequenceChecker sequence_checker_;
60 // In Release mode, CalledOnValidSequence will always return true.
61 #if ENABLE_SEQUENCE_CHECKER
62 class SequenceChecker
: public SequenceCheckerImpl
{
64 explicit SequenceChecker(
65 const scoped_refptr
<SequencedTaskRunner
>& sequenced_task_runner
)
66 : SequenceCheckerImpl(sequenced_task_runner
) {}
69 class SequenceChecker
: public SequenceCheckerDoNothing
{
71 explicit SequenceChecker(
72 const scoped_refptr
<SequencedTaskRunner
>& sequenced_task_runner
) {}
74 #endif // ENABLE_SEQUENCE_CHECKER
76 #undef ENABLE_SEQUENCE_CHECKER
80 #endif // BASE_SEQUENCE_CHECKER_H_