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

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

Issue 2557083002: Run ScopedTaskScheduler tasks synchronously. (Closed)
Patch Set: rebase Created 4 years 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
« no previous file with comments | « content/public/test/test_browser_thread_bundle.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/scoped_task_scheduler.h"
10 #include "content/browser/browser_thread_impl.h" 11 #include "content/browser/browser_thread_impl.h"
11 #include "content/public/test/test_browser_thread.h" 12 #include "content/public/test/test_browser_thread.h"
12 13
13 namespace content { 14 namespace content {
14 15
15 TestBrowserThreadBundle::TestBrowserThreadBundle() 16 TestBrowserThreadBundle::TestBrowserThreadBundle()
16 : TestBrowserThreadBundle(DEFAULT) {} 17 : TestBrowserThreadBundle(DEFAULT) {}
17 18
18 TestBrowserThreadBundle::TestBrowserThreadBundle(int options) 19 TestBrowserThreadBundle::TestBrowserThreadBundle(int options)
19 : options_(options), threads_started_(false) { 20 : options_(options), threads_started_(false) {
(...skipping 25 matching lines...) Expand all
45 db_thread_->Stop(); 46 db_thread_->Stop();
46 base::RunLoop().RunUntilIdle(); 47 base::RunLoop().RunUntilIdle();
47 // This is the point at which we normally shut down the thread pool. So flush 48 // This is the point at which we normally shut down the thread pool. So flush
48 // it again in case any shutdown tasks have been posted to the pool from the 49 // it again in case any shutdown tasks have been posted to the pool from the
49 // threads above. 50 // threads above.
50 BrowserThreadImpl::FlushThreadPoolHelperForTesting(); 51 BrowserThreadImpl::FlushThreadPoolHelperForTesting();
51 base::RunLoop().RunUntilIdle(); 52 base::RunLoop().RunUntilIdle();
52 ui_thread_->Stop(); 53 ui_thread_->Stop();
53 base::RunLoop().RunUntilIdle(); 54 base::RunLoop().RunUntilIdle();
54 55
56 task_scheduler_.reset();
57
55 // |message_loop_| needs to explicitly go away before fake threads in order 58 // |message_loop_| needs to explicitly go away before fake threads in order
56 // for DestructionObservers hooked to |message_loop_| to be able to invoke 59 // for DestructionObservers hooked to |message_loop_| to be able to invoke
57 // BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread(). 60 // BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread().
58 CHECK(message_loop_->IsIdleForTesting()); 61 CHECK(message_loop_->IsIdleForTesting());
59 message_loop_.reset(); 62 message_loop_.reset();
60 } 63 }
61 64
62 void TestBrowserThreadBundle::Init() { 65 void TestBrowserThreadBundle::Init() {
63 // Check for conflicting options can't have two IO threads. 66 // Check for conflicting options can't have two IO threads.
64 CHECK(!(options_ & IO_MAINLOOP) || !(options_ & REAL_IO_THREAD)); 67 CHECK(!(options_ & IO_MAINLOOP) || !(options_ & REAL_IO_THREAD));
65 // There must be a thread to start to use DONT_START_THREADS 68 // There must be a thread to start to use DONT_START_THREADS
66 CHECK((options_ & ~IO_MAINLOOP) != DONT_START_THREADS); 69 CHECK((options_ & ~IO_MAINLOOP) != DONT_START_THREADS);
67 70
68 if (options_ & IO_MAINLOOP) { 71 if (options_ & IO_MAINLOOP) {
69 message_loop_.reset(new base::MessageLoopForIO()); 72 message_loop_.reset(new base::MessageLoopForIO());
70 } else { 73 } else {
71 message_loop_.reset(new base::MessageLoopForUI()); 74 message_loop_.reset(new base::MessageLoopForUI());
72 } 75 }
73 76
77 task_scheduler_.reset(
78 new base::test::ScopedTaskScheduler(message_loop_.get()));
79
74 ui_thread_.reset( 80 ui_thread_.reset(
75 new TestBrowserThread(BrowserThread::UI, message_loop_.get())); 81 new TestBrowserThread(BrowserThread::UI, message_loop_.get()));
76 82
77 if (options_ & REAL_DB_THREAD) { 83 if (options_ & REAL_DB_THREAD) {
78 db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); 84 db_thread_.reset(new TestBrowserThread(BrowserThread::DB));
79 } else { 85 } else {
80 db_thread_.reset( 86 db_thread_.reset(
81 new TestBrowserThread(BrowserThread::DB, message_loop_.get())); 87 new TestBrowserThread(BrowserThread::DB, message_loop_.get()));
82 } 88 }
83 89
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 if (options_ & REAL_FILE_THREAD) 121 if (options_ & REAL_FILE_THREAD)
116 file_thread_->Start(); 122 file_thread_->Start();
117 123
118 if (options_ & REAL_IO_THREAD) 124 if (options_ & REAL_IO_THREAD)
119 io_thread_->StartIOThread(); 125 io_thread_->StartIOThread();
120 126
121 threads_started_ = true; 127 threads_started_ = true;
122 } 128 }
123 129
124 } // namespace content 130 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/test_browser_thread_bundle.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698