OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/test/android/java_handler_thread_for_testing.h" | |
6 | |
7 #include "base/message_loop/message_loop.h" | |
8 | |
9 namespace base { | |
10 | |
danakj
2016/08/17 18:40:15
nit: drop whitespace
gsennton
2016/08/17 19:23:47
Done.
| |
11 namespace android { | |
12 | |
13 base::android::ScopedJavaLocalRef<jobject> | |
14 TestJavaMessageHandlerFactory::CreateMessageHandler( | |
15 JNIEnv* env, | |
16 base::MessagePump::Delegate* delegate, | |
17 MessagePumpForUI* message_pump, | |
18 WaitableEvent* test_done_event) { | |
19 return TestSystemMessageHandlerLink::createTestSystemMessageHandler( | |
20 env, delegate, message_pump, test_done_event); | |
21 } | |
22 | |
23 JavaHandlerThreadForTesting::JavaHandlerThreadForTesting( | |
24 const char* name, | |
25 base::WaitableEvent* test_done_event) | |
26 : JavaHandlerThread(name), | |
27 message_handler_factory_(new TestJavaMessageHandlerFactory()), | |
28 test_done_event_(test_done_event) {} | |
29 | |
30 JavaHandlerThreadForTesting::~JavaHandlerThreadForTesting() {} | |
danakj
2016/08/17 18:40:15
nit: = default;
gsennton
2016/08/17 19:23:47
Done.
| |
31 | |
32 void JavaHandlerThreadForTesting::StartMessageLoop() { | |
33 static_cast<MessageLoopForUI*>(message_loop_.get()) | |
34 ->StartForTesting( | |
35 message_handler_factory_.get(), | |
36 reinterpret_cast<base::WaitableEvent*>(test_done_event_)); | |
37 } | |
38 | |
39 void JavaHandlerThreadForTesting::StopMessageLoop() { | |
40 // Instead of calling MessageLoop::QuitWhenIdle here we call | |
41 // MessageLoop::QuitNow. This is because QuitWhenIdle will have no effect on | |
42 // the message loop after MessageLoop::Abort has been called (which should | |
43 // have happened at this point). | |
44 static_cast<MessageLoopForUI*>(message_loop_.get())->QuitNow(); | |
45 // The message loop must be destroyed on the thread it is attached to. | |
46 message_loop_.reset(); | |
47 } | |
48 | |
49 } // namespace base | |
50 } // namespace android | |
OLD | NEW |