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_IMPL_H_ michael@0: #define BASE_SEQUENCE_CHECKER_IMPL_H_ michael@0: michael@0: #include "base/base_export.h" michael@0: #include "base/basictypes.h" michael@0: #include "base/synchronization/lock.h" michael@0: #include "base/threading/sequenced_worker_pool.h" michael@0: #include "base/threading/thread_checker_impl.h" michael@0: michael@0: namespace base { michael@0: michael@0: // SequenceCheckerImpl is used to help verify that some methods of a michael@0: // class are called in sequence -- that is, called from the same michael@0: // SequencedTaskRunner. It is a generalization of ThreadChecker; in michael@0: // particular, it behaves exactly like ThreadChecker if constructed michael@0: // on a thread that is not part of a SequencedWorkerPool. michael@0: class BASE_EXPORT SequenceCheckerImpl { michael@0: public: michael@0: SequenceCheckerImpl(); michael@0: ~SequenceCheckerImpl(); michael@0: michael@0: // Returns whether the we are being called on the same sequence token michael@0: // as previous calls. If there is no associated sequence, then returns michael@0: // whether we are being called on the underlying ThreadChecker's thread. michael@0: bool CalledOnValidSequencedThread() const; michael@0: michael@0: // Unbinds the checker from the currently associated sequence. The michael@0: // checker will be re-bound on the next call to CalledOnValidSequence(). michael@0: void DetachFromSequence(); michael@0: michael@0: private: michael@0: void EnsureSequenceTokenAssigned() const; michael@0: michael@0: // Guards all variables below. michael@0: mutable Lock lock_; michael@0: michael@0: // Used if |sequence_token_| is not valid. michael@0: ThreadCheckerImpl thread_checker_; michael@0: mutable bool sequence_token_assigned_; michael@0: michael@0: mutable SequencedWorkerPool::SequenceToken sequence_token_; michael@0: michael@0: DISALLOW_COPY_AND_ASSIGN(SequenceCheckerImpl); michael@0: }; michael@0: michael@0: } // namespace base michael@0: michael@0: #endif // BASE_SEQUENCE_CHECKER_IMPL_H_