michael@0: // Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_SEQUENCE_CHECKER_H_ michael@0: #define BASE_SEQUENCE_CHECKER_H_ michael@0: michael@0: #include "base/memory/ref_counted.h" michael@0: michael@0: // See comments for the similar block in thread_checker.h. michael@0: #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) michael@0: #define ENABLE_SEQUENCE_CHECKER 1 michael@0: #else michael@0: #define ENABLE_SEQUENCE_CHECKER 0 michael@0: #endif michael@0: michael@0: #if ENABLE_SEQUENCE_CHECKER michael@0: #include "base/sequence_checker_impl.h" michael@0: #endif michael@0: michael@0: namespace base { michael@0: michael@0: class SequencedTaskRunner; michael@0: michael@0: // Do nothing implementation, for use in release mode. michael@0: // michael@0: // Note: You should almost always use the SequenceChecker class to get michael@0: // the right version for your build configuration. michael@0: class SequenceCheckerDoNothing { michael@0: public: michael@0: bool CalledOnValidSequencedThread() const { michael@0: return true; michael@0: } michael@0: michael@0: void DetachFromSequence() {} michael@0: }; michael@0: michael@0: // SequenceChecker is a helper class used to help verify that some michael@0: // methods of a class are called in sequence -- that is, called from michael@0: // the same SequencedTaskRunner. It is a generalization of michael@0: // ThreadChecker; see comments in sequence_checker_impl.h for details. michael@0: // michael@0: // Example: michael@0: // class MyClass { michael@0: // public: michael@0: // void Foo() { michael@0: // DCHECK(sequence_checker_.CalledOnValidSequence()); michael@0: // ... (do stuff) ... michael@0: // } michael@0: // michael@0: // private: michael@0: // SequenceChecker sequence_checker_; michael@0: // } michael@0: // michael@0: // In Release mode, CalledOnValidSequence will always return true. michael@0: #if ENABLE_SEQUENCE_CHECKER michael@0: class SequenceChecker : public SequenceCheckerImpl { michael@0: }; michael@0: #else michael@0: class SequenceChecker : public SequenceCheckerDoNothing { michael@0: }; michael@0: #endif // ENABLE_SEQUENCE_CHECKER michael@0: michael@0: #undef ENABLE_SEQUENCE_CHECKER michael@0: michael@0: } // namespace base michael@0: michael@0: #endif // BASE_SEQUENCE_CHECKER_H_