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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/test/scoped_async_task_scheduler.h" |
10 #include "base/test/scoped_task_scheduler.h" | 12 #include "base/test/scoped_task_scheduler.h" |
11 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
12 #include "content/public/test/test_browser_thread.h" | 14 #include "content/public/test/test_browser_thread.h" |
13 | 15 |
14 namespace content { | 16 namespace content { |
15 | 17 |
16 TestBrowserThreadBundle::TestBrowserThreadBundle() | 18 TestBrowserThreadBundle::TestBrowserThreadBundle() |
17 : TestBrowserThreadBundle(DEFAULT) {} | 19 : TestBrowserThreadBundle(DEFAULT) {} |
18 | 20 |
19 TestBrowserThreadBundle::TestBrowserThreadBundle(int options) | 21 TestBrowserThreadBundle::TestBrowserThreadBundle(int options) |
(...skipping 28 matching lines...) Expand all Loading... |
48 db_thread_->Stop(); | 50 db_thread_->Stop(); |
49 base::RunLoop().RunUntilIdle(); | 51 base::RunLoop().RunUntilIdle(); |
50 // 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 |
51 // 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 |
52 // threads above. | 54 // threads above. |
53 BrowserThreadImpl::FlushThreadPoolHelperForTesting(); | 55 BrowserThreadImpl::FlushThreadPoolHelperForTesting(); |
54 base::RunLoop().RunUntilIdle(); | 56 base::RunLoop().RunUntilIdle(); |
55 ui_thread_->Stop(); | 57 ui_thread_->Stop(); |
56 base::RunLoop().RunUntilIdle(); | 58 base::RunLoop().RunUntilIdle(); |
57 | 59 |
58 task_scheduler_.reset(); | 60 scoped_async_task_scheduler_.reset(); |
| 61 scoped_task_scheduler_.reset(); |
59 | 62 |
60 // |message_loop_| needs to explicitly go away before fake threads in order | 63 // |message_loop_| needs to explicitly go away before fake threads in order |
61 // for DestructionObservers hooked to |message_loop_| to be able to invoke | 64 // for DestructionObservers hooked to |message_loop_| to be able to invoke |
62 // BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread(). | 65 // BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread(). |
63 CHECK(message_loop_->IsIdleForTesting()); | 66 CHECK(message_loop_->IsIdleForTesting()); |
64 message_loop_.reset(); | 67 message_loop_.reset(); |
65 } | 68 } |
66 | 69 |
67 void TestBrowserThreadBundle::Init() { | 70 void TestBrowserThreadBundle::Init() { |
68 // Check for conflicting options can't have two IO threads. | 71 // 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())); | 85 new TestBrowserThread(BrowserThread::UI, message_loop_.get())); |
83 | 86 |
84 if (!(options_ & DONT_CREATE_THREADS)) | 87 if (!(options_ & DONT_CREATE_THREADS)) |
85 CreateThreads(); | 88 CreateThreads(); |
86 } | 89 } |
87 | 90 |
88 // This method mimics the work done in BrowserMainLoop::CreateThreads(). | 91 // This method mimics the work done in BrowserMainLoop::CreateThreads(). |
89 void TestBrowserThreadBundle::CreateThreads() { | 92 void TestBrowserThreadBundle::CreateThreads() { |
90 DCHECK(!threads_created_); | 93 DCHECK(!threads_created_); |
91 | 94 |
92 task_scheduler_.reset( | 95 if (options_ & REAL_TASK_SCHEDULER) { |
93 new base::test::ScopedTaskScheduler(message_loop_.get())); | 96 scoped_async_task_scheduler_ = |
| 97 base::MakeUnique<base::test::ScopedAsyncTaskScheduler>(); |
| 98 } else { |
| 99 scoped_task_scheduler_ = |
| 100 base::MakeUnique<base::test::ScopedTaskScheduler>(message_loop_.get()); |
| 101 } |
94 | 102 |
95 if (options_ & REAL_DB_THREAD) { | 103 if (options_ & REAL_DB_THREAD) { |
96 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); | 104 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); |
97 db_thread_->Start(); | 105 db_thread_->Start(); |
98 } else { | 106 } else { |
99 db_thread_.reset( | 107 db_thread_.reset( |
100 new TestBrowserThread(BrowserThread::DB, message_loop_.get())); | 108 new TestBrowserThread(BrowserThread::DB, message_loop_.get())); |
101 } | 109 } |
102 | 110 |
103 if (options_ & REAL_FILE_THREAD) { | 111 if (options_ & REAL_FILE_THREAD) { |
(...skipping 16 matching lines...) Expand all Loading... |
120 io_thread_->StartIOThread(); | 128 io_thread_->StartIOThread(); |
121 } else { | 129 } else { |
122 io_thread_.reset( | 130 io_thread_.reset( |
123 new TestBrowserThread(BrowserThread::IO, message_loop_.get())); | 131 new TestBrowserThread(BrowserThread::IO, message_loop_.get())); |
124 } | 132 } |
125 | 133 |
126 threads_created_ = true; | 134 threads_created_ = true; |
127 } | 135 } |
128 | 136 |
129 } // namespace content | 137 } // namespace content |
OLD | NEW |