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