Bug 1413999 - Part3: IPC part, send trailers to child process r=dragana

The aim of this patch is to send trailers to child process via SendOnStopRequest.

--HG--
extra : rebase_source : 1a5e16e140ef20cfe2e723c3800d7feeebd9a5af
This commit is contained in:
Kershaw Chang 2018-01-03 02:05:00 +02:00
Родитель 73d9823e67
Коммит 62a41d6974
8 изменённых файлов: 52 добавлений и 23 удалений

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

@ -179,9 +179,10 @@ HttpBackgroundChannelChild::RecvOnTransportAndData(
IPCResult IPCResult
HttpBackgroundChannelChild::RecvOnStopRequest( HttpBackgroundChannelChild::RecvOnStopRequest(
const nsresult& aChannelStatus, const nsresult& aChannelStatus,
const ResourceTimingStruct& aTiming, const ResourceTimingStruct& aTiming,
const TimeStamp& aLastActiveTabOptHit) const TimeStamp& aLastActiveTabOptHit,
const nsHttpHeaderArray& aResponseTrailers)
{ {
LOG(("HttpBackgroundChannelChild::RecvOnStopRequest [this=%p]\n", this)); LOG(("HttpBackgroundChannelChild::RecvOnStopRequest [this=%p]\n", this));
MOZ_ASSERT(OnSocketThread()); MOZ_ASSERT(OnSocketThread());
@ -200,18 +201,22 @@ HttpBackgroundChannelChild::RecvOnStopRequest(
static_cast<uint32_t>(aChannelStatus))); static_cast<uint32_t>(aChannelStatus)));
mQueuedRunnables.AppendElement( mQueuedRunnables.AppendElement(
NewRunnableMethod<const nsresult, const ResourceTimingStruct, const TimeStamp>( NewRunnableMethod<const nsresult,
const ResourceTimingStruct,
const TimeStamp,
const nsHttpHeaderArray>(
"HttpBackgroundChannelChild::RecvOnStopRequest", "HttpBackgroundChannelChild::RecvOnStopRequest",
this, this,
&HttpBackgroundChannelChild::RecvOnStopRequest, &HttpBackgroundChannelChild::RecvOnStopRequest,
aChannelStatus, aChannelStatus,
aTiming, aTiming,
aLastActiveTabOptHit)); aLastActiveTabOptHit,
aResponseTrailers));
return IPC_OK(); return IPC_OK();
} }
mChannelChild->ProcessOnStopRequest(aChannelStatus, aTiming); mChannelChild->ProcessOnStopRequest(aChannelStatus, aTiming, aResponseTrailers);
return IPC_OK(); return IPC_OK();
} }

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

@ -49,7 +49,8 @@ protected:
IPCResult RecvOnStopRequest(const nsresult& aChannelStatus, IPCResult RecvOnStopRequest(const nsresult& aChannelStatus,
const ResourceTimingStruct& aTiming, const ResourceTimingStruct& aTiming,
const TimeStamp& aLastActiveTabOptHit) override; const TimeStamp& aLastActiveTabOptHit,
const nsHttpHeaderArray& aResponseTrailers) override;
IPCResult RecvOnProgress(const int64_t& aProgress, IPCResult RecvOnProgress(const int64_t& aProgress,
const int64_t& aProgressMax) override; const int64_t& aProgressMax) override;

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

@ -220,7 +220,8 @@ HttpBackgroundChannelParent::OnTransportAndData(
bool bool
HttpBackgroundChannelParent::OnStopRequest(const nsresult& aChannelStatus, HttpBackgroundChannelParent::OnStopRequest(const nsresult& aChannelStatus,
const ResourceTimingStruct& aTiming) const ResourceTimingStruct& aTiming,
const nsHttpHeaderArray& aResponseTrailers)
{ {
LOG(("HttpBackgroundChannelParent::OnStopRequest [this=%p " LOG(("HttpBackgroundChannelParent::OnStopRequest [this=%p "
"status=%" PRIx32 "]\n", this, static_cast<uint32_t>(aChannelStatus))); "status=%" PRIx32 "]\n", this, static_cast<uint32_t>(aChannelStatus)));
@ -233,12 +234,15 @@ HttpBackgroundChannelParent::OnStopRequest(const nsresult& aChannelStatus,
if (!IsOnBackgroundThread()) { if (!IsOnBackgroundThread()) {
MutexAutoLock lock(mBgThreadMutex); MutexAutoLock lock(mBgThreadMutex);
nsresult rv = mBackgroundThread->Dispatch( nsresult rv = mBackgroundThread->Dispatch(
NewRunnableMethod<const nsresult, const ResourceTimingStruct>( NewRunnableMethod<const nsresult,
const ResourceTimingStruct,
const nsHttpHeaderArray>(
"net::HttpBackgroundChannelParent::OnStopRequest", "net::HttpBackgroundChannelParent::OnStopRequest",
this, this,
&HttpBackgroundChannelParent::OnStopRequest, &HttpBackgroundChannelParent::OnStopRequest,
aChannelStatus, aChannelStatus,
aTiming), aTiming,
aResponseTrailers),
NS_DISPATCH_NORMAL); NS_DISPATCH_NORMAL);
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv)); MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
@ -249,7 +253,7 @@ HttpBackgroundChannelParent::OnStopRequest(const nsresult& aChannelStatus,
// See the child code for why we do this. // See the child code for why we do this.
TimeStamp lastActTabOpt = nsHttp::GetLastActiveTabLoadOptimizationHit(); TimeStamp lastActTabOpt = nsHttp::GetLastActiveTabLoadOptimizationHit();
return SendOnStopRequest(aChannelStatus, aTiming, lastActTabOpt); return SendOnStopRequest(aChannelStatus, aTiming, lastActTabOpt, aResponseTrailers);
} }
bool bool

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

@ -52,7 +52,8 @@ public:
// To send OnStopRequest message over background channel. // To send OnStopRequest message over background channel.
bool OnStopRequest(const nsresult& aChannelStatus, bool OnStopRequest(const nsresult& aChannelStatus,
const ResourceTimingStruct& aTiming); const ResourceTimingStruct& aTiming,
const nsHttpHeaderArray& aResponseTrailers);
// To send OnProgress message over background channel. // To send OnProgress message over background channel.
bool OnProgress(const int64_t& aProgress, bool OnProgress(const int64_t& aProgress,

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

@ -979,28 +979,33 @@ class StopRequestEvent : public NeckoTargetChannelEvent<HttpChannelChild>
public: public:
StopRequestEvent(HttpChannelChild* child, StopRequestEvent(HttpChannelChild* child,
const nsresult& channelStatus, const nsresult& channelStatus,
const ResourceTimingStruct& timing) const ResourceTimingStruct& timing,
const nsHttpHeaderArray& aResponseTrailers)
: NeckoTargetChannelEvent<HttpChannelChild>(child) : NeckoTargetChannelEvent<HttpChannelChild>(child)
, mChannelStatus(channelStatus) , mChannelStatus(channelStatus)
, mTiming(timing) {} , mTiming(timing)
, mResponseTrailers(aResponseTrailers) {}
void Run() { mChild->OnStopRequest(mChannelStatus, mTiming); } void Run() { mChild->OnStopRequest(mChannelStatus, mTiming, mResponseTrailers); }
private: private:
nsresult mChannelStatus; nsresult mChannelStatus;
ResourceTimingStruct mTiming; ResourceTimingStruct mTiming;
nsHttpHeaderArray mResponseTrailers;
}; };
void void
HttpChannelChild::ProcessOnStopRequest(const nsresult& aChannelStatus, HttpChannelChild::ProcessOnStopRequest(const nsresult& aChannelStatus,
const ResourceTimingStruct& aTiming) const ResourceTimingStruct& aTiming,
const nsHttpHeaderArray& aResponseTrailers)
{ {
LOG(("HttpChannelChild::ProcessOnStopRequest [this=%p]\n", this)); LOG(("HttpChannelChild::ProcessOnStopRequest [this=%p]\n", this));
MOZ_ASSERT(OnSocketThread()); MOZ_ASSERT(OnSocketThread());
MOZ_RELEASE_ASSERT(!mFlushedForDiversion, MOZ_RELEASE_ASSERT(!mFlushedForDiversion,
"Should not be receiving any more callbacks from parent!"); "Should not be receiving any more callbacks from parent!");
mEventQ->RunOrEnqueue(new StopRequestEvent(this, aChannelStatus, aTiming), mEventQ->RunOrEnqueue(new StopRequestEvent(this, aChannelStatus,
aTiming, aResponseTrailers),
mDivertingToParent); mDivertingToParent);
} }
@ -1036,7 +1041,8 @@ HttpChannelChild::MaybeDivertOnStop(const nsresult& aChannelStatus)
void void
HttpChannelChild::OnStopRequest(const nsresult& channelStatus, HttpChannelChild::OnStopRequest(const nsresult& channelStatus,
const ResourceTimingStruct& timing) const ResourceTimingStruct& timing,
const nsHttpHeaderArray& aResponseTrailers)
{ {
LOG(("HttpChannelChild::OnStopRequest [this=%p status=%" PRIx32 "]\n", LOG(("HttpChannelChild::OnStopRequest [this=%p status=%" PRIx32 "]\n",
this, static_cast<uint32_t>(channelStatus))); this, static_cast<uint32_t>(channelStatus)));
@ -1089,6 +1095,8 @@ HttpChannelChild::OnStopRequest(const nsresult& channelStatus,
mCacheReadStart = timing.cacheReadStart; mCacheReadStart = timing.cacheReadStart;
mCacheReadEnd = timing.cacheReadEnd; mCacheReadEnd = timing.cacheReadEnd;
mResponseTrailers = new nsHttpHeaderArray(aResponseTrailers);
DoPreOnStopRequest(channelStatus); DoPreOnStopRequest(channelStatus);
{ // We must flush the queue before we Send__delete__ { // We must flush the queue before we Send__delete__

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

@ -242,7 +242,8 @@ private:
const uint32_t& aCount, const uint32_t& aCount,
const nsCString& aData); const nsCString& aData);
void ProcessOnStopRequest(const nsresult& aStatusCode, void ProcessOnStopRequest(const nsresult& aStatusCode,
const ResourceTimingStruct& aTiming); const ResourceTimingStruct& aTiming,
const nsHttpHeaderArray& aResponseTrailers);
void ProcessOnProgress(const int64_t& aProgress, const int64_t& aProgressMax); void ProcessOnProgress(const int64_t& aProgress, const int64_t& aProgressMax);
void ProcessOnStatus(const nsresult& aStatus); void ProcessOnStatus(const nsresult& aStatus);
void ProcessFlushedForDiversion(); void ProcessFlushedForDiversion();
@ -415,7 +416,9 @@ private:
const uint64_t& offset, const uint64_t& offset,
const uint32_t& count, const uint32_t& count,
const nsCString& data); const nsCString& data);
void OnStopRequest(const nsresult& channelStatus, const ResourceTimingStruct& timing); void OnStopRequest(const nsresult& channelStatus,
const ResourceTimingStruct& timing,
const nsHttpHeaderArray& aResponseTrailers);
void MaybeDivertOnStop(const nsresult& aChannelStatus); void MaybeDivertOnStop(const nsresult& aChannelStatus);
void OnProgress(const int64_t& progress, const int64_t& progressMax); void OnProgress(const int64_t& progress, const int64_t& progressMax);
void OnStatus(const nsresult& status); void OnStatus(const nsresult& status);

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

@ -1596,12 +1596,16 @@ HttpChannelParent::OnStopRequest(nsIRequest *aRequest,
httpChannelImpl->SetWarningReporter(nullptr); httpChannelImpl->SetWarningReporter(nullptr);
} }
nsHttpHeaderArray *responseTrailer = mChannel->GetResponseTrailers();
// Either IPC channel is closed or background channel // Either IPC channel is closed or background channel
// is ready to send OnStopRequest. // is ready to send OnStopRequest.
MOZ_ASSERT(mIPCClosed || mBgParent); MOZ_ASSERT(mIPCClosed || mBgParent);
if (mIPCClosed || if (mIPCClosed ||
!mBgParent || !mBgParent->OnStopRequest(aStatusCode, timing)) { !mBgParent ||
!mBgParent->OnStopRequest(aStatusCode, timing,
responseTrailer ? *responseTrailer : nsHttpHeaderArray())) {
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }

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

@ -11,6 +11,7 @@ include PURLClassifierInfo;
include "mozilla/net/NeckoMessageUtils.h"; include "mozilla/net/NeckoMessageUtils.h";
using class nsHttpHeaderArray from "nsHttpHeaderArray.h";
using struct mozilla::net::ResourceTimingStruct from "mozilla/net/TimingStruct.h"; using struct mozilla::net::ResourceTimingStruct from "mozilla/net/TimingStruct.h";
namespace mozilla { namespace mozilla {
@ -36,8 +37,10 @@ child:
uint32_t count, uint32_t count,
nsCString data); nsCString data);
async OnStopRequest(nsresult channelStatus, ResourceTimingStruct timing, async OnStopRequest(nsresult channelStatus,
TimeStamp lastActiveTabOptimization); ResourceTimingStruct timing,
TimeStamp lastActiveTabOptimization,
nsHttpHeaderArray responseTrailers);
async OnProgress(int64_t progress, int64_t progressMax); async OnProgress(int64_t progress, int64_t progressMax);