| 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/public/test/test_browser_thread.h" | 10 #include "content/public/test/test_browser_thread.h" |
| 10 | 11 |
| 11 namespace content { | 12 namespace content { |
| 12 | 13 |
| 13 TestBrowserThreadBundle::TestBrowserThreadBundle() { | 14 TestBrowserThreadBundle::TestBrowserThreadBundle() { |
| 14 Init(DEFAULT); | 15 Init(DEFAULT); |
| 15 } | 16 } |
| 16 | 17 |
| 17 TestBrowserThreadBundle::TestBrowserThreadBundle(int options) { | 18 TestBrowserThreadBundle::TestBrowserThreadBundle(int options) { |
| 18 Init(options); | 19 Init(options); |
| 19 } | 20 } |
| 20 | 21 |
| 21 TestBrowserThreadBundle::~TestBrowserThreadBundle() { | 22 TestBrowserThreadBundle::~TestBrowserThreadBundle() { |
| 23 // To avoid memory leaks, we must ensure that any tasks posted to the blocking |
| 24 // pool via PostTaskAndReply are able to reply back to the originating thread. |
| 25 // Thus we must flush the blocking pool while the browser threads still exist. |
| 26 base::RunLoop().RunUntilIdle(); |
| 27 BrowserThreadImpl::FlushThreadPoolHelper(); |
| 28 |
| 22 // To ensure a clean teardown, each thread's message loop must be flushed | 29 // To ensure a clean teardown, each thread's message loop must be flushed |
| 23 // just before the thread is destroyed. But destroying a fake thread does not | 30 // just before the thread is destroyed. But destroying a fake thread does not |
| 24 // automatically flush the message loop, so we have to do it manually. | 31 // automatically flush the message loop, so we have to do it manually. |
| 25 // See http://crbug.com/247525 for discussion. | 32 // See http://crbug.com/247525 for discussion. |
| 26 base::RunLoop().RunUntilIdle(); | 33 base::RunLoop().RunUntilIdle(); |
| 27 io_thread_.reset(); | 34 io_thread_.reset(); |
| 28 base::RunLoop().RunUntilIdle(); | 35 base::RunLoop().RunUntilIdle(); |
| 29 cache_thread_.reset(); | 36 cache_thread_.reset(); |
| 30 base::RunLoop().RunUntilIdle(); | 37 base::RunLoop().RunUntilIdle(); |
| 31 process_launcher_thread_.reset(); | 38 process_launcher_thread_.reset(); |
| 32 base::RunLoop().RunUntilIdle(); | 39 base::RunLoop().RunUntilIdle(); |
| 33 file_user_blocking_thread_.reset(); | 40 file_user_blocking_thread_.reset(); |
| 34 base::RunLoop().RunUntilIdle(); | 41 base::RunLoop().RunUntilIdle(); |
| 35 file_thread_.reset(); | 42 file_thread_.reset(); |
| 36 base::RunLoop().RunUntilIdle(); | 43 base::RunLoop().RunUntilIdle(); |
| 37 db_thread_.reset(); | 44 db_thread_.reset(); |
| 38 base::RunLoop().RunUntilIdle(); | 45 base::RunLoop().RunUntilIdle(); |
| 46 // This is the point at which we normally shut down the thread pool. So flush |
| 47 // it again in case any shutdown tasks have been posted to the pool from the |
| 48 // threads above. |
| 49 BrowserThreadImpl::FlushThreadPoolHelper(); |
| 50 base::RunLoop().RunUntilIdle(); |
| 39 ui_thread_.reset(); | 51 ui_thread_.reset(); |
| 40 base::RunLoop().RunUntilIdle(); | 52 base::RunLoop().RunUntilIdle(); |
| 41 } | 53 } |
| 42 | 54 |
| 43 void TestBrowserThreadBundle::Init(int options) { | 55 void TestBrowserThreadBundle::Init(int options) { |
| 44 if (options & IO_MAINLOOP) { | 56 if (options & IO_MAINLOOP) { |
| 45 message_loop_.reset(new base::MessageLoopForIO()); | 57 message_loop_.reset(new base::MessageLoopForIO()); |
| 46 } else { | 58 } else { |
| 47 message_loop_.reset(new base::MessageLoopForUI()); | 59 message_loop_.reset(new base::MessageLoopForUI()); |
| 48 } | 60 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 if (options & REAL_IO_THREAD) { | 109 if (options & REAL_IO_THREAD) { |
| 98 io_thread_.reset(new TestBrowserThread(BrowserThread::IO)); | 110 io_thread_.reset(new TestBrowserThread(BrowserThread::IO)); |
| 99 io_thread_->StartIOThread(); | 111 io_thread_->StartIOThread(); |
| 100 } else { | 112 } else { |
| 101 io_thread_.reset( | 113 io_thread_.reset( |
| 102 new TestBrowserThread(BrowserThread::IO, message_loop_.get())); | 114 new TestBrowserThread(BrowserThread::IO, message_loop_.get())); |
| 103 } | 115 } |
| 104 } | 116 } |
| 105 | 117 |
| 106 } // namespace content | 118 } // namespace content |
| OLD | NEW |