Bug 1310127 - Part 4: Use MOZ_MUST_USE in netwerk/protocol/http r=mcmanus
authorWei-Cheng Pan <wpan@mozilla.com>
Wed, 28 Dec 2016 14:43:47 +0800
changeset 346158 6305df95b90a68c7a42395ba19db5276d2c5c1ca
parent 346157 3367be6232733dc3c4005476870ba99c9530ac11
child 346159 03ddf10ea39e39fd8457d9e98771c09efedfcfd3
push id31459
push usercbook@mozilla.com
push dateTue, 07 Mar 2017 14:05:14 +0000
treeherdermozilla-central@1fb56ba248d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1310127
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1310127 - Part 4: Use MOZ_MUST_USE in netwerk/protocol/http r=mcmanus This patch contains some changes that may alter control flows. MozReview-Commit-ID: Kcc2DWJZ8L5
netwerk/base/Predictor.cpp
netwerk/base/nsAsyncRedirectVerifyHelper.cpp
netwerk/protocol/http/Http2Stream.cpp
netwerk/protocol/http/HttpBaseChannel.cpp
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/NullHttpTransaction.cpp
netwerk/protocol/http/nsHttpAuthCache.cpp
netwerk/protocol/http/nsHttpChannelAuthProvider.cpp
netwerk/protocol/http/nsHttpConnection.cpp
netwerk/protocol/http/nsHttpConnectionMgr.cpp
netwerk/protocol/http/nsHttpTransaction.cpp
netwerk/protocol/viewsource/nsViewSourceChannel.cpp
--- a/netwerk/base/Predictor.cpp
+++ b/netwerk/base/Predictor.cpp
@@ -1364,17 +1364,18 @@ Predictor::Prefetch(nsIURI *uri, nsIURI 
 
   nsCOMPtr<nsIHttpChannel> httpChannel;
   httpChannel = do_QueryInterface(channel);
   if (!httpChannel) {
     PREDICTOR_LOG(("    Could not get HTTP Channel from new channel!"));
     return NS_ERROR_UNEXPECTED;
   }
 
-  httpChannel->SetReferrer(referrer);
+  rv = httpChannel->SetReferrer(referrer);
+  NS_ENSURE_SUCCESS(rv, rv);
   // XXX - set a header here to indicate this is a prefetch?
 
   nsCOMPtr<nsIStreamListener> listener = new PrefetchListener(verifier, uri,
                                                               this);
   PREDICTOR_LOG(("    calling AsyncOpen2 listener=%p channel=%p", listener.get(),
                  channel.get()));
   rv = channel->AsyncOpen2(listener);
   if (NS_FAILED(rv)) {
--- a/netwerk/base/nsAsyncRedirectVerifyHelper.cpp
+++ b/netwerk/base/nsAsyncRedirectVerifyHelper.cpp
@@ -266,18 +266,18 @@ nsAsyncRedirectVerifyHelper::Run()
 
 bool
 nsAsyncRedirectVerifyHelper::IsOldChannelCanceled()
 {
     bool canceled;
     nsCOMPtr<nsIHttpChannelInternal> oldChannelInternal =
         do_QueryInterface(mOldChan);
     if (oldChannelInternal) {
-        oldChannelInternal->GetCanceled(&canceled);
-        if (canceled) {
+        nsresult rv = oldChannelInternal->GetCanceled(&canceled);
+        if (NS_SUCCEEDED(rv) && canceled) {
             return true;
         }
     } else if (mOldChan) {
         // For non-HTTP channels check on the status, failure
         // indicates the channel has probably been canceled.
         nsresult status = NS_ERROR_FAILURE;
         mOldChan->GetStatus(&status);
         if (NS_FAILED(status)) {
--- a/netwerk/protocol/http/Http2Stream.cpp
+++ b/netwerk/protocol/http/Http2Stream.cpp
@@ -411,17 +411,21 @@ Http2Stream::ParseHttpRequestHeaders(con
   // the whole header has been consumed.
   uint32_t oldLen = mFlatHttpRequestHeaders.Length();
   mFlatHttpRequestHeaders.SetLength(endHeader + 2);
   *countUsed = avail - (oldLen - endHeader) + 4;
   mRequestHeadersDone = 1;
 
   nsAutoCString authorityHeader;
   nsAutoCString hashkey;
-  head->GetHeader(nsHttp::Host, authorityHeader);
+  nsresult rv = head->GetHeader(nsHttp::Host, authorityHeader);
+  if (NS_FAILED(rv)) {
+    MOZ_ASSERT(false);
+    return rv;
+  }
 
   nsAutoCString requestURI;
   head->RequestURI(requestURI);
   CreatePushHashKey(nsDependentCString(head->IsHTTPS() ? "https" : "http"),
                     authorityHeader, mSession->Serial(),
                     requestURI,
                     mOrigin, hashkey);
 
@@ -511,17 +515,21 @@ Http2Stream::GenerateOpen()
     return NS_ERROR_UNEXPECTED;
   }
 
   // Now we need to convert the flat http headers into a set
   // of HTTP/2 headers by writing to mTxInlineFrame{sz}
 
   nsCString compressedData;
   nsAutoCString authorityHeader;
-  head->GetHeader(nsHttp::Host, authorityHeader);
+  nsresult rv = head->GetHeader(nsHttp::Host, authorityHeader);
+  if (NS_FAILED(rv)) {
+    MOZ_ASSERT(false);
+    return rv;
+  }
 
   nsDependentCString scheme(head->IsHTTPS() ? "https" : "http");
   if (head->IsConnect()) {
     MOZ_ASSERT(mTransaction->QuerySpdyConnectTransaction());
     mIsTunnel = true;
     mRequestBodyLenRemaining = 0x0fffffffffffffffULL;
 
     // Our normal authority has an implicit port, best to use an
@@ -535,23 +543,24 @@ Http2Stream::GenerateOpen()
     authorityHeader.Append(':');
     authorityHeader.AppendInt(ci->OriginPort());
   }
 
   nsAutoCString method;
   nsAutoCString path;
   head->Method(method);
   head->Path(path);
-  mSession->Compressor()->EncodeHeaderBlock(mFlatHttpRequestHeaders,
-                                            method,
-                                            path,
-                                            authorityHeader,
-                                            scheme,
-                                            head->IsConnect(),
-                                            compressedData);
+  rv = mSession->Compressor()->EncodeHeaderBlock(mFlatHttpRequestHeaders,
+                                                 method,
+                                                 path,
+                                                 authorityHeader,
+                                                 scheme,
+                                                 head->IsConnect(),
+                                                 compressedData);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   int64_t clVal = mSession->Compressor()->GetParsedContentLength();
   if (clVal != -1) {
     mRequestBodyLenRemaining = clVal;
   }
 
   // Determine whether to put the fin bit on the header frame or whether
   // to wait for a data packet to put it on.
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -2591,17 +2591,18 @@ HttpBaseChannel::ForcePending(bool aForc
 }
 
 NS_IMETHODIMP
 HttpBaseChannel::GetLastModifiedTime(PRTime* lastModifiedTime)
 {
   if (!mResponseHead)
     return NS_ERROR_NOT_AVAILABLE;
   uint32_t lastMod;
-  mResponseHead->GetLastModifiedValue(&lastMod);
+  nsresult rv = mResponseHead->GetLastModifiedValue(&lastMod);
+  NS_ENSURE_SUCCESS(rv, rv);
   *lastModifiedTime = lastMod;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HttpBaseChannel::GetCorsIncludeCredentials(bool* aInclude)
 {
   *aInclude = mCorsIncludeCredentials;
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -1916,17 +1916,18 @@ HttpChannelChild::Resume()
   // Don't SendResume at all if we're diverting callbacks to the parent (unless
   // suspend was sent earlier); otherwise, resume will be called at the correct
   // time in the parent itself.
   if (!--mSuspendCount && (!mDivertingToParent || mSuspendSent)) {
     if (RemoteChannelExists()) {
       SendResume();
     }
     if (mCallOnResume) {
-      AsyncCall(mCallOnResume);
+      rv = AsyncCall(mCallOnResume);
+      NS_ENSURE_SUCCESS(rv, rv);
       mCallOnResume = nullptr;
     }
   }
   if (mSynthesizedResponsePump) {
     mSynthesizedResponsePump->Resume();
   }
   mEventQ->Resume();
 
--- a/netwerk/protocol/http/NullHttpTransaction.cpp
+++ b/netwerk/protocol/http/NullHttpTransaction.cpp
@@ -61,23 +61,24 @@ public:
                             : NS_LITERAL_CSTRING("http://") ) + mHost + port);
     if (NS_FAILED(rv)) {
       return NS_OK;
     }
 
     RefPtr<NullHttpChannel> channel = new NullHttpChannel();
     rv = channel->Init(uri, 0, nullptr, 0, nullptr);
     MOZ_ASSERT(NS_SUCCEEDED(rv));
-    mActivityDistributor->ObserveActivity(
+    rv = mActivityDistributor->ObserveActivity(
       nsCOMPtr<nsISupports>(do_QueryObject(channel)),
       mActivityType,
       mActivitySubtype,
       mTimestamp,
       mExtraSizeData,
       mExtraStringData);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     return NS_OK;
   }
 private:
   nsCOMPtr<nsIHttpActivityObserver> mActivityDistributor;
   nsCString mHost;
   int32_t mPort;
   bool mEndToEndSSL;
--- a/netwerk/protocol/http/nsHttpAuthCache.cpp
+++ b/netwerk/protocol/http/nsHttpAuthCache.cpp
@@ -584,17 +584,18 @@ nsHttpAuthNode::SetAuthEntry(const char 
 
         // We want the latest identity be at the begining of the list so that
         // the newest working credentials are sent first on new requests.
         // Changing a realm is sometimes used to "timeout" authrozization.
         mList.InsertElementAt(0, entry);
     }
     else {
         // update the entry...
-        entry->Set(path, realm, creds, challenge, ident, metadata);
+        nsresult rv = entry->Set(path, realm, creds, challenge, ident, metadata);
+        NS_ENSURE_SUCCESS(rv, rv);
     }
 
     return NS_OK;
 }
 
 void
 nsHttpAuthNode::ClearAuthEntry(const char *realm)
 {
--- a/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp
+++ b/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp
@@ -106,17 +106,17 @@ nsHttpChannelAuthProvider::Init(nsIHttpA
 {
     MOZ_ASSERT(channel, "channel expected!");
 
     mAuthChannel = channel;
 
     nsresult rv = mAuthChannel->GetURI(getter_AddRefs(mURI));
     if (NS_FAILED(rv)) return rv;
 
-    mAuthChannel->GetIsSSL(&mUsingSSL);
+    rv = mAuthChannel->GetIsSSL(&mUsingSSL);
     if (NS_FAILED(rv)) return rv;
 
     nsCOMPtr<nsIProxiedChannel> proxied(do_QueryInterface(channel));
     if (proxied) {
         nsCOMPtr<nsIProxyInfo> pi;
         rv = proxied->GetProxyInfo(getter_AddRefs(pi));
         if (NS_FAILED(rv)) return rv;
 
--- a/netwerk/protocol/http/nsHttpConnection.cpp
+++ b/netwerk/protocol/http/nsHttpConnection.cpp
@@ -644,17 +644,18 @@ nsHttpConnection::Activate(nsAHttpTransa
     rv = StartShortLivedTCPKeepalives();
     if (NS_FAILED(rv)) {
         LOG(("nsHttpConnection::Activate [%p] "
              "StartShortLivedTCPKeepalives failed rv[0x%" PRIx32 "]",
              this, static_cast<uint32_t>(rv)));
     }
 
     if (mTLSFilter) {
-        mTLSFilter->SetProxiedTransaction(trans);
+        rv = mTLSFilter->SetProxiedTransaction(trans);
+        NS_ENSURE_SUCCESS(rv, rv);
         mTransaction = mTLSFilter;
     }
 
     rv = OnOutputStreamReady(mSocketOut);
 
 failed_activation:
     if (NS_FAILED(rv)) {
         mTransaction = nullptr;
--- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp
+++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp
@@ -1247,17 +1247,18 @@ nsHttpConnectionMgr::TryDispatchTransact
     // essentially pipelining without head of line blocking
 
     if (!(caps & NS_HTTP_DISALLOW_SPDY) && gHttpHandler->IsSpdyEnabled()) {
         RefPtr<nsHttpConnection> conn = GetSpdyPreferredConn(ent);
         if (conn) {
             if ((caps & NS_HTTP_ALLOW_KEEPALIVE) || !conn->IsExperienced()) {
                 LOG(("   dispatch to spdy: [conn=%p]\n", conn.get()));
                 trans->RemoveDispatchedAsBlocking();  /* just in case */
-                DispatchTransaction(ent, trans, conn);
+                nsresult rv = DispatchTransaction(ent, trans, conn);
+                NS_ENSURE_SUCCESS(rv, rv);
                 return NS_OK;
             }
             unusedSpdyPersistentConnection = conn;
         }
     }
 
     // If this is not a blocking transaction and the request context for it is
     // currently processing one or more blocking transactions then we
@@ -1336,17 +1337,18 @@ nsHttpConnectionMgr::TryDispatchTransact
             // If there are no idle connections left at all, we need to make
             // sure that we are not pruning dead connections anymore.
             ConditionallyStopPruneDeadConnectionsTimer();
         }
         if (conn) {
             // This will update the class of the connection to be the class of
             // the transaction dispatched on it.
             AddActiveConn(conn, ent);
-            DispatchTransaction(ent, trans, conn);
+            nsresult rv = DispatchTransaction(ent, trans, conn);
+            NS_ENSURE_SUCCESS(rv, rv);
             LOG(("   dispatched step 2 (idle) trans=%p\n", trans));
             return NS_OK;
         }
     }
 
     // step 3
     // consider pipelining scripts and revalidations
     // h1 pipelining has been removed
--- a/netwerk/protocol/http/nsHttpTransaction.cpp
+++ b/netwerk/protocol/http/nsHttpTransaction.cpp
@@ -1471,17 +1471,19 @@ nsHttpTransaction::HandleContentStart()
 
         // Save http version, mResponseHead isn't available anymore after
         // TakeResponseHead() is called
         mHttpVersion = mResponseHead->Version();
         mHttpResponseCode = mResponseHead->Status();
 
         // notify the connection, give it a chance to cause a reset.
         bool reset = false;
-        mConnection->OnHeadersAvailable(this, mRequestHead, mResponseHead, &reset);
+        nsresult rv = mConnection->OnHeadersAvailable(this, mRequestHead,
+                                                      mResponseHead, &reset);
+        NS_ENSURE_SUCCESS(rv, rv);
 
         // looks like we should ignore this response, resetting...
         if (reset) {
             LOG(("resetting transaction's response head\n"));
             mHaveAllHeaders = false;
             mHaveStatusLine = false;
             mReceivedData = false;
             mSentData = false;
@@ -1727,17 +1729,18 @@ nsHttpTransaction::ProcessData(char *buf
         // count > countRead + countRemaining <==> chunked transfer encoding
         //
         rv = HandleContent(buf, count, countRead, &countRemaining);
         if (NS_FAILED(rv)) return rv;
         // we may have read more than our share, in which case we must give
         // the excess bytes back to the connection
         if (mResponseIsComplete && countRemaining) {
             MOZ_ASSERT(mConnection);
-            mConnection->PushBack(buf + *countRead, countRemaining);
+            rv = mConnection->PushBack(buf + *countRead, countRemaining);
+            NS_ENSURE_SUCCESS(rv, rv);
         }
 
         if (!mContentDecodingCheck && mResponseHead) {
             mContentDecoding =
                 mResponseHead->HasHeader(nsHttp::Content_Encoding);
             mContentDecodingCheck = true;
         }
     }
@@ -1854,18 +1857,18 @@ nsHttpTransaction::CheckForStickyAuthSch
       nsAutoCString contractid;
       contractid.Assign(NS_HTTP_AUTHENTICATOR_CONTRACTID_PREFIX);
       contractid.Append(schema);
 
       // using a new instance because of thread safety of auth modules refcnt
       nsCOMPtr<nsIHttpAuthenticator> authenticator(do_CreateInstance(contractid.get()));
       if (authenticator) {
           uint32_t flags;
-          authenticator->GetAuthFlags(&flags);
-          if (flags & nsIHttpAuthenticator::CONNECTION_BASED) {
+          nsresult rv = authenticator->GetAuthFlags(&flags);
+          if (NS_SUCCEEDED(rv) && (flags & nsIHttpAuthenticator::CONNECTION_BASED)) {
               LOG(("  connection made sticky, found %s auth shema", schema.get()));
               // This is enough to make this transaction keep it's current connection,
               // prevents the connection from being released back to the pool.
               mCaps |= NS_HTTP_STICKY_CONNECTION;
               break;
           }
       }
 
--- a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp
+++ b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp
@@ -930,18 +930,19 @@ nsViewSourceChannel::VisitResponseHeader
 {
     if (!mHttpChannel)
         return NS_ERROR_NULL_POINTER;
 
     NS_NAMED_LITERAL_CSTRING(contentTypeStr, "Content-Type");
     nsAutoCString contentType;
     nsresult rv =
         mHttpChannel->GetResponseHeader(contentTypeStr, contentType);
-    if (NS_SUCCEEDED(rv))
-        aVisitor->VisitHeader(contentTypeStr, contentType);
+    if (NS_SUCCEEDED(rv)) {
+        return aVisitor->VisitHeader(contentTypeStr, contentType);
+    }
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsViewSourceChannel::GetOriginalResponseHeader(const nsACString & aHeader,
                                                nsIHttpHeaderVisitor *aVisitor)
 {
     nsAutoCString value;