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 | |
37 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier) | 13 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier) |
38 : impl_(new TestBrowserThreadImpl(identifier)) { | 14 : impl_(new BrowserThreadImpl(identifier)) { |
39 } | 15 } |
40 | 16 |
41 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier, | 17 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier, |
42 MessageLoop* message_loop) | 18 MessageLoop* message_loop) |
43 : impl_(new TestBrowserThreadImpl(identifier, message_loop)) { | 19 : impl_(new BrowserThreadImpl(identifier, message_loop)) { |
44 } | 20 } |
45 | 21 |
46 TestBrowserThread::~TestBrowserThread() { | 22 TestBrowserThread::~TestBrowserThread() { |
47 Stop(); | 23 Stop(); |
48 } | 24 } |
49 | 25 |
50 bool TestBrowserThread::Start() { | 26 bool TestBrowserThread::Start() { |
51 return impl_->Start(); | 27 return impl_->Start(); |
52 } | 28 } |
53 | 29 |
54 bool TestBrowserThread::StartIOThread() { | 30 bool TestBrowserThread::StartIOThread() { |
55 base::Thread::Options options; | 31 base::Thread::Options options; |
56 options.message_loop_type = MessageLoop::TYPE_IO; | 32 options.message_loop_type = MessageLoop::TYPE_IO; |
57 return impl_->StartWithOptions(options); | 33 return impl_->StartWithOptions(options); |
58 } | 34 } |
59 | 35 |
60 void TestBrowserThread::Stop() { | 36 void TestBrowserThread::Stop() { |
61 impl_->Stop(); | 37 impl_->Stop(); |
62 } | 38 } |
63 | 39 |
64 bool TestBrowserThread::IsRunning() { | 40 bool TestBrowserThread::IsRunning() { |
65 return impl_->IsRunning(); | 41 return impl_->IsRunning(); |
66 } | 42 } |
67 | 43 |
68 base::Thread* TestBrowserThread::DeprecatedGetThreadObject() { | 44 base::Thread* TestBrowserThread::DeprecatedGetThreadObject() { |
69 return impl_.get(); | 45 return impl_.get(); |
70 } | 46 } |
71 | 47 |
72 void TestBrowserThread::DeprecatedSetMessageLoop(MessageLoop* loop) { | |
73 impl_->set_message_loop(loop); | |
74 } | |
75 | |
76 } // namespace content | 48 } // namespace content |
OLD | NEW |