Skip to content

Commit

Permalink
Bug 1767609 - Create Http2StreamBase r=necko-reviewers,kershaw
Browse files Browse the repository at this point in the history
  • Loading branch information
ddragana committed Jun 13, 2022
1 parent 1b8bae7 commit cf69013
Show file tree
Hide file tree
Showing 13 changed files with 2,380 additions and 2,206 deletions.
30 changes: 15 additions & 15 deletions netwerk/protocol/http/Http2Push.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Http2PushedStreamWrapper::~Http2PushedStreamWrapper() {
Http2PushedStream* Http2PushedStreamWrapper::GetStream() {
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
if (mStream) {
Http2Stream* stream = mStream;
Http2StreamBase* stream = mStream;
return static_cast<Http2PushedStream*>(stream);
}
return nullptr;
Expand All @@ -92,7 +92,7 @@ Http2PushedStream* Http2PushedStreamWrapper::GetStream() {
void Http2PushedStreamWrapper::OnPushFailed() {
if (OnSocketThread()) {
if (mStream) {
Http2Stream* stream = mStream;
Http2StreamBase* stream = mStream;
static_cast<Http2PushedStream*>(stream)->OnPushFailed();
}
} else {
Expand All @@ -109,10 +109,10 @@ void Http2PushedStreamWrapper::OnPushFailed() {

Http2PushedStream::Http2PushedStream(
Http2PushTransactionBuffer* aTransaction, Http2Session* aSession,
Http2Stream* aAssociatedStream, uint32_t aID,
Http2StreamBase* aAssociatedStream, uint32_t aID,
uint64_t aCurrentForegroundTabOuterContentWindowId)
: Http2Stream(aTransaction, aSession, 0,
aCurrentForegroundTabOuterContentWindowId),
: Http2StreamBase(aTransaction, aSession, 0,
aCurrentForegroundTabOuterContentWindowId),
mAssociatedTransaction(aAssociatedStream->Transaction()),
mBufferedPush(aTransaction) {
LOG3(("Http2PushedStream ctor this=%p 0x%X\n", this, aID));
Expand Down Expand Up @@ -140,7 +140,7 @@ bool Http2PushedStream::GetPushComplete() { return mPushCompleted; }
nsresult Http2PushedStream::WriteSegments(nsAHttpSegmentWriter* writer,
uint32_t count,
uint32_t* countWritten) {
nsresult rv = Http2Stream::WriteSegments(writer, count, countWritten);
nsresult rv = Http2StreamBase::WriteSegments(writer, count, countWritten);
if (NS_SUCCEEDED(rv) && *countWritten) {
mLastRead = TimeStamp::Now();
}
Expand Down Expand Up @@ -196,9 +196,9 @@ bool Http2PushedStream::TryOnPush() {
return true;
}

// side effect free static method to determine if Http2Stream implements
// side effect free static method to determine if Http2StreamBase implements
// nsIHttpPushListener
bool Http2PushedStream::TestOnPush(Http2Stream* stream) {
bool Http2PushedStream::TestOnPush(Http2StreamBase* stream) {
if (!stream) {
return false;
}
Expand Down Expand Up @@ -234,9 +234,9 @@ nsresult Http2PushedStream::ReadSegments(nsAHttpSegmentReader* reader, uint32_t,
// the write side of a pushed transaction just involves manipulating a
// little state
SetSentFin(true);
Http2Stream::mRequestHeadersDone = 1;
Http2Stream::mOpenGenerated = 1;
Http2Stream::ChangeState(UPSTREAM_COMPLETE);
Http2StreamBase::mRequestHeadersDone = 1;
Http2StreamBase::mOpenGenerated = 1;
Http2StreamBase::ChangeState(UPSTREAM_COMPLETE);
} break;

case UPSTREAM_COMPLETE:
Expand Down Expand Up @@ -265,7 +265,7 @@ void Http2PushedStream::AdjustInitialWindow() {
("Http2PushStream::AdjustInitialWindow %p 0x%X "
"calling super consumer %p 0x%X\n",
this, mStreamID, mConsumerStream, mConsumerStream->StreamID()));
Http2Stream::AdjustInitialWindow();
Http2StreamBase::AdjustInitialWindow();
// Http2PushedStream::ReadSegments is needed to call TransmitFrame()
// and actually get this information into the session bytestream
RefPtr<Http2Session> session = Session();
Expand All @@ -275,7 +275,7 @@ void Http2PushedStream::AdjustInitialWindow() {
// anyway, so we're good to go.
}

void Http2PushedStream::SetConsumerStream(Http2Stream* consumer) {
void Http2PushedStream::SetConsumerStream(Http2StreamBase* consumer) {
LOG3(("Http2PushedStream::SetConsumerStream this=%p consumer=%p", this,
consumer));

Expand All @@ -290,7 +290,7 @@ bool Http2PushedStream::GetHashKey(nsCString& key) {
return true;
}

void Http2PushedStream::ConnectPushedStream(Http2Stream* stream) {
void Http2PushedStream::ConnectPushedStream(Http2StreamBase* stream) {
RefPtr<Http2Session> session = Session();
session->ConnectPushedStream(stream);
}
Expand Down Expand Up @@ -434,7 +434,7 @@ nsresult Http2PushTransactionBuffer::WriteSegments(nsAHttpSegmentWriter* writer,
}

if (Available() || mIsDone) {
Http2Stream* consumer = mPushStream->GetConsumerStream();
Http2StreamBase* consumer = mPushStream->GetConsumerStream();

if (consumer) {
LOG3(
Expand Down
24 changes: 13 additions & 11 deletions netwerk/protocol/http/Http2Push.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// https://www.rfc-editor.org/rfc/rfc7540.txt

#include "Http2Session.h"
#include "Http2Stream.h"
#include "Http2StreamBase.h"

#include "mozilla/Attributes.h"
#include "mozilla/TimeStamp.h"
Expand All @@ -25,33 +25,35 @@ namespace net {

class Http2PushTransactionBuffer;

class Http2PushedStream final : public Http2Stream {
class Http2PushedStream final : public Http2StreamBase {
public:
Http2PushedStream(Http2PushTransactionBuffer* aTransaction,
Http2Session* aSession, Http2Stream* aAssociatedStream,
Http2Session* aSession, Http2StreamBase* aAssociatedStream,
uint32_t aID,
uint64_t aCurrentForegroundTabOuterContentWindowId);

bool GetPushComplete();

// The consumer stream is the synthetic pull stream hooked up to this push
virtual Http2Stream* GetConsumerStream() override { return mConsumerStream; };
virtual Http2StreamBase* GetConsumerStream() override {
return mConsumerStream;
};

void SetConsumerStream(Http2Stream* consumer);
void SetConsumerStream(Http2StreamBase* consumer);
[[nodiscard]] bool GetHashKey(nsCString& key);

// override of Http2Stream
// override of Http2StreamBase
[[nodiscard]] nsresult ReadSegments(nsAHttpSegmentReader*, uint32_t,
uint32_t*) override;
[[nodiscard]] nsresult WriteSegments(nsAHttpSegmentWriter*, uint32_t,
uint32_t*) override;
void AdjustInitialWindow() override;

nsIRequestContext* RequestContext() override { return mRequestContext; };
void ConnectPushedStream(Http2Stream* stream);
void ConnectPushedStream(Http2StreamBase* stream);

[[nodiscard]] bool TryOnPush();
[[nodiscard]] static bool TestOnPush(Http2Stream* stream);
[[nodiscard]] static bool TestOnPush(Http2StreamBase* stream);

virtual bool DeferCleanup(nsresult status) override;
void SetDeferCleanupOnSuccess(bool val) { mDeferCleanupOnSuccess = val; }
Expand All @@ -65,7 +67,7 @@ class Http2PushedStream final : public Http2Stream {
[[nodiscard]] nsresult GetBufferedData(char* buf, uint32_t count,
uint32_t* countWritten);

// overload of Http2Stream
// overload of Http2StreamBase
virtual bool HasSink() override { return !!mConsumerStream; }
virtual void SetPushComplete() override { mPushCompleted = true; }
virtual void TopBrowsingContextIdChanged(uint64_t) override;
Expand All @@ -77,7 +79,7 @@ class Http2PushedStream final : public Http2Stream {
virtual ~Http2PushedStream() = default;
// paired request stream that consumes from real http/2 one.. null until a
// match is made.
Http2Stream* mConsumerStream{nullptr};
Http2StreamBase* mConsumerStream{nullptr};

nsCOMPtr<nsIRequestContext> mRequestContext;

Expand Down Expand Up @@ -152,7 +154,7 @@ class Http2PushedStreamWrapper : public nsISupports {
nsCString mRequestString;
nsCString mResourceUrl;
uint32_t mStreamID;
WeakPtr<Http2Stream> mStream;
WeakPtr<Http2StreamBase> mStream;
};

} // namespace net
Expand Down
Loading

0 comments on commit cf69013

Please sign in to comment.