| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ios/web/public/test/test_web_thread_bundle.h" | 5 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.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_async_task_scheduler.h" |
| 11 #include "base/test/scoped_task_scheduler.h" | |
| 12 #include "ios/web/public/test/test_web_thread.h" | 11 #include "ios/web/public/test/test_web_thread.h" |
| 13 #include "ios/web/web_thread_impl.h" | 12 #include "ios/web/web_thread_impl.h" |
| 14 | 13 |
| 15 namespace web { | 14 namespace web { |
| 16 | 15 |
| 17 TestWebThreadBundle::TestWebThreadBundle() { | 16 TestWebThreadBundle::TestWebThreadBundle() { |
| 18 Init(TestWebThreadBundle::DEFAULT); | 17 Init(TestWebThreadBundle::DEFAULT); |
| 19 } | 18 } |
| 20 | 19 |
| 21 TestWebThreadBundle::TestWebThreadBundle(int options) { | 20 TestWebThreadBundle::TestWebThreadBundle(int options) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 46 base::RunLoop().RunUntilIdle(); | 45 base::RunLoop().RunUntilIdle(); |
| 47 // This is the point at which the thread pool is normally shut down. So flush | 46 // This is the point at which the thread pool is normally shut down. So flush |
| 48 // it again in case any shutdown tasks have been posted to the pool from the | 47 // it again in case any shutdown tasks have been posted to the pool from the |
| 49 // threads above. | 48 // threads above. |
| 50 WebThreadImpl::FlushThreadPoolHelperForTesting(); | 49 WebThreadImpl::FlushThreadPoolHelperForTesting(); |
| 51 base::RunLoop().RunUntilIdle(); | 50 base::RunLoop().RunUntilIdle(); |
| 52 ui_thread_.reset(); | 51 ui_thread_.reset(); |
| 53 base::RunLoop().RunUntilIdle(); | 52 base::RunLoop().RunUntilIdle(); |
| 54 | 53 |
| 55 scoped_async_task_scheduler_.reset(); | 54 scoped_async_task_scheduler_.reset(); |
| 56 scoped_task_scheduler_.reset(); | |
| 57 } | 55 } |
| 58 | 56 |
| 59 void TestWebThreadBundle::Init(int options) { | 57 void TestWebThreadBundle::Init(int options) { |
| 60 if (options & TestWebThreadBundle::IO_MAINLOOP) { | 58 if (options & TestWebThreadBundle::IO_MAINLOOP) { |
| 61 message_loop_.reset(new base::MessageLoopForIO()); | 59 message_loop_.reset(new base::MessageLoopForIO()); |
| 62 } else { | 60 } else { |
| 63 message_loop_.reset(new base::MessageLoopForUI()); | 61 message_loop_.reset(new base::MessageLoopForUI()); |
| 64 } | 62 } |
| 65 | 63 |
| 66 ui_thread_.reset(new TestWebThread(WebThread::UI, message_loop_.get())); | 64 ui_thread_.reset(new TestWebThread(WebThread::UI, message_loop_.get())); |
| 67 | 65 |
| 68 if (options & REAL_TASK_SCHEDULER) { | 66 scoped_async_task_scheduler_ = |
| 69 scoped_async_task_scheduler_ = | 67 base::MakeUnique<base::test::ScopedAsyncTaskScheduler>(); |
| 70 base::MakeUnique<base::test::ScopedAsyncTaskScheduler>(); | |
| 71 } else { | |
| 72 scoped_task_scheduler_ = | |
| 73 base::MakeUnique<base::test::ScopedTaskScheduler>(message_loop_.get()); | |
| 74 } | |
| 75 | 68 |
| 76 if (options & TestWebThreadBundle::REAL_DB_THREAD) { | 69 if (options & TestWebThreadBundle::REAL_DB_THREAD) { |
| 77 db_thread_.reset(new TestWebThread(WebThread::DB)); | 70 db_thread_.reset(new TestWebThread(WebThread::DB)); |
| 78 db_thread_->Start(); | 71 db_thread_->Start(); |
| 79 } else { | 72 } else { |
| 80 db_thread_.reset(new TestWebThread(WebThread::DB, message_loop_.get())); | 73 db_thread_.reset(new TestWebThread(WebThread::DB, message_loop_.get())); |
| 81 } | 74 } |
| 82 | 75 |
| 83 if (options & TestWebThreadBundle::REAL_FILE_THREAD) { | 76 if (options & TestWebThreadBundle::REAL_FILE_THREAD) { |
| 84 file_thread_.reset(new TestWebThread(WebThread::FILE)); | 77 file_thread_.reset(new TestWebThread(WebThread::FILE)); |
| 85 file_thread_->Start(); | 78 file_thread_->Start(); |
| 86 } else { | 79 } else { |
| 87 file_thread_.reset(new TestWebThread(WebThread::FILE, message_loop_.get())); | 80 file_thread_.reset(new TestWebThread(WebThread::FILE, message_loop_.get())); |
| 88 } | 81 } |
| 89 | 82 |
| 90 file_user_blocking_thread_.reset( | 83 file_user_blocking_thread_.reset( |
| 91 new TestWebThread(WebThread::FILE_USER_BLOCKING, message_loop_.get())); | 84 new TestWebThread(WebThread::FILE_USER_BLOCKING, message_loop_.get())); |
| 92 | 85 |
| 93 cache_thread_.reset(new TestWebThread(WebThread::CACHE, message_loop_.get())); | 86 cache_thread_.reset(new TestWebThread(WebThread::CACHE, message_loop_.get())); |
| 94 | 87 |
| 95 if (options & TestWebThreadBundle::REAL_IO_THREAD) { | 88 if (options & TestWebThreadBundle::REAL_IO_THREAD) { |
| 96 io_thread_.reset(new TestWebThread(WebThread::IO)); | 89 io_thread_.reset(new TestWebThread(WebThread::IO)); |
| 97 io_thread_->StartIOThread(); | 90 io_thread_->StartIOThread(); |
| 98 } else { | 91 } else { |
| 99 io_thread_.reset(new TestWebThread(WebThread::IO, message_loop_.get())); | 92 io_thread_.reset(new TestWebThread(WebThread::IO, message_loop_.get())); |
| 100 } | 93 } |
| 101 } | 94 } |
| 102 | 95 |
| 103 } // namespace web | 96 } // namespace web |
| OLD | NEW |