OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/test/test_browser_thread.h" | 5 #include "content/test/test_browser_thread.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
| 13 // This gives access to set_message_loop(). |
| 14 class TestBrowserThreadImpl : public BrowserThreadImpl { |
| 15 public: |
| 16 explicit TestBrowserThreadImpl(BrowserThread::ID identifier) |
| 17 : BrowserThreadImpl(identifier) { |
| 18 } |
| 19 |
| 20 TestBrowserThreadImpl(BrowserThread::ID identifier, |
| 21 MessageLoop* message_loop) |
| 22 : BrowserThreadImpl(identifier, message_loop) { |
| 23 } |
| 24 |
| 25 virtual ~TestBrowserThreadImpl() { |
| 26 Stop(); |
| 27 } |
| 28 |
| 29 void set_message_loop(MessageLoop* loop) { |
| 30 Thread::set_message_loop(loop); |
| 31 } |
| 32 |
| 33 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadImpl); |
| 35 }; |
| 36 |
13 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier) | 37 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier) |
14 : impl_(new BrowserThreadImpl(identifier)) { | 38 : impl_(new TestBrowserThreadImpl(identifier)) { |
15 } | 39 } |
16 | 40 |
17 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier, | 41 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier, |
18 MessageLoop* message_loop) | 42 MessageLoop* message_loop) |
19 : impl_(new BrowserThreadImpl(identifier, message_loop)) { | 43 : impl_(new TestBrowserThreadImpl(identifier, message_loop)) { |
20 } | 44 } |
21 | 45 |
22 TestBrowserThread::~TestBrowserThread() { | 46 TestBrowserThread::~TestBrowserThread() { |
23 Stop(); | 47 Stop(); |
24 } | 48 } |
25 | 49 |
26 bool TestBrowserThread::Start() { | 50 bool TestBrowserThread::Start() { |
27 return impl_->Start(); | 51 return impl_->Start(); |
28 } | 52 } |
29 | 53 |
30 bool TestBrowserThread::StartIOThread() { | 54 bool TestBrowserThread::StartIOThread() { |
31 base::Thread::Options options; | 55 base::Thread::Options options; |
32 options.message_loop_type = MessageLoop::TYPE_IO; | 56 options.message_loop_type = MessageLoop::TYPE_IO; |
33 return impl_->StartWithOptions(options); | 57 return impl_->StartWithOptions(options); |
34 } | 58 } |
35 | 59 |
36 void TestBrowserThread::Stop() { | 60 void TestBrowserThread::Stop() { |
37 impl_->Stop(); | 61 impl_->Stop(); |
38 } | 62 } |
39 | 63 |
40 bool TestBrowserThread::IsRunning() { | 64 bool TestBrowserThread::IsRunning() { |
41 return impl_->IsRunning(); | 65 return impl_->IsRunning(); |
42 } | 66 } |
43 | 67 |
44 base::Thread* TestBrowserThread::DeprecatedGetThreadObject() { | 68 base::Thread* TestBrowserThread::DeprecatedGetThreadObject() { |
45 return impl_.get(); | 69 return impl_.get(); |
46 } | 70 } |
47 | 71 |
| 72 void TestBrowserThread::DeprecatedSetMessageLoop(MessageLoop* loop) { |
| 73 impl_->set_message_loop(loop); |
| 74 } |
| 75 |
48 } // namespace content | 76 } // namespace content |
OLD | NEW |