Bug 1343741 - Part4: Label the timer in PACResolver, r=mayhemer

This commit is contained in:
Kershaw Chang 2017-07-05 00:48:00 +02:00
Родитель 5279c25aa6
Коммит 1239057218
3 изменённых файлов: 19 добавлений и 9 удалений

Просмотреть файл

@ -269,8 +269,9 @@ class PACResolver final : public nsIDNSListener
public:
NS_DECL_THREADSAFE_ISUPPORTS
PACResolver()
explicit PACResolver(nsIEventTarget *aTarget)
: mStatus(NS_ERROR_FAILURE)
, mMainThreadEventTarget(aTarget)
{
}
@ -299,10 +300,11 @@ public:
return NS_OK;
}
nsresult mStatus;
nsCOMPtr<nsICancelable> mRequest;
nsCOMPtr<nsIDNSRecord> mResponse;
nsCOMPtr<nsITimer> mTimer;
nsresult mStatus;
nsCOMPtr<nsICancelable> mRequest;
nsCOMPtr<nsIDNSRecord> mResponse;
nsCOMPtr<nsITimer> mTimer;
nsCOMPtr<nsIEventTarget> mMainThreadEventTarget;
private:
~PACResolver() {}
@ -405,7 +407,7 @@ ProxyAutoConfig::ResolveAddress(const nsCString &aHostName,
if (!dns)
return false;
RefPtr<PACResolver> helper = new PACResolver();
RefPtr<PACResolver> helper = new PACResolver(mMainThreadEventTarget);
OriginAttributes attrs;
if (NS_FAILED(dns->AsyncResolveNative(aHostName,
@ -420,6 +422,7 @@ ProxyAutoConfig::ResolveAddress(const nsCString &aHostName,
if (!mTimer)
mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
if (mTimer) {
mTimer->SetTarget(mMainThreadEventTarget);
mTimer->InitWithCallback(helper, aTimeout, nsITimer::TYPE_ONE_SHOT);
helper->mTimer = mTimer;
}
@ -678,13 +681,15 @@ nsresult
ProxyAutoConfig::Init(const nsCString &aPACURI,
const nsCString &aPACScript,
bool aIncludePath,
uint32_t aExtraHeapSize)
uint32_t aExtraHeapSize,
nsIEventTarget *aEventTarget)
{
mPACURI = aPACURI;
mPACScript = sPacUtils;
mPACScript.Append(aPACScript);
mIncludePath = aIncludePath;
mExtraHeapSize = aExtraHeapSize;
mMainThreadEventTarget = aEventTarget;
if (!GetRunning())
return SetupJS();

Просмотреть файл

@ -10,6 +10,7 @@
#include "nsString.h"
#include "nsCOMPtr.h"
class nsIEventTarget;
class nsITimer;
namespace JS {
class CallArgs;
@ -32,7 +33,8 @@ public:
nsresult Init(const nsCString &aPACURI,
const nsCString &aPACScript,
bool aIncludePath,
uint32_t aExtraHeapSize);
uint32_t aExtraHeapSize,
nsIEventTarget *aEventTarget);
void SetThreadLocalIndex(uint32_t index);
void Shutdown();
void GC();
@ -98,6 +100,7 @@ private:
uint32_t mExtraHeapSize;
nsCString mRunningHost;
nsCOMPtr<nsITimer> mTimer;
nsCOMPtr<nsIEventTarget> mMainThreadEventTarget;
};
} // namespace net

Просмотреть файл

@ -242,10 +242,12 @@ public:
if (mSetupPAC) {
mSetupPAC = false;
nsCOMPtr<nsIEventTarget> target = mPACMan->GetNeckoTarget();
mPACMan->mPAC.Init(mSetupPACURI,
mSetupPACData,
mPACMan->mIncludePath,
mExtraHeapSize);
mExtraHeapSize,
target);
RefPtr<PACLoadComplete> runnable = new PACLoadComplete(mPACMan);
mPACMan->Dispatch(runnable.forget());