Chromium Code Reviews| Index: base/sequence_and_task_token.h |
| diff --git a/base/sequence_token.h b/base/sequence_and_task_token.h |
| similarity index 40% |
| rename from base/sequence_token.h |
| rename to base/sequence_and_task_token.h |
| index 8d1398ea3c592f082cddcc607733795382b4f028..aba22c669eab2ec29670b295cf87c2ff9f551d52 100644 |
| --- a/base/sequence_token.h |
| +++ b/base/sequence_and_task_token.h |
| @@ -2,8 +2,8 @@ |
| // 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_ |
| +#ifndef BASE_SEQUENCE_AND_TASK_TOKEN_H_ |
|
gab
2016/08/08 16:34:22
Since TaskToken is more-or-less an implementation
fdoray
2016/08/08 17:45:18
Done.
|
| +#define BASE_SEQUENCE_AND_TASK_TOKEN_H_ |
| #include "base/base_export.h" |
| #include "base/macros.h" |
| @@ -34,8 +34,8 @@ class BASE_EXPORT SequenceToken { |
| static SequenceToken Create(); |
| // Returns the SequenceToken associated with the task running on the current |
| - // thread, as determined by the active ScopedSetSequenceTokenForCurrentThread |
| - // if any. |
| + // thread, as determined by the active |
| + // ScopedSetSequenceAndTaskTokenForCurrentThread if any. |
| static SequenceToken GetForCurrentThread(); |
| private: |
| @@ -45,21 +45,64 @@ class BASE_EXPORT SequenceToken { |
| int token_ = kInvalidSequenceToken; |
| }; |
| -// Throughout its lifetime, determines the value returned by |
| -// SequenceToken::GetForCurrentThread(). |
| -class BASE_EXPORT ScopedSetSequenceTokenForCurrentThread { |
| +// A token that identifies a task. |
|
gab
2016/08/08 16:34:22
Expand comment to explain why this is necessary.
fdoray
2016/08/08 17:45:18
Done.
|
| +class BASE_EXPORT TaskToken { |
| public: |
| - ScopedSetSequenceTokenForCurrentThread(const SequenceToken& token); |
| - ~ScopedSetSequenceTokenForCurrentThread(); |
| + // Instantiates an invalid TaskToken. |
| + TaskToken() = default; |
| + |
| + // Explicitly allow copy. |
| + TaskToken(const TaskToken& other) = default; |
| + TaskToken& operator=(const TaskToken& other) = default; |
| + |
| + // An invalid TaskToken is not equal to any other TaskToken, including |
| + // other invalid TaskTokens. |
| + bool operator==(const TaskToken& other) const; |
| + bool operator!=(const TaskToken& other) const; |
| + |
| + // Returns true if this is a valid TaskToken. |
| + bool IsValid() const; |
| + |
| + // Returns the TaskToken associated with the task running on the current |
| + // thread, as determined by the active |
| + // ScopedSetSequenceAndTaskTokenForCurrentThread if any. |
| + static TaskToken GetForCurrentThread(); |
| + |
| + private: |
| + friend class ScopedSetSequenceAndTaskTokenForCurrentThread; |
| + |
| + TaskToken(int token) : token_(token) {} |
|
gab
2016/08/08 16:34:22
Comment explaining why this is private (and also j
fdoray
2016/08/08 17:45:18
Done.
|
| + |
| + // Returns a valid TaskToken which isn't equal to any previously returned |
| + // TaskToken. |
| + static TaskToken Create(); |
| + |
| + static constexpr int kInvalidTaskToken = -1; |
| + int token_ = kInvalidTaskToken; |
| +}; |
| + |
| +// Instantiate this in the scope where a single task runs. |
| +class BASE_EXPORT ScopedSetSequenceAndTaskTokenForCurrentThread { |
| + public: |
| + // Throughout the lifetime of the constructed object, |
| + // SequenceToken::GetForCurrentThread() will return |sequence_token| and |
| + // TaskToken::GetForCurrentThread() will return a TaskToken which is not equal |
| + // to any TaskToken returned in the scope of another |
| + // ScopedSetSequenceAndTaskTokenForCurrentThread. |
| + ScopedSetSequenceAndTaskTokenForCurrentThread( |
| + const SequenceToken& sequence_token); |
| + ~ScopedSetSequenceAndTaskTokenForCurrentThread(); |
| private: |
| friend class SequenceToken; |
| + friend class TaskToken; |
|
gab
2016/08/08 16:34:22
Cyclic-friending is weird, why is this needed?
fdoray
2016/08/08 17:45:18
ScopedSetSequenceTokenForCurrentThread needs to be
|
| - const SequenceToken token_; |
| + const SequenceToken sequence_token_; |
| + const TaskToken task_token_; |
| - DISALLOW_COPY_AND_ASSIGN(ScopedSetSequenceTokenForCurrentThread); |
| + DISALLOW_COPY_AND_ASSIGN(ScopedSetSequenceAndTaskTokenForCurrentThread); |
| }; |
| } // namespace base |
| -#endif // BASE_SEQUENCE_TOKEN_H_ |
| +#endif // BASE_SEQUENCE_AND_TASK_TOKEN_H_ |