Skip to content

Commit

Permalink
[embedlite] Align task posting
Browse files Browse the repository at this point in the history
  • Loading branch information
rainemak committed Apr 8, 2020
1 parent c59c3f4 commit 9615502
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 54 deletions.
54 changes: 24 additions & 30 deletions embedding/embedlite/EmbedLiteApp.cpp
Expand Up @@ -15,6 +15,7 @@

#include "mozilla/embedlite/EmbedLiteAPI.h"
#include "mozilla/layers/CompositorThread.h" // for CompositorThreadHolder
#include "mozilla/dom/MessageChannel.h" // for MessageChannel

#include "EmbedLiteUILoop.h"
#include "EmbedLiteSubThread.h"
Expand Down Expand Up @@ -52,11 +53,11 @@ EmbedLiteApp::GetInstance()
}

EmbedLiteApp::EmbedLiteApp()
: mListener(NULL)
, mUILoop(NULL)
, mSubThread(NULL)
, mAppParent(NULL)
, mAppChild(NULL)
: mListener(nullptr)
, mUILoop(nullptr)
, mSubThread(nullptr)
, mAppParent(nullptr)
, mAppChild(nullptr)
, mEmbedType(EMBED_INVALID)
, mState(STOPPED)
, mRenderType(RENDER_AUTO)
Expand Down Expand Up @@ -111,11 +112,11 @@ EmbedLiteApp::GetUILoop() {
void*
EmbedLiteApp::PostTask(EMBEDTaskCallback callback, void* userData, int timeout)
{
CancelableTask* newTask = NewRunnableFunction(callback, userData);
RefPtr<Runnable> newTask = NewRunnableFunction(callback, userData);
if (timeout) {
mUILoop->PostDelayedTask(FROM_HERE, newTask, timeout);
mUILoop->PostDelayedTask(newTask.forget(), timeout);
} else {
mUILoop->PostTask(FROM_HERE, newTask);
mUILoop->PostTask(newTask.forget());
}

return (void*)newTask;
Expand All @@ -129,14 +130,14 @@ EmbedLiteApp::PostCompositorTask(EMBEDTaskCallback callback, void* userData, int
return nullptr;
}

RefPtr<CancelableRunnable> newTask = NewRunnableFunction(callback, userData);
RefPtr<Runnable> newTask = NewRunnableFunction(callback, userData);
MessageLoop* compositorLoop = mozilla::layers::CompositorThreadHolder::Loop();
MOZ_ASSERT(compositorLoop);

if (timeout) {
compositorLoop->PostDelayedTask(FROM_HERE, newTask, timeout);
compositorLoop->PostDelayedTask(newTask.forget(), timeout);
} else {
compositorLoop->PostTask(FROM_HERE, newTask);
compositorLoop->PostTask(newTask.forget());
}

return (void*)newTask;
Expand All @@ -146,7 +147,7 @@ void
EmbedLiteApp::CancelTask(void* aTask)
{
if (aTask) {
static_cast<CancelableTask*>(aTask)->Cancel();
static_cast<CancelableRunnable*>(aTask)->Cancel();
}
}

Expand Down Expand Up @@ -195,8 +196,7 @@ EmbedLiteApp::StartWithCustomPump(EmbedType aEmbedType, EmbedLiteMessagePump* aE
SetState(STARTING);
mEmbedType = aEmbedType;
mUILoop = aEventLoop->GetMessageLoop();
mUILoop->PostTask(FROM_HERE,
NewRunnableFunction(&EmbedLiteApp::StartChild, this));
mUILoop->PostTask(NewRunnableFunction(&EmbedLiteApp::StartChild, this));
mUILoop->StartLoop();
mIsAsyncLoop = true;
return true;
Expand All @@ -213,12 +213,11 @@ EmbedLiteApp::Start(EmbedType aEmbedType)
mEmbedType = aEmbedType;
base::AtExitManager exitManager;
mUILoop = new EmbedLiteUILoop();
mUILoop->PostTask(FROM_HERE,
NewRunnableFunction(&EmbedLiteApp::StartChild, this));
mUILoop->PostTask(NewRunnableFunction(&EmbedLiteApp::StartChild, this));
mUILoop->StartLoop();
if (mSubThread) {
mSubThread->Stop();
mSubThread = NULL;
mSubThread = nullptr;
} else if (mListener) {
NS_ASSERTION(mListener->StopChildThread(),
"StopChildThread must be implemented when ExecuteChildThread defined");
Expand Down Expand Up @@ -264,10 +263,9 @@ EmbedLiteApp::StartChildThread()

mAppParent = new EmbedLiteAppThreadParent();
mAppChild = new EmbedLiteAppThreadChild(mUILoop);
MessageLoop::current()->PostTask(FROM_HERE,
NewRunnableMethod(mAppChild.get(),
&EmbedLiteAppThreadChild::Init,
mAppParent->GetIPCChannel()));
MessageLoop::current()->PostTask(NewRunnableMethod<mozilla::ipc::MessageChannel*>(mAppChild.get(),
&EmbedLiteAppThreadChild::Init,
mAppParent->GetIPCChannel()));

return true;
}
Expand Down Expand Up @@ -317,8 +315,7 @@ EmbedLiteApp::Stop()

if (mState == INITIALIZED) {
if (mViews.empty() && mWindows.empty()) {
mUILoop->PostTask(FROM_HERE,
NewRunnableFunction(&EmbedLiteApp::PreDestroy, this));
mUILoop->PostTask(NewRunnableFunction(&EmbedLiteApp::PreDestroy, this));
} else {
for (auto viewPair : mViews) {
viewPair.second->Destroy();
Expand All @@ -342,7 +339,7 @@ EmbedLiteApp::Shutdown()
if (mEmbedType == EMBED_THREAD) {
if (mSubThread) {
mSubThread->Stop();
mSubThread = NULL;
mSubThread = nullptr;
} else if (mListener) {
NS_ASSERTION(mListener->StopChildThread(),
"StopChildThread must be implemented when ExecuteChildThread defined");
Expand Down Expand Up @@ -488,8 +485,7 @@ EmbedLiteApp::ChildReadyToDestroy()
{
LOGT();
if (mState == DESTROYING) {
mUILoop->PostTask(FROM_HERE,
NewRunnableFunction(&_FinalStop, this));
mUILoop->PostTask(NewRunnableFunction(&_FinalStop, this));
}
if (mEmbedType == EMBED_PROCESS) {
mAppParent = nullptr;
Expand Down Expand Up @@ -527,8 +523,7 @@ EmbedLiteApp::ViewDestroyed(uint32_t id)
mListener->LastViewDestroyed();
}
if (mState == DESTROYING) {
mUILoop->PostTask(FROM_HERE,
NewRunnableFunction(&EmbedLiteApp::PreDestroy, this));
mUILoop->PostTask(NewRunnableFunction(&EmbedLiteApp::PreDestroy, this));
}
}
}
Expand Down Expand Up @@ -596,8 +591,7 @@ EmbedLiteApp::Initialized()
NS_ASSERTION(mState == STARTING || mState == DESTROYING, "Wrong timing");

if (mState == DESTROYING) {
mUILoop->PostTask(FROM_HERE,
NewRunnableFunction(&EmbedLiteApp::PreDestroy, this));
mUILoop->PostTask(NewRunnableFunction(&EmbedLiteApp::PreDestroy, this));
return;
}

Expand Down
8 changes: 4 additions & 4 deletions embedding/embedlite/EmbedLiteMessagePump.cpp
Expand Up @@ -142,11 +142,11 @@ EmbedLiteMessagePump::PostTask(EMBEDTaskCallback callback,
if (!mEmbedPump->GetLoop()) {
return nullptr;
}
CancelableTask* newTask = NewRunnableFunction(callback, userData);
RefPtr<mozilla::Runnable> newTask = NewRunnableFunction(callback, userData);
if (timeout) {
mEmbedPump->GetLoop()->PostDelayedTask(FROM_HERE, newTask, timeout);
mEmbedPump->GetLoop()->PostDelayedTask(newTask.forget(), timeout);
} else {
mEmbedPump->GetLoop()->PostTask(FROM_HERE, newTask);
mEmbedPump->GetLoop()->PostTask(newTask.forget());
}

return (void*)newTask;
Expand All @@ -156,7 +156,7 @@ void
EmbedLiteMessagePump::CancelTask(void* aTask)
{
if (aTask) {
static_cast<CancelableTask*>(aTask)->Cancel();
static_cast<CancelableRunnable*>(aTask)->Cancel();
}
}

Expand Down
Expand Up @@ -26,6 +26,7 @@
#include "EmbedLiteAppProcessParent.h"
#include "mozilla/ipc/BrowserProcessSubThread.h"
#include "nsThreadManager.h"
#include "nsThreadUtils.h" // for mozilla::Runnable
#include "nsAutoPtr.h"
#include "base/command_line.h"
#include "nsDirectoryService.h"
Expand Down Expand Up @@ -280,7 +281,7 @@ DelayedDeleteSubprocess(GeckoChildProcessHost* aSubprocess)
// This runnable only exists to delegate ownership of the
// EmbedLiteAppProcessParent to this runnable, until it's deleted by the event
// system.
struct DelayedDeleteContentParentTask : public nsRunnable
struct DelayedDeleteContentParentTask : public mozilla::Runnable
{
explicit DelayedDeleteContentParentTask(EmbedLiteAppProcessParent* aObj) : mObj(aObj) { }

Expand Down
4 changes: 2 additions & 2 deletions embedding/embedlite/embedshared/EmbedLitePuppetWidget.cpp
Expand Up @@ -111,8 +111,8 @@ EmbedLitePuppetWidget::EmbedLitePuppetWidget(EmbedLiteWindowBaseChild* window)
: EmbedLitePuppetWidget(window, nullptr)
{
if (sUseExternalGLContext && sRequestGLContextEarly) {
CompositorThreadHolder::Loop()->PostTask(FROM_HERE,
NewRunnableFunction(&CreateGLContextEarly, window->GetUniqueID()));
CompositorThreadHolder::Loop()->PostTask(NewRunnableFunction(&CreateGLContextEarly,
window->GetUniqueID()));
}
}

Expand Down
16 changes: 6 additions & 10 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseChild.cpp
Expand Up @@ -111,19 +111,14 @@ EmbedLiteViewBaseChild::EmbedLiteViewBaseChild(const uint32_t& aWindowId, const
mWindow = EmbedLiteAppBaseChild::GetInstance()->GetWindowByID(aWindowId);
MOZ_ASSERT(mWindow != nullptr);

mInitWindowTask = NewRunnableMethod(this, &EmbedLiteViewBaseChild::InitGeckoWindow,
aParentId, isPrivateWindow);
MessageLoop::current()->PostTask(FROM_HERE, mInitWindowTask);
MessageLoop::current()->PostTask(NewRunnableMethod(this, &EmbedLiteViewBaseChild::InitGeckoWindow,
aParentId, isPrivateWindow));
}

EmbedLiteViewBaseChild::~EmbedLiteViewBaseChild()
{
LOGT();
NS_ASSERTION(mControllerListeners.IsEmpty(), "Controller listeners list is not empty...");
if (mInitWindowTask) {
mInitWindowTask->Cancel();
mInitWindowTask = nullptr;
}
if (mWindowObserverRegistered) {
mWindow->GetWidget()->RemoveObserver(this);
}
Expand Down Expand Up @@ -164,10 +159,11 @@ bool EmbedLiteViewBaseChild::RecvDestroy()
void
EmbedLiteViewBaseChild::InitGeckoWindow(const uint32_t& parentId, const bool& isPrivateWindow)
{
if (mInitWindowTask) {
mInitWindowTask->Cancel();
if (!mWindow) {
LOGT("Init called for already destroyed object");
return;
}
mInitWindowTask = nullptr;

LOGT("parentID: %u", parentId);
nsresult rv;

Expand Down
1 change: 0 additions & 1 deletion embedding/embedlite/embedshared/EmbedLiteViewBaseChild.h
Expand Up @@ -226,7 +226,6 @@ class EmbedLiteViewBaseChild : public PEmbedLiteViewChild,
RefPtr<TabChildHelper> mHelper;
bool mIMEComposing;
uint64_t mPendingTouchPreventedBlockId;
CancelableTask* mInitWindowTask;

nsDataHashtable<nsStringHashKey, bool/*start with key*/> mRegisteredMessages;
nsTArray<EmbedLiteContentController*> mControllerListeners;
Expand Down
4 changes: 2 additions & 2 deletions embedding/embedlite/embedthread/EmbedContentController.cpp
Expand Up @@ -175,9 +175,9 @@ void EmbedContentController::ClearRenderFrame()
* Schedules a runnable to run on the controller/UI thread at some time
* in the future.
*/
void EmbedContentController::PostDelayedTask(Task* aTask, int aDelayMs)
void EmbedContentController::PostDelayedTask(already_AddRefed<Runnable> aTask, int aDelayMs)
{
MessageLoop::current()->PostDelayedTask(FROM_HERE, aTask, aDelayMs);
MessageLoop::current()->PostDelayedTask(Move(aTask), aDelayMs);
}

EmbedLiteViewListener *EmbedContentController::GetListener() const
Expand Down
2 changes: 1 addition & 1 deletion embedding/embedlite/embedthread/EmbedContentController.h
Expand Up @@ -36,7 +36,7 @@ class EmbedContentController : public mozilla::layers::GeckoContentController
virtual void HandleLongTap(const CSSPoint& aPoint, Modifiers aModifiers, const ScrollableLayerGuid& aGuid, uint64_t aInputBlockId) override;
virtual void AcknowledgeScrollUpdate(const FrameMetrics::ViewID&, const uint32_t&) override;
void ClearRenderFrame();
virtual void PostDelayedTask(Task* aTask, int aDelayMs) override;
virtual void PostDelayedTask(already_AddRefed<Runnable> aTask, int aDelayMs) override;
bool HitTestAPZC(mozilla::ScreenIntPoint& aPoint);

virtual void NotifyAPZStateChange(const ScrollableLayerGuid& aGuid,
Expand Down
3 changes: 2 additions & 1 deletion embedding/embedlite/modules/EmbedLiteAppService.cpp
Expand Up @@ -22,6 +22,7 @@
#include "nsIDOMWindowUtils.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsThreadUtils.h" // for mozilla::Runnable
#include "EmbedLiteAppThreadChild.h"
#include "EmbedLiteViewThreadChild.h"
#include "nsIBaseWindow.h"
Expand All @@ -43,7 +44,7 @@ using namespace mozilla::widget;

namespace
{
class AsyncArrayRemove : public nsRunnable
class AsyncArrayRemove : public mozilla::Runnable
{
protected:
nsCString mName;
Expand Down
3 changes: 2 additions & 1 deletion embedding/embedlite/utils/TabChildHelper.cpp
Expand Up @@ -26,6 +26,7 @@
#include "nsIDocShell.h"
#include "nsViewportInfo.h"
#include "nsPIWindowRoot.h"
#include "nsThreadUtils.h" // for mozilla::Runnable
#include "mozilla/Preferences.h"
#include "nsIFrame.h"
#include "nsView.h"
Expand Down Expand Up @@ -115,7 +116,7 @@ TabChildHelper::Disconnect()
}
}

class EmbedUnloadScriptEvent : public nsRunnable
class EmbedUnloadScriptEvent : public mozilla::Runnable
{
public:
EmbedUnloadScriptEvent(TabChildHelper* aTabChild, TabChildGlobal* aTabChildGlobal)
Expand Down
1 change: 0 additions & 1 deletion embedding/embedlite/utils/TabChildHelper.h
Expand Up @@ -18,7 +18,6 @@
#include "nsIDocument.h"
#include "TabChild.h"

class CancelableTask;
class nsPresContext;
class nsIDOMWindowUtils;

Expand Down

0 comments on commit 9615502

Please sign in to comment.