aboutsummaryrefslogtreecommitdiff
path: root/base/message_loop/message_pump_android.cc
diff options
context:
space:
mode:
authorJay Civelli <jcivelli@google.com>2017-03-29 16:17:00 -0700
committerJay Civelli <jcivelli@google.com>2017-07-24 13:31:43 -0700
commit8ac9103e05b66812c25348943383f9365d1ce3e0 (patch)
tree63a61c9698e719de1a24de6fca21e29401f92842 /base/message_loop/message_pump_android.cc
parent24543f227908c2e949bb9a15b40276f59fcc9a0a (diff)
downloadlibmojo-8ac9103e05b66812c25348943383f9365d1ce3e0.tar.gz
libmojo: Uprev the library to r456626 from Chromium
Pulled the latest and greatest version of libmojo from Chromium. The merge was done against r456626 which corresponds to git commit 08266b3fca707804065a2cfd60331722ade41969 of Mar 14, 2017 Notable changes are: - generated binding files are now split in 2 files, interface.mojom.h and interface.mojom-shared.h Change-Id: Idcfd27310e2c9d3c452b671c7ff7a755c3963618
Diffstat (limited to 'base/message_loop/message_pump_android.cc')
-rw-r--r--base/message_loop/message_pump_android.cc56
1 files changed, 44 insertions, 12 deletions
diff --git a/base/message_loop/message_pump_android.cc b/base/message_loop/message_pump_android.cc
index a0eee12..bedb205 100644
--- a/base/message_loop/message_pump_android.cc
+++ b/base/message_loop/message_pump_android.cc
@@ -6,14 +6,17 @@
#include <jni.h>
+#include "base/android/java_message_handler_factory.h"
#include "base/android/jni_android.h"
#include "base/android/scoped_java_ref.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/time/time.h"
#include "jni/SystemMessageHandler_jni.h"
+using base::android::JavaParamRef;
using base::android::ScopedJavaLocalRef;
// ----------------------------------------------------------------------------
@@ -24,10 +27,14 @@ using base::android::ScopedJavaLocalRef;
static void DoRunLoopOnce(JNIEnv* env,
const JavaParamRef<jobject>& obj,
jlong native_delegate,
+ jlong native_message_pump,
jlong delayed_scheduled_time_ticks) {
base::MessagePump::Delegate* delegate =
reinterpret_cast<base::MessagePump::Delegate*>(native_delegate);
DCHECK(delegate);
+ base::MessagePumpForUI* pump =
+ reinterpret_cast<base::MessagePumpForUI*>(native_message_pump);
+ DCHECK(pump);
// This is based on MessagePumpForUI::DoRunLoop() from desktop.
// Note however that our system queue is handled in the java side.
// In desktop we inspect and process a single system message and then
@@ -35,6 +42,11 @@ static void DoRunLoopOnce(JNIEnv* env,
// On Android, the java message queue may contain messages for other handlers
// that will be processed before calling here again.
bool did_work = delegate->DoWork();
+ if (pump->ShouldAbort()) {
+ // There is a pending JNI exception, return to Java so that the exception is
+ // thrown correctly.
+ return;
+ }
// In the java side, |SystemMessageHandler| keeps a single "delayed" message.
// It's an expensive operation to |removeMessage| there, so this is optimized
@@ -60,6 +72,11 @@ static void DoRunLoopOnce(JNIEnv* env,
// avoid comparisons with TimeDelta / Now() (expensive).
base::TimeTicks next_delayed_work_time;
did_work |= delegate->DoDelayedWork(&next_delayed_work_time);
+ if (pump->ShouldAbort()) {
+ // There is a pending JNI exception, return to Java so that the exception is
+ // thrown correctly
+ return;
+ }
if (!next_delayed_work_time.is_null()) {
// Schedule a new message if there's nothing already scheduled or there's a
@@ -81,13 +98,16 @@ static void DoRunLoopOnce(JNIEnv* env,
return;
delegate->DoIdleWork();
+ // Note that we do not check whether we should abort here since we are
+ // returning to the JVM anyway. If, in the future, we add any more code after
+ // the call to DoIdleWork() here, we should add an abort-check and return
+ // immediately if the check passes.
}
namespace base {
MessagePumpForUI::MessagePumpForUI()
- : run_loop_(NULL) {
-}
+ : run_loop_(nullptr), should_abort_(false) {}
MessagePumpForUI::~MessagePumpForUI() {
}
@@ -97,7 +117,7 @@ void MessagePumpForUI::Run(Delegate* delegate) {
" test_stub_android.h";
}
-void MessagePumpForUI::Start(Delegate* delegate) {
+JNIEnv* MessagePumpForUI::StartInternal() {
run_loop_ = new RunLoop();
// Since the RunLoop was just created above, BeforeRun should be guaranteed to
// return true (it only returns false if the RunLoop has been Quit already).
@@ -108,10 +128,23 @@ void MessagePumpForUI::Start(Delegate* delegate) {
JNIEnv* env = base::android::AttachCurrentThread();
DCHECK(env);
+ return env;
+}
+
+void MessagePumpForUI::Start(Delegate* delegate) {
+ JNIEnv* env = StartInternal();
+ system_message_handler_obj_.Reset(Java_SystemMessageHandler_create(
+ env, reinterpret_cast<intptr_t>(delegate),
+ reinterpret_cast<intptr_t>(this)));
+}
+void MessagePumpForUI::StartForUnitTest(
+ Delegate* delegate,
+ base::android::JavaMessageHandlerFactory* factory,
+ WaitableEvent* test_done_event) {
+ JNIEnv* env = StartInternal();
system_message_handler_obj_.Reset(
- Java_SystemMessageHandler_create(
- env, reinterpret_cast<intptr_t>(delegate)));
+ factory->CreateMessageHandler(env, delegate, this, test_done_event));
}
void MessagePumpForUI::Quit() {
@@ -119,8 +152,8 @@ void MessagePumpForUI::Quit() {
JNIEnv* env = base::android::AttachCurrentThread();
DCHECK(env);
- Java_SystemMessageHandler_removeAllPendingMessages(env,
- system_message_handler_obj_.obj());
+ Java_SystemMessageHandler_removeAllPendingMessages(
+ env, system_message_handler_obj_);
system_message_handler_obj_.Reset();
}
@@ -137,8 +170,7 @@ void MessagePumpForUI::ScheduleWork() {
JNIEnv* env = base::android::AttachCurrentThread();
DCHECK(env);
- Java_SystemMessageHandler_scheduleWork(env,
- system_message_handler_obj_.obj());
+ Java_SystemMessageHandler_scheduleWork(env, system_message_handler_obj_);
}
void MessagePumpForUI::ScheduleDelayedWork(const TimeTicks& delayed_work_time) {
@@ -151,9 +183,9 @@ void MessagePumpForUI::ScheduleDelayedWork(const TimeTicks& delayed_work_time) {
(delayed_work_time - TimeTicks::Now()).InMillisecondsRoundedUp();
// Note that we're truncating to milliseconds as required by the java side,
// even though delayed_work_time is microseconds resolution.
- Java_SystemMessageHandler_scheduleDelayedWork(env,
- system_message_handler_obj_.obj(),
- delayed_work_time.ToInternalValue(), millis);
+ Java_SystemMessageHandler_scheduleDelayedWork(
+ env, system_message_handler_obj_, delayed_work_time.ToInternalValue(),
+ millis);
}
// static