InterfacePtr::Bind does not accept a SequencedTaskRunner

16 views
Skip to first unread message

François Doray

unread,
May 11, 2018, 10:14:49 AM5/11/18
to scheduler-dev, Gabriel Charette, Sam McNally, chromi...@chromium.org
ResourceDispatcher::StartAsync takes a SingleThreadTaskRunner as argument. I would like to change this to SequencedTaskRunner, to be able to change the call to base::CreateSingleThreadTaskRunnerWithTraits() in ResourceDispatcher::StartSync to base::CreateSequencedTaskRunnerWithTraits().

Unfortunately, this argument is passed to URLLoaderClientImpl -> URLLoaderClientImpl::Bind -> InterfacePtr::Bind, which only accepts a SingleThreadTaskRunner. According to the discussion on https://chromium-review.googlesource.com/c/chromium/src/+/544717, this is because if someone wants to bind an interface to a SequencedTaskRunner which is not a SingleThreadTaskRunner, they should just pass nullptr, and rely on the default behavior of picking up the SequencedTaskRunnerHandle. Explicitly providing a SingleThreadTaskRunner is only useful to bind an interface to a specific queue of the Blink scheduler.

That suggests that the argument of URLLoaderClientImpl should remain a SingleThreadTaskRunner, and we should pass nullptr when we want to run on a SequencedTaskRunner which isn't a SingleThreadTaskRunner. But that argument isn't only used to bind an interface, it's also used to post tasks. That means that I would need to add logic to get the SequencedTaskRunnerHandle to post tasks when the argument is nullptr (maybe by making GetTaskRunnerToUseFromUserProvidedTaskRunner public).

What solution do you recommend?
  1. Make GetTaskRunnerToUseFromUserProvidedTaskRunner() public, so that any code can easily accept a specific SingleThreadTaskRunner, or run on SequencedTaskRunnerHandle otherwise.
  2. Allow a SequencedTaskRunner argument in InterfacePtr::Bind, making it trivial to write classes that can run both on a SingleThreadTaskRunner and a SequencedTaskRunner.
  3. ?
Thanks!
Reply all
Reply to author
Forward
0 new messages