Chromium Code Reviews| Index: base/test/android/java_handler_thread_for_testing.cc |
| diff --git a/base/test/android/java_handler_thread_for_testing.cc b/base/test/android/java_handler_thread_for_testing.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e62bd955951fa9a6fd70ffd6a5315fb0ae97300d |
| --- /dev/null |
| +++ b/base/test/android/java_handler_thread_for_testing.cc |
| @@ -0,0 +1,50 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/test/android/java_handler_thread_for_testing.h" |
| + |
| +#include "base/message_loop/message_loop.h" |
| + |
| +namespace base { |
| + |
|
danakj
2016/08/17 18:40:15
nit: drop whitespace
gsennton
2016/08/17 19:23:47
Done.
|
| +namespace android { |
| + |
| +base::android::ScopedJavaLocalRef<jobject> |
| +TestJavaMessageHandlerFactory::CreateMessageHandler( |
| + JNIEnv* env, |
| + base::MessagePump::Delegate* delegate, |
| + MessagePumpForUI* message_pump, |
| + WaitableEvent* test_done_event) { |
| + return TestSystemMessageHandlerLink::createTestSystemMessageHandler( |
| + env, delegate, message_pump, test_done_event); |
| +} |
| + |
| +JavaHandlerThreadForTesting::JavaHandlerThreadForTesting( |
| + const char* name, |
| + base::WaitableEvent* test_done_event) |
| + : JavaHandlerThread(name), |
| + message_handler_factory_(new TestJavaMessageHandlerFactory()), |
| + test_done_event_(test_done_event) {} |
| + |
| +JavaHandlerThreadForTesting::~JavaHandlerThreadForTesting() {} |
|
danakj
2016/08/17 18:40:15
nit: = default;
gsennton
2016/08/17 19:23:47
Done.
|
| + |
| +void JavaHandlerThreadForTesting::StartMessageLoop() { |
| + static_cast<MessageLoopForUI*>(message_loop_.get()) |
| + ->StartForTesting( |
| + message_handler_factory_.get(), |
| + reinterpret_cast<base::WaitableEvent*>(test_done_event_)); |
| +} |
| + |
| +void JavaHandlerThreadForTesting::StopMessageLoop() { |
| + // Instead of calling MessageLoop::QuitWhenIdle here we call |
| + // MessageLoop::QuitNow. This is because QuitWhenIdle will have no effect on |
| + // the message loop after MessageLoop::Abort has been called (which should |
| + // have happened at this point). |
| + static_cast<MessageLoopForUI*>(message_loop_.get())->QuitNow(); |
| + // The message loop must be destroyed on the thread it is attached to. |
| + message_loop_.reset(); |
| +} |
| + |
| +} // namespace base |
| +} // namespace android |