1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/chromium/base/sequence_checker_impl.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 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_IMPL_H_ 1.9 +#define BASE_SEQUENCE_CHECKER_IMPL_H_ 1.10 + 1.11 +#include "base/base_export.h" 1.12 +#include "base/basictypes.h" 1.13 +#include "base/synchronization/lock.h" 1.14 +#include "base/threading/sequenced_worker_pool.h" 1.15 +#include "base/threading/thread_checker_impl.h" 1.16 + 1.17 +namespace base { 1.18 + 1.19 +// SequenceCheckerImpl is used to help verify that some methods of a 1.20 +// class are called in sequence -- that is, called from the same 1.21 +// SequencedTaskRunner. It is a generalization of ThreadChecker; in 1.22 +// particular, it behaves exactly like ThreadChecker if constructed 1.23 +// on a thread that is not part of a SequencedWorkerPool. 1.24 +class BASE_EXPORT SequenceCheckerImpl { 1.25 + public: 1.26 + SequenceCheckerImpl(); 1.27 + ~SequenceCheckerImpl(); 1.28 + 1.29 + // Returns whether the we are being called on the same sequence token 1.30 + // as previous calls. If there is no associated sequence, then returns 1.31 + // whether we are being called on the underlying ThreadChecker's thread. 1.32 + bool CalledOnValidSequencedThread() const; 1.33 + 1.34 + // Unbinds the checker from the currently associated sequence. The 1.35 + // checker will be re-bound on the next call to CalledOnValidSequence(). 1.36 + void DetachFromSequence(); 1.37 + 1.38 + private: 1.39 + void EnsureSequenceTokenAssigned() const; 1.40 + 1.41 + // Guards all variables below. 1.42 + mutable Lock lock_; 1.43 + 1.44 + // Used if |sequence_token_| is not valid. 1.45 + ThreadCheckerImpl thread_checker_; 1.46 + mutable bool sequence_token_assigned_; 1.47 + 1.48 + mutable SequencedWorkerPool::SequenceToken sequence_token_; 1.49 + 1.50 + DISALLOW_COPY_AND_ASSIGN(SequenceCheckerImpl); 1.51 +}; 1.52 + 1.53 +} // namespace base 1.54 + 1.55 +#endif // BASE_SEQUENCE_CHECKER_IMPL_H_