зеркало из 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 "nsIHttpAuthenticator.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIInputStreamPriority.h"
|
||||
#include "nsIMultiplexInputStream.h"
|
||||
#include "nsIOService.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;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ XPIDL_SOURCES += [
|
|||
'nsIFile.idl',
|
||||
'nsIInputStream.idl',
|
||||
'nsIInputStreamLength.idl',
|
||||
'nsIInputStreamPriority.idl',
|
||||
'nsIInputStreamTee.idl',
|
||||
'nsIIOUtil.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 "nsIAsyncInputStream.h"
|
||||
#include "nsIAsyncOutputStream.h"
|
||||
#include "nsIInputStreamPriority.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
|
@ -130,7 +131,8 @@ class nsPipeInputStream final : public nsIAsyncInputStream,
|
|||
public nsISearchableInputStream,
|
||||
public nsICloneableInputStream,
|
||||
public nsIClassInfo,
|
||||
public nsIBufferedInputStream {
|
||||
public nsIBufferedInputStream,
|
||||
public nsIInputStreamPriority {
|
||||
public:
|
||||
// Pipe input streams preserve their refcount changes when record/replaying,
|
||||
// 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_NSICLASSINFO
|
||||
NS_DECL_NSIBUFFEREDINPUTSTREAM
|
||||
NS_DECL_NSIINPUTSTREAMPRIORITY
|
||||
|
||||
explicit nsPipeInputStream(nsPipe* aPipe)
|
||||
: mPipe(aPipe),
|
||||
|
@ -150,7 +153,8 @@ class nsPipeInputStream final : public nsIAsyncInputStream,
|
|||
mInputStatus(NS_OK),
|
||||
mBlocking(true),
|
||||
mBlocked(false),
|
||||
mCallbackFlags(0) {}
|
||||
mCallbackFlags(0),
|
||||
mPriority(nsIRunnablePriority::PRIORITY_NORMAL) {}
|
||||
|
||||
explicit nsPipeInputStream(const nsPipeInputStream& aOther)
|
||||
: mPipe(aOther.mPipe),
|
||||
|
@ -159,7 +163,8 @@ class nsPipeInputStream final : public nsIAsyncInputStream,
|
|||
mBlocking(aOther.mBlocking),
|
||||
mBlocked(false),
|
||||
mCallbackFlags(0),
|
||||
mReadState(aOther.mReadState) {}
|
||||
mReadState(aOther.mReadState),
|
||||
mPriority(nsIRunnablePriority::PRIORITY_NORMAL) {}
|
||||
|
||||
nsresult Fill();
|
||||
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
|
||||
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, nsIBufferedInputStream)
|
||||
NS_INTERFACE_TABLE_ENTRY(nsPipeInputStream, nsIClassInfo)
|
||||
NS_INTERFACE_TABLE_ENTRY(nsPipeInputStream, nsIInputStreamPriority)
|
||||
NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsPipeInputStream, nsIInputStream,
|
||||
nsIAsyncInputStream)
|
||||
NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsPipeInputStream, nsISupports,
|
||||
|
@ -1272,6 +1279,18 @@ nsPipeInputStream::CloseWithStatus(nsresult aReason) {
|
|||
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
|
||||
nsPipeInputStream::Close() { return CloseWithStatus(NS_BASE_STREAM_CLOSED); }
|
||||
|
||||
|
@ -1384,7 +1403,7 @@ nsPipeInputStream::AsyncWait(nsIInputStreamCallback* aCallback, uint32_t aFlags,
|
|||
nsCOMPtr<nsIInputStreamCallback> proxy;
|
||||
if (aTarget) {
|
||||
proxy = NS_NewInputStreamReadyEvent("nsPipeInputStream::AsyncWait",
|
||||
aCallback, aTarget);
|
||||
aCallback, aTarget, mPriority);
|
||||
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
|
||||
// instead of Run().
|
||||
class nsInputStreamReadyEvent final : public CancelableRunnable,
|
||||
public nsIInputStreamCallback {
|
||||
public nsIInputStreamCallback,
|
||||
public nsIRunnablePriority {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
nsInputStreamReadyEvent(const char* aName, nsIInputStreamCallback* aCallback,
|
||||
nsIEventTarget* aTarget)
|
||||
: CancelableRunnable(aName), mCallback(aCallback), mTarget(aTarget) {}
|
||||
nsIEventTarget* aTarget, uint32_t aPriority)
|
||||
: CancelableRunnable(aName),
|
||||
mCallback(aCallback),
|
||||
mTarget(aTarget),
|
||||
mPriority(aPriority) {}
|
||||
|
||||
private:
|
||||
~nsInputStreamReadyEvent() {
|
||||
|
@ -57,7 +61,7 @@ class nsInputStreamReadyEvent final : public CancelableRunnable,
|
|||
nsresult rv = mTarget->IsOnCurrentThread(&val);
|
||||
if (NS_FAILED(rv) || !val) {
|
||||
nsCOMPtr<nsIInputStreamCallback> event = NS_NewInputStreamReadyEvent(
|
||||
"~nsInputStreamReadyEvent", mCallback, mTarget);
|
||||
"~nsInputStreamReadyEvent", mCallback, mTarget, mPriority);
|
||||
mCallback = nullptr;
|
||||
if (event) {
|
||||
rv = event->OnInputStreamReady(nullptr);
|
||||
|
@ -98,14 +102,20 @@ class nsInputStreamReadyEvent final : public CancelableRunnable,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetPriority(uint32_t* aPriority) override {
|
||||
*aPriority = mPriority;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIAsyncInputStream> mStream;
|
||||
nsCOMPtr<nsIInputStreamCallback> mCallback;
|
||||
nsCOMPtr<nsIEventTarget> mTarget;
|
||||
uint32_t mPriority;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsInputStreamReadyEvent, CancelableRunnable,
|
||||
nsIInputStreamCallback)
|
||||
nsIInputStreamCallback, nsIRunnablePriority)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
@ -193,11 +203,11 @@ NS_IMPL_ISUPPORTS_INHERITED(nsOutputStreamReadyEvent, CancelableRunnable,
|
|||
|
||||
already_AddRefed<nsIInputStreamCallback> NS_NewInputStreamReadyEvent(
|
||||
const char* aName, nsIInputStreamCallback* aCallback,
|
||||
nsIEventTarget* aTarget) {
|
||||
nsIEventTarget* aTarget, uint32_t aPriority) {
|
||||
NS_ASSERTION(aCallback, "null callback");
|
||||
NS_ASSERTION(aTarget, "null target");
|
||||
RefPtr<nsInputStreamReadyEvent> ev =
|
||||
new nsInputStreamReadyEvent(aName, aCallback, aTarget);
|
||||
new nsInputStreamReadyEvent(aName, aCallback, aTarget, aPriority);
|
||||
return ev.forget();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "nsStringFwd.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsIRunnable.h"
|
||||
|
||||
class nsIAsyncInputStream;
|
||||
class nsIOutputStream;
|
||||
|
@ -27,10 +28,13 @@ class nsIEventTarget;
|
|||
*
|
||||
* This function is designed to be used to implement AsyncWait when the
|
||||
* 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(
|
||||
const char* aName, nsIInputStreamCallback* aNotify,
|
||||
nsIEventTarget* aTarget);
|
||||
const char* aName, nsIInputStreamCallback* aNotify, nsIEventTarget* aTarget,
|
||||
uint32_t aPriority = nsIRunnablePriority::PRIORITY_NORMAL);
|
||||
|
||||
/**
|
||||
* A "one-shot" proxy of the OnOutputStreamReady callback. The resulting
|
||||
|
|
Загрузка…
Ссылка в новой задаче