Index: base/sequence_token.h |
diff --git a/base/sequence_token.h b/base/sequence_token.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d023ae68ca84f9489573b737e6ffb8333d1bc3ac |
--- /dev/null |
+++ b/base/sequence_token.h |
@@ -0,0 +1,64 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef BASE_SEQUENCE_TOKEN_H_ |
+#define BASE_SEQUENCE_TOKEN_H_ |
+ |
+#include "base/base_export.h" |
+#include "base/macros.h" |
+ |
+namespace base { |
+namespace internal { |
gab
2016/07/21 21:14:24
I think internal:: should be reserved for implemen
fdoray
2016/07/25 13:24:28
Done.
|
+ |
+// A token that identifies a series of sequenced tasks (i.e. tasks that run one |
+// at a time in posting order). |
+class BASE_EXPORT SequenceToken { |
+ public: |
+ // Instantiates an invalid SequenceToken. |
+ SequenceToken() = default; |
+ |
+ // Explicitly allow copy. |
+ SequenceToken(const SequenceToken& other) = default; |
+ SequenceToken& operator=(const SequenceToken& other) = default; |
+ |
+ bool operator==(const SequenceToken& other) const; |
+ bool operator!=(const SequenceToken& other) const; |
+ |
+ // Returns true if this is a valid SequenceToken. |
+ bool IsValid() const; |
+ |
+ // Returns a valid SequenceToken which isn't equal to any previously returned |
+ // SequenceToken. |
+ static SequenceToken Create(); |
+ |
+ // Returns the SequenceToken associated with the task running on the current |
+ // thread, as determined by the active ScopedSetCurrentSequenceToken if any. |
+ static SequenceToken GetCurrent(); |
+ |
+ private: |
+ SequenceToken(int token) : token_(token) {} |
+ |
+ static constexpr int kInvalidSequenceToken = -1; |
+ int token_ = kInvalidSequenceToken; |
+}; |
+ |
+// Throughout its lifetime, determines the value returned by |
+// SequenceToken::GetCurrent(). |
+class BASE_EXPORT ScopedSetCurrentSequenceToken { |
+ public: |
+ ScopedSetCurrentSequenceToken(const SequenceToken& token); |
+ ~ScopedSetCurrentSequenceToken(); |
+ |
+ private: |
+ friend class SequenceToken; |
+ |
+ const SequenceToken token_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ScopedSetCurrentSequenceToken); |
+}; |
+ |
+} // namespace internal |
+} // namespace base |
+ |
+#endif // BASE_SEQUENCE_TOKEN_H_ |