зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1608114 - Increase the priority of the TRR main thread events r=mayhemer
Differential Revision: https://phabricator.services.mozilla.com/D61306 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
6cbfa720de
Коммит
74f9a5e3d8
|
@ -32,6 +32,7 @@
|
||||||
#include "nsIHttpActivityObserver.h"
|
#include "nsIHttpActivityObserver.h"
|
||||||
#include "nsIHttpAuthenticator.h"
|
#include "nsIHttpAuthenticator.h"
|
||||||
#include "nsIInputStream.h"
|
#include "nsIInputStream.h"
|
||||||
|
#include "nsIInputStreamPriority.h"
|
||||||
#include "nsIMultiplexInputStream.h"
|
#include "nsIMultiplexInputStream.h"
|
||||||
#include "nsIOService.h"
|
#include "nsIOService.h"
|
||||||
#include "nsIPipe.h"
|
#include "nsIPipe.h"
|
||||||
|
@ -1898,6 +1899,14 @@ nsresult nsHttpTransaction::HandleContent(char* buf, uint32_t count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mConnInfo->GetIsTrrServiceChannel()) {
|
||||||
|
// For the TRR channel we want to increase priority so a DoH response
|
||||||
|
// isn't blocked by other main thread events.
|
||||||
|
nsCOMPtr<nsIInputStreamPriority> pri = do_QueryInterface(mPipeIn);
|
||||||
|
if (pri) {
|
||||||
|
pri->SetPriority(nsIRunnablePriority::PRIORITY_MEDIUMHIGH);
|
||||||
|
}
|
||||||
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ XPIDL_SOURCES += [
|
||||||
'nsIFile.idl',
|
'nsIFile.idl',
|
||||||
'nsIInputStream.idl',
|
'nsIInputStream.idl',
|
||||||
'nsIInputStreamLength.idl',
|
'nsIInputStreamLength.idl',
|
||||||
|
'nsIInputStreamPriority.idl',
|
||||||
'nsIInputStreamTee.idl',
|
'nsIInputStreamTee.idl',
|
||||||
'nsIIOUtil.idl',
|
'nsIIOUtil.idl',
|
||||||
'nsILineInputStream.idl',
|
'nsILineInputStream.idl',
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
#include "nsISupports.idl"
|
||||||
|
#include "nsIRunnable.idl"
|
||||||
|
|
||||||
|
[scriptable, uuid(daa45b24-98ee-4eb2-9cec-aad0bc023e9d)]
|
||||||
|
interface nsIInputStreamPriority : nsISupports
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* An input stream implementing this interface will dispatch runnable
|
||||||
|
* events with this priority. See nsIRunnablePriority.
|
||||||
|
*/
|
||||||
|
attribute unsigned long priority;
|
||||||
|
};
|
|
@ -25,6 +25,7 @@
|
||||||
#include "nsPipe.h"
|
#include "nsPipe.h"
|
||||||
#include "nsIAsyncInputStream.h"
|
#include "nsIAsyncInputStream.h"
|
||||||
#include "nsIAsyncOutputStream.h"
|
#include "nsIAsyncOutputStream.h"
|
||||||
|
#include "nsIInputStreamPriority.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
|
||||||
|
@ -130,7 +131,8 @@ class nsPipeInputStream final : public nsIAsyncInputStream,
|
||||||
public nsISearchableInputStream,
|
public nsISearchableInputStream,
|
||||||
public nsICloneableInputStream,
|
public nsICloneableInputStream,
|
||||||
public nsIClassInfo,
|
public nsIClassInfo,
|
||||||
public nsIBufferedInputStream {
|
public nsIBufferedInputStream,
|
||||||
|
public nsIInputStreamPriority {
|
||||||
public:
|
public:
|
||||||
// Pipe input streams preserve their refcount changes when record/replaying,
|
// Pipe input streams preserve their refcount changes when record/replaying,
|
||||||
// as otherwise the thread which destroys the stream may vary between
|
// as otherwise the thread which destroys the stream may vary between
|
||||||
|
@ -143,6 +145,7 @@ class nsPipeInputStream final : public nsIAsyncInputStream,
|
||||||
NS_DECL_NSICLONEABLEINPUTSTREAM
|
NS_DECL_NSICLONEABLEINPUTSTREAM
|
||||||
NS_DECL_NSICLASSINFO
|
NS_DECL_NSICLASSINFO
|
||||||
NS_DECL_NSIBUFFEREDINPUTSTREAM
|
NS_DECL_NSIBUFFEREDINPUTSTREAM
|
||||||
|
NS_DECL_NSIINPUTSTREAMPRIORITY
|
||||||
|
|
||||||
explicit nsPipeInputStream(nsPipe* aPipe)
|
explicit nsPipeInputStream(nsPipe* aPipe)
|
||||||
: mPipe(aPipe),
|
: mPipe(aPipe),
|
||||||
|
@ -150,7 +153,8 @@ class nsPipeInputStream final : public nsIAsyncInputStream,
|
||||||
mInputStatus(NS_OK),
|
mInputStatus(NS_OK),
|
||||||
mBlocking(true),
|
mBlocking(true),
|
||||||
mBlocked(false),
|
mBlocked(false),
|
||||||
mCallbackFlags(0) {}
|
mCallbackFlags(0),
|
||||||
|
mPriority(nsIRunnablePriority::PRIORITY_NORMAL) {}
|
||||||
|
|
||||||
explicit nsPipeInputStream(const nsPipeInputStream& aOther)
|
explicit nsPipeInputStream(const nsPipeInputStream& aOther)
|
||||||
: mPipe(aOther.mPipe),
|
: mPipe(aOther.mPipe),
|
||||||
|
@ -159,7 +163,8 @@ class nsPipeInputStream final : public nsIAsyncInputStream,
|
||||||
mBlocking(aOther.mBlocking),
|
mBlocking(aOther.mBlocking),
|
||||||
mBlocked(false),
|
mBlocked(false),
|
||||||
mCallbackFlags(0),
|
mCallbackFlags(0),
|
||||||
mReadState(aOther.mReadState) {}
|
mReadState(aOther.mReadState),
|
||||||
|
mPriority(nsIRunnablePriority::PRIORITY_NORMAL) {}
|
||||||
|
|
||||||
nsresult Fill();
|
nsresult Fill();
|
||||||
void SetNonBlocking(bool aNonBlocking) { mBlocking = !aNonBlocking; }
|
void SetNonBlocking(bool aNonBlocking) { mBlocking = !aNonBlocking; }
|
||||||
|
@ -205,6 +210,7 @@ class nsPipeInputStream final : public nsIAsyncInputStream,
|
||||||
|
|
||||||
// requires pipe's monitor; usually treat as an opaque token to pass to nsPipe
|
// requires pipe's monitor; usually treat as an opaque token to pass to nsPipe
|
||||||
nsPipeReadState mReadState;
|
nsPipeReadState mReadState;
|
||||||
|
uint32_t mPriority;
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -1154,6 +1160,7 @@ NS_INTERFACE_TABLE_HEAD(nsPipeInputStream)
|
||||||
NS_INTERFACE_TABLE_ENTRY(nsPipeInputStream, nsICloneableInputStream)
|
NS_INTERFACE_TABLE_ENTRY(nsPipeInputStream, nsICloneableInputStream)
|
||||||
NS_INTERFACE_TABLE_ENTRY(nsPipeInputStream, nsIBufferedInputStream)
|
NS_INTERFACE_TABLE_ENTRY(nsPipeInputStream, nsIBufferedInputStream)
|
||||||
NS_INTERFACE_TABLE_ENTRY(nsPipeInputStream, nsIClassInfo)
|
NS_INTERFACE_TABLE_ENTRY(nsPipeInputStream, nsIClassInfo)
|
||||||
|
NS_INTERFACE_TABLE_ENTRY(nsPipeInputStream, nsIInputStreamPriority)
|
||||||
NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsPipeInputStream, nsIInputStream,
|
NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsPipeInputStream, nsIInputStream,
|
||||||
nsIAsyncInputStream)
|
nsIAsyncInputStream)
|
||||||
NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsPipeInputStream, nsISupports,
|
NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsPipeInputStream, nsISupports,
|
||||||
|
@ -1272,6 +1279,18 @@ nsPipeInputStream::CloseWithStatus(nsresult aReason) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsPipeInputStream::SetPriority(uint32_t priority) {
|
||||||
|
mPriority = priority;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsPipeInputStream::GetPriority(uint32_t* priority) {
|
||||||
|
*priority = mPriority;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsPipeInputStream::Close() { return CloseWithStatus(NS_BASE_STREAM_CLOSED); }
|
nsPipeInputStream::Close() { return CloseWithStatus(NS_BASE_STREAM_CLOSED); }
|
||||||
|
|
||||||
|
@ -1384,7 +1403,7 @@ nsPipeInputStream::AsyncWait(nsIInputStreamCallback* aCallback, uint32_t aFlags,
|
||||||
nsCOMPtr<nsIInputStreamCallback> proxy;
|
nsCOMPtr<nsIInputStreamCallback> proxy;
|
||||||
if (aTarget) {
|
if (aTarget) {
|
||||||
proxy = NS_NewInputStreamReadyEvent("nsPipeInputStream::AsyncWait",
|
proxy = NS_NewInputStreamReadyEvent("nsPipeInputStream::AsyncWait",
|
||||||
aCallback, aTarget);
|
aCallback, aTarget, mPriority);
|
||||||
aCallback = proxy;
|
aCallback = proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,13 +33,17 @@ static NS_DEFINE_CID(kStreamTransportServiceCID, NS_STREAMTRANSPORTSERVICE_CID);
|
||||||
// those can be shut down at any time, and in these cases, Cancel() is called
|
// those can be shut down at any time, and in these cases, Cancel() is called
|
||||||
// instead of Run().
|
// instead of Run().
|
||||||
class nsInputStreamReadyEvent final : public CancelableRunnable,
|
class nsInputStreamReadyEvent final : public CancelableRunnable,
|
||||||
public nsIInputStreamCallback {
|
public nsIInputStreamCallback,
|
||||||
|
public nsIRunnablePriority {
|
||||||
public:
|
public:
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
NS_DECL_ISUPPORTS_INHERITED
|
||||||
|
|
||||||
nsInputStreamReadyEvent(const char* aName, nsIInputStreamCallback* aCallback,
|
nsInputStreamReadyEvent(const char* aName, nsIInputStreamCallback* aCallback,
|
||||||
nsIEventTarget* aTarget)
|
nsIEventTarget* aTarget, uint32_t aPriority)
|
||||||
: CancelableRunnable(aName), mCallback(aCallback), mTarget(aTarget) {}
|
: CancelableRunnable(aName),
|
||||||
|
mCallback(aCallback),
|
||||||
|
mTarget(aTarget),
|
||||||
|
mPriority(aPriority) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~nsInputStreamReadyEvent() {
|
~nsInputStreamReadyEvent() {
|
||||||
|
@ -57,7 +61,7 @@ class nsInputStreamReadyEvent final : public CancelableRunnable,
|
||||||
nsresult rv = mTarget->IsOnCurrentThread(&val);
|
nsresult rv = mTarget->IsOnCurrentThread(&val);
|
||||||
if (NS_FAILED(rv) || !val) {
|
if (NS_FAILED(rv) || !val) {
|
||||||
nsCOMPtr<nsIInputStreamCallback> event = NS_NewInputStreamReadyEvent(
|
nsCOMPtr<nsIInputStreamCallback> event = NS_NewInputStreamReadyEvent(
|
||||||
"~nsInputStreamReadyEvent", mCallback, mTarget);
|
"~nsInputStreamReadyEvent", mCallback, mTarget, mPriority);
|
||||||
mCallback = nullptr;
|
mCallback = nullptr;
|
||||||
if (event) {
|
if (event) {
|
||||||
rv = event->OnInputStreamReady(nullptr);
|
rv = event->OnInputStreamReady(nullptr);
|
||||||
|
@ -98,14 +102,20 @@ class nsInputStreamReadyEvent final : public CancelableRunnable,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHOD GetPriority(uint32_t* aPriority) override {
|
||||||
|
*aPriority = mPriority;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nsCOMPtr<nsIAsyncInputStream> mStream;
|
nsCOMPtr<nsIAsyncInputStream> mStream;
|
||||||
nsCOMPtr<nsIInputStreamCallback> mCallback;
|
nsCOMPtr<nsIInputStreamCallback> mCallback;
|
||||||
nsCOMPtr<nsIEventTarget> mTarget;
|
nsCOMPtr<nsIEventTarget> mTarget;
|
||||||
|
uint32_t mPriority;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS_INHERITED(nsInputStreamReadyEvent, CancelableRunnable,
|
NS_IMPL_ISUPPORTS_INHERITED(nsInputStreamReadyEvent, CancelableRunnable,
|
||||||
nsIInputStreamCallback)
|
nsIInputStreamCallback, nsIRunnablePriority)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -193,11 +203,11 @@ NS_IMPL_ISUPPORTS_INHERITED(nsOutputStreamReadyEvent, CancelableRunnable,
|
||||||
|
|
||||||
already_AddRefed<nsIInputStreamCallback> NS_NewInputStreamReadyEvent(
|
already_AddRefed<nsIInputStreamCallback> NS_NewInputStreamReadyEvent(
|
||||||
const char* aName, nsIInputStreamCallback* aCallback,
|
const char* aName, nsIInputStreamCallback* aCallback,
|
||||||
nsIEventTarget* aTarget) {
|
nsIEventTarget* aTarget, uint32_t aPriority) {
|
||||||
NS_ASSERTION(aCallback, "null callback");
|
NS_ASSERTION(aCallback, "null callback");
|
||||||
NS_ASSERTION(aTarget, "null target");
|
NS_ASSERTION(aTarget, "null target");
|
||||||
RefPtr<nsInputStreamReadyEvent> ev =
|
RefPtr<nsInputStreamReadyEvent> ev =
|
||||||
new nsInputStreamReadyEvent(aName, aCallback, aTarget);
|
new nsInputStreamReadyEvent(aName, aCallback, aTarget, aPriority);
|
||||||
return ev.forget();
|
return ev.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "nsStringFwd.h"
|
#include "nsStringFwd.h"
|
||||||
#include "nsIInputStream.h"
|
#include "nsIInputStream.h"
|
||||||
#include "nsTArray.h"
|
#include "nsTArray.h"
|
||||||
|
#include "nsIRunnable.h"
|
||||||
|
|
||||||
class nsIAsyncInputStream;
|
class nsIAsyncInputStream;
|
||||||
class nsIOutputStream;
|
class nsIOutputStream;
|
||||||
|
@ -27,10 +28,13 @@ class nsIEventTarget;
|
||||||
*
|
*
|
||||||
* This function is designed to be used to implement AsyncWait when the
|
* This function is designed to be used to implement AsyncWait when the
|
||||||
* aTarget parameter is non-null.
|
* aTarget parameter is non-null.
|
||||||
|
*
|
||||||
|
* The optional aPriority parameter allows the input stream runnable events
|
||||||
|
* to be dispatched with a different priority than normal.
|
||||||
*/
|
*/
|
||||||
extern already_AddRefed<nsIInputStreamCallback> NS_NewInputStreamReadyEvent(
|
extern already_AddRefed<nsIInputStreamCallback> NS_NewInputStreamReadyEvent(
|
||||||
const char* aName, nsIInputStreamCallback* aNotify,
|
const char* aName, nsIInputStreamCallback* aNotify, nsIEventTarget* aTarget,
|
||||||
nsIEventTarget* aTarget);
|
uint32_t aPriority = nsIRunnablePriority::PRIORITY_NORMAL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A "one-shot" proxy of the OnOutputStreamReady callback. The resulting
|
* A "one-shot" proxy of the OnOutputStreamReady callback. The resulting
|
||||||
|
|
Загрузка…
Ссылка в новой задаче