From ae61aca9b175e9cb5adadf41ab1a7254a57d7afc Mon Sep 17 00:00:00 2001 From: Markus Handell Date: Wed, 1 Mar 2023 13:05:08 +0100 Subject: [PATCH] Implement support for Chrome task origin tracing. #3.7/4 This CL completes migration to the new TaskQueueBase interface permitting location tracing in Chrome. Bug: chromium:1416199 Change-Id: Iff7ff5796752a1520384a3db0135a1d4b9438988 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/294540 Reviewed-by: Harald Alvestrand Commit-Queue: Markus Handell Reviewed-by: Danil Chapovalov Cr-Commit-Position: refs/heads/main@{#39439} --- api/task_queue/task_queue_base.h | 44 +++++++++++++++----------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/api/task_queue/task_queue_base.h b/api/task_queue/task_queue_base.h index 9c4fdd79c1..da7a00d438 100644 --- a/api/task_queue/task_queue_base.h +++ b/api/task_queue/task_queue_base.h @@ -63,10 +63,9 @@ class RTC_LOCKABLE RTC_EXPORT TaskQueueBase { // Note that this guarantee does not apply to delayed tasks. // // May be called on any thread or task queue, including this task queue. - // TODO(crbug.com/1416199): Remove virtual and pass location of the caller - // once subclasses migrated. - virtual void PostTask(absl::AnyInvocable task) { - PostTaskImpl(std::move(task), PostTaskTraits{}, Location::Current()); + void PostTask(absl::AnyInvocable task, + const Location& location = Location::Current()) { + PostTaskImpl(std::move(task), PostTaskTraits{}, location); } // Prefer PostDelayedTask() over PostDelayedHighPrecisionTask() whenever @@ -92,13 +91,12 @@ class RTC_LOCKABLE RTC_EXPORT TaskQueueBase { // https://crbug.com/webrtc/13583 for more information. // // May be called on any thread or task queue, including this task queue. - // TODO(crbug.com/1416199): Remove virtual and pass location of the caller - // once subclasses migrated. - virtual void PostDelayedTask(absl::AnyInvocable task, - TimeDelta delay) { + void PostDelayedTask(absl::AnyInvocable task, + TimeDelta delay, + const Location& location = Location::Current()) { PostDelayedTaskImpl(std::move(task), delay, PostDelayedTaskTraits{.high_precision = false}, - Location::Current()); + location); } // Prefer PostDelayedTask() over PostDelayedHighPrecisionTask() whenever @@ -117,26 +115,28 @@ class RTC_LOCKABLE RTC_EXPORT TaskQueueBase { // battery, when the timer precision can be as poor as 15 ms. // // May be called on any thread or task queue, including this task queue. - // TODO(crbug.com/1416199): Remove virtual and pass location of the caller - // once subclasses migrated. - virtual void PostDelayedHighPrecisionTask(absl::AnyInvocable task, - TimeDelta delay) { + void PostDelayedHighPrecisionTask( + absl::AnyInvocable task, + TimeDelta delay, + const Location& location = Location::Current()) { PostDelayedTaskImpl(std::move(task), delay, PostDelayedTaskTraits{.high_precision = true}, - Location::Current()); + location); } // As specified by `precision`, calls either PostDelayedTask() or // PostDelayedHighPrecisionTask(). - void PostDelayedTaskWithPrecision(DelayPrecision precision, - absl::AnyInvocable task, - TimeDelta delay) { + void PostDelayedTaskWithPrecision( + DelayPrecision precision, + absl::AnyInvocable task, + TimeDelta delay, + const Location& location = Location::Current()) { switch (precision) { case DelayPrecision::kLow: - PostDelayedTask(std::move(task), delay); + PostDelayedTask(std::move(task), delay, location); break; case DelayPrecision::kHigh: - PostDelayedHighPrecisionTask(std::move(task), delay); + PostDelayedHighPrecisionTask(std::move(task), delay, location); break; } } @@ -173,19 +173,17 @@ class RTC_LOCKABLE RTC_EXPORT TaskQueueBase { // Subclasses should implement this method to support the behavior defined in // the PostTask and PostTaskTraits docs above. - // TODO(crbug.com/1416199): make pure virtual once subclasses migrate. virtual void PostTaskImpl(absl::AnyInvocable task, const PostTaskTraits& traits, - const Location& location) {} + const Location& location) = 0; // Subclasses should implement this method to support the behavior defined in // the PostDelayedTask/PostHighPrecisionDelayedTask and PostDelayedTaskTraits // docs above. - // TODO(crbug.com/1416199): make pure virtual once subclasses migrate. virtual void PostDelayedTaskImpl(absl::AnyInvocable task, TimeDelta delay, const PostDelayedTaskTraits& traits, - const Location& location) {} + const Location& location) = 0; // Users of the TaskQueue should call Delete instead of directly deleting // this object.