Bug 1343741 - Part3: Pass labelled event target to nsIProtocolProxyService::AsyncResolve, r=mayhemer

For dispatching runnable in nsPACMan, this patch sends a labelled event target via nsIProtocolProxyService::AsyncResolve.
This commit is contained in:
Kershaw Chang 2017-07-05 00:48:00 +02:00
Родитель 4cbb89d09b
Коммит 5279c25aa6
11 изменённых файлов: 56 добавлений и 32 удалений

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

@ -370,11 +370,14 @@ PeerConnectionMedia::InitProxy()
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIEventTarget> target = mParent->GetWindow()
? mParent->GetWindow()->EventTargetFor(TaskCategory::Network)
: nullptr;
RefPtr<ProtocolProxyQueryHandler> handler = new ProtocolProxyQueryHandler(this);
rv = pps->AsyncResolve(channel,
nsIProtocolProxyService::RESOLVE_PREFER_HTTPS_PROXY |
nsIProtocolProxyService::RESOLVE_ALWAYS_TUNNEL,
handler, getter_AddRefs(mProxyRequest));
handler, target, getter_AddRefs(mProxyRequest));
if (NS_FAILED(rv)) {
CSFLogError(logTag, "%s: Failed to resolve protocol proxy: %d", __FUNCTION__, (int)rv);
return NS_ERROR_FAILURE;

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

@ -1892,9 +1892,11 @@ nsIOService::SpeculativeConnectInternal(nsIURI *aURI,
new IOServiceProxyCallback(aCallbacks, this);
nsCOMPtr<nsIProtocolProxyService2> pps2 = do_QueryInterface(pps);
if (pps2) {
return pps2->AsyncResolve2(channel, 0, callback, getter_AddRefs(cancelable));
return pps2->AsyncResolve2(channel, 0, callback, nullptr,
getter_AddRefs(cancelable));
}
return pps->AsyncResolve(channel, 0, callback, getter_AddRefs(cancelable));
return pps->AsyncResolve(channel, 0, callback, nullptr,
getter_AddRefs(cancelable));
}
NS_IMETHODIMP

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

@ -13,6 +13,7 @@ interface nsIProtocolProxyChannelFilter;
interface nsIProxyInfo;
interface nsIChannel;
interface nsIURI;
interface nsIEventTarget;
/**
* nsIProtocolProxyService provides methods to access information about
@ -79,6 +80,8 @@ interface nsIProtocolProxyService : nsISupports
* not correspond to a RESOLVE_ flag are reserved for future use.
* @param aCallback
* The object to be notified when the result is available.
* @param aMainThreadTarget
* A labelled event target for dispatching runnables to main thread.
*
* @return An object that can be used to cancel the asychronous operation.
* If canceled, the cancelation status (aReason) will be forwarded
@ -99,7 +102,8 @@ interface nsIProtocolProxyService : nsISupports
* @see nsIProxiedProtocolHandler::newProxiedChannel
*/
nsICancelable asyncResolve(in nsISupports aChannelOrURI, in unsigned long aFlags,
in nsIProtocolProxyCallback aCallback);
in nsIProtocolProxyCallback aCallback,
[optional] in nsIEventTarget aMainThreadTarget);
/**
* This method may be called to construct a nsIProxyInfo instance from

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

@ -26,5 +26,6 @@ interface nsIProtocolProxyService2 : nsIProtocolProxyService
* The nsICancelable return value will be null in that case.
*/
nsICancelable asyncResolve2(in nsIChannel aChannel, in unsigned long aFlags,
in nsIProtocolProxyCallback aCallback);
in nsIProtocolProxyCallback aCallback,
[optional] in nsIEventTarget aMainThreadTarget);
};

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

@ -248,7 +248,7 @@ public:
mExtraHeapSize);
RefPtr<PACLoadComplete> runnable = new PACLoadComplete(mPACMan);
NS_DispatchToMainThread(runnable);
mPACMan->Dispatch(runnable.forget());
return NS_OK;
}
@ -293,7 +293,7 @@ PendingPACQuery::Complete(nsresult status, const nsCString &pacString)
RefPtr<ExecuteCallback> runnable = new ExecuteCallback(mCallback, status);
runnable->SetPACString(pacString);
if (mOnMainThreadOnly)
NS_DispatchToMainThread(runnable);
mPACMan->Dispatch(runnable.forget());
else
runnable->Run();
}
@ -307,7 +307,7 @@ PendingPACQuery::UseAlternatePACFile(const nsCString &pacURL)
RefPtr<ExecuteCallback> runnable = new ExecuteCallback(mCallback, NS_OK);
runnable->SetPACURL(pacURL);
if (mOnMainThreadOnly)
NS_DispatchToMainThread(runnable);
mPACMan->Dispatch(runnable.forget());
else
runnable->Run();
}
@ -328,8 +328,9 @@ static uint32_t sThreadLocalIndex = 0xdeadbeef; // out of range
static const char *kPACIncludePath =
"network.proxy.autoconfig_url.include_path";
nsPACMan::nsPACMan()
: mLoadPending(false)
nsPACMan::nsPACMan(nsIEventTarget *mainThreadEventTarget)
: NeckoTargetHolder(mainThreadEventTarget)
, mLoadPending(false)
, mShutdown(false)
, mLoadFailureCount(0)
, mInProgress(false)
@ -351,7 +352,7 @@ nsPACMan::~nsPACMan()
}
else {
RefPtr<ShutdownThread> runnable = new ShutdownThread(mPACThread);
NS_DispatchToMainThread(runnable);
Dispatch(runnable.forget());
}
}
@ -371,7 +372,7 @@ nsPACMan::Shutdown()
PostCancelPendingQ(NS_ERROR_ABORT);
RefPtr<WaitForThreadShutdown> runnable = new WaitForThreadShutdown(this);
NS_DispatchToMainThread(runnable);
Dispatch(runnable.forget());
}
nsresult
@ -438,9 +439,12 @@ nsPACMan::LoadPACFromURI(const nsCString &spec)
// queries the enter between now and when we actually load the PAC file.
if (!mLoadPending) {
nsresult rv;
if (NS_FAILED(rv = NS_DispatchToCurrentThread(NewRunnableMethod("nsPACMan::StartLoading",
this, &nsPACMan::StartLoading))))
nsCOMPtr<nsIRunnable> runnable =
NewRunnableMethod("nsPACMan::StartLoading", this, &nsPACMan::StartLoading);
nsresult rv = NS_IsMainThread()
? Dispatch(runnable.forget())
: GetCurrentThreadEventTarget()->Dispatch(runnable.forget());
if (NS_FAILED(rv))
return rv;
mLoadPending = true;
}

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

@ -21,6 +21,7 @@
#include "mozilla/TimeStamp.h"
#include "mozilla/Logging.h"
#include "mozilla/Atomics.h"
#include "mozilla/net/NeckoTargetHolder.h"
class nsISystemProxySettings;
class nsIThread;
@ -90,11 +91,12 @@ private:
class nsPACMan final : public nsIStreamLoaderObserver
, public nsIInterfaceRequestor
, public nsIChannelEventSink
, public NeckoTargetHolder
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
nsPACMan();
explicit nsPACMan(nsIEventTarget *mainThreadEventTarget);
/**
* This method may be called to shutdown the PAC manager. Any async queries

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

@ -1147,7 +1147,7 @@ nsProtocolProxyService::IsProxyDisabled(nsProxyInfo *pi)
}
nsresult
nsProtocolProxyService::SetupPACThread()
nsProtocolProxyService::SetupPACThread(nsIEventTarget *mainThreadEventTarget)
{
if (mIsShutdown) {
return NS_ERROR_FAILURE;
@ -1156,7 +1156,7 @@ nsProtocolProxyService::SetupPACThread()
if (mPACMan)
return NS_OK;
mPACMan = new nsPACMan();
mPACMan = new nsPACMan(mainThreadEventTarget);
bool mainThreadOnly;
nsresult rv;
@ -1319,7 +1319,8 @@ nsresult
nsProtocolProxyService::AsyncResolveInternal(nsIChannel *channel, uint32_t flags,
nsIProtocolProxyCallback *callback,
nsICancelable **result,
bool isSyncOK)
bool isSyncOK,
nsIEventTarget *mainThreadEventTarget)
{
NS_ENSURE_ARG_POINTER(channel);
NS_ENSURE_ARG_POINTER(callback);
@ -1350,6 +1351,11 @@ nsProtocolProxyService::AsyncResolveInternal(nsIChannel *channel, uint32_t flags
}
}
rv = SetupPACThread(mainThreadEventTarget);
if (NS_FAILED(rv)) {
return rv;
}
// SystemProxySettings and PAC files can block the main thread
// but if neither of them are in use, we can just do the work
// right here and directly invoke the callback
@ -1386,14 +1392,17 @@ nsProtocolProxyService::AsyncResolveInternal(nsIChannel *channel, uint32_t flags
NS_IMETHODIMP
nsProtocolProxyService::AsyncResolve2(nsIChannel *channel, uint32_t flags,
nsIProtocolProxyCallback *callback,
nsIEventTarget *mainThreadEventTarget,
nsICancelable **result)
{
return AsyncResolveInternal(channel, flags, callback, result, true);
return AsyncResolveInternal(channel, flags, callback,
result, true, mainThreadEventTarget);
}
NS_IMETHODIMP
nsProtocolProxyService::AsyncResolve(nsISupports *channelOrURI, uint32_t flags,
nsIProtocolProxyCallback *callback,
nsIEventTarget *mainThreadEventTarget,
nsICancelable **result)
{
@ -1424,7 +1433,8 @@ nsProtocolProxyService::AsyncResolve(nsISupports *channelOrURI, uint32_t flags,
NS_ENSURE_SUCCESS(rv, rv);
}
return AsyncResolveInternal(channel, flags, callback, result, false);
return AsyncResolveInternal(channel, flags, callback,
result, false, mainThreadEventTarget);
}
NS_IMETHODIMP
@ -1914,9 +1924,6 @@ nsProtocolProxyService::Resolve_Internal(nsIChannel *channel,
nsIProxyInfo **result)
{
NS_ENSURE_ARG_POINTER(channel);
nsresult rv = SetupPACThread();
if (NS_FAILED(rv))
return rv;
*usePACThread = false;
*result = nullptr;
@ -1925,7 +1932,7 @@ nsProtocolProxyService::Resolve_Internal(nsIChannel *channel,
return NS_OK; // Can't proxy this (filters may not override)
nsCOMPtr<nsIURI> uri;
rv = GetProxyURI(channel, getter_AddRefs(uri));
nsresult rv = GetProxyURI(channel, getter_AddRefs(uri));
if (NS_FAILED(rv)) return rv;
// See bug #586908.

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

@ -298,7 +298,7 @@ protected:
void MaybeDisableDNSPrefetch(nsIProxyInfo *aProxy);
private:
nsresult SetupPACThread();
nsresult SetupPACThread(nsIEventTarget *mainThreadEventTarget = nullptr);
nsresult ResetPACThread();
nsresult ReloadNetworkPAC();
@ -406,7 +406,8 @@ private:
nsresult AsyncResolveInternal(nsIChannel *channel, uint32_t flags,
nsIProtocolProxyCallback *callback,
nsICancelable **result,
bool isSyncOK);
bool isSyncOK,
nsIEventTarget *mainThreadEventTarget);
bool mIsShutdown;
nsCOMPtr<nsIThread> mProxySettingThread;
};

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

@ -1706,7 +1706,7 @@ nsFtpState::Init(nsFtpChannel *channel)
do_GetService(NS_PROTOCOLPROXYSERVICE_CONTRACTID);
if (pps && !mChannel->ProxyInfo()) {
pps->AsyncResolve(static_cast<nsIChannel*>(mChannel), 0, this,
pps->AsyncResolve(static_cast<nsIChannel*>(mChannel), 0, this, nullptr,
getter_AddRefs(mProxyRequest));
}

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

@ -3012,11 +3012,11 @@ nsHttpChannel::ResolveProxy()
// then it is ok to use that version.
nsCOMPtr<nsIProtocolProxyService2> pps2 = do_QueryInterface(pps);
if (pps2) {
rv = pps2->AsyncResolve2(this, mProxyResolveFlags,
this, getter_AddRefs(mProxyRequest));
rv = pps2->AsyncResolve2(this, mProxyResolveFlags, this,
nullptr, getter_AddRefs(mProxyRequest));
} else {
rv = pps->AsyncResolve(static_cast<nsIChannel*>(this), mProxyResolveFlags,
this, getter_AddRefs(mProxyRequest));
this, nullptr, getter_AddRefs(mProxyRequest));
}
return rv;

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

@ -2932,7 +2932,7 @@ WebSocketChannel::ApplyForAdmission()
rv = pps->AsyncResolve(mHttpChannel,
nsIProtocolProxyService::RESOLVE_PREFER_HTTPS_PROXY |
nsIProtocolProxyService::RESOLVE_ALWAYS_TUNNEL,
this, getter_AddRefs(mCancelable));
this, nullptr, getter_AddRefs(mCancelable));
NS_ASSERTION(NS_FAILED(rv) || mCancelable,
"nsIProtocolProxyService::AsyncResolve succeeded but didn't "
"return a cancelable object!");