Chromium Code Reviews| Index: base/pending_task.cc |
| diff --git a/base/pending_task.cc b/base/pending_task.cc |
| index 73834bd46071ab61c0f902b599497a72a494c35c..a7938fcf16d1c46fb3a95cfd4ce894dd4f28f102 100644 |
| --- a/base/pending_task.cc |
| +++ b/base/pending_task.cc |
| @@ -4,10 +4,38 @@ |
| #include "base/pending_task.h" |
| +#include "base/json/json_writer.h" |
| +#include "base/logging.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "base/trace_event/trace_event.h" |
| #include "base/tracked_objects.h" |
| +#include "base/values.h" |
| namespace base { |
| +PendingTask::TracingInfo::TracingInfo( |
| + const tracked_objects::Location& posted_from) |
| + : posted_from_(posted_from) { |
| +#if DCHECK_IS_ON() |
| + // TracingInfo should only be obtained when tracing is enabled or it will |
| + // generate unnecessary copies. |
| + bool tracing_enabled; |
|
caseq
2016/09/29 22:46:36
considering this is hot code, you really want to k
gab
2016/10/03 15:18:57
This is only hot code if both (1) dchecks are enab
|
| + TRACE_EVENT_CATEGORY_GROUP_ENABLED("toplevel", &tracing_enabled); |
| + DCHECK(tracing_enabled); |
| +#endif // DCHECK_IS_ON() |
| +} |
| + |
| +PendingTask::TracingInfo::~TracingInfo() = default; |
| + |
| +void PendingTask::TracingInfo::AppendAsTraceFormat(std::string* out) const { |
| + DictionaryValue dict; |
| + dict.SetString("src_file", posted_from_.file_name()); |
| + dict.SetString("src_func", posted_from_.function_name()); |
| + std::string tmp; |
| + JSONWriter::Write(dict, &tmp); |
| + out->append(tmp); |
| +} |
| + |
| PendingTask::PendingTask(const tracked_objects::Location& posted_from, |
| base::Closure task) |
| : base::TrackingInfo(posted_from, TimeTicks()), |
| @@ -32,8 +60,7 @@ PendingTask::PendingTask(const tracked_objects::Location& posted_from, |
| PendingTask::PendingTask(PendingTask&& other) = default; |
| -PendingTask::~PendingTask() { |
| -} |
| +PendingTask::~PendingTask() = default; |
| PendingTask& PendingTask::operator=(PendingTask&& other) = default; |
| @@ -53,4 +80,9 @@ bool PendingTask::operator<(const PendingTask& other) const { |
| return (sequence_num - other.sequence_num) > 0; |
| } |
| +std::unique_ptr<trace_event::ConvertableToTraceFormat> |
| +PendingTask::GetTracingInfo() const { |
| + return MakeUnique<TracingInfo>(posted_from); |
| +} |
| + |
| } // namespace base |