зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1834278 - Get rid of nsIMessageLoop. r=emilio
This is unused now. Differential Revision: https://phabricator.services.mozilla.com/D185039
This commit is contained in:
Родитель
b01dd971c1
Коммит
e10181029f
|
@ -2954,38 +2954,6 @@
|
|||
"parent": "nsISupports",
|
||||
"uuid": "2998574d-8993-407a-b1a5-8ad7417653e1"
|
||||
},
|
||||
{
|
||||
"consts": [],
|
||||
"flags": [],
|
||||
"methods": [
|
||||
{
|
||||
"flags": [],
|
||||
"name": "postIdleTask",
|
||||
"params": [
|
||||
{
|
||||
"flags": [
|
||||
"in"
|
||||
],
|
||||
"type": {
|
||||
"name": "nsIRunnable",
|
||||
"tag": "TD_INTERFACE_TYPE"
|
||||
}
|
||||
},
|
||||
{
|
||||
"flags": [
|
||||
"in"
|
||||
],
|
||||
"type": {
|
||||
"tag": "TD_UINT32"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"name": "nsIMessageLoop",
|
||||
"parent": "nsISupports",
|
||||
"uuid": "3e8c58e8-e52c-43e0-8e66-669ca788ff5f"
|
||||
},
|
||||
{
|
||||
"consts": [],
|
||||
"flags": [],
|
||||
|
@ -3194,4 +3162,4 @@
|
|||
"parent": "nsISupports",
|
||||
"uuid": "9188bc86-f92e-11d2-81ef-0060083a0bcf"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
|
|
@ -12,12 +12,6 @@ Classes = [
|
|||
'headers': ['nsDebugImpl.h'],
|
||||
'processes': ProcessSelector.ALLOW_IN_GPU_RDD_SOCKET_AND_UTILITY_PROCESS,
|
||||
},
|
||||
{
|
||||
'cid': '{67b3ac0c-d806-4d48-939e-6a819e6c248f}',
|
||||
'contract_ids': ['@mozilla.org/message-loop;1'],
|
||||
'legacy_constructor': 'nsMessageLoopConstructor',
|
||||
'headers': ['/xpcom/base/nsMessageLoop.h'],
|
||||
},
|
||||
{
|
||||
'cid': '{68bf4793-5204-45cf-9ee2-69adffbc2e38}',
|
||||
'contract_ids': ['@mozilla.org/xpcom/memory-watcher;1'],
|
||||
|
|
|
@ -15,7 +15,6 @@ XPIDL_SOURCES += [
|
|||
"nsIInterfaceRequestor.idl",
|
||||
"nsIMemoryInfoDumper.idl",
|
||||
"nsIMemoryReporter.idl",
|
||||
"nsIMessageLoop.idl",
|
||||
"nsISecurityConsoleMessage.idl",
|
||||
"nsISupports.idl",
|
||||
"nsIUUIDGenerator.idl",
|
||||
|
@ -181,7 +180,6 @@ UNIFIED_SOURCES += [
|
|||
"nsMemoryImpl.cpp",
|
||||
"nsMemoryInfoDumper.cpp",
|
||||
"nsMemoryReporterManager.cpp",
|
||||
"nsMessageLoop.cpp",
|
||||
"NSPRLogModulesParser.cpp",
|
||||
"nsSecurityConsoleMessage.cpp",
|
||||
"nsSystemInfo.cpp",
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 "nsISupports.idl"
|
||||
|
||||
interface nsIRunnable;
|
||||
|
||||
/**
|
||||
* This service allows access to the current thread's Chromium MessageLoop
|
||||
* instance, with some extra sugar added. If you're calling from C++, it may
|
||||
* or may not make sense for you to use this interface. If you're calling from
|
||||
* JS, you don't have a choice!
|
||||
*
|
||||
* Right now, you can only call PostIdleTask(), and the wrath of khuey is
|
||||
* stopping you from adding other methods.
|
||||
*
|
||||
* nsIMessageLoop's contractid is "@mozilla.org/message-loop;1".
|
||||
*/
|
||||
[builtinclass, scriptable, uuid(3E8C58E8-E52C-43E0-8E66-669CA788FF5F)]
|
||||
interface nsIMessageLoop : nsISupports
|
||||
{
|
||||
/**
|
||||
* Posts a task to be run when this thread's message loop is idle, or after
|
||||
* ensureRunsAfterMS milliseconds have elapsed. (That is, the task is
|
||||
* guaranteed to run /eventually/.)
|
||||
*
|
||||
* Note that if the event loop is busy, we will hold a reference to the task
|
||||
* until ensureRunsAfterMS milliseconds have elapsed. Be careful when
|
||||
* specifying long timeouts and tasks which hold references to windows or
|
||||
* other large objects, because you can leak memory in a difficult-to-detect
|
||||
* way!
|
||||
*/
|
||||
void postIdleTask(in nsIRunnable task, in uint32_t ensureRunsAfterMS);
|
||||
};
|
|
@ -1,151 +0,0 @@
|
|||
/* -*- 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 "nsMessageLoop.h"
|
||||
#include "mozilla/WeakPtr.h"
|
||||
#include "base/message_loop.h"
|
||||
#include "base/task.h"
|
||||
#include "nsINamed.h"
|
||||
#include "nsIRunnable.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
namespace {
|
||||
|
||||
/**
|
||||
* This Task runs its nsIRunnable when Run() is called, or after
|
||||
* aEnsureRunsAfterMS milliseconds have elapsed since the object was
|
||||
* constructed.
|
||||
*
|
||||
* Note that the MessageLoop owns this object and will delete it after it calls
|
||||
* Run(). Tread lightly.
|
||||
*/
|
||||
class MessageLoopIdleTask : public Runnable, public SupportsWeakPtr {
|
||||
public:
|
||||
MessageLoopIdleTask(nsIRunnable* aTask, uint32_t aEnsureRunsAfterMS);
|
||||
NS_IMETHOD Run() override;
|
||||
|
||||
private:
|
||||
nsresult Init(uint32_t aEnsureRunsAfterMS);
|
||||
|
||||
nsCOMPtr<nsIRunnable> mTask;
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
|
||||
virtual ~MessageLoopIdleTask() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* This timer callback calls MessageLoopIdleTask::Run() when its timer fires.
|
||||
* (The timer can't call back into MessageLoopIdleTask directly since that's
|
||||
* not a refcounted object; it's owned by the MessageLoop.)
|
||||
*
|
||||
* We keep a weak reference to the MessageLoopIdleTask, although a raw pointer
|
||||
* should in theory suffice: When the MessageLoopIdleTask runs (right before
|
||||
* the MessageLoop deletes it), it cancels its timer. But the weak pointer
|
||||
* saves us from worrying about an edge case somehow messing us up here.
|
||||
*/
|
||||
class MessageLoopTimerCallback : public nsITimerCallback, public nsINamed {
|
||||
public:
|
||||
explicit MessageLoopTimerCallback(MessageLoopIdleTask* aTask);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSITIMERCALLBACK
|
||||
|
||||
NS_IMETHOD GetName(nsACString& aName) override {
|
||||
aName.AssignLiteral("MessageLoopTimerCallback");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
WeakPtr<MessageLoopIdleTask> mTask;
|
||||
|
||||
virtual ~MessageLoopTimerCallback() = default;
|
||||
};
|
||||
|
||||
MessageLoopIdleTask::MessageLoopIdleTask(nsIRunnable* aTask,
|
||||
uint32_t aEnsureRunsAfterMS)
|
||||
: mozilla::Runnable("MessageLoopIdleTask"), mTask(aTask) {
|
||||
// Init() really shouldn't fail, but if it does, we schedule our runnable
|
||||
// immediately, because it's more important to guarantee that we run the task
|
||||
// eventually than it is to run the task when we're idle.
|
||||
nsresult rv = Init(aEnsureRunsAfterMS);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING(
|
||||
"Running idle task early because we couldn't initialize our timer.");
|
||||
NS_DispatchToCurrentThread(mTask);
|
||||
|
||||
mTask = nullptr;
|
||||
mTimer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult MessageLoopIdleTask::Init(uint32_t aEnsureRunsAfterMS) {
|
||||
RefPtr<MessageLoopTimerCallback> callback =
|
||||
new MessageLoopTimerCallback(this);
|
||||
return NS_NewTimerWithCallback(getter_AddRefs(mTimer), callback,
|
||||
aEnsureRunsAfterMS, nsITimer::TYPE_ONE_SHOT);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MessageLoopIdleTask::Run() {
|
||||
// Null out our pointers because if Run() was called by the timer, this
|
||||
// object will be kept alive by the MessageLoop until the MessageLoop calls
|
||||
// Run().
|
||||
|
||||
if (mTimer) {
|
||||
mTimer->Cancel();
|
||||
mTimer = nullptr;
|
||||
}
|
||||
|
||||
if (mTask) {
|
||||
mTask->Run();
|
||||
mTask = nullptr;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
MessageLoopTimerCallback::MessageLoopTimerCallback(MessageLoopIdleTask* aTask)
|
||||
: mTask(aTask) {}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MessageLoopTimerCallback::Notify(nsITimer* aTimer) {
|
||||
// We don't expect to hit the case when the timer fires but mTask has been
|
||||
// deleted, because mTask should cancel the timer before the mTask is
|
||||
// deleted. But you never know...
|
||||
NS_WARNING_ASSERTION(mTask, "This timer shouldn't have fired.");
|
||||
|
||||
if (mTask) {
|
||||
mTask->Run();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(MessageLoopTimerCallback, nsITimerCallback, nsINamed)
|
||||
|
||||
} // namespace
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsMessageLoop, nsIMessageLoop)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMessageLoop::PostIdleTask(nsIRunnable* aTask, uint32_t aEnsureRunsAfterMS) {
|
||||
// The message loop owns MessageLoopIdleTask and deletes it after calling
|
||||
// Run(). Be careful...
|
||||
RefPtr<MessageLoopIdleTask> idle =
|
||||
new MessageLoopIdleTask(aTask, aEnsureRunsAfterMS);
|
||||
MessageLoop::current()->PostIdleTask(idle.forget());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMessageLoopConstructor(const nsIID& aIID, void** aInstancePtr) {
|
||||
nsISupports* messageLoop = new nsMessageLoop();
|
||||
return messageLoop->QueryInterface(aIID, aInstancePtr);
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/* -*- 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 "nsIMessageLoop.h"
|
||||
|
||||
/*
|
||||
* nsMessageLoop implements nsIMessageLoop, which wraps Chromium's MessageLoop
|
||||
* class and adds a bit of sugar.
|
||||
*/
|
||||
class nsMessageLoop : public nsIMessageLoop {
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMESSAGELOOP
|
||||
|
||||
private:
|
||||
virtual ~nsMessageLoop() = default;
|
||||
};
|
||||
|
||||
#define NS_MESSAGE_LOOP_CID \
|
||||
{ \
|
||||
0x67b3ac0c, 0xd806, 0x4d48, { \
|
||||
0x93, 0x9e, 0x6a, 0x81, 0x9e, 0x6c, 0x24, 0x8f \
|
||||
} \
|
||||
}
|
||||
|
||||
extern nsresult nsMessageLoopConstructor(const nsIID& aIID,
|
||||
void** aInstancePtr);
|
|
@ -66,7 +66,6 @@
|
|||
|
||||
#include "nsSystemInfo.h"
|
||||
#include "nsMemoryReporterManager.h"
|
||||
#include "nsMessageLoop.h"
|
||||
#include "nss.h"
|
||||
#include "nsNSSComponent.h"
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче