Descriptionbase: Let ThreadTaskRunnerHandle::Get() return NULL
We are migrating clients of MessageLoopProxy to ThreadTaskRunnerHandle
as the former class is deprecated. One difference between the classes is
that MessageLoopProxy::current() can return NULL if the current thread
has no active message loop, whereas ThreadTaskRunnerHandle::Get() will
fail a DCHECK if it is called without an active task runner. There are
at least four ways to work around this during the migration:
1. Vet all callers of MessageLoopProxy::current() to see if they expect
to run in a context without a message loop. If so, modify them to
check for the presence of a task runner with
ThreadTaskRunnerHandle::IsSet() before calling
ThreadTaskRunnerHandle::Get(). This is infeasible due to the number
of call sites.
2. Modify all call sites to call IsSet() before Get(). Not great
because adds lots of visual noise and boilerplate.
3. Add some new getter to ThreadTaskRunnerHandle which is allowed to
return NULL. Unsure what to call this without making calling code
overly verbose.
4. Change to contract of ThreadTaskRunnerHandle::Get() so that it is
allowed to return NULL. This allows automatic migration of
MessageLoopProxy callers to ThreadTaskRunnerHandle and does not
affect any current users of ThreadTaskRunnerHandle.
This patch implements option #4. As a followup we might want to remove
IsSet() since it is somewhat redundant (although it does read better at
the call site).
BUG=465354
Patch Set 1 #
Messages
Total messages: 10 (2 generated)
|