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/memory/ptr_util.h" | |
| 7 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/test/scoped_task_scheduler.h" | |
| 9 #include "content/browser/browser_thread_impl.h" | 11 #include "content/browser/browser_thread_impl.h" |
| 10 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread.h" |
| 11 | 13 |
| 12 namespace content { | 14 namespace content { |
| 13 | 15 |
| 14 TestBrowserThreadBundle::TestBrowserThreadBundle() | 16 TestBrowserThreadBundle::TestBrowserThreadBundle() |
| 15 : TestBrowserThreadBundle(DEFAULT) {} | 17 : TestBrowserThreadBundle(DEFAULT) {} |
| 16 | 18 |
| 17 TestBrowserThreadBundle::TestBrowserThreadBundle(int options) | 19 TestBrowserThreadBundle::TestBrowserThreadBundle(int options) |
| 18 : options_(options), threads_started_(false) { | 20 : options_(options), threads_started_(false) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 ui_thread_.reset(); | 53 ui_thread_.reset(); |
| 52 base::RunLoop().RunUntilIdle(); | 54 base::RunLoop().RunUntilIdle(); |
| 53 } | 55 } |
| 54 | 56 |
| 55 void TestBrowserThreadBundle::Init() { | 57 void TestBrowserThreadBundle::Init() { |
| 56 // Check for conflicting options can't have two IO threads. | 58 // Check for conflicting options can't have two IO threads. |
| 57 CHECK(!(options_ & IO_MAINLOOP) || !(options_ & REAL_IO_THREAD)); | 59 CHECK(!(options_ & IO_MAINLOOP) || !(options_ & REAL_IO_THREAD)); |
| 58 // There must be a thread to start to use DONT_START_THREADS | 60 // There must be a thread to start to use DONT_START_THREADS |
| 59 CHECK((options_ & ~IO_MAINLOOP) != DONT_START_THREADS); | 61 CHECK((options_ & ~IO_MAINLOOP) != DONT_START_THREADS); |
| 60 | 62 |
| 61 if (options_ & IO_MAINLOOP) { | 63 task_scheduler_ = base::MakeUnique<base::test::ScopedTaskScheduler>( |
| 62 message_loop_.reset(new base::MessageLoopForIO()); | 64 options_ & IO_MAINLOOP ? base::test::ScopedTaskScheduler::DEFAULT |
|
gab
2016/12/08 20:15:45
I prefered that the loop be owned by TestBrowserTh
fdoray
2016/12/09 16:26:42
Done.
| |
| 63 } else { | 65 : base::test::ScopedTaskScheduler::UI_MAIN_LOOP); |
|
gab
2016/12/08 20:15:45
So if using a REAL_IO_THREAD, it's not possible to
fdoray
2016/12/09 16:26:42
n/a See https://codereview.chromium.org/2557083002
gab
2016/12/09 20:04:17
But we might still want a REAL_TASK_SCHEDULER? Wou
fdoray
2016/12/12 18:18:50
I would wait until we have a real use case before
| |
| 64 message_loop_.reset(new base::MessageLoopForUI()); | |
| 65 } | |
| 66 | 66 |
| 67 ui_thread_.reset( | 67 ui_thread_.reset( |
| 68 new TestBrowserThread(BrowserThread::UI, message_loop_.get())); | 68 new TestBrowserThread(BrowserThread::UI, base::MessageLoop::current())); |
| 69 | 69 |
| 70 if (options_ & REAL_DB_THREAD) { | 70 if (options_ & REAL_DB_THREAD) { |
| 71 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); | 71 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); |
| 72 } else { | 72 } else { |
| 73 db_thread_.reset( | 73 db_thread_.reset( |
| 74 new TestBrowserThread(BrowserThread::DB, message_loop_.get())); | 74 new TestBrowserThread(BrowserThread::DB, base::MessageLoop::current())); |
| 75 } | 75 } |
| 76 | 76 |
| 77 if (options_ & REAL_FILE_THREAD) { | 77 if (options_ & REAL_FILE_THREAD) { |
| 78 file_thread_.reset(new TestBrowserThread(BrowserThread::FILE)); | 78 file_thread_.reset(new TestBrowserThread(BrowserThread::FILE)); |
| 79 } else { | 79 } else { |
| 80 file_thread_.reset( | 80 file_thread_.reset(new TestBrowserThread(BrowserThread::FILE, |
| 81 new TestBrowserThread(BrowserThread::FILE, message_loop_.get())); | 81 base::MessageLoop::current())); |
| 82 } | 82 } |
| 83 | 83 |
| 84 file_user_blocking_thread_.reset(new TestBrowserThread( | 84 file_user_blocking_thread_.reset(new TestBrowserThread( |
| 85 BrowserThread::FILE_USER_BLOCKING, message_loop_.get())); | 85 BrowserThread::FILE_USER_BLOCKING, base::MessageLoop::current())); |
| 86 process_launcher_thread_.reset(new TestBrowserThread( | 86 process_launcher_thread_.reset(new TestBrowserThread( |
| 87 BrowserThread::PROCESS_LAUNCHER, message_loop_.get())); | 87 BrowserThread::PROCESS_LAUNCHER, base::MessageLoop::current())); |
| 88 cache_thread_.reset( | 88 cache_thread_.reset(new TestBrowserThread(BrowserThread::CACHE, |
| 89 new TestBrowserThread(BrowserThread::CACHE, message_loop_.get())); | 89 base::MessageLoop::current())); |
| 90 | 90 |
| 91 if (options_ & REAL_IO_THREAD) { | 91 if (options_ & REAL_IO_THREAD) { |
| 92 io_thread_.reset(new TestBrowserThread(BrowserThread::IO)); | 92 io_thread_.reset(new TestBrowserThread(BrowserThread::IO)); |
| 93 } else { | 93 } else { |
| 94 io_thread_.reset( | 94 io_thread_.reset( |
| 95 new TestBrowserThread(BrowserThread::IO, message_loop_.get())); | 95 new TestBrowserThread(BrowserThread::IO, base::MessageLoop::current())); |
| 96 } | 96 } |
| 97 | 97 |
| 98 if (!(options_ & DONT_START_THREADS)) | 98 if (!(options_ & DONT_START_THREADS)) |
| 99 Start(); | 99 Start(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void TestBrowserThreadBundle::Start() { | 102 void TestBrowserThreadBundle::Start() { |
| 103 DCHECK(!threads_started_); | 103 DCHECK(!threads_started_); |
| 104 | 104 |
| 105 if (options_ & REAL_DB_THREAD) | 105 if (options_ & REAL_DB_THREAD) |
| 106 db_thread_->Start(); | 106 db_thread_->Start(); |
| 107 | 107 |
| 108 if (options_ & REAL_FILE_THREAD) | 108 if (options_ & REAL_FILE_THREAD) |
| 109 file_thread_->Start(); | 109 file_thread_->Start(); |
| 110 | 110 |
| 111 if (options_ & REAL_IO_THREAD) | 111 if (options_ & REAL_IO_THREAD) |
| 112 io_thread_->StartIOThread(); | 112 io_thread_->StartIOThread(); |
| 113 | 113 |
| 114 threads_started_ = true; | 114 threads_started_ = true; |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace content | 117 } // namespace content |
| OLD | NEW |