| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/message_pump_android.h" | 5 #include "base/message_pump_android.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 jlong millis = | 54 jlong millis = |
| 55 (delayed_work_time - base::TimeTicks::Now()).InMillisecondsRoundedUp(); | 55 (delayed_work_time - base::TimeTicks::Now()).InMillisecondsRoundedUp(); |
| 56 Java_SystemMessageHandler_setDelayedTimer(env, obj, millis); | 56 Java_SystemMessageHandler_setDelayedTimer(env, obj, millis); |
| 57 } | 57 } |
| 58 return more_work_is_plausible; | 58 return more_work_is_plausible; |
| 59 } | 59 } |
| 60 | 60 |
| 61 namespace base { | 61 namespace base { |
| 62 | 62 |
| 63 MessagePumpForUI::MessagePumpForUI() | 63 MessagePumpForUI::MessagePumpForUI() |
| 64 : state_(NULL) { | 64 : run_loop_(NULL) { |
| 65 } | 65 } |
| 66 | 66 |
| 67 MessagePumpForUI::~MessagePumpForUI() { | 67 MessagePumpForUI::~MessagePumpForUI() { |
| 68 } | 68 } |
| 69 | 69 |
| 70 void MessagePumpForUI::Run(Delegate* delegate) { | 70 void MessagePumpForUI::Run(Delegate* delegate) { |
| 71 NOTREACHED() << "UnitTests should rely on MessagePumpForUIStub in" | 71 NOTREACHED() << "UnitTests should rely on MessagePumpForUIStub in" |
| 72 " test_stub_android.h"; | 72 " test_stub_android.h"; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void MessagePumpForUI::Start(Delegate* delegate) { | 75 void MessagePumpForUI::Start(Delegate* delegate) { |
| 76 state_ = new MessageLoop::AutoRunState(MessageLoop::current()); | 76 run_loop_ = new MessageLoop::RunLoop(); |
| 77 run_loop_->BeforeRun(); |
| 77 | 78 |
| 78 DCHECK(g_system_message_handler_obj.Get().is_null()); | 79 DCHECK(g_system_message_handler_obj.Get().is_null()); |
| 79 | 80 |
| 80 JNIEnv* env = base::android::AttachCurrentThread(); | 81 JNIEnv* env = base::android::AttachCurrentThread(); |
| 81 DCHECK(env); | 82 DCHECK(env); |
| 82 | 83 |
| 83 g_system_message_handler_obj.Get().Reset( | 84 g_system_message_handler_obj.Get().Reset( |
| 84 Java_SystemMessageHandler_create(env, reinterpret_cast<jint>(delegate))); | 85 Java_SystemMessageHandler_create(env, reinterpret_cast<jint>(delegate))); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void MessagePumpForUI::Quit() { | 88 void MessagePumpForUI::Quit() { |
| 88 if (!g_system_message_handler_obj.Get().is_null()) { | 89 if (!g_system_message_handler_obj.Get().is_null()) { |
| 89 JNIEnv* env = base::android::AttachCurrentThread(); | 90 JNIEnv* env = base::android::AttachCurrentThread(); |
| 90 DCHECK(env); | 91 DCHECK(env); |
| 91 | 92 |
| 92 Java_SystemMessageHandler_removeTimer(env, | 93 Java_SystemMessageHandler_removeTimer(env, |
| 93 g_system_message_handler_obj.Get().obj()); | 94 g_system_message_handler_obj.Get().obj()); |
| 94 g_system_message_handler_obj.Get().Reset(); | 95 g_system_message_handler_obj.Get().Reset(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 if (state_) { | 98 if (run_loop_) { |
| 98 delete state_; | 99 run_loop_->AfterRun(); |
| 99 state_ = NULL; | 100 delete run_loop_; |
| 101 run_loop_ = NULL; |
| 100 } | 102 } |
| 101 } | 103 } |
| 102 | 104 |
| 103 void MessagePumpForUI::ScheduleWork() { | 105 void MessagePumpForUI::ScheduleWork() { |
| 104 if (g_system_message_handler_obj.Get().is_null()) | 106 if (g_system_message_handler_obj.Get().is_null()) |
| 105 return; | 107 return; |
| 106 | 108 |
| 107 JNIEnv* env = base::android::AttachCurrentThread(); | 109 JNIEnv* env = base::android::AttachCurrentThread(); |
| 108 DCHECK(env); | 110 DCHECK(env); |
| 109 | 111 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 125 Java_SystemMessageHandler_setDelayedTimer(env, | 127 Java_SystemMessageHandler_setDelayedTimer(env, |
| 126 g_system_message_handler_obj.Get().obj(), millis); | 128 g_system_message_handler_obj.Get().obj(), millis); |
| 127 } | 129 } |
| 128 | 130 |
| 129 // Register native methods | 131 // Register native methods |
| 130 bool RegisterSystemMessageHandler(JNIEnv* env) { | 132 bool RegisterSystemMessageHandler(JNIEnv* env) { |
| 131 return RegisterNativesImpl(env); | 133 return RegisterNativesImpl(env); |
| 132 } | 134 } |
| 133 | 135 |
| 134 } // namespace base | 136 } // namespace base |
| OLD | NEW |