1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/chromium/base/sequence_checker.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef BASE_SEQUENCE_CHECKER_H_ 1.9 +#define BASE_SEQUENCE_CHECKER_H_ 1.10 + 1.11 +#include "base/memory/ref_counted.h" 1.12 + 1.13 +// See comments for the similar block in thread_checker.h. 1.14 +#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) 1.15 +#define ENABLE_SEQUENCE_CHECKER 1 1.16 +#else 1.17 +#define ENABLE_SEQUENCE_CHECKER 0 1.18 +#endif 1.19 + 1.20 +#if ENABLE_SEQUENCE_CHECKER 1.21 +#include "base/sequence_checker_impl.h" 1.22 +#endif 1.23 + 1.24 +namespace base { 1.25 + 1.26 +class SequencedTaskRunner; 1.27 + 1.28 +// Do nothing implementation, for use in release mode. 1.29 +// 1.30 +// Note: You should almost always use the SequenceChecker class to get 1.31 +// the right version for your build configuration. 1.32 +class SequenceCheckerDoNothing { 1.33 + public: 1.34 + bool CalledOnValidSequencedThread() const { 1.35 + return true; 1.36 + } 1.37 + 1.38 + void DetachFromSequence() {} 1.39 +}; 1.40 + 1.41 +// SequenceChecker is a helper class used to help verify that some 1.42 +// methods of a class are called in sequence -- that is, called from 1.43 +// the same SequencedTaskRunner. It is a generalization of 1.44 +// ThreadChecker; see comments in sequence_checker_impl.h for details. 1.45 +// 1.46 +// Example: 1.47 +// class MyClass { 1.48 +// public: 1.49 +// void Foo() { 1.50 +// DCHECK(sequence_checker_.CalledOnValidSequence()); 1.51 +// ... (do stuff) ... 1.52 +// } 1.53 +// 1.54 +// private: 1.55 +// SequenceChecker sequence_checker_; 1.56 +// } 1.57 +// 1.58 +// In Release mode, CalledOnValidSequence will always return true. 1.59 +#if ENABLE_SEQUENCE_CHECKER 1.60 +class SequenceChecker : public SequenceCheckerImpl { 1.61 +}; 1.62 +#else 1.63 +class SequenceChecker : public SequenceCheckerDoNothing { 1.64 +}; 1.65 +#endif // ENABLE_SEQUENCE_CHECKER 1.66 + 1.67 +#undef ENABLE_SEQUENCE_CHECKER 1.68 + 1.69 +} // namespace base 1.70 + 1.71 +#endif // BASE_SEQUENCE_CHECKER_H_