Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Issue 1075213002: base: Let ThreadTaskRunnerHandle::Get() return NULL (Closed)

Created:
5 years, 8 months ago by Sami
Modified:
5 years, 7 months ago
Reviewers:
danakj, jam, Ryan Sleevi
CC:
chromium-reviews, erikwright+watch_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

base: 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 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+24 lines, -2 lines) Patch
M base/BUILD.gn View 1 chunk +1 line, -0 lines 0 comments Download
M base/base.gyp View 1 chunk +1 line, -0 lines 0 comments Download
M base/thread_task_runner_handle.cc View 1 chunk +1 line, -2 lines 0 comments Download
A base/thread_task_runner_handle_unittest.cc View 1 chunk +21 lines, -0 lines 0 comments Download

Messages

Total messages: 10 (2 generated)
Sami
WDYT?
5 years, 8 months ago (2015-04-10 11:05:15 UTC) #2
danakj
+rsleevi for thoughts
5 years, 8 months ago (2015-04-10 17:52:59 UTC) #4
danakj
This seems cool to me, but I have no grasp of what could go wrong ...
5 years, 8 months ago (2015-04-10 18:02:12 UTC) #5
Sami
Thanks Dana. I also wasn't able to find out why these two functions have different ...
5 years, 8 months ago (2015-04-10 18:09:46 UTC) #6
Ryan Sleevi
On 2015/04/10 18:09:46, Sami wrote: > Thanks Dana. I also wasn't able to find out ...
5 years, 8 months ago (2015-04-10 21:13:24 UTC) #7
danakj
On Fri, Apr 10, 2015 at 2:13 PM, <rsleevi@chromium.org> wrote: > On 2015/04/10 18:09:46, Sami ...
5 years, 8 months ago (2015-04-10 21:16:34 UTC) #8
jam
I agree with Ryan that it's best to not have NULL returns for these getters; ...
5 years, 8 months ago (2015-04-13 14:28:27 UTC) #9
Sami
5 years, 8 months ago (2015-04-13 16:19:17 UTC) #10
On 2015/04/13 14:28:27, jam wrote:
> I agree with Ryan that it's best to not have NULL returns for these getters;
we
> are adding extra complexity to production code just for tests. There are easy
> way to instantiate MLs for tests already through TestBrowserThreadBundle

Ah, I didn't realize that would mainly happen in tests. If that's the case then
I can see how much effort it is to fix the affected tests. However if there are
cases where we hit this in production code that isn't tested, then those code
paths will trigger a crash crash (not just a DCHECK failure). Luckily the crash
dump should be fairly obvious to decode.

Powered by Google App Engine
This is Rietveld 408576698