Bug 1307665 - Use MOZ_MUST_USE in netwerk/protocol/ftp r?valentin draft
authorWei-Cheng Pan <wpan@mozilla.com>
Mon, 03 Oct 2016 14:54:58 +0800
changeset 421885 c44c0ac1be85ebbd7508b5800b77756d01a078c6
parent 420990 ea104eeb14cc54da9a06c3766da63f73117723a0
child 533196 19ade0897a98eb7df17e9c0f4a2ab353cd17d6f5
push id31626
push userbmo:wpan@mozilla.com
push dateFri, 07 Oct 2016 02:16:10 +0000
reviewersvalentin
bugs1307665
milestone52.0a1
Bug 1307665 - Use MOZ_MUST_USE in netwerk/protocol/ftp r?valentin MozReview-Commit-ID: 2iu6SMcwfPX
netwerk/protocol/ftp/FTPChannelChild.h
netwerk/protocol/ftp/FTPChannelParent.cpp
netwerk/protocol/ftp/FTPChannelParent.h
netwerk/protocol/ftp/nsFTPChannel.h
netwerk/protocol/ftp/nsFtpConnectionThread.cpp
netwerk/protocol/ftp/nsFtpConnectionThread.h
netwerk/protocol/ftp/nsFtpControlConnection.h
netwerk/protocol/ftp/nsFtpProtocolHandler.h
--- a/netwerk/protocol/ftp/FTPChannelChild.h
+++ b/netwerk/protocol/ftp/FTPChannelChild.h
@@ -60,19 +60,19 @@ public:
   void ReleaseIPDLReference();
 
   NS_IMETHOD AsyncOpen(nsIStreamListener* listener, nsISupports* aContext) override;
 
   // Note that we handle this ourselves, overriding the nsBaseChannel
   // default behavior, in order to be e10s-friendly.
   NS_IMETHOD IsPending(bool* result) override;
 
-  nsresult OpenContentStream(bool async,
-                             nsIInputStream** stream,
-                             nsIChannel** channel) override;
+  MOZ_MUST_USE nsresult OpenContentStream(bool async,
+                                          nsIInputStream** stream,
+                                          nsIChannel** channel) override;
 
   bool IsSuspended();
 
   void FlushedForDiversion();
 
 protected:
   virtual ~FTPChannelChild();
 
--- a/netwerk/protocol/ftp/FTPChannelParent.cpp
+++ b/netwerk/protocol/ftp/FTPChannelParent.cpp
@@ -238,26 +238,28 @@ FTPChannelParent::RecvCancel(const nsres
 
   return true;
 }
 
 bool
 FTPChannelParent::RecvSuspend()
 {
   if (mChannel) {
-    SuspendChannel();
+    nsresult rv = SuspendChannel();
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
   return true;
 }
 
 bool
 FTPChannelParent::RecvResume()
 {
   if (mChannel) {
-    ResumeChannel();
+    nsresult rv = ResumeChannel();
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
   return true;
 }
 
 class FTPDivertDataAvailableEvent : public ChannelEvent
 {
 public:
   FTPDivertDataAvailableEvent(FTPChannelParent* aParent,
@@ -843,17 +845,18 @@ FTPChannelParent::NotifyDiversionFailed(
   }
 
   bool isPending = false;
   nsresult rv = mChannel->IsPending(&isPending);
   MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
 
   // Resume only we suspended earlier.
   if (mSuspendedForDiversion) {
-    ResumeChannel();
+    rv = ResumeChannel();
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
   // Channel has already sent OnStartRequest to the child, so ensure that we
   // call it here if it hasn't already been called.
   if (!mDivertedOnStartRequest) {
     nsCOMPtr<nsIForcePendingChannel> forcePendingIChan = do_QueryInterface(mChannel);
     if (forcePendingIChan) {
       forcePendingIChan->ForcePending(true);
     }
--- a/netwerk/protocol/ftp/FTPChannelParent.h
+++ b/netwerk/protocol/ftp/FTPChannelParent.h
@@ -44,52 +44,53 @@ public:
   NS_DECL_NSIPARENTCHANNEL
   NS_DECL_NSIINTERFACEREQUESTOR
   NS_DECL_NSICHANNELEVENTSINK
 
   FTPChannelParent(const dom::PBrowserOrId& aIframeEmbedding,
                    nsILoadContext* aLoadContext,
                    PBOverrideStatus aOverrideStatus);
 
-  bool Init(const FTPChannelCreationArgs& aOpenArgs);
+  MOZ_MUST_USE bool Init(const FTPChannelCreationArgs& aOpenArgs);
 
   // ADivertableParentChannel functions.
   void DivertTo(nsIStreamListener *aListener) override;
-  nsresult SuspendForDiversion() override;
-  nsresult SuspendMessageDiversion() override;
-  nsresult ResumeMessageDiversion() override;
+  MOZ_MUST_USE nsresult SuspendForDiversion() override;
+  MOZ_MUST_USE nsresult SuspendMessageDiversion() override;
+  MOZ_MUST_USE nsresult ResumeMessageDiversion() override;
 
   // Calls OnStartRequest for "DivertTo" listener, then notifies child channel
   // that it should divert OnDataAvailable and OnStopRequest calls to this
   // parent channel.
   void StartDiversion();
 
   // Handles calling OnStart/Stop if there are errors during diversion.
   // Called asynchronously from FailDiversion.
   void NotifyDiversionFailed(nsresult aErrorCode, bool aSkipResume = true);
 
   NS_IMETHOD SetErrorMsg(const char *aMsg, bool aUseUTF8) override;
 
 protected:
   virtual ~FTPChannelParent();
 
   // private, supporting function for ADivertableParentChannel.
-  nsresult ResumeForDiversion();
+  MOZ_MUST_USE nsresult ResumeForDiversion();
 
   // Asynchronously calls NotifyDiversionFailed.
   void FailDiversion(nsresult aErrorCode, bool aSkipResume = true);
 
-  bool DoAsyncOpen(const URIParams& aURI, const uint64_t& aStartPos,
-                   const nsCString& aEntityID,
-                   const OptionalInputStreamParams& aUploadStream,
-                   const OptionalLoadInfoArgs& aLoadInfoArgs);
+  MOZ_MUST_USE bool DoAsyncOpen(const URIParams& aURI,
+                                const uint64_t& aStartPos,
+                                const nsCString& aEntityID,
+                                const OptionalInputStreamParams& aUploadStream,
+                                const OptionalLoadInfoArgs& aLoadInfoArgs);
 
   // used to connect redirected-to channel in parent with just created
   // ChildChannel.  Used during HTTP->FTP redirects.
-  bool ConnectChannel(const uint32_t& channelId);
+  MOZ_MUST_USE bool ConnectChannel(const uint32_t& channelId);
 
   void DivertOnDataAvailable(const nsCString& data,
                              const uint64_t& offset,
                              const uint32_t& count);
   void DivertOnStopRequest(const nsresult& statusCode);
   void DivertComplete();
 
   friend class FTPDivertDataAvailableEvent;
@@ -100,18 +101,18 @@ protected:
   virtual bool RecvSuspend() override;
   virtual bool RecvResume() override;
   virtual bool RecvDivertOnDataAvailable(const nsCString& data,
                                          const uint64_t& offset,
                                          const uint32_t& count) override;
   virtual bool RecvDivertOnStopRequest(const nsresult& statusCode) override;
   virtual bool RecvDivertComplete() override;
 
-  nsresult SuspendChannel();
-  nsresult ResumeChannel();
+  MOZ_MUST_USE nsresult SuspendChannel();
+  MOZ_MUST_USE nsresult ResumeChannel();
 
   virtual void ActorDestroy(ActorDestroyReason why) override;
 
   void OfflineDisconnect() override;
   uint32_t GetAppId() override;
 
   // if configured to use HTTP proxy for FTP, this can an an HTTP channel.
   nsCOMPtr<nsIChannel> mChannel;
--- a/netwerk/protocol/ftp/nsFTPChannel.h
+++ b/netwerk/protocol/ftp/nsFTPChannel.h
@@ -97,19 +97,21 @@ public:
     NS_IMETHOD Suspend() override;
     NS_IMETHOD Resume() override;
 
 public:
     NS_IMETHOD ForcePending(bool aForcePending) override;
 
 protected:
     virtual ~nsFtpChannel() {}
-    virtual nsresult OpenContentStream(bool async, nsIInputStream **result,
-                                       nsIChannel** channel) override;
-    virtual bool GetStatusArg(nsresult status, nsString &statusArg) override;
+    virtual MOZ_MUST_USE nsresult
+    OpenContentStream(bool async, nsIInputStream **result,
+                      nsIChannel** channel) override;
+    virtual MOZ_MUST_USE bool GetStatusArg(nsresult status,
+                                           nsString &statusArg) override;
     virtual void OnCallbacksChanged() override;
 
 private:
     nsCOMPtr<nsIProxyInfo>           mProxyInfo;
     nsCOMPtr<nsIFTPEventSink>        mFTPEventSink;
     nsCOMPtr<nsIInputStream>         mUploadStream;
     uint64_t                         mStartPos;
     nsCString                        mEntityID;
--- a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp
+++ b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp
@@ -128,17 +128,18 @@ nsFtpState::OnInputStreamReady(nsIAsyncI
 
     return NS_OK;
 }
 
 void
 nsFtpState::OnControlDataAvailable(const char *aData, uint32_t aDataLen)
 {
     LOG(("FTP:(%p) control data available [%u]\n", this, aDataLen));
-    mControlConnection->WaitData(this);  // queue up another call
+    nsresult rv = mControlConnection->WaitData(this);  // queue up another call
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 
     if (!mReceivedControlData) {
         // parameter can be null cause the channel fills them in.
         OnTransportStatus(nullptr, NS_NET_STATUS_BEGIN_FTP_TRANSACTION, 0, 0);
         mReceivedControlData = true;
     }
 
     // Sometimes we can get two responses in the same packet, eg from LIST.
@@ -259,25 +260,28 @@ nsFtpState::EstablishControlConnection()
             
     nsresult rv;
 
     LOG(("FTP:(%x) trying cached control\n", this));
         
     // Look to see if we can use a cached control connection:
     RefPtr<nsFtpControlConnection> connection;
     // Don't use cached control if anonymous (bug #473371)
-    if (!mChannel->HasLoadFlag(nsIRequest::LOAD_ANONYMOUS))
-        gFtpHandler->RemoveConnection(mChannel->URI(), getter_AddRefs(connection));
+    if (!mChannel->HasLoadFlag(nsIRequest::LOAD_ANONYMOUS)) {
+        rv = gFtpHandler->RemoveConnection(mChannel->URI(), getter_AddRefs(connection));
+        Unused << rv;
+    }
 
     if (connection) {
         mControlConnection.swap(connection);
         if (mControlConnection->IsAlive())
         {
             // set stream listener of the control connection to be us.        
-            mControlConnection->WaitData(this);
+            rv = mControlConnection->WaitData(this);
+            MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
             
             // read cached variables into us. 
             mServerType = mControlConnection->mServerType;           
             mPassword   = mControlConnection->mPassword;
             mPwd        = mControlConnection->mPwd;
             mUseUTF8    = mControlConnection->mUseUTF8;
             mTryingCachedControl = true;
 
@@ -294,17 +298,18 @@ nsFtpState::EstablishControlConnection()
             // if we succeed, return.  Otherwise, we need to create a transport
             rv = mControlConnection->Connect(mChannel->ProxyInfo(), this);
             if (NS_SUCCEEDED(rv))
                 return rv;
         }
         LOG(("FTP:(%p) cached CC(%p) is unusable\n", this,
             mControlConnection.get()));
 
-        mControlConnection->WaitData(nullptr);
+        rv = mControlConnection->WaitData(nullptr);
+        MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
         mControlConnection = nullptr;
     }
 
     LOG(("FTP:(%p) creating CC\n", this));
         
     mState = FTP_READ_BUF;
     mNextState = FTP_S_USER;
     
@@ -1756,40 +1761,43 @@ nsFtpState::KillControlConnection()
     // FIX: need a better way to determine if we can cache the connections.
     //      there are some errors which do not mean that we need to kill the connection
     //      e.g. fnf.
 
     if (!mControlConnection)
         return;
 
     // kill the reference to ourselves in the control connection.
-    mControlConnection->WaitData(nullptr);
+    nsresult rv = mControlConnection->WaitData(nullptr);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 
     if (NS_SUCCEEDED(mInternalError) &&
         NS_SUCCEEDED(mControlStatus) &&
         mControlConnection->IsAlive() &&
         mCacheConnection) {
 
         LOG_INFO(("FTP:(%p) caching CC(%p)", this, mControlConnection.get()));
 
         // Store connection persistent data
         mControlConnection->mServerType = mServerType;           
         mControlConnection->mPassword = mPassword;
         mControlConnection->mPwd = mPwd;
         mControlConnection->mUseUTF8 = mUseUTF8;
         
-        nsresult rv = NS_OK;
+        rv = NS_OK;
         // Don't cache controlconnection if anonymous (bug #473371)
         if (!mChannel->HasLoadFlag(nsIRequest::LOAD_ANONYMOUS))
             rv = gFtpHandler->InsertConnection(mChannel->URI(),
                                                mControlConnection);
         // Can't cache it?  Kill it then.  
-        mControlConnection->Disconnect(rv);
+        rv = mControlConnection->Disconnect(rv);
+        MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
     } else {
-        mControlConnection->Disconnect(NS_BINDING_ABORTED);
+        rv = mControlConnection->Disconnect(NS_BINDING_ABORTED);
+        MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
     }     
 
     mControlConnection = nullptr;
 }
 
 class nsFtpAsyncAlert : public Runnable
 {
 public:
@@ -2146,17 +2154,18 @@ nsFtpState::CloseWithStatus(nsresult sta
 {
     LOG(("FTP:(%p) close [%x]\n", this, status));
 
     // Shutdown the control connection processing if we are being closed with an
     // error.  Note: This method may be called several times.
     if (!IsClosed() && status != NS_BASE_STREAM_CLOSED && NS_FAILED(status)) {
         if (NS_SUCCEEDED(mInternalError))
             mInternalError = status;
-        StopProcessing();
+        nsresult rv = StopProcessing();
+        MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
     }
 
     if (mUploadRequest) {
         mUploadRequest->Cancel(NS_ERROR_ABORT);
         mUploadRequest = nullptr;
     }
 
     if (mDataTransport) {
--- a/netwerk/protocol/ftp/nsFtpConnectionThread.h
+++ b/netwerk/protocol/ftp/nsFtpConnectionThread.h
@@ -92,62 +92,63 @@ public:
     NS_IMETHOD ReadSegments(nsWriteSegmentFun fun, void *closure,
                             uint32_t count, uint32_t *result) override;
 
     // nsFtpControlConnectionListener methods:
     virtual void OnControlDataAvailable(const char *data, uint32_t dataLen) override;
     virtual void OnControlError(nsresult status) override;
 
     nsFtpState();
-    nsresult Init(nsFtpChannel *channel);
+    MOZ_MUST_USE nsresult Init(nsFtpChannel *channel);
 
 protected:
     // Notification from nsBaseContentStream::AsyncWait
     virtual void OnCallbackPending() override;
 
 private:
     virtual ~nsFtpState();
 
     ///////////////////////////////////
     // BEGIN: STATE METHODS
-    nsresult        S_user(); FTP_STATE       R_user();
-    nsresult        S_pass(); FTP_STATE       R_pass();
-    nsresult        S_syst(); FTP_STATE       R_syst();
-    nsresult        S_acct(); FTP_STATE       R_acct();
+    MOZ_MUST_USE nsresult        S_user(); FTP_STATE       R_user();
+    MOZ_MUST_USE nsresult        S_pass(); FTP_STATE       R_pass();
+    MOZ_MUST_USE nsresult        S_syst(); FTP_STATE       R_syst();
+    MOZ_MUST_USE nsresult        S_acct(); FTP_STATE       R_acct();
 
-    nsresult        S_type(); FTP_STATE       R_type();
-    nsresult        S_cwd();  FTP_STATE       R_cwd();
+    MOZ_MUST_USE nsresult        S_type(); FTP_STATE       R_type();
+    MOZ_MUST_USE nsresult        S_cwd();  FTP_STATE       R_cwd();
 
-    nsresult        S_size(); FTP_STATE       R_size();
-    nsresult        S_mdtm(); FTP_STATE       R_mdtm();
-    nsresult        S_list(); FTP_STATE       R_list();
+    MOZ_MUST_USE nsresult        S_size(); FTP_STATE       R_size();
+    MOZ_MUST_USE nsresult        S_mdtm(); FTP_STATE       R_mdtm();
+    MOZ_MUST_USE nsresult        S_list(); FTP_STATE       R_list();
 
-    nsresult        S_rest(); FTP_STATE       R_rest();
-    nsresult        S_retr(); FTP_STATE       R_retr();
-    nsresult        S_stor(); FTP_STATE       R_stor();
-    nsresult        S_pasv(); FTP_STATE       R_pasv();
-    nsresult        S_pwd();  FTP_STATE       R_pwd();
-    nsresult        S_feat(); FTP_STATE       R_feat();
-    nsresult        S_opts(); FTP_STATE       R_opts();
+    MOZ_MUST_USE nsresult        S_rest(); FTP_STATE       R_rest();
+    MOZ_MUST_USE nsresult        S_retr(); FTP_STATE       R_retr();
+    MOZ_MUST_USE nsresult        S_stor(); FTP_STATE       R_stor();
+    MOZ_MUST_USE nsresult        S_pasv(); FTP_STATE       R_pasv();
+    MOZ_MUST_USE nsresult        S_pwd();  FTP_STATE       R_pwd();
+    MOZ_MUST_USE nsresult        S_feat(); FTP_STATE       R_feat();
+    MOZ_MUST_USE nsresult        S_opts(); FTP_STATE       R_opts();
     // END: STATE METHODS
     ///////////////////////////////////
 
     // internal methods
-    void        MoveToNextState(FTP_STATE nextState);
-    nsresult    Process();
+    void MoveToNextState(FTP_STATE nextState);
+    MOZ_MUST_USE nsresult Process();
 
     void KillControlConnection();
-    nsresult StopProcessing();
-    nsresult EstablishControlConnection();
-    nsresult SendFTPCommand(const nsCSubstring& command);
+    MOZ_MUST_USE nsresult StopProcessing();
+    MOZ_MUST_USE nsresult EstablishControlConnection();
+    MOZ_MUST_USE nsresult SendFTPCommand(const nsCSubstring& command);
     void ConvertFilespecToVMS(nsCString& fileSpec);
     void ConvertDirspecToVMS(nsCString& fileSpec);
     void ConvertDirspecFromVMS(nsCString& fileSpec);
-    nsresult BuildStreamConverter(nsIStreamListener** convertStreamListener);
-    nsresult SetContentType();
+    MOZ_MUST_USE nsresult
+    BuildStreamConverter(nsIStreamListener** convertStreamListener);
+    MOZ_MUST_USE nsresult SetContentType();
 
     /**
      * This method is called to kick-off the FTP state machine.  mState is
      * reset to FTP_COMMAND_CONNECT, and the FTP state machine progresses from
      * there.  This method is initially called (indirectly) from the channel's
      * AsyncOpen implementation.
      */
     void Connect();
--- a/netwerk/protocol/ftp/nsFtpControlConnection.h
+++ b/netwerk/protocol/ftp/nsFtpControlConnection.h
@@ -43,31 +43,32 @@ class nsFtpControlConnection final : pub
     ~nsFtpControlConnection();
 
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIINPUTSTREAMCALLBACK
 
     nsFtpControlConnection(const nsCSubstring& host, uint32_t port);
 
-    nsresult Connect(nsIProxyInfo* proxyInfo, nsITransportEventSink* eventSink);
-    nsresult Disconnect(nsresult status);
-    nsresult Write(const nsCSubstring& command);
+    MOZ_MUST_USE nsresult Connect(nsIProxyInfo* proxyInfo,
+                                  nsITransportEventSink* eventSink);
+    MOZ_MUST_USE nsresult Disconnect(nsresult status);
+    MOZ_MUST_USE nsresult Write(const nsCSubstring& command);
 
     bool IsAlive();
 
     nsITransport *Transport()   { return mSocket; }
 
     /**
      * Call this function to be notified asynchronously when there is data
      * available for the socket.  The listener passed to this method replaces
      * any existing listener, and the listener can be null to disconnect the
      * previous listener.
      */
-    nsresult WaitData(nsFtpControlConnectionListener *listener);
+    MOZ_MUST_USE nsresult WaitData(nsFtpControlConnectionListener *listener);
 
     uint32_t         mServerType;           // what kind of server is it.
     nsString         mPassword;
     int32_t          mSuspendedWrite;
     nsCString        mPwd;
     uint32_t         mSessionId;
     bool             mUseUTF8;
 
--- a/netwerk/protocol/ftp/nsFtpProtocolHandler.h
+++ b/netwerk/protocol/ftp/nsFtpProtocolHandler.h
@@ -22,21 +22,23 @@ class nsFtpProtocolHandler final : publi
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSIPROTOCOLHANDLER
     NS_DECL_NSIPROXIEDPROTOCOLHANDLER
     NS_DECL_NSIOBSERVER
     
     nsFtpProtocolHandler();
     
-    nsresult Init();
+    MOZ_MUST_USE nsresult Init();
 
     // FTP Connection list access
-    nsresult InsertConnection(nsIURI *aKey, nsFtpControlConnection *aConn);
-    nsresult RemoveConnection(nsIURI *aKey, nsFtpControlConnection **aConn);
+    MOZ_MUST_USE nsresult InsertConnection(nsIURI *aKey,
+                                           nsFtpControlConnection *aConn);
+    MOZ_MUST_USE nsresult RemoveConnection(nsIURI *aKey,
+                                           nsFtpControlConnection **aConn);
     uint32_t GetSessionId() { return mSessionId; }
 
     uint8_t GetDataQoSBits() { return mDataQoSBits; }
     uint8_t GetControlQoSBits() { return mControlQoSBits; }
 
 private:
     virtual ~nsFtpProtocolHandler();
 
@@ -49,17 +51,18 @@ private:
         timerStruct() : key(nullptr) {}
         
         ~timerStruct() {
             if (timer)
                 timer->Cancel();
             if (key)
                 free(key);
             if (conn) {
-                conn->Disconnect(NS_ERROR_ABORT);
+                nsresult rv = conn->Disconnect(NS_ERROR_ABORT);
+                MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
             }
         }
     };
 
     static void Timeout(nsITimer *aTimer, void *aClosure);
     void ClearAllConnections();
 
     nsTArray<timerStruct*> mRootConnectionList;