Chromium Code Reviews| Index: content/public/test/test_browser_thread.cc |
| diff --git a/content/public/test/test_browser_thread.cc b/content/public/test/test_browser_thread.cc |
| index ae83f78f78aad1455f8a9f98aa6c4f003ef4499b..b5148bf46e4bd43f7cba08012cd8a968ffd8b888 100644 |
| --- a/content/public/test/test_browser_thread.cc |
| +++ b/content/public/test/test_browser_thread.cc |
| @@ -40,15 +40,32 @@ class TestBrowserThreadImpl : public BrowserThreadImpl { |
| }; |
| TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier) |
| - : impl_(new TestBrowserThreadImpl(identifier)) { |
| -} |
| + : impl_(new TestBrowserThreadImpl(identifier)), identifier_(identifier) {} |
| TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier, |
| base::MessageLoop* message_loop) |
| - : impl_(new TestBrowserThreadImpl(identifier, message_loop)) {} |
| + : impl_(new TestBrowserThreadImpl(identifier, message_loop)), |
| + identifier_(identifier) {} |
| TestBrowserThread::~TestBrowserThread() { |
| - Stop(); |
| + // The upcoming BrowserThreadImpl::ResetGlobalsForTesting() call requires that |
| + // |impl_| have triggered the shutdown phase for its BrowserThread::ID. This |
| + // either happens when the thread is stopped (if real) or destroyed (when fake |
| + // -- i.e. using an externally provided MessageLoop). |
| + impl_.reset(); |
| + |
| + // Resets BrowserThreadImpl globals binding |identifier_| to |impl_|. This is |
|
robliao
2016/12/08 01:57:17
How does the below set the binding from |identifie
gab
2016/12/08 18:49:41
I meant to say that it clears that very binding, r
|
| + // fine since the underlying MessageLoop has already been flushed and deleted |
| + // in Stop(). In the case of an externally provided MessageLoop however, this |
| + // means that TaskRunners obtained through |
| + // |BrowserThreadImpl::GetTaskRunnerForThread(identifier_)| will no longer |
| + // recognize their BrowserThreadImpl for RunsTasksOnCurrentThread(). This |
| + // happens most often when such verifications are made from |
| + // MessageLoop::DestructionObservers. Callers that care to work around that |
| + // should instead use this shutdown sequence: TestBrowserThread::Stop() -> |
|
robliao
2016/12/08 01:57:17
Nit: Might be easier to read this as a sequenced l
gab
2016/12/08 18:49:41
Done.
|
| + // ~MessageLoop() -> ~TestBrowserThread() (~TestBrowserThreadBundle() does |
| + // this). |
| + BrowserThreadImpl::ResetGlobalsForTesting(identifier_); |
| } |
| bool TestBrowserThread::Start() { |