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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/test/scoped_async_task_scheduler.h" | |
| 10 #include "base/test/scoped_task_scheduler.h" | 11 #include "base/test/scoped_task_scheduler.h" |
| 11 #include "content/browser/browser_thread_impl.h" | 12 #include "content/browser/browser_thread_impl.h" |
| 12 #include "content/public/test/test_browser_thread.h" | 13 #include "content/public/test/test_browser_thread.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 TestBrowserThreadBundle::TestBrowserThreadBundle() | 17 TestBrowserThreadBundle::TestBrowserThreadBundle() |
| 17 : TestBrowserThreadBundle(DEFAULT) {} | 18 : TestBrowserThreadBundle(DEFAULT) {} |
| 18 | 19 |
| 19 TestBrowserThreadBundle::TestBrowserThreadBundle(int options) | 20 TestBrowserThreadBundle::TestBrowserThreadBundle(int options) |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 48 db_thread_->Stop(); | 49 db_thread_->Stop(); |
| 49 base::RunLoop().RunUntilIdle(); | 50 base::RunLoop().RunUntilIdle(); |
| 50 // This is the point at which we normally shut down the thread pool. So flush | 51 // This is the point at which we normally shut down the thread pool. So flush |
| 51 // it again in case any shutdown tasks have been posted to the pool from the | 52 // it again in case any shutdown tasks have been posted to the pool from the |
| 52 // threads above. | 53 // threads above. |
| 53 BrowserThreadImpl::FlushThreadPoolHelperForTesting(); | 54 BrowserThreadImpl::FlushThreadPoolHelperForTesting(); |
| 54 base::RunLoop().RunUntilIdle(); | 55 base::RunLoop().RunUntilIdle(); |
| 55 ui_thread_->Stop(); | 56 ui_thread_->Stop(); |
| 56 base::RunLoop().RunUntilIdle(); | 57 base::RunLoop().RunUntilIdle(); |
| 57 | 58 |
| 58 task_scheduler_.reset(); | 59 scoped_async_task_scheduler_.reset(); |
| 60 scoped_task_scheduler_.reset(); | |
| 59 | 61 |
| 60 // |message_loop_| needs to explicitly go away before fake threads in order | 62 // |message_loop_| needs to explicitly go away before fake threads in order |
| 61 // for DestructionObservers hooked to |message_loop_| to be able to invoke | 63 // for DestructionObservers hooked to |message_loop_| to be able to invoke |
| 62 // BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread(). | 64 // BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread(). |
| 63 CHECK(message_loop_->IsIdleForTesting()); | 65 CHECK(message_loop_->IsIdleForTesting()); |
| 64 message_loop_.reset(); | 66 message_loop_.reset(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 void TestBrowserThreadBundle::Init() { | 69 void TestBrowserThreadBundle::Init() { |
| 68 // Check for conflicting options can't have two IO threads. | 70 // Check for conflicting options can't have two IO threads. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 79 ui_thread_.reset( | 81 ui_thread_.reset( |
| 80 new TestBrowserThread(BrowserThread::UI, message_loop_.get())); | 82 new TestBrowserThread(BrowserThread::UI, message_loop_.get())); |
| 81 | 83 |
| 82 if (!(options_ & DONT_CREATE_THREADS)) | 84 if (!(options_ & DONT_CREATE_THREADS)) |
| 83 CreateThreads(); | 85 CreateThreads(); |
| 84 } | 86 } |
| 85 | 87 |
| 86 void TestBrowserThreadBundle::CreateThreads() { | 88 void TestBrowserThreadBundle::CreateThreads() { |
| 87 DCHECK(!threads_created_); | 89 DCHECK(!threads_created_); |
| 88 | 90 |
| 89 task_scheduler_.reset( | 91 if (options_ & REAL_TASK_SCHEDULER) { |
| 90 new base::test::ScopedTaskScheduler(message_loop_.get())); | 92 scoped_async_task_scheduler_.reset( |
| 93 new base::test::ScopedAsyncTaskScheduler()); | |
|
robliao
2017/01/12 20:15:02
Should Async instead have been an option off of Sc
fdoray
2017/01/12 21:25:56
No. It is very convenient to be able to add a Scop
robliao
2017/01/12 21:31:03
Do we expect many uses of ScopedAsyncTaskScheduler
| |
| 94 } else { | |
| 95 scoped_task_scheduler_.reset( | |
| 96 new base::test::ScopedTaskScheduler(message_loop_.get())); | |
| 97 } | |
| 91 | 98 |
| 92 if (options_ & REAL_DB_THREAD) { | 99 if (options_ & REAL_DB_THREAD) { |
| 93 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); | 100 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); |
| 94 db_thread_->Start(); | 101 db_thread_->Start(); |
| 95 } else { | 102 } else { |
| 96 db_thread_.reset( | 103 db_thread_.reset( |
| 97 new TestBrowserThread(BrowserThread::DB, message_loop_.get())); | 104 new TestBrowserThread(BrowserThread::DB, message_loop_.get())); |
| 98 } | 105 } |
| 99 | 106 |
| 100 if (options_ & REAL_FILE_THREAD) { | 107 if (options_ & REAL_FILE_THREAD) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 117 io_thread_->StartIOThread(); | 124 io_thread_->StartIOThread(); |
| 118 } else { | 125 } else { |
| 119 io_thread_.reset( | 126 io_thread_.reset( |
| 120 new TestBrowserThread(BrowserThread::IO, message_loop_.get())); | 127 new TestBrowserThread(BrowserThread::IO, message_loop_.get())); |
| 121 } | 128 } |
| 122 | 129 |
| 123 threads_created_ = true; | 130 threads_created_ = true; |
| 124 } | 131 } |
| 125 | 132 |
| 126 } // namespace content | 133 } // namespace content |
| OLD | NEW |