Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: content/public/test/test_browser_thread_bundle.cc

Issue 2628903002: Change DONT_START_THREADS to DONT_CREATE_THREADS in TestBrowserThreadBundle. (Closed)
Patch Set: fix test error Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/test/test_browser_thread_bundle.cc
diff --git a/content/public/test/test_browser_thread_bundle.cc b/content/public/test/test_browser_thread_bundle.cc
index 211ecdfa4ab099dc04ba6b1c6f5f2ce8704b6ab9..a7fdd7602757462d7d6ec8245224ee7b84f4e93a 100644
--- a/content/public/test/test_browser_thread_bundle.cc
+++ b/content/public/test/test_browser_thread_bundle.cc
@@ -17,11 +17,13 @@ TestBrowserThreadBundle::TestBrowserThreadBundle()
: TestBrowserThreadBundle(DEFAULT) {}
TestBrowserThreadBundle::TestBrowserThreadBundle(int options)
- : options_(options), threads_started_(false) {
+ : options_(options), threads_created_(false) {
Init();
}
TestBrowserThreadBundle::~TestBrowserThreadBundle() {
+ DCHECK(threads_created_);
+
// To avoid memory leaks, we must ensure that any tasks posted to the blocking
// pool via PostTaskAndReply are able to reply back to the originating thread.
// Thus we must flush the blocking pool while the browser threads still exist.
@@ -65,8 +67,8 @@ TestBrowserThreadBundle::~TestBrowserThreadBundle() {
void TestBrowserThreadBundle::Init() {
// Check for conflicting options can't have two IO threads.
CHECK(!(options_ & IO_MAINLOOP) || !(options_ & REAL_IO_THREAD));
- // There must be a thread to start to use DONT_START_THREADS
- CHECK((options_ & ~IO_MAINLOOP) != DONT_START_THREADS);
+ // There must be a thread to start to use DONT_CREATE_THREADS
+ CHECK((options_ & ~IO_MAINLOOP) != DONT_CREATE_THREADS);
if (options_ & IO_MAINLOOP) {
message_loop_.reset(new base::MessageLoopForIO());
@@ -74,14 +76,22 @@ void TestBrowserThreadBundle::Init() {
message_loop_.reset(new base::MessageLoopForUI());
}
- task_scheduler_.reset(
- new base::test::ScopedTaskScheduler(message_loop_.get()));
-
ui_thread_.reset(
new TestBrowserThread(BrowserThread::UI, message_loop_.get()));
gab 2017/01/12 19:47:35 Why is the UI thread unconditionally created?
fdoray 2017/01/12 19:59:10 TestBrowserThreadBundle::CreateThreads() mimics Br
gab 2017/01/12 20:13:27 I see, then add a comment to that effect here and
fdoray 2017/01/12 21:02:56 Done.
+ if (!(options_ & DONT_CREATE_THREADS))
+ CreateThreads();
+}
+
+void TestBrowserThreadBundle::CreateThreads() {
+ DCHECK(!threads_created_);
+
+ task_scheduler_.reset(
+ new base::test::ScopedTaskScheduler(message_loop_.get()));
+
if (options_ & REAL_DB_THREAD) {
db_thread_.reset(new TestBrowserThread(BrowserThread::DB));
+ db_thread_->Start();
} else {
db_thread_.reset(
new TestBrowserThread(BrowserThread::DB, message_loop_.get()));
@@ -89,6 +99,7 @@ void TestBrowserThreadBundle::Init() {
if (options_ & REAL_FILE_THREAD) {
file_thread_.reset(new TestBrowserThread(BrowserThread::FILE));
+ file_thread_->Start();
} else {
file_thread_.reset(
new TestBrowserThread(BrowserThread::FILE, message_loop_.get()));
@@ -103,28 +114,13 @@ void TestBrowserThreadBundle::Init() {
if (options_ & REAL_IO_THREAD) {
io_thread_.reset(new TestBrowserThread(BrowserThread::IO));
+ io_thread_->StartIOThread();
} else {
io_thread_.reset(
new TestBrowserThread(BrowserThread::IO, message_loop_.get()));
}
- if (!(options_ & DONT_START_THREADS))
- Start();
-}
-
-void TestBrowserThreadBundle::Start() {
- DCHECK(!threads_started_);
-
- if (options_ & REAL_DB_THREAD)
- db_thread_->Start();
-
- if (options_ & REAL_FILE_THREAD)
- file_thread_->Start();
-
- if (options_ & REAL_IO_THREAD)
- io_thread_->StartIOThread();
-
- threads_started_ = true;
+ threads_created_ = true;
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698