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 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_ | 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_ |
6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_ | 6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 | 9 |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/message_loop/message_pump.h" | 14 #include "base/message_loop/message_pump.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 | 17 |
18 namespace android { | |
19 class JavaMessageHandlerFactory; | |
20 } | |
21 | |
18 class RunLoop; | 22 class RunLoop; |
19 class TimeTicks; | 23 class TimeTicks; |
24 class WaitableEvent; | |
20 | 25 |
21 // This class implements a MessagePump needed for TYPE_UI MessageLoops on | 26 // This class implements a MessagePump needed for TYPE_UI MessageLoops on |
22 // OS_ANDROID platform. | 27 // OS_ANDROID platform. |
23 class BASE_EXPORT MessagePumpForUI : public MessagePump { | 28 class BASE_EXPORT MessagePumpForUI : public MessagePump { |
24 public: | 29 public: |
25 MessagePumpForUI(); | 30 MessagePumpForUI(); |
26 ~MessagePumpForUI() override; | 31 ~MessagePumpForUI() override; |
27 | 32 |
28 void Run(Delegate* delegate) override; | 33 void Run(Delegate* delegate) override; |
29 void Quit() override; | 34 void Quit() override; |
30 void ScheduleWork() override; | 35 void ScheduleWork() override; |
31 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override; | 36 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override; |
32 | 37 |
33 virtual void Start(Delegate* delegate); | 38 virtual void Start(Delegate* delegate); |
39 void StartForUnitTest(Delegate* delegate, | |
40 base::android::JavaMessageHandlerFactory* factory, | |
41 WaitableEvent* test_done_event); | |
42 | |
43 // We call Abort when there is a pending JNI exception, meaning that the | |
44 // current thread will crash when we return to Java. | |
45 // We can't call any jni-methods before returning to Java as we would then | |
nyquist
2016/08/18 15:50:02
Nit: JNI and missing period at end of sentence.
gsennton
2016/08/18 18:56:54
Done.
| |
46 // cause a native crash (instead of the original Java crash) | |
47 void Abort() { should_abort_ = true; } | |
48 bool ShouldAbort() const { return should_abort_; } | |
34 | 49 |
35 static bool RegisterBindings(JNIEnv* env); | 50 static bool RegisterBindings(JNIEnv* env); |
36 | 51 |
37 private: | 52 private: |
53 JNIEnv* StartInternal(); | |
54 | |
38 RunLoop* run_loop_; | 55 RunLoop* run_loop_; |
39 base::android::ScopedJavaGlobalRef<jobject> system_message_handler_obj_; | 56 base::android::ScopedJavaGlobalRef<jobject> system_message_handler_obj_; |
57 bool should_abort_; | |
40 | 58 |
41 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); | 59 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); |
42 }; | 60 }; |
43 | 61 |
44 } // namespace base | 62 } // namespace base |
45 | 63 |
46 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_ | 64 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_ |
OLD | NEW |