| 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/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
| 10 #include "content/public/test/test_browser_thread.h" | 10 #include "content/public/test/test_browser_thread.h" |
| 11 | 11 |
| 12 #if defined(OS_ANDROID) |
| 13 #include "content/public/test/nested_message_pump_android.h" |
| 14 #endif // OS_ANDROID |
| 15 |
| 12 namespace content { | 16 namespace content { |
| 13 | 17 |
| 14 TestBrowserThreadBundle::TestBrowserThreadBundle() | 18 TestBrowserThreadBundle::TestBrowserThreadBundle() |
| 15 : TestBrowserThreadBundle(DEFAULT) {} | 19 : TestBrowserThreadBundle(DEFAULT) {} |
| 16 | 20 |
| 17 TestBrowserThreadBundle::TestBrowserThreadBundle(int options) | 21 TestBrowserThreadBundle::TestBrowserThreadBundle(int options) |
| 18 : options_(options), threads_started_(false) { | 22 : options_(options), threads_started_(false) { |
| 19 Init(); | 23 Init(); |
| 20 } | 24 } |
| 21 | 25 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 50 base::RunLoop().RunUntilIdle(); | 54 base::RunLoop().RunUntilIdle(); |
| 51 ui_thread_.reset(); | 55 ui_thread_.reset(); |
| 52 base::RunLoop().RunUntilIdle(); | 56 base::RunLoop().RunUntilIdle(); |
| 53 } | 57 } |
| 54 | 58 |
| 55 void TestBrowserThreadBundle::Init() { | 59 void TestBrowserThreadBundle::Init() { |
| 56 // Check for conflicting options can't have two IO threads. | 60 // Check for conflicting options can't have two IO threads. |
| 57 CHECK(!(options_ & IO_MAINLOOP) || !(options_ & REAL_IO_THREAD)); | 61 CHECK(!(options_ & IO_MAINLOOP) || !(options_ & REAL_IO_THREAD)); |
| 58 // There must be a thread to start to use DONT_START_THREADS | 62 // There must be a thread to start to use DONT_START_THREADS |
| 59 CHECK((options_ & ~IO_MAINLOOP) != DONT_START_THREADS); | 63 CHECK((options_ & ~IO_MAINLOOP) != DONT_START_THREADS); |
| 64 // MessageLoopForIO doesn't currently support custom message pumps. |
| 65 CHECK(!(options_ & IO_MAINLOOP) || !(options_ & NESTED_JAVA_ON_ANDROID)); |
| 60 | 66 |
| 61 if (options_ & IO_MAINLOOP) { | 67 if (options_ & IO_MAINLOOP) { |
| 62 message_loop_.reset(new base::MessageLoopForIO()); | 68 message_loop_.reset(new base::MessageLoopForIO()); |
| 63 } else { | 69 } |
| 70 #if defined(OS_ANDROID) |
| 71 else if (options_ & NESTED_JAVA_ON_ANDROID) { |
| 72 message_loop_.reset(new base::MessageLoopForUI( |
| 73 scoped_ptr<base::MessagePump>(new NestedMessagePumpAndroid()))); |
| 74 static_cast<base::MessageLoopForUI*>(message_loop_.get())->Start(); |
| 75 } |
| 76 #endif // OS_ANDROID |
| 77 else { |
| 64 message_loop_.reset(new base::MessageLoopForUI()); | 78 message_loop_.reset(new base::MessageLoopForUI()); |
| 65 } | 79 } |
| 66 | 80 |
| 67 ui_thread_.reset( | 81 ui_thread_.reset( |
| 68 new TestBrowserThread(BrowserThread::UI, message_loop_.get())); | 82 new TestBrowserThread(BrowserThread::UI, message_loop_.get())); |
| 69 | 83 |
| 70 if (options_ & REAL_DB_THREAD) { | 84 if (options_ & REAL_DB_THREAD) { |
| 71 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); | 85 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); |
| 72 } else { | 86 } else { |
| 73 db_thread_.reset( | 87 db_thread_.reset( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 if (options_ & REAL_CACHE_THREAD) | 149 if (options_ & REAL_CACHE_THREAD) |
| 136 cache_thread_->Start(); | 150 cache_thread_->Start(); |
| 137 | 151 |
| 138 if (options_ & REAL_IO_THREAD) | 152 if (options_ & REAL_IO_THREAD) |
| 139 io_thread_->StartIOThread(); | 153 io_thread_->StartIOThread(); |
| 140 | 154 |
| 141 threads_started_ = true; | 155 threads_started_ = true; |
| 142 } | 156 } |
| 143 | 157 |
| 144 } // namespace content | 158 } // namespace content |
| OLD | NEW |