Bug 1497235 - P3: Pass classOfService to socket process, r=dragana
authorKershaw Chang <kershaw@mozilla.com>
Tue, 29 Jan 2019 18:17:29 +0100
changeset 448036 ea6dacc7189bddb8ff3638e4eb3f8a53dd958a20
parent 448035 41d3a13f5782ead12d6db9e94bf1a647f9734414
child 448037 3395adff5c4dce4d305407dcff3b73a2b4637249
push id29
push userkjang@mozilla.com
push dateTue, 29 Jan 2019 17:18:03 +0000
reviewersdragana
bugs1497235
milestone66.0a1
Bug 1497235 - P3: Pass classOfService to socket process, r=dragana Summary: Simply pass classOfService to socket process via Init() message.
netwerk/protocol/http/HttpTransactionChild.cpp
netwerk/protocol/http/HttpTransactionChild.h
netwerk/protocol/http/HttpTransactionParent.cpp
netwerk/protocol/http/PHttpTransaction.ipdl
netwerk/protocol/http/nsAHttpTransactionShell.h
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/protocol/http/nsHttpTransaction.cpp
--- a/netwerk/protocol/http/HttpTransactionChild.cpp
+++ b/netwerk/protocol/http/HttpTransactionChild.cpp
@@ -63,17 +63,18 @@ nsresult
 HttpTransactionChild::InitInternal(uint32_t caps,
                                    const HttpConnectionInfoCloneArgs &infoArgs,
                                    nsHttpRequestHead *requestHead,
                                    nsIInputStream *requestBody,
                                    uint64_t requestContentLength,
                                    bool requestBodyHasHeaders,
                                    nsIEventTarget *target,
                                    uint64_t topLevelOuterContentWindowId,
-                                   uint64_t requestContextID)
+                                   uint64_t requestContextID,
+                                   uint32_t classOfService)
 {
   LOG(("HttpTransactionChild::InitInternal [this=%p caps=%x]\n", this, caps));
 
   nsProxyInfo *proxyInfo = new nsProxyInfo(infoArgs.proxyInfo().type(),
                                            infoArgs.proxyInfo().host(),
                                            infoArgs.proxyInfo().port(),
                                            infoArgs.proxyInfo().username(),
                                            infoArgs.proxyInfo().password(),
@@ -102,17 +103,17 @@ HttpTransactionChild::InitInternal(uint3
 
   nsCOMPtr<nsIRequestContext> rc = CreateRequestContext(requestContextID);
   LOG(("  CreateRequestContext this=%p id=%" PRIx64, this, requestContextID));
 
   nsresult rv =
    mTransaction->Init(caps, cinfo, requestHead, requestBody,
                       requestContentLength, requestBodyHasHeaders,
                       target, nullptr, // TODO: security callback
-                      this, topLevelOuterContentWindowId, rc);
+                      this, topLevelOuterContentWindowId, rc, classOfService);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     mTransaction = nullptr;
   }
 
   return rv;
 }
 
 mozilla::ipc::IPCResult
@@ -152,26 +153,28 @@ HttpTransactionChild::RecvResumePump()
 mozilla::ipc::IPCResult
 HttpTransactionChild::RecvInit(const uint32_t& aCaps,
                                const HttpConnectionInfoCloneArgs& aArgs,
                                const nsHttpRequestHead& aReqHeaders,
                                const OptionalIPCStream& aRequestBody,
                                const uint64_t& aReqContentLength,
                                const bool& aReqBodyIncludesHeaders,
                                const uint64_t& aTopLevelOuterContentWindowId,
-                               const uint64_t& aRequestContextID)
+                               const uint64_t& aRequestContextID,
+                               const uint32_t& aClassOfService)
 {
   mRequestHead = aReqHeaders;
   mUploadStream = mozilla::ipc::DeserializeIPCStream(aRequestBody);
   // TODO: let parent process know about the failure
   if (NS_FAILED(InitInternal(aCaps, aArgs, &mRequestHead, mUploadStream,
                              aReqContentLength, aReqBodyIncludesHeaders,
                              GetCurrentThreadEventTarget(),
                              aTopLevelOuterContentWindowId,
-                             aRequestContextID))) {
+                             aRequestContextID,
+                             aClassOfService))) {
     LOG(("HttpTransactionChild::RecvInit: [this=%p] InitInternal failed!\n", this));
   }
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 HttpTransactionChild::RecvRead(const int32_t& priority)
 {
--- a/netwerk/protocol/http/HttpTransactionChild.h
+++ b/netwerk/protocol/http/HttpTransactionChild.h
@@ -36,17 +36,18 @@ public:
   mozilla::ipc::IPCResult
   RecvInit(const uint32_t& aCaps,
            const HttpConnectionInfoCloneArgs& aArgs,
            const nsHttpRequestHead& aReqHeaders,
            const OptionalIPCStream& aRequestBody,
            const uint64_t& aReqContentLength,
            const bool& aReqBodyIncludesHeaders,
            const uint64_t& aTopLevelOuterContentWindowId,
-           const uint64_t& aRequestContextID) override;
+           const uint64_t& aRequestContextID,
+           const uint32_t& aClassOfService) override;
   mozilla::ipc::IPCResult RecvRead(const int32_t& priority) override;
   mozilla::ipc::IPCResult RecvReschedule(const int32_t& priority) override;
   mozilla::ipc::IPCResult RecvUpdateClassOfService(const uint32_t& classOfService) override;
   mozilla::ipc::IPCResult RecvCancel(const nsresult& reason) override;
   mozilla::ipc::IPCResult RecvCancelPump(const nsresult& aStatus) override;
   mozilla::ipc::IPCResult RecvSuspendPump() override;
   mozilla::ipc::IPCResult RecvResumePump() override;
   mozilla::ipc::IPCResult RecvSetDNSWasRefreshed() override;
@@ -58,17 +59,18 @@ private:
   MOZ_MUST_USE nsresult InitInternal(uint32_t               caps,
                                      const HttpConnectionInfoCloneArgs &aArgs, // remove proxyInfo first
                                      nsHttpRequestHead     *reqHeaders,
                                      nsIInputStream        *reqBody, // use the trick in bug 1277681
                                      uint64_t               reqContentLength,
                                      bool                   reqBodyIncludesHeaders,
                                      nsIEventTarget        *consumerTarget, // Will remove
                                      uint64_t               topLevelOuterContentWindowId,
-                                     uint64_t               requestContextID);
+                                     uint64_t               requestContextID,
+                                     uint32_t               classOfService);
 
   nsHttpRequestHead mRequestHead;
   nsCOMPtr<nsIInputStream> mUploadStream;
   RefPtr<nsHttpTransaction> mTransaction;
   nsCOMPtr<nsIRequest> mTransactionPump;
   NetAddr mSelfAddr;
   NetAddr mPeerAddr;
 };
--- a/netwerk/protocol/http/HttpTransactionParent.cpp
+++ b/netwerk/protocol/http/HttpTransactionParent.cpp
@@ -89,17 +89,18 @@ HttpTransactionParent::Init(uint32_t cap
                             nsHttpRequestHead *requestHead,
                             nsIInputStream *requestBody,
                             uint64_t requestContentLength,
                             bool requestBodyHasHeaders,
                             nsIEventTarget *target,
                             nsIInterfaceRequestor *callbacks,
                             nsITransportEventSink *eventsink,
                             uint64_t topLevelOuterContentWindowId,
-                            nsIRequestContext *requestContext)
+                            nsIRequestContext *requestContext,
+                            uint32_t classOfService)
 {
   LOG(("HttpTransactionParent::Init [this=%p caps=%x]\n", this, caps));
 
   if (!mIPCOpen) {
     return NS_ERROR_FAILURE;
   }
 
   mEventsink = eventsink;
@@ -114,17 +115,17 @@ HttpTransactionParent::Init(uint32_t cap
 
   uint64_t requestContextID = requestContext
     ? requestContext->GetID()
     : 0;
 
   // TODO: handle |target| later
   if (!SendInit(caps, infoArgs, *requestHead, autoStream.TakeOptionalValue(),
                 requestContentLength, requestBodyHasHeaders,
-                topLevelOuterContentWindowId, requestContextID)) {
+                topLevelOuterContentWindowId, requestContextID, classOfService)) {
     return NS_ERROR_FAILURE;
   }
 
   mTargetThread = GetCurrentThreadEventTarget();
   return NS_OK;
 }
 
 nsresult
--- a/netwerk/protocol/http/PHttpTransaction.ipdl
+++ b/netwerk/protocol/http/PHttpTransaction.ipdl
@@ -47,17 +47,18 @@ child:
   async __delete__();
   async Init(uint32_t caps,
              HttpConnectionInfoCloneArgs aArgs,
              nsHttpRequestHead reqHeaders,
              OptionalIPCStream requestBody,
              uint64_t reqContentLength,
              bool reqBodyIncludesHeaders,
              uint64_t topLevelOuterContentWindowId,
-             uint64_t requestContextID);
+             uint64_t requestContextID,
+             uint32_t classOfService);
   async Read(int32_t priority);
   async Reschedule(int32_t priority);
   async UpdateClassOfService(uint32_t classOfService);
   async Cancel(nsresult reason);
 
   async CancelPump(nsresult status);
   async SuspendPump();
   async ResumePump();
--- a/netwerk/protocol/http/nsAHttpTransactionShell.h
+++ b/netwerk/protocol/http/nsAHttpTransactionShell.h
@@ -60,17 +60,18 @@ public:
        nsHttpRequestHead     *reqHeaders,
        nsIInputStream        *reqBody,
        uint64_t               reqContentLength,
        bool                   reqBodyIncludesHeaders,
        nsIEventTarget        *consumerTarget,
        nsIInterfaceRequestor *callbacks,
        nsITransportEventSink *eventsink,
        uint64_t               topLevelOuterContentWindowId,
-       nsIRequestContext     *requestContext) = 0;
+       nsIRequestContext     *requestContext,
+       uint32_t               classOfService) = 0;
 
   // @param aListener
   //        receives notifications.
   // @param pump
   //        the pump that will contain the response data. async wait on this
   //        input stream for data. On first notification, headers should be
   //        available (check transaction status).
   virtual nsresult AsyncRead(nsIStreamListener *listener,
@@ -119,17 +120,18 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsAHttpTra
        nsHttpRequestHead     *reqHeaders, \
        nsIInputStream        *reqBody, \
        uint64_t               reqContentLength, \
        bool                   reqBodyIncludesHeaders, \
        nsIEventTarget        *consumerTarget, \
        nsIInterfaceRequestor *callbacks, \
        nsITransportEventSink *eventsink, \
        uint64_t               topLevelOuterContentWindowId, \
-       nsIRequestContext     *requestContext) override; \
+       nsIRequestContext     *requestContext, \
+       uint32_t               classOfService) override; \
   virtual nsresult AsyncRead(nsIStreamListener *listener, \
                              int32_t priority, \
                              nsIRequest **pump) override; \
   virtual nsresult AsyncReschedule(int32_t priority) override; \
   virtual void AsyncUpdateClassOfService(uint32_t classOfService) override; \
   virtual nsresult AsyncCancel(nsresult reason) override; \
   virtual nsHttpResponseHead* TakeResponseHead() override; \
   virtual nsISupports* SecurityInfo() override; \
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -1281,28 +1281,26 @@ nsresult nsHttpChannel::SetupTransaction
 
   EnsureTopLevelOuterContentWindowId();
   EnsureRequestContext();
 
   nsCOMPtr<nsIAsyncInputStream> responseStream;
   rv = mTransaction->Init(mCaps, mConnectionInfo, &mRequestHead, mUploadStream,
                           mReqContentLength, mUploadStreamHasHeaders,
                           GetCurrentThreadEventTarget(), callbacks, this,
-                          mTopLevelOuterContentWindowId, mRequestContext);
+                          mTopLevelOuterContentWindowId, mRequestContext,
+                          mClassOfService);
   if (NS_FAILED(rv)) {
     mTransaction = nullptr;
     return rv;
   }
 
   // TODO: this line is added for security callback workaround
   // mTransaction->SetSecurityCallbacks(callbacks);
 
-  // TODO: make throttling work again
-  // mTransaction->SetClassOfService(mClassOfService);
-
   return NS_OK;
 }
 
 enum class Report { Error, Warning };
 
 // Helper Function to report messages to the console when the loaded
 // script had a wrong MIME type.
 void ReportMimeTypeMismatch(nsHttpChannel *aChannel, const char *aMessageName,
--- a/netwerk/protocol/http/nsHttpTransaction.cpp
+++ b/netwerk/protocol/http/nsHttpTransaction.cpp
@@ -254,32 +254,35 @@ nsHttpTransaction::~nsHttpTransaction() 
   }
 }
 
 nsresult nsHttpTransaction::Init(
     uint32_t caps, nsHttpConnectionInfo *cinfo, nsHttpRequestHead *requestHead,
     nsIInputStream *requestBody, uint64_t requestContentLength,
     bool requestBodyHasHeaders, nsIEventTarget *target,
     nsIInterfaceRequestor *callbacks, nsITransportEventSink *eventsink,
-    uint64_t topLevelOuterContentWindowId, nsIRequestContext *requestContext) {
+    uint64_t topLevelOuterContentWindowId, nsIRequestContext *requestContext,
+    uint32_t classOfService) {
   nsresult rv;
 
   LOG1(("nsHttpTransaction::Init [this=%p caps=%x]\n", this, caps));
 
   MOZ_ASSERT(cinfo);
   MOZ_ASSERT(requestHead);
   MOZ_ASSERT(target);
   MOZ_ASSERT(NS_IsMainThread());
 
   mTopLevelOuterContentWindowId = topLevelOuterContentWindowId;
   LOG(("  window-id = %" PRIx64, mTopLevelOuterContentWindowId));
 
   mRequestContext = requestContext;
   LOG1(("nsHttpTransaction %p SetRequestContext %p\n", this, mRequestContext.get()));
 
+  SetClassOfService(classOfService);
+
   mActivityDistributor = services::GetActivityDistributor();
   if (!mActivityDistributor) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   bool activityDistributorActive;
   rv = mActivityDistributor->GetIsActive(&activityDistributorActive);
   if (NS_SUCCEEDED(rv) && activityDistributorActive) {