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/public/test/test_browser_thread.h" | 5 #include "content/public/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 #include "content/browser/notification_service_impl.h" | 10 #include "content/browser/notification_service_impl.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 // This gives access to set_message_loop(). | |
15 class TestBrowserThreadImpl : public BrowserThreadImpl { | 14 class TestBrowserThreadImpl : public BrowserThreadImpl { |
16 public: | 15 public: |
17 explicit TestBrowserThreadImpl(BrowserThread::ID identifier) | 16 explicit TestBrowserThreadImpl(BrowserThread::ID identifier) |
18 : BrowserThreadImpl(identifier), | 17 : BrowserThreadImpl(identifier), |
19 notification_service_(NULL) { | 18 notification_service_(NULL) { |
20 } | 19 } |
21 | 20 |
22 TestBrowserThreadImpl(BrowserThread::ID identifier, | 21 TestBrowserThreadImpl(BrowserThread::ID identifier, |
23 MessageLoop* message_loop) | 22 MessageLoop* message_loop) |
24 : BrowserThreadImpl(identifier, message_loop), | 23 : BrowserThreadImpl(identifier, message_loop), |
25 notification_service_(NULL) { | 24 notification_service_(NULL) { |
26 } | 25 } |
27 | 26 |
28 virtual ~TestBrowserThreadImpl() { | 27 virtual ~TestBrowserThreadImpl() { |
29 Stop(); | 28 Stop(); |
30 } | 29 } |
31 | 30 |
32 void set_message_loop(MessageLoop* loop) { | |
33 Thread::set_message_loop(loop); | |
34 } | |
35 | |
36 virtual void Init() OVERRIDE { | 31 virtual void Init() OVERRIDE { |
37 notification_service_ = new NotificationServiceImpl; | 32 notification_service_ = new NotificationServiceImpl; |
38 BrowserThreadImpl::Init(); | 33 BrowserThreadImpl::Init(); |
39 } | 34 } |
40 | 35 |
41 virtual void CleanUp() OVERRIDE { | 36 virtual void CleanUp() OVERRIDE { |
42 delete notification_service_; | 37 delete notification_service_; |
43 notification_service_ = NULL; | 38 notification_service_ = NULL; |
44 BrowserThreadImpl::CleanUp(); | 39 BrowserThreadImpl::CleanUp(); |
45 } | 40 } |
46 | 41 |
47 private: | 42 private: |
48 NotificationService* notification_service_; | 43 NotificationService* notification_service_; |
| 44 |
49 DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadImpl); | 45 DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadImpl); |
50 }; | 46 }; |
51 | 47 |
52 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier) | 48 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier) |
53 : impl_(new TestBrowserThreadImpl(identifier)) { | 49 : impl_(new TestBrowserThreadImpl(identifier)) { |
54 } | 50 } |
55 | 51 |
56 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier, | 52 TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier, |
57 MessageLoop* message_loop) | 53 MessageLoop* message_loop) |
58 : impl_(new TestBrowserThreadImpl(identifier, message_loop)) { | 54 : impl_(new TestBrowserThreadImpl(identifier, message_loop)) { |
(...skipping 18 matching lines...) Expand all Loading... |
77 } | 73 } |
78 | 74 |
79 bool TestBrowserThread::IsRunning() { | 75 bool TestBrowserThread::IsRunning() { |
80 return impl_->IsRunning(); | 76 return impl_->IsRunning(); |
81 } | 77 } |
82 | 78 |
83 base::Thread* TestBrowserThread::DeprecatedGetThreadObject() { | 79 base::Thread* TestBrowserThread::DeprecatedGetThreadObject() { |
84 return impl_.get(); | 80 return impl_.get(); |
85 } | 81 } |
86 | 82 |
87 void TestBrowserThread::DeprecatedSetMessageLoop(MessageLoop* loop) { | |
88 impl_->set_message_loop(loop); | |
89 } | |
90 | |
91 } // namespace content | 83 } // namespace content |
OLD | NEW |