android: Rename MessagePumpForUI as MessagePumpAndroid
This is a followup to crrev.com/1270888. Currently there is only one
MessagePump class in use for Android (outside testing), and it is called
MessagePumpForUI. There is no plan to create more MessagePump classes
for Android. Though as the interfaces diverges, it would be nicer to
give the Android messagepump a distinct name, if only for easier
grep-ability.
For consistency, the testing class is also renamed: MessagePumpForUIStub
-> MessagePumpAndroidStub.
The next followup would be to change the popular constructor of the
MessagePumpAndroid to take MessagePumpType as a parameter. It is the
only MessagePump subclass that needs it.
Bug: 326417367
Change-Id: If4b5be53cc86a0ba4a195381e9c0d6581fbfc61e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5361513
Reviewed-by: Alexander Timin <[email protected]>
Commit-Queue: Egor Pasko <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1271124}
diff --git a/base/message_loop/message_pump_android.cc b/base/message_loop/message_pump_android.cc
index ba42c381..7610675 100644
--- a/base/message_loop/message_pump_android.cc
+++ b/base/message_loop/message_pump_android.cc
@@ -41,7 +41,7 @@
return 0;
DCHECK(events & ALOOPER_EVENT_INPUT);
- MessagePumpForUI* pump = reinterpret_cast<MessagePumpForUI*>(data);
+ MessagePumpAndroid* pump = reinterpret_cast<MessagePumpAndroid*>(data);
pump->OnNonDelayedLooperCallback();
return 1; // continue listening for events
}
@@ -51,7 +51,7 @@
return 0;
DCHECK(events & ALOOPER_EVENT_INPUT);
- MessagePumpForUI* pump = reinterpret_cast<MessagePumpForUI*>(data);
+ MessagePumpAndroid* pump = reinterpret_cast<MessagePumpAndroid*>(data);
pump->OnDelayedLooperCallback();
return 1; // continue listening for events
}
@@ -61,7 +61,7 @@
constexpr uint64_t kTryNativeWorkBeforeIdleBit = uint64_t(1) << 32;
} // namespace
-MessagePumpForUI::MessagePumpForUI()
+MessagePumpAndroid::MessagePumpAndroid()
: env_(base::android::AttachCurrentThread()) {
// The Android native ALooper uses epoll to poll our file descriptors and wake
// us up. We use a simple level-triggered eventfd to signal that non-delayed
@@ -85,7 +85,7 @@
&DelayedLooperCallback, reinterpret_cast<void*>(this));
}
-MessagePumpForUI::~MessagePumpForUI() {
+MessagePumpAndroid::~MessagePumpAndroid() {
DCHECK_EQ(ALooper_forThread(), looper_);
ALooper_removeFd(looper_, non_delayed_fd_);
ALooper_removeFd(looper_, delayed_fd_);
@@ -96,7 +96,7 @@
close(delayed_fd_);
}
-void MessagePumpForUI::OnDelayedLooperCallback() {
+void MessagePumpAndroid::OnDelayedLooperCallback() {
// There may be non-Chromium callbacks on the same ALooper which may have left
// a pending exception set, and ALooper does not check for this between
// callbacks. Check here, and if there's already an exception, just skip this
@@ -127,7 +127,7 @@
DoDelayedLooperWork();
}
-void MessagePumpForUI::DoDelayedLooperWork() {
+void MessagePumpAndroid::DoDelayedLooperWork() {
delayed_scheduled_time_.reset();
Delegate::NextWorkInfo next_work_info = delegate_->DoWork();
@@ -145,7 +145,7 @@
ScheduleDelayedWork(next_work_info);
}
-void MessagePumpForUI::OnNonDelayedLooperCallback() {
+void MessagePumpAndroid::OnNonDelayedLooperCallback() {
// There may be non-Chromium callbacks on the same ALooper which may have left
// a pending exception set, and ALooper does not check for this between
// callbacks. Check here, and if there's already an exception, just skip this
@@ -174,7 +174,7 @@
DoNonDelayedLooperWork(do_idle_work);
}
-void MessagePumpForUI::DoNonDelayedLooperWork(bool do_idle_work) {
+void MessagePumpAndroid::DoNonDelayedLooperWork(bool do_idle_work) {
// Note: We can't skip DoWork() even if |do_idle_work| is true here (i.e. no
// additional ScheduleWork() since yielding to native) as delayed tasks might
// have come in and we need to re-sample |next_work_info|.
@@ -247,7 +247,7 @@
}
}
-void MessagePumpForUI::DoIdleWork() {
+void MessagePumpAndroid::DoIdleWork() {
if (delegate_->DoIdleWork()) {
// If DoIdleWork() resulted in any work, we're not idle yet. We need to pump
// the loop here because we may in fact be idle after doing idle work
@@ -256,11 +256,11 @@
}
}
-void MessagePumpForUI::Run(Delegate* delegate) {
+void MessagePumpAndroid::Run(Delegate* delegate) {
CHECK(false) << "Unexpected call to Run()";
}
-void MessagePumpForUI::Attach(Delegate* delegate) {
+void MessagePumpAndroid::Attach(Delegate* delegate) {
DCHECK(!quit_);
// Since the Looper is controlled by the UI thread or JavaHandlerThread, we
@@ -276,7 +276,7 @@
NOTREACHED();
}
-void MessagePumpForUI::Quit() {
+void MessagePumpAndroid::Quit() {
if (quit_)
return;
@@ -297,11 +297,11 @@
}
}
-void MessagePumpForUI::ScheduleWork() {
+void MessagePumpAndroid::ScheduleWork() {
ScheduleWorkInternal(/*do_idle_work=*/false);
}
-void MessagePumpForUI::ScheduleWorkInternal(bool do_idle_work) {
+void MessagePumpAndroid::ScheduleWorkInternal(bool do_idle_work) {
// Write (add) |value| to the eventfd. This tells the Looper to wake up and
// call our callback, allowing us to run tasks. This also allows us to detect,
// when we clear the fd, whether additional work was scheduled after we
@@ -322,7 +322,7 @@
DPCHECK(ret >= 0);
}
-void MessagePumpForUI::ScheduleDelayedWork(
+void MessagePumpAndroid::ScheduleDelayedWork(
const Delegate::NextWorkInfo& next_work_info) {
if (ShouldQuit())
return;
@@ -347,7 +347,7 @@
DPCHECK(ret >= 0);
}
-void MessagePumpForUI::QuitWhenIdle(base::OnceClosure callback) {
+void MessagePumpAndroid::QuitWhenIdle(base::OnceClosure callback) {
DCHECK(!on_quit_callback_);
DCHECK(run_loop_);
on_quit_callback_ = std::move(callback);
@@ -356,11 +356,11 @@
ScheduleWork();
}
-MessagePump::Delegate* MessagePumpForUI::SetDelegate(Delegate* delegate) {
+MessagePump::Delegate* MessagePumpAndroid::SetDelegate(Delegate* delegate) {
return std::exchange(delegate_, delegate);
}
-bool MessagePumpForUI::SetQuit(bool quit) {
+bool MessagePumpAndroid::SetQuit(bool quit) {
return std::exchange(quit_, quit);
}