зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1333962 - Add nsILabelableRunnable to label runnables like vsync (r=kanru)
MozReview-Commit-ID: FdvqV0LfFsz
This commit is contained in:
Родитель
a9ed818bea
Коммит
587e22d043
|
@ -28,8 +28,10 @@
|
|||
#include "mozilla/dom/StorageIPC.h"
|
||||
#include "mozilla/dom/GamepadEventChannelChild.h"
|
||||
#include "mozilla/dom/GamepadTestChannelChild.h"
|
||||
#include "mozilla/dom/MessagePortChild.h"
|
||||
#include "mozilla/dom/LocalStorage.h"
|
||||
#include "mozilla/dom/MessagePortChild.h"
|
||||
#include "mozilla/dom/TabChild.h"
|
||||
#include "mozilla/dom/TabGroup.h"
|
||||
#include "mozilla/ipc/IPCStreamAlloc.h"
|
||||
#include "mozilla/ipc/PBackgroundTestChild.h"
|
||||
#include "mozilla/ipc/PChildToParentStreamChild.h"
|
||||
|
@ -625,6 +627,23 @@ BackgroundChildImpl::RecvDispatchLocalStorageChange(
|
|||
return IPC_OK();
|
||||
}
|
||||
|
||||
bool
|
||||
BackgroundChildImpl::GetMessageSchedulerGroups(const Message& aMsg, nsTArray<RefPtr<SchedulerGroup>>& aGroups)
|
||||
{
|
||||
if (aMsg.type() == layout::PVsync::MessageType::Msg_Notify__ID) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
aGroups.Clear();
|
||||
if (dom::TabChild::HasActiveTabs()) {
|
||||
for (dom::TabChild* tabChild : dom::TabChild::GetActiveTabs()) {
|
||||
aGroups.AppendElement(tabChild->TabGroup());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace ipc
|
||||
} // namespace mozilla
|
||||
|
||||
|
|
|
@ -222,6 +222,9 @@ protected:
|
|||
const nsString& aNewValue,
|
||||
const PrincipalInfo& aPrincipalInfo,
|
||||
const bool& aIsPrivate) override;
|
||||
|
||||
bool
|
||||
GetMessageSchedulerGroups(const Message& aMsg, nsTArray<RefPtr<SchedulerGroup>>& aGroups) override;
|
||||
};
|
||||
|
||||
class BackgroundChildImpl::ThreadLocal final
|
||||
|
|
|
@ -1988,6 +1988,17 @@ MessageChannel::MessageTask::GetPriority(uint32_t* aPriority)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
MessageChannel::MessageTask::GetAffectedSchedulerGroups(nsTArray<RefPtr<SchedulerGroup>>& aGroups)
|
||||
{
|
||||
if (!mChannel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mChannel->AssertWorkerThread();
|
||||
return mChannel->mListener->GetMessageSchedulerGroups(mMessage, aGroups);
|
||||
}
|
||||
|
||||
void
|
||||
MessageChannel::DispatchMessage(Message &&aMsg)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "nsExceptionHandler.h"
|
||||
#endif
|
||||
#include "MessageLink.h"
|
||||
#include "nsILabelableRunnable.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
#include <deque>
|
||||
|
@ -548,7 +549,8 @@ class MessageChannel : HasResultCodes, MessageLoop::DestructionObserver
|
|||
class MessageTask :
|
||||
public CancelableRunnable,
|
||||
public LinkedListElement<RefPtr<MessageTask>>,
|
||||
public nsIRunnablePriority
|
||||
public nsIRunnablePriority,
|
||||
public nsILabelableRunnable
|
||||
{
|
||||
public:
|
||||
explicit MessageTask(MessageChannel* aChannel, Message&& aMessage);
|
||||
|
@ -566,6 +568,8 @@ class MessageChannel : HasResultCodes, MessageLoop::DestructionObserver
|
|||
Message& Msg() { return mMessage; }
|
||||
const Message& Msg() const { return mMessage; }
|
||||
|
||||
bool GetAffectedSchedulerGroups(nsTArray<RefPtr<SchedulerGroup>>& aGroups) override;
|
||||
|
||||
private:
|
||||
MessageTask() = delete;
|
||||
MessageTask(const MessageTask&) = delete;
|
||||
|
|
|
@ -62,6 +62,8 @@ enum {
|
|||
class nsIEventTarget;
|
||||
|
||||
namespace mozilla {
|
||||
class SchedulerGroup;
|
||||
|
||||
namespace dom {
|
||||
class ContentParent;
|
||||
} // namespace dom
|
||||
|
@ -381,6 +383,16 @@ public:
|
|||
virtual void ProcessRemoteNativeEventsInInterruptCall() {
|
||||
}
|
||||
|
||||
// Override this method in top-level protocols to change the SchedulerGroups
|
||||
// that a message might affect. This should be used only as a last resort
|
||||
// when it's difficult to determine an EventTarget ahead of time. See the
|
||||
// comment in nsILabelableRunnable.h for more information.
|
||||
virtual bool
|
||||
GetMessageSchedulerGroups(const Message& aMsg, nsTArray<RefPtr<SchedulerGroup>>& aGroups)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual already_AddRefed<nsIEventTarget>
|
||||
GetMessageEventTarget(const Message& aMsg);
|
||||
|
||||
|
|
|
@ -355,6 +355,14 @@ SchedulerGroup::Runnable::Runnable(already_AddRefed<nsIRunnable>&& aRunnable,
|
|||
{
|
||||
}
|
||||
|
||||
bool
|
||||
SchedulerGroup::Runnable::GetAffectedSchedulerGroups(nsTArray<RefPtr<SchedulerGroup>>& aGroups)
|
||||
{
|
||||
aGroups.Clear();
|
||||
aGroups.AppendElement(Group());
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SchedulerGroup::Runnable::GetName(nsACString& aName)
|
||||
{
|
||||
|
@ -406,6 +414,7 @@ SchedulerGroup::Runnable::GetPriority(uint32_t* aPriority)
|
|||
NS_IMPL_ISUPPORTS_INHERITED(SchedulerGroup::Runnable,
|
||||
mozilla::Runnable,
|
||||
nsIRunnablePriority,
|
||||
nsILabelableRunnable,
|
||||
SchedulerGroup::Runnable)
|
||||
|
||||
SchedulerGroup::AutoProcessEvent::AutoProcessEvent()
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "mozilla/TaskCategory.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsILabelableRunnable.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
|
@ -81,12 +82,16 @@ public:
|
|||
MOZ_ASSERT(IsSafeToRun());
|
||||
}
|
||||
|
||||
class Runnable final : public mozilla::Runnable, public nsIRunnablePriority
|
||||
class Runnable final : public mozilla::Runnable
|
||||
, public nsIRunnablePriority
|
||||
, public nsILabelableRunnable
|
||||
{
|
||||
public:
|
||||
Runnable(already_AddRefed<nsIRunnable>&& aRunnable,
|
||||
SchedulerGroup* aGroup);
|
||||
|
||||
bool GetAffectedSchedulerGroups(nsTArray<RefPtr<SchedulerGroup>>& aGroups) override;
|
||||
|
||||
SchedulerGroup* Group() const { return mGroup; }
|
||||
|
||||
NS_IMETHOD GetName(nsACString& aName) override;
|
||||
|
|
|
@ -26,6 +26,7 @@ EXPORTS += [
|
|||
'MainThreadUtils.h',
|
||||
'nsICancelableRunnable.h',
|
||||
'nsIIdleRunnable.h',
|
||||
'nsILabelableRunnable.h',
|
||||
'nsMemoryPressure.h',
|
||||
'nsProcess.h',
|
||||
'nsProxyRelease.h',
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#ifndef nsILabelableRunnable_h
|
||||
#define nsILabelableRunnable_h
|
||||
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
namespace mozilla {
|
||||
class SchedulerGroup;
|
||||
}
|
||||
|
||||
#define NS_ILABELABLERUNNABLE_IID \
|
||||
{ 0x40da1ea1, 0x0b81, 0x4249, \
|
||||
{ 0x96, 0x46, 0x61, 0x92, 0x23, 0x39, 0xc3, 0xe8 } }
|
||||
|
||||
// In some cases, it is not possible to assign a SchedulerGroup to a runnable
|
||||
// when it is dispatched. For example, the vsync runnable affects whichever tabs
|
||||
// happen to be in the foreground when the vsync runs. The nsILabelableRunnable
|
||||
// interfaces makes it possible to query a runnable to see what SchedulerGroups
|
||||
// it could belong to if it ran right now. For vsyncs, for example, this would
|
||||
// return whichever tabs are foreground at the moment.
|
||||
//
|
||||
// This interface should be used very sparingly. In general, it is far
|
||||
// preferable to label a runnable when it is dispatched since that gives the
|
||||
// scheduler more flexibility and will improve performance.
|
||||
//
|
||||
// To use this interface, QI a runnable to nsILabelableRunnable and then call
|
||||
// GetAffectedSchedulerGroups.
|
||||
class nsILabelableRunnable : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ILABELABLERUNNABLE_IID);
|
||||
|
||||
// Returns true if the runnable can be labeled right now. In this case,
|
||||
// aGroups will contain the set of SchedulerGroups that can be affected by the
|
||||
// runnable. If this returns false, no assumptions can be made about which
|
||||
// SchedulerGroups are affected by the runnable.
|
||||
virtual bool GetAffectedSchedulerGroups(nsTArray<RefPtr<mozilla::SchedulerGroup>>& aGroups) = 0;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsILabelableRunnable, NS_ILABELABLERUNNABLE_IID);
|
||||
|
||||
#endif // nsILabelableRunnable_h
|
Загрузка…
Ссылка в новой задаче