security/sandbox/chromium/base/sequence_checker.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #ifndef BASE_SEQUENCE_CHECKER_H_
michael@0 6 #define BASE_SEQUENCE_CHECKER_H_
michael@0 7
michael@0 8 #include "base/memory/ref_counted.h"
michael@0 9
michael@0 10 // See comments for the similar block in thread_checker.h.
michael@0 11 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
michael@0 12 #define ENABLE_SEQUENCE_CHECKER 1
michael@0 13 #else
michael@0 14 #define ENABLE_SEQUENCE_CHECKER 0
michael@0 15 #endif
michael@0 16
michael@0 17 #if ENABLE_SEQUENCE_CHECKER
michael@0 18 #include "base/sequence_checker_impl.h"
michael@0 19 #endif
michael@0 20
michael@0 21 namespace base {
michael@0 22
michael@0 23 class SequencedTaskRunner;
michael@0 24
michael@0 25 // Do nothing implementation, for use in release mode.
michael@0 26 //
michael@0 27 // Note: You should almost always use the SequenceChecker class to get
michael@0 28 // the right version for your build configuration.
michael@0 29 class SequenceCheckerDoNothing {
michael@0 30 public:
michael@0 31 bool CalledOnValidSequencedThread() const {
michael@0 32 return true;
michael@0 33 }
michael@0 34
michael@0 35 void DetachFromSequence() {}
michael@0 36 };
michael@0 37
michael@0 38 // SequenceChecker is a helper class used to help verify that some
michael@0 39 // methods of a class are called in sequence -- that is, called from
michael@0 40 // the same SequencedTaskRunner. It is a generalization of
michael@0 41 // ThreadChecker; see comments in sequence_checker_impl.h for details.
michael@0 42 //
michael@0 43 // Example:
michael@0 44 // class MyClass {
michael@0 45 // public:
michael@0 46 // void Foo() {
michael@0 47 // DCHECK(sequence_checker_.CalledOnValidSequence());
michael@0 48 // ... (do stuff) ...
michael@0 49 // }
michael@0 50 //
michael@0 51 // private:
michael@0 52 // SequenceChecker sequence_checker_;
michael@0 53 // }
michael@0 54 //
michael@0 55 // In Release mode, CalledOnValidSequence will always return true.
michael@0 56 #if ENABLE_SEQUENCE_CHECKER
michael@0 57 class SequenceChecker : public SequenceCheckerImpl {
michael@0 58 };
michael@0 59 #else
michael@0 60 class SequenceChecker : public SequenceCheckerDoNothing {
michael@0 61 };
michael@0 62 #endif // ENABLE_SEQUENCE_CHECKER
michael@0 63
michael@0 64 #undef ENABLE_SEQUENCE_CHECKER
michael@0 65
michael@0 66 } // namespace base
michael@0 67
michael@0 68 #endif // BASE_SEQUENCE_CHECKER_H_

mercurial