Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/public/test/test_browser_thread_bundle.h" | 5 #include "content/public/test/test_browser_thread_bundle.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/test/scoped_async_task_scheduler.h" | 11 #include "base/test/scoped_async_task_scheduler.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | |
| 12 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
| 13 #include "content/public/test/test_browser_thread.h" | 14 #include "content/public/test/test_browser_thread.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 TestBrowserThreadBundle::TestBrowserThreadBundle() | 18 TestBrowserThreadBundle::TestBrowserThreadBundle() |
| 18 : TestBrowserThreadBundle(DEFAULT) {} | 19 : TestBrowserThreadBundle(DEFAULT) {} |
| 19 | 20 |
| 20 TestBrowserThreadBundle::TestBrowserThreadBundle(int options) | 21 TestBrowserThreadBundle::TestBrowserThreadBundle(int options) |
| 21 : options_(options), threads_created_(false) { | 22 : options_(options), threads_created_(false) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 51 // This is the point at which we normally shut down the thread pool. So flush | 52 // This is the point at which we normally shut down the thread pool. So flush |
| 52 // it again in case any shutdown tasks have been posted to the pool from the | 53 // it again in case any shutdown tasks have been posted to the pool from the |
| 53 // threads above. | 54 // threads above. |
| 54 BrowserThreadImpl::FlushThreadPoolHelperForTesting(); | 55 BrowserThreadImpl::FlushThreadPoolHelperForTesting(); |
| 55 base::RunLoop().RunUntilIdle(); | 56 base::RunLoop().RunUntilIdle(); |
| 56 ui_thread_->Stop(); | 57 ui_thread_->Stop(); |
| 57 base::RunLoop().RunUntilIdle(); | 58 base::RunLoop().RunUntilIdle(); |
| 58 | 59 |
| 59 scoped_async_task_scheduler_.reset(); | 60 scoped_async_task_scheduler_.reset(); |
| 60 | 61 |
| 62 // Disable redirection of SequencedWorkerPools to TaskScheduler. | |
| 63 base::SequencedWorkerPool::EnableForProcess(); | |
|
gab
2017/03/22 16:23:30
Do we need this? Sounds better to have tasks be re
fdoray
2017/04/03 14:57:28
In TestBrowserThreadBundle::CreateThreads(), we en
gab
2017/04/03 16:56:17
I see expand comment here then, something like:
/
| |
| 64 | |
| 61 // |message_loop_| needs to explicitly go away before fake threads in order | 65 // |message_loop_| needs to explicitly go away before fake threads in order |
| 62 // for DestructionObservers hooked to |message_loop_| to be able to invoke | 66 // for DestructionObservers hooked to |message_loop_| to be able to invoke |
| 63 // BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread(). | 67 // BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread(). |
| 64 CHECK(message_loop_->IsIdleForTesting()); | 68 CHECK(message_loop_->IsIdleForTesting()); |
| 65 message_loop_.reset(); | 69 message_loop_.reset(); |
| 66 } | 70 } |
| 67 | 71 |
| 68 void TestBrowserThreadBundle::Init() { | 72 void TestBrowserThreadBundle::Init() { |
| 69 // Check for conflicting options can't have two IO threads. | 73 // Check for conflicting options can't have two IO threads. |
| 70 CHECK(!(options_ & IO_MAINLOOP) || !(options_ & REAL_IO_THREAD)); | 74 CHECK(!(options_ & IO_MAINLOOP) || !(options_ & REAL_IO_THREAD)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 86 CreateThreads(); | 90 CreateThreads(); |
| 87 } | 91 } |
| 88 | 92 |
| 89 // This method mimics the work done in BrowserMainLoop::CreateThreads(). | 93 // This method mimics the work done in BrowserMainLoop::CreateThreads(). |
| 90 void TestBrowserThreadBundle::CreateThreads() { | 94 void TestBrowserThreadBundle::CreateThreads() { |
| 91 DCHECK(!threads_created_); | 95 DCHECK(!threads_created_); |
| 92 | 96 |
| 93 scoped_async_task_scheduler_ = | 97 scoped_async_task_scheduler_ = |
| 94 base::MakeUnique<base::test::ScopedAsyncTaskScheduler>(); | 98 base::MakeUnique<base::test::ScopedAsyncTaskScheduler>(); |
| 95 | 99 |
| 100 // Enable redirection of SequencedWorkerPools to TaskScheduler. | |
| 101 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); | |
| 102 | |
| 96 if (options_ & REAL_DB_THREAD) { | 103 if (options_ & REAL_DB_THREAD) { |
| 97 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); | 104 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); |
| 98 db_thread_->Start(); | 105 db_thread_->Start(); |
| 99 } else { | 106 } else { |
| 100 db_thread_.reset( | 107 db_thread_.reset( |
| 101 new TestBrowserThread(BrowserThread::DB, message_loop_.get())); | 108 new TestBrowserThread(BrowserThread::DB, message_loop_.get())); |
| 102 } | 109 } |
| 103 | 110 |
| 104 if (options_ & REAL_FILE_THREAD) { | 111 if (options_ & REAL_FILE_THREAD) { |
| 105 file_thread_.reset(new TestBrowserThread(BrowserThread::FILE)); | 112 file_thread_.reset(new TestBrowserThread(BrowserThread::FILE)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 121 io_thread_->StartIOThread(); | 128 io_thread_->StartIOThread(); |
| 122 } else { | 129 } else { |
| 123 io_thread_.reset( | 130 io_thread_.reset( |
| 124 new TestBrowserThread(BrowserThread::IO, message_loop_.get())); | 131 new TestBrowserThread(BrowserThread::IO, message_loop_.get())); |
| 125 } | 132 } |
| 126 | 133 |
| 127 threads_created_ = true; | 134 threads_created_ = true; |
| 128 } | 135 } |
| 129 | 136 |
| 130 } // namespace content | 137 } // namespace content |
| OLD | NEW |