mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1582637 - Inline MediaDevices' FuzzTimer callback and invert coalescing logic. r=jib
If MediaDevices received recurring devicechange events from MediaManager, the FuzzTimer would be restarted for each one, to coalesce them into the same js event. If the internal events kept coming sooner than the fuzz timer timeout, the fuzz timer would never fire. This patch inverts the logic, so that the first scheduled fuzz timer fires, and any intermediate internal events are ignored. After it has fired, a new internal event triggers a new fuzz timer. Differential Revision: https://phabricator.services.mozilla.com/D48519 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
6bf15a7fdf
commit
0316bbe28b
@ -23,32 +23,13 @@
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class FuzzTimerCallBack final : public nsITimerCallback, public nsINamed {
|
||||
~FuzzTimerCallBack() {}
|
||||
|
||||
public:
|
||||
explicit FuzzTimerCallBack(MediaDevices* aMediaDevices)
|
||||
: mMediaDevices(aMediaDevices) {}
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Notify(nsITimer* aTimer) final {
|
||||
mMediaDevices->DispatchTrustedEvent(NS_LITERAL_STRING("devicechange"));
|
||||
return NS_OK;
|
||||
MediaDevices::~MediaDevices() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
if (mFuzzTimer) {
|
||||
mFuzzTimer->Cancel();
|
||||
}
|
||||
|
||||
NS_IMETHOD GetName(nsACString& aName) override {
|
||||
aName.AssignLiteral("FuzzTimerCallBack");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<MediaDevices> mMediaDevices;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(FuzzTimerCallBack, nsITimerCallback, nsINamed)
|
||||
|
||||
MediaDevices::~MediaDevices() { mDeviceChangeListener.DisconnectIfExists(); }
|
||||
mDeviceChangeListener.DisconnectIfExists();
|
||||
}
|
||||
|
||||
static bool IsSameOriginWithAllParentDocs(nsINode* aDoc) {
|
||||
MOZ_ASSERT(aDoc);
|
||||
@ -229,19 +210,26 @@ void MediaDevices::OnDeviceChange() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mFuzzTimer) {
|
||||
mFuzzTimer = NS_NewTimer();
|
||||
if (mFuzzTimer) {
|
||||
// An event is already in flight.
|
||||
return;
|
||||
}
|
||||
|
||||
mFuzzTimer = NS_NewTimer();
|
||||
|
||||
if (!mFuzzTimer) {
|
||||
MOZ_ASSERT(false);
|
||||
return;
|
||||
}
|
||||
|
||||
mFuzzTimer->Cancel();
|
||||
RefPtr<FuzzTimerCallBack> cb = new FuzzTimerCallBack(this);
|
||||
mFuzzTimer->InitWithCallback(cb, DEVICECHANGE_HOLD_TIME_IN_MS,
|
||||
nsITimer::TYPE_ONE_SHOT);
|
||||
mFuzzTimer->InitWithNamedFuncCallback(
|
||||
[](nsITimer*, void* aClosure) {
|
||||
MediaDevices* md = static_cast<MediaDevices*>(aClosure);
|
||||
md->DispatchTrustedEvent(NS_LITERAL_STRING("devicechange"));
|
||||
md->mFuzzTimer = nullptr;
|
||||
},
|
||||
this, DEVICECHANGE_HOLD_TIME_IN_MS, nsITimer::TYPE_ONE_SHOT,
|
||||
"MediaDevices::mFuzzTimer Callback");
|
||||
}
|
||||
|
||||
mozilla::dom::EventHandlerNonNull* MediaDevices::GetOndevicechange() {
|
||||
|
Loading…
Reference in New Issue
Block a user