| Index: base/trace_event/blame_context.h
|
| diff --git a/base/trace_event/blame_context.h b/base/trace_event/blame_context.h
|
| index 81c35afc8b932e0533874dbf43beae418817e6d2..9ec62c5078984d434a5b9e321ea9261f65bb951c 100644
|
| --- a/base/trace_event/blame_context.h
|
| +++ b/base/trace_event/blame_context.h
|
| @@ -9,6 +9,7 @@
|
|
|
| #include "base/base_export.h"
|
| #include "base/macros.h"
|
| +#include "base/threading/thread_checker.h"
|
| #include "base/trace_event/trace_log.h"
|
|
|
| namespace base {
|
| @@ -32,6 +33,19 @@ namespace trace_event {
|
| // page instead looking at each <iframe> individually. In this case the work
|
| // should be attributed to a blame context which is the parent of all <iframe>
|
| // blame contexts.
|
| +//
|
| +//
|
| +// *** THREAD SAFETY ***
|
| +//
|
| +// All member functions of BlameContext, except those marked with "ThreadSafe",
|
| +// must be called from the same thread where the instance is constructed.
|
| +//
|
| +// Any subclass overriding OnTraceLogEnabled()/Disabled() must perform thread
|
| +// checking and make sure that any call to a other non-ThreadSafe function from
|
| +// a different thread is done as a task posted to task_runner().
|
| +//
|
| +// Any subclass must call UnregisterFromTraceLog() at the beginning of its dtor
|
| +// to prevent access from the TraceLog when the instance is being destructed.
|
| class BASE_EXPORT BlameContext
|
| : public trace_event::TraceLog::EnabledStateObserver {
|
| public:
|
| @@ -94,6 +108,7 @@ class BASE_EXPORT BlameContext
|
| const char* scope() const { return scope_; }
|
| int64_t id() const { return id_; }
|
|
|
| + // ThreadSafe
|
| // trace_event::TraceLog::EnabledStateObserver implementation:
|
| void OnTraceLogEnabled() override;
|
| void OnTraceLogDisabled() override;
|
| @@ -105,6 +120,16 @@ class BASE_EXPORT BlameContext
|
| // call this base method.
|
| virtual void AsValueInto(trace_event::TracedValue* state);
|
|
|
| + // NOTE: Call this function at the beginning of any subclass's destructor to
|
| + // prevent access from the TraceLog when the instance is being destructed.
|
| + void UnregisterFromTraceLog();
|
| +
|
| + // ThreadSafe
|
| + // Allow subclasses to access task runner and weak pointers so that they can
|
| + // override OnTraceLogEnabled()/Disabled() without breaking thread safety.
|
| + SingleThreadTaskRunner* task_runner() { return task_runner_.get(); }
|
| + WeakPtr<BlameContext> get_weak() { return weak_factory_.GetWeakPtr(); }
|
| +
|
| private:
|
| bool WasInitialized() const;
|
|
|
| @@ -120,6 +145,13 @@ class BASE_EXPORT BlameContext
|
|
|
| const unsigned char* category_group_enabled_;
|
|
|
| + // Indicator of whether the instance is registered at the TraceLog.
|
| + bool registered_;
|
| +
|
| + ThreadChecker thread_checker_;
|
| + scoped_refptr<SingleThreadTaskRunner> task_runner_;
|
| + WeakPtrFactory<BlameContext> weak_factory_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(BlameContext);
|
| };
|
|
|
|
|