| 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 13 matching lines...) Expand all Loading... |
| 82 new TestBrowserThread(BrowserThread::UI, message_loop_.get())); | 84 new TestBrowserThread(BrowserThread::UI, message_loop_.get())); |
| 83 | 85 |
| 84 if (!(options_ & DONT_CREATE_THREADS)) | 86 if (!(options_ & DONT_CREATE_THREADS)) |
| 85 CreateThreads(); | 87 CreateThreads(); |
| 86 } | 88 } |
| 87 | 89 |
| 88 // This method mimics the work done in BrowserMainLoop::CreateThreads(). | 90 // This method mimics the work done in BrowserMainLoop::CreateThreads(). |
| 89 void TestBrowserThreadBundle::CreateThreads() { | 91 void TestBrowserThreadBundle::CreateThreads() { |
| 90 DCHECK(!threads_created_); | 92 DCHECK(!threads_created_); |
| 91 | 93 |
| 92 task_scheduler_.reset( | 94 if (options_ & REAL_TASK_SCHEDULER) { |
| 93 new base::test::ScopedTaskScheduler(message_loop_.get())); | 95 scoped_async_task_scheduler_.reset( |
| 96 new base::test::ScopedAsyncTaskScheduler()); |
| 97 } else { |
| 98 scoped_task_scheduler_.reset( |
| 99 new base::test::ScopedTaskScheduler(message_loop_.get())); |
| 100 } |
| 94 | 101 |
| 95 if (options_ & REAL_DB_THREAD) { | 102 if (options_ & REAL_DB_THREAD) { |
| 96 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); | 103 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); |
| 97 db_thread_->Start(); | 104 db_thread_->Start(); |
| 98 } else { | 105 } else { |
| 99 db_thread_.reset( | 106 db_thread_.reset( |
| 100 new TestBrowserThread(BrowserThread::DB, message_loop_.get())); | 107 new TestBrowserThread(BrowserThread::DB, message_loop_.get())); |
| 101 } | 108 } |
| 102 | 109 |
| 103 if (options_ & REAL_FILE_THREAD) { | 110 if (options_ & REAL_FILE_THREAD) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 120 io_thread_->StartIOThread(); | 127 io_thread_->StartIOThread(); |
| 121 } else { | 128 } else { |
| 122 io_thread_.reset( | 129 io_thread_.reset( |
| 123 new TestBrowserThread(BrowserThread::IO, message_loop_.get())); | 130 new TestBrowserThread(BrowserThread::IO, message_loop_.get())); |
| 124 } | 131 } |
| 125 | 132 |
| 126 threads_created_ = true; | 133 threads_created_ = true; |
| 127 } | 134 } |
| 128 | 135 |
| 129 } // namespace content | 136 } // namespace content |
| OLD | NEW |