The current TaskQueue::AddTask code might immediately run an added task without posting it for later execution. There are (at least one) cases where the original client of a task, which might not even be aware of the task system, might not expect that to happen and so might not be prepared for the possibility that the provided callback might be run during the call chain containing that lead to AddTask. It would be safer to always post-task the execution of Task::Run.
The specific call chain that lead me to realize this is a potential problem is:
RecentTabHelper::WebContentsWasHidden (unaware of the usage of TaskQueue by OfflinePageModelTaskified)
OfflinePageModelTaskified::GetOfflineIdsForClientId
TaskQueue::AddTask
TaskQueue::StartTaskIfAvailable
Task::Run (depending on the implementation, could immediately execute the callback)
WebContentsWasHidden's implementation relies on the current state of RecentTabHelper being unchanged during the call to GetOfflineIdsForClientId, what could happen should the provided callback be executed in the meantime. This is not the case in practice here but that's by chance and not by design.
CC-ing some interested parties to check if there's any concerns about executing this simple change.
Comment 1 by bugdroid1@chromium.org
, Oct 17