Bug 1357578 - Convert PRCList usage in nsPluginHost to mozilla::LinkedList. r=erahm,r=bsemdberg

This commit is contained in:
Łukasz Kędziorski 2017-05-02 17:12:00 -07:00
parent 3b736de62a
commit 264fce8c06
3 changed files with 17 additions and 28 deletions

View File

@ -3851,20 +3851,19 @@ nsPluginHost::CanUsePluginForMIMEType(const nsACString& aMIMEType)
// Runnable that does an async destroy of a plugin.
class nsPluginDestroyRunnable : public Runnable,
public PRCList
public mozilla::LinkedListElement<nsPluginDestroyRunnable>
{
public:
explicit nsPluginDestroyRunnable(nsNPAPIPluginInstance *aInstance)
: Runnable("nsPluginDestroyRunnable"),
mInstance(aInstance)
{
PR_INIT_CLIST(this);
PR_APPEND_LINK(this, &sRunnableListHead);
sRunnableList.insertBack(this);
}
~nsPluginDestroyRunnable() override
{
PR_REMOVE_LINK(this);
this->remove();
}
NS_IMETHOD Run() override
@ -3882,16 +3881,12 @@ public:
return NS_OK;
}
nsPluginDestroyRunnable *r =
static_cast<nsPluginDestroyRunnable*>(PR_NEXT_LINK(&sRunnableListHead));
while (r != &sRunnableListHead) {
for (auto r : sRunnableList) {
if (r != this && r->mInstance == instance) {
// There's another runnable scheduled to tear down
// instance. Let it do the job.
return NS_OK;
}
r = static_cast<nsPluginDestroyRunnable*>(PR_NEXT_LINK(r));
}
PLUGIN_LOG(PLUGIN_LOG_NORMAL,
@ -3910,14 +3905,12 @@ public:
protected:
RefPtr<nsNPAPIPluginInstance> mInstance;
static PRCList sRunnableListHead;
static mozilla::LinkedList<nsPluginDestroyRunnable> sRunnableList;
};
PRCList nsPluginDestroyRunnable::sRunnableListHead =
PR_INIT_STATIC_CLIST(&nsPluginDestroyRunnable::sRunnableListHead);
mozilla::LinkedList<nsPluginDestroyRunnable> nsPluginDestroyRunnable::sRunnableList;
PRCList PluginDestructionGuard::sListHead =
PR_INIT_STATIC_CLIST(&PluginDestructionGuard::sListHead);
mozilla::LinkedList<PluginDestructionGuard> PluginDestructionGuard::sList;
PluginDestructionGuard::PluginDestructionGuard(nsNPAPIPluginInstance *aInstance)
: mInstance(aInstance)
@ -3941,7 +3934,7 @@ PluginDestructionGuard::~PluginDestructionGuard()
{
NS_ASSERTION(NS_IsMainThread(), "Should be on the main thread");
PR_REMOVE_LINK(this);
this->remove();
if (mDelayedDestroy) {
// We've attempted to destroy the plugin instance we're holding on
@ -3964,16 +3957,12 @@ PluginDestructionGuard::DelayDestroy(nsNPAPIPluginInstance *aInstance)
// Find the first guard on the stack and make it do a delayed
// destroy upon destruction.
PluginDestructionGuard *g =
static_cast<PluginDestructionGuard*>(PR_LIST_HEAD(&sListHead));
while (g != &sListHead) {
for (auto g : sList) {
if (g->mInstance == aInstance) {
g->mDelayedDestroy = true;
return true;
}
g = static_cast<PluginDestructionGuard*>(PR_NEXT_LINK(g));
}
return false;

View File

@ -6,11 +6,12 @@
#ifndef nsPluginHost_h_
#define nsPluginHost_h_
#include "mozilla/LinkedList.h"
#include "nsIPluginHost.h"
#include "nsIObserver.h"
#include "nsCOMPtr.h"
#include "prlink.h"
#include "prclist.h"
#include "nsIPluginTag.h"
#include "nsPluginsDir.h"
#include "nsPluginDirServiceProvider.h"
@ -414,7 +415,7 @@ private:
static nsPluginHost* sInst;
};
class PluginDestructionGuard : protected PRCList
class PluginDestructionGuard : public mozilla::LinkedListElement<PluginDestructionGuard>
{
public:
explicit PluginDestructionGuard(nsNPAPIPluginInstance *aInstance);
@ -432,8 +433,7 @@ protected:
mDelayedDestroy = false;
PR_INIT_CLIST(this);
PR_INSERT_BEFORE(this, &sListHead);
sList.insertBack(this);
}
void InitAsync()
@ -442,16 +442,15 @@ protected:
mDelayedDestroy = false;
PR_INIT_CLIST(this);
// Instances with active surrogates must be inserted *after* sListHead so
// Instances with active surrogates must be inserted *in front of* sList so
// that they appear to be at the bottom of the stack
PR_INSERT_AFTER(this, &sListHead);
sList.insertFront(this);
}
RefPtr<nsNPAPIPluginInstance> mInstance;
bool mDelayedDestroy;
static PRCList sListHead;
static mozilla::LinkedList<PluginDestructionGuard> sList;
};
#endif // nsPluginHost_h_

View File

@ -30,6 +30,7 @@
#include "nsNPAPIPlugin.h"
#include "nsPrintfCString.h"
#include "prsystem.h"
#include "prclist.h"
#include "PluginQuirks.h"
#include "gfxPlatform.h"
#ifdef MOZ_GECKO_PROFILER