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

Side by Side Diff: content/public/test/test_browser_thread_bundle.cc

Issue 2767923002: Always use an async TaskScheduler in TestBrowserThreadBundle. (Closed)
Patch Set: self-review Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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
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();
62 60
63 // |message_loop_| needs to explicitly go away before fake threads in order 61 // |message_loop_| needs to explicitly go away before fake threads in order
64 // for DestructionObservers hooked to |message_loop_| to be able to invoke 62 // for DestructionObservers hooked to |message_loop_| to be able to invoke
65 // BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread(). 63 // BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread().
66 CHECK(message_loop_->IsIdleForTesting()); 64 CHECK(message_loop_->IsIdleForTesting());
67 message_loop_.reset(); 65 message_loop_.reset();
68 } 66 }
69 67
70 void TestBrowserThreadBundle::Init() { 68 void TestBrowserThreadBundle::Init() {
71 // Check for conflicting options can't have two IO threads. 69 // Check for conflicting options can't have two IO threads.
(...skipping 13 matching lines...) Expand all
85 new TestBrowserThread(BrowserThread::UI, message_loop_.get())); 83 new TestBrowserThread(BrowserThread::UI, message_loop_.get()));
86 84
87 if (!(options_ & DONT_CREATE_THREADS)) 85 if (!(options_ & DONT_CREATE_THREADS))
88 CreateThreads(); 86 CreateThreads();
89 } 87 }
90 88
91 // This method mimics the work done in BrowserMainLoop::CreateThreads(). 89 // This method mimics the work done in BrowserMainLoop::CreateThreads().
92 void TestBrowserThreadBundle::CreateThreads() { 90 void TestBrowserThreadBundle::CreateThreads() {
93 DCHECK(!threads_created_); 91 DCHECK(!threads_created_);
94 92
95 if (options_ & REAL_TASK_SCHEDULER) { 93 scoped_async_task_scheduler_ =
96 scoped_async_task_scheduler_ = 94 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 95
103 if (options_ & REAL_DB_THREAD) { 96 if (options_ & REAL_DB_THREAD) {
104 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); 97 db_thread_.reset(new TestBrowserThread(BrowserThread::DB));
105 db_thread_->Start(); 98 db_thread_->Start();
106 } else { 99 } else {
107 db_thread_.reset( 100 db_thread_.reset(
108 new TestBrowserThread(BrowserThread::DB, message_loop_.get())); 101 new TestBrowserThread(BrowserThread::DB, message_loop_.get()));
109 } 102 }
110 103
111 if (options_ & REAL_FILE_THREAD) { 104 if (options_ & REAL_FILE_THREAD) {
(...skipping 16 matching lines...) Expand all
128 io_thread_->StartIOThread(); 121 io_thread_->StartIOThread();
129 } else { 122 } else {
130 io_thread_.reset( 123 io_thread_.reset(
131 new TestBrowserThread(BrowserThread::IO, message_loop_.get())); 124 new TestBrowserThread(BrowserThread::IO, message_loop_.get()));
132 } 125 }
133 126
134 threads_created_ = true; 127 threads_created_ = true;
135 } 128 }
136 129
137 } // namespace content 130 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698