mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-12 00:50:40 +00:00
Bug 1826530 - Break platform-dependent MessagePumps out to platform-specific files. r=ipc-reviewers,nika
This makes things a bit clearer when adding the mac implementation. Differential Revision: https://phabricator.services.mozilla.com/D175100
This commit is contained in:
parent
8e1b221afc
commit
919c5ee057
@ -335,100 +335,6 @@ void MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate* aDelegate) {
|
||||
keep_running_ = true;
|
||||
}
|
||||
|
||||
#if defined(XP_WIN)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(MessagePumpForNonMainUIThreads, MessagePump)
|
||||
NS_IMPL_RELEASE_INHERITED(MessagePumpForNonMainUIThreads, MessagePump)
|
||||
NS_IMPL_QUERY_INTERFACE(MessagePumpForNonMainUIThreads, nsIThreadObserver)
|
||||
|
||||
# define CHECK_QUIT_STATE \
|
||||
{ \
|
||||
if (state_->should_quit) { \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
|
||||
void MessagePumpForNonMainUIThreads::DoRunLoop() {
|
||||
MOZ_RELEASE_ASSERT(!NS_IsMainThread(),
|
||||
"Use mozilla::ipc::MessagePump instead!");
|
||||
|
||||
// If this is a chromium thread and no nsThread is associated
|
||||
// with it, this call will create a new nsThread.
|
||||
nsIThread* thread = NS_GetCurrentThread();
|
||||
MOZ_ASSERT(thread);
|
||||
|
||||
// Set the main thread observer so we can wake up when
|
||||
// xpcom events need to get processed.
|
||||
nsCOMPtr<nsIThreadInternal> ti(do_QueryInterface(thread));
|
||||
MOZ_ASSERT(ti);
|
||||
ti->SetObserver(this);
|
||||
|
||||
base::ScopedNSAutoreleasePool autoReleasePool;
|
||||
for (;;) {
|
||||
autoReleasePool.Recycle();
|
||||
|
||||
bool didWork = NS_ProcessNextEvent(thread, false);
|
||||
|
||||
didWork |= ProcessNextWindowsMessage();
|
||||
CHECK_QUIT_STATE
|
||||
|
||||
didWork |= state_->delegate->DoWork();
|
||||
CHECK_QUIT_STATE
|
||||
|
||||
didWork |= state_->delegate->DoDelayedWork(&delayed_work_time_);
|
||||
if (didWork && delayed_work_time_.is_null()) {
|
||||
KillTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this));
|
||||
}
|
||||
CHECK_QUIT_STATE
|
||||
|
||||
if (didWork) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DebugOnly<bool> didIdleWork = state_->delegate->DoIdleWork();
|
||||
MOZ_ASSERT(!didIdleWork);
|
||||
CHECK_QUIT_STATE
|
||||
|
||||
SetInWait();
|
||||
bool hasWork = NS_HasPendingEvents(thread);
|
||||
if (didWork || hasWork) {
|
||||
ClearInWait();
|
||||
continue;
|
||||
}
|
||||
WaitForWork(); // Calls MsgWaitForMultipleObjectsEx(QS_ALLINPUT)
|
||||
ClearInWait();
|
||||
}
|
||||
|
||||
ClearInWait();
|
||||
|
||||
ti->SetObserver(nullptr);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MessagePumpForNonMainUIThreads::OnDispatchedEvent() {
|
||||
// If our thread is sleeping in DoRunLoop's call to WaitForWork() and an
|
||||
// event posts to the nsIThread event queue - break our thread out of
|
||||
// chromium's WaitForWork.
|
||||
if (GetInWait()) {
|
||||
ScheduleWork();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MessagePumpForNonMainUIThreads::OnProcessNextEvent(nsIThreadInternal* thread,
|
||||
bool mayWait) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MessagePumpForNonMainUIThreads::AfterProcessNextEvent(nsIThreadInternal* thread,
|
||||
bool eventWasProcessed) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif // XP_WIN
|
||||
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
void MessagePumpForAndroidUI::Run(Delegate* delegate) {
|
||||
MOZ_CRASH("MessagePumpForAndroidUI should never be Run.");
|
||||
|
26
ipc/glue/MessagePump_android.cpp
Normal file
26
ipc/glue/MessagePump_android.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "MessagePump.h"
|
||||
|
||||
namespace mozilla::ipc {
|
||||
void MessagePumpForAndroidUI::Run(Delegate* delegate) {
|
||||
MOZ_CRASH("MessagePumpForAndroidUI should never be Run.");
|
||||
}
|
||||
|
||||
void MessagePumpForAndroidUI::Quit() {
|
||||
MOZ_CRASH("MessagePumpForAndroidUI should never be Quit.");
|
||||
}
|
||||
|
||||
void MessagePumpForAndroidUI::ScheduleWork() {
|
||||
MOZ_CRASH("MessagePumpForAndroidUI should never ScheduleWork");
|
||||
}
|
||||
|
||||
void MessagePumpForAndroidUI::ScheduleDelayedWork(
|
||||
const TimeTicks& delayed_work_time) {
|
||||
MOZ_CRASH("MessagePumpForAndroidUI should never ScheduleDelayedWork");
|
||||
}
|
||||
} // namespace mozilla::ipc
|
101
ipc/glue/MessagePump_windows.cpp
Normal file
101
ipc/glue/MessagePump_windows.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "MessagePump.h"
|
||||
|
||||
#include "base/scoped_nsautorelease_pool.h"
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(MessagePumpForNonMainUIThreads, MessagePump)
|
||||
NS_IMPL_RELEASE_INHERITED(MessagePumpForNonMainUIThreads, MessagePump)
|
||||
NS_IMPL_QUERY_INTERFACE(MessagePumpForNonMainUIThreads, nsIThreadObserver)
|
||||
|
||||
#define CHECK_QUIT_STATE \
|
||||
{ \
|
||||
if (state_->should_quit) { \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
|
||||
void MessagePumpForNonMainUIThreads::DoRunLoop() {
|
||||
MOZ_RELEASE_ASSERT(!NS_IsMainThread(),
|
||||
"Use mozilla::ipc::MessagePump instead!");
|
||||
|
||||
// If this is a chromium thread and no nsThread is associated
|
||||
// with it, this call will create a new nsThread.
|
||||
nsIThread* thread = NS_GetCurrentThread();
|
||||
MOZ_ASSERT(thread);
|
||||
|
||||
// Set the main thread observer so we can wake up when
|
||||
// xpcom events need to get processed.
|
||||
nsCOMPtr<nsIThreadInternal> ti(do_QueryInterface(thread));
|
||||
MOZ_ASSERT(ti);
|
||||
ti->SetObserver(this);
|
||||
|
||||
base::ScopedNSAutoreleasePool autoReleasePool;
|
||||
for (;;) {
|
||||
autoReleasePool.Recycle();
|
||||
|
||||
bool didWork = NS_ProcessNextEvent(thread, false);
|
||||
|
||||
didWork |= ProcessNextWindowsMessage();
|
||||
CHECK_QUIT_STATE
|
||||
|
||||
didWork |= state_->delegate->DoWork();
|
||||
CHECK_QUIT_STATE
|
||||
|
||||
didWork |= state_->delegate->DoDelayedWork(&delayed_work_time_);
|
||||
if (didWork && delayed_work_time_.is_null()) {
|
||||
KillTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this));
|
||||
}
|
||||
CHECK_QUIT_STATE
|
||||
|
||||
if (didWork) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DebugOnly<bool> didIdleWork = state_->delegate->DoIdleWork();
|
||||
MOZ_ASSERT(!didIdleWork);
|
||||
CHECK_QUIT_STATE
|
||||
|
||||
SetInWait();
|
||||
bool hasWork = NS_HasPendingEvents(thread);
|
||||
if (didWork || hasWork) {
|
||||
ClearInWait();
|
||||
continue;
|
||||
}
|
||||
WaitForWork(); // Calls MsgWaitForMultipleObjectsEx(QS_ALLINPUT)
|
||||
ClearInWait();
|
||||
}
|
||||
|
||||
ClearInWait();
|
||||
|
||||
ti->SetObserver(nullptr);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MessagePumpForNonMainUIThreads::OnDispatchedEvent() {
|
||||
// If our thread is sleeping in DoRunLoop's call to WaitForWork() and an
|
||||
// event posts to the nsIThread event queue - break our thread out of
|
||||
// chromium's WaitForWork.
|
||||
if (GetInWait()) {
|
||||
ScheduleWork();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MessagePumpForNonMainUIThreads::OnProcessNextEvent(nsIThreadInternal* thread,
|
||||
bool mayWait) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MessagePumpForNonMainUIThreads::AfterProcessNextEvent(nsIThreadInternal* thread,
|
||||
bool eventWasProcessed) {
|
||||
return NS_OK;
|
||||
}
|
@ -219,6 +219,11 @@ else:
|
||||
"GeckoChildProcessHost.cpp",
|
||||
]
|
||||
|
||||
if CONFIG["OS_ARCH"] == "WINNT":
|
||||
UNIFIED_SOURCES += ["MessagePump_windows.cpp"]
|
||||
elif CONFIG["OS_TARGET"] == "Android":
|
||||
UNIFIED_SOURCES += ["MessagePump_android.cpp"]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
"/caps",
|
||||
"/dom/broadcastchannel",
|
||||
|
Loading…
Reference in New Issue
Block a user