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

Side by Side Diff: ios/web/test/test_web_thread_bundle.cc

Issue 1406983008: [iOS] ios/web no longer depends on content::BrowserThread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 1 month 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 | « ios/web/test/test_web_thread_adapter.cc ('k') | ios/web/test/test_web_thread_bundle_adapter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ios/web/public/test/test_web_thread_bundle.h" 5 #include "ios/web/public/test/test_web_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 "ios/web/public/test/test_web_thread.h" 9 #include "ios/web/public/test/test_web_thread.h"
10 #include "ios/web/web_thread_impl.h" 10 #include "ios/web/web_thread_impl.h"
11 11
12 namespace web { 12 namespace web {
13 13
14 // Implmentation of TestWebThreadBundle using TestWebThreads. 14 TestWebThreadBundle::TestWebThreadBundle() {
15 // TODO(stuartmorgan): The only reason this is a separate impl class is to
16 // keep the implementation details out of the header so that it can be shared
17 // with the adapter implementation that uses TestBrowserThreadBundle. Once that
18 // version is gone, fold this into TestWebThreadBundle.
19 class TestWebThreadBundleImpl {
20 public:
21 explicit TestWebThreadBundleImpl();
22 explicit TestWebThreadBundleImpl(int options);
23
24 ~TestWebThreadBundleImpl();
25
26 private:
27 void Init(int options);
28
29 scoped_ptr<base::MessageLoop> message_loop_;
30 scoped_ptr<TestWebThread> ui_thread_;
31 scoped_ptr<TestWebThread> db_thread_;
32 scoped_ptr<TestWebThread> file_thread_;
33 scoped_ptr<TestWebThread> file_user_blocking_thread_;
34 scoped_ptr<TestWebThread> cache_thread_;
35 scoped_ptr<TestWebThread> io_thread_;
36
37 DISALLOW_COPY_AND_ASSIGN(TestWebThreadBundleImpl);
38 };
39
40 TestWebThreadBundleImpl::TestWebThreadBundleImpl() {
41 Init(TestWebThreadBundle::DEFAULT); 15 Init(TestWebThreadBundle::DEFAULT);
42 } 16 }
43 17
44 TestWebThreadBundleImpl::TestWebThreadBundleImpl(int options) { 18 TestWebThreadBundle::TestWebThreadBundle(int options) {
45 Init(options); 19 Init(options);
46 } 20 }
47 21
48 TestWebThreadBundleImpl::~TestWebThreadBundleImpl() { 22 TestWebThreadBundle::~TestWebThreadBundle() {
49 // To avoid memory leaks, ensure that any tasks posted to the blocking pool 23 // To avoid memory leaks, ensure that any tasks posted to the blocking pool
50 // via PostTaskAndReply are able to reply back to the originating thread, by 24 // via PostTaskAndReply are able to reply back to the originating thread, by
51 // flushing the blocking pool while the browser threads still exist. 25 // flushing the blocking pool while the browser threads still exist.
52 base::RunLoop().RunUntilIdle(); 26 base::RunLoop().RunUntilIdle();
53 WebThreadImpl::FlushThreadPoolHelperForTesting(); 27 WebThreadImpl::FlushThreadPoolHelperForTesting();
54 28
55 // 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
56 // 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
57 // automatically flush the message loop, so do it manually. 31 // automatically flush the message loop, so do it manually.
58 // See http://crbug.com/247525 for discussion. 32 // See http://crbug.com/247525 for discussion.
(...skipping 10 matching lines...) Expand all
69 base::RunLoop().RunUntilIdle(); 43 base::RunLoop().RunUntilIdle();
70 // This is the point at which the thread pool is normally shut down. So flush 44 // This is the point at which the thread pool is normally shut down. So flush
71 // it again in case any shutdown tasks have been posted to the pool from the 45 // it again in case any shutdown tasks have been posted to the pool from the
72 // threads above. 46 // threads above.
73 WebThreadImpl::FlushThreadPoolHelperForTesting(); 47 WebThreadImpl::FlushThreadPoolHelperForTesting();
74 base::RunLoop().RunUntilIdle(); 48 base::RunLoop().RunUntilIdle();
75 ui_thread_.reset(); 49 ui_thread_.reset();
76 base::RunLoop().RunUntilIdle(); 50 base::RunLoop().RunUntilIdle();
77 } 51 }
78 52
79 void TestWebThreadBundleImpl::Init(int options) { 53 void TestWebThreadBundle::Init(int options) {
80 if (options & TestWebThreadBundle::IO_MAINLOOP) { 54 if (options & TestWebThreadBundle::IO_MAINLOOP) {
81 message_loop_.reset(new base::MessageLoopForIO()); 55 message_loop_.reset(new base::MessageLoopForIO());
82 } else { 56 } else {
83 message_loop_.reset(new base::MessageLoopForUI()); 57 message_loop_.reset(new base::MessageLoopForUI());
84 } 58 }
85 59
86 ui_thread_.reset(new TestWebThread(WebThread::UI, message_loop_.get())); 60 ui_thread_.reset(new TestWebThread(WebThread::UI, message_loop_.get()));
87 61
88 if (options & TestWebThreadBundle::REAL_DB_THREAD) { 62 if (options & TestWebThreadBundle::REAL_DB_THREAD) {
89 db_thread_.reset(new TestWebThread(WebThread::DB)); 63 db_thread_.reset(new TestWebThread(WebThread::DB));
(...skipping 27 matching lines...) Expand all
117 } 91 }
118 92
119 if (options & TestWebThreadBundle::REAL_IO_THREAD) { 93 if (options & TestWebThreadBundle::REAL_IO_THREAD) {
120 io_thread_.reset(new TestWebThread(WebThread::IO)); 94 io_thread_.reset(new TestWebThread(WebThread::IO));
121 io_thread_->StartIOThread(); 95 io_thread_->StartIOThread();
122 } else { 96 } else {
123 io_thread_.reset(new TestWebThread(WebThread::IO, message_loop_.get())); 97 io_thread_.reset(new TestWebThread(WebThread::IO, message_loop_.get()));
124 } 98 }
125 } 99 }
126 100
127 #pragma mark - TestWebThreadBundle
128
129 TestWebThreadBundle::TestWebThreadBundle()
130 : impl_(new TestWebThreadBundleImpl()) {
131 }
132
133 TestWebThreadBundle::TestWebThreadBundle(int options)
134 : impl_(new TestWebThreadBundleImpl(options)) {
135 }
136
137 TestWebThreadBundle::~TestWebThreadBundle() {
138 }
139
140 } // namespace web 101 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/test/test_web_thread_adapter.cc ('k') | ios/web/test/test_web_thread_bundle_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698