Bug 1402888 - Remove nsIStreamTransportService::createOutputStream, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 26 Sep 2017 07:22:32 +0200
changeset 670361 7e992ffa004cbe740486fc477e34ab6b9321f57b
parent 670360 560296786c0cefbc749f54b20ba8afcd79ffd12a
child 670362 0e2959069bc35bfa468203980316ff63ca388b28
push id81612
push userbmo:dharvey@mozilla.com
push dateTue, 26 Sep 2017 10:16:26 +0000
reviewerssmaug
bugs1402888
milestone58.0a1
Bug 1402888 - Remove nsIStreamTransportService::createOutputStream, r=smaug
netwerk/base/nsIStreamTransportService.idl
netwerk/base/nsStreamTransportService.cpp
--- a/netwerk/base/nsIStreamTransportService.idl
+++ b/netwerk/base/nsIStreamTransportService.idl
@@ -31,39 +31,16 @@ interface nsIStreamTransportService : ns
      *
      * @return nsITransport instance.
      */
     nsITransport createInputTransport(in nsIInputStream aStream,
                                       in boolean aCloseWhenDone);
 
     void InputAvailable(in nsIInputStream aStream,
                         in nsIInputAvailableCallback aCallback);
-    /**
-     * CreateOutputTransport
-     *
-     * @param aStream
-     *        The output stream that will be written to on a background thread.
-     *        This stream must implement "blocking" stream semantics.
-     * @param aStartOffset
-     *        The output stream will be written starting at this offset.  Pass
-     *        -1 to write to the current stream offset.  NOTE: this parameter
-     *        is ignored if the stream does not support nsISeekableStream.
-     * @param aWriteLimit
-     *        This parameter limits the number of bytes that will be written to
-     *        the output stream.  Pass -1 for unlimited writing.
-     * @param aCloseWhenDone
-     *        Specify this flag to have the output stream closed once its
-     *        contents have been completely written.
-     *
-     * @return nsITransport instance.
-     */
-    nsITransport createOutputTransport(in nsIOutputStream aStream,
-                                       in long long aStartOffset,
-                                       in long long aWriteLimit,
-                                       in boolean aCloseWhenDone);
 };
 
 [builtinclass, uuid(ff2da731-44d0-4dd9-8236-c99387fec721)]
 interface nsIInputAvailableCallback : nsISupports
 {
   void onInputAvailableComplete(in unsigned long long available,
 			        in nsresult available_return_code);
 };
--- a/netwerk/base/nsStreamTransportService.cpp
+++ b/netwerk/base/nsStreamTransportService.cpp
@@ -188,225 +188,16 @@ nsInputStreamTransport::ReadSegments(nsW
 NS_IMETHODIMP
 nsInputStreamTransport::IsNonBlocking(bool *result)
 {
     *result = false;
     return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
-// nsOutputStreamTransport
-//
-// Implements nsIOutputStream as a wrapper around the real input stream.  This
-// allows the transport to support seeking, range-limiting, progress reporting,
-// and close-when-done semantics while utilizing NS_AsyncCopy.
-//-----------------------------------------------------------------------------
-
-class nsOutputStreamTransport : public nsITransport
-                              , public nsIOutputStream
-{
-public:
-    NS_DECL_THREADSAFE_ISUPPORTS
-    NS_DECL_NSITRANSPORT
-    NS_DECL_NSIOUTPUTSTREAM
-
-    nsOutputStreamTransport(nsIOutputStream *sink,
-                            int64_t offset,
-                            int64_t limit,
-                            bool closeWhenDone)
-        : mSink(sink)
-        , mOffset(offset)
-        , mLimit(limit)
-        , mCloseWhenDone(closeWhenDone)
-        , mFirstTime(true)
-        , mInProgress(false)
-    {
-    }
-
-private:
-    virtual ~nsOutputStreamTransport()
-    {
-    }
-
-    nsCOMPtr<nsIAsyncOutputStream>  mPipeOut;
-
-    // while the copy is active, these members may only be accessed from the
-    // nsIOutputStream implementation.
-    nsCOMPtr<nsITransportEventSink> mEventSink;
-    nsCOMPtr<nsIOutputStream>       mSink;
-    int64_t                         mOffset;
-    int64_t                         mLimit;
-    bool                            mCloseWhenDone;
-    bool                            mFirstTime;
-
-    // this variable serves as a lock to prevent the state of the transport
-    // from being modified once the copy is in progress.
-    bool                            mInProgress;
-};
-
-NS_IMPL_ISUPPORTS(nsOutputStreamTransport,
-                  nsITransport,
-                  nsIOutputStream)
-
-/** nsITransport **/
-
-NS_IMETHODIMP
-nsOutputStreamTransport::OpenInputStream(uint32_t flags,
-                                         uint32_t segsize,
-                                         uint32_t segcount,
-                                         nsIInputStream **result)
-{
-    // this transport only supports writing!
-    NS_NOTREACHED("nsOutputStreamTransport::OpenInputStream");
-    return NS_ERROR_UNEXPECTED;
-}
-
-NS_IMETHODIMP
-nsOutputStreamTransport::OpenOutputStream(uint32_t flags,
-                                          uint32_t segsize,
-                                          uint32_t segcount,
-                                          nsIOutputStream **result)
-{
-    NS_ENSURE_TRUE(!mInProgress, NS_ERROR_IN_PROGRESS);
-
-    nsresult rv;
-    nsCOMPtr<nsIEventTarget> target =
-            do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
-    if (NS_FAILED(rv)) return rv;
-
-    // XXX if the caller requests an unbuffered stream, then perhaps
-    //     we'd want to simply return mSink; however, then we would
-    //     not be writing to mSink on a background thread.  is this ok?
-
-    bool nonblocking = !(flags & OPEN_BLOCKING);
-
-    net_ResolveSegmentParams(segsize, segcount);
-
-    nsCOMPtr<nsIAsyncInputStream> pipeIn;
-    rv = NS_NewPipe2(getter_AddRefs(pipeIn),
-                     getter_AddRefs(mPipeOut),
-                     true, nonblocking,
-                     segsize, segcount);
-    if (NS_FAILED(rv)) return rv;
-
-    mInProgress = true;
-
-    // startup async copy process...
-    rv = NS_AsyncCopy(pipeIn, this, target,
-                      NS_ASYNCCOPY_VIA_READSEGMENTS, segsize);
-    if (NS_SUCCEEDED(rv))
-        NS_ADDREF(*result = mPipeOut);
-
-    return rv;
-}
-
-NS_IMETHODIMP
-nsOutputStreamTransport::Close(nsresult reason)
-{
-    if (NS_SUCCEEDED(reason))
-        reason = NS_BASE_STREAM_CLOSED;
-
-    return mPipeOut->CloseWithStatus(reason);
-}
-
-NS_IMETHODIMP
-nsOutputStreamTransport::SetEventSink(nsITransportEventSink *sink,
-                                      nsIEventTarget *target)
-{
-    NS_ENSURE_TRUE(!mInProgress, NS_ERROR_IN_PROGRESS);
-
-    if (target)
-        return net_NewTransportEventSinkProxy(getter_AddRefs(mEventSink),
-                                              sink, target);
-
-    mEventSink = sink;
-    return NS_OK;
-}
-
-/** nsIOutputStream **/
-
-NS_IMETHODIMP
-nsOutputStreamTransport::Close()
-{
-    if (mCloseWhenDone)
-        mSink->Close();
-
-    // make additional writes return early...
-    mOffset = mLimit = 0;
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-nsOutputStreamTransport::Flush()
-{
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-nsOutputStreamTransport::Write(const char *buf, uint32_t count, uint32_t *result)
-{
-    if (mFirstTime) {
-        mFirstTime = false;
-        if (mOffset != 0) {
-            // write to current position if offset equal to max
-            if (mOffset != -1) {
-                nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(mSink);
-                if (seekable)
-                    seekable->Seek(nsISeekableStream::NS_SEEK_SET, mOffset);
-            }
-            // reset offset to zero so we can use it to enforce limit
-            mOffset = 0;
-        }
-    }
-
-    // limit amount written
-    uint64_t max = count;
-    if (mLimit != -1) {
-        max = mLimit - mOffset;
-        if (max == 0) {
-            *result = 0;
-            return NS_OK;
-        }
-    }
-
-    if (count > max)
-        count = static_cast<uint32_t>(max);
-
-    nsresult rv = mSink->Write(buf, count, result);
-
-    if (NS_SUCCEEDED(rv)) {
-        mOffset += *result;
-        if (mEventSink)
-            mEventSink->OnTransportStatus(this, NS_NET_STATUS_WRITING, mOffset,
-                                          mLimit);
-    }
-    return rv;
-}
-
-NS_IMETHODIMP
-nsOutputStreamTransport::WriteSegments(nsReadSegmentFun reader, void *closure,
-                                       uint32_t count, uint32_t *result)
-{
-    return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsOutputStreamTransport::WriteFrom(nsIInputStream *in, uint32_t count, uint32_t *result)
-{
-    return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsOutputStreamTransport::IsNonBlocking(bool *result)
-{
-    *result = false;
-    return NS_OK;
-}
-
-//-----------------------------------------------------------------------------
 // nsStreamTransportService
 //-----------------------------------------------------------------------------
 
 nsStreamTransportService::~nsStreamTransportService()
 {
     NS_ASSERTION(!mPool, "thread pool wasn't shutdown");
 }
 
@@ -501,31 +292,16 @@ nsStreamTransportService::CreateInputTra
         new nsInputStreamTransport(stream, closeWhenDone);
     if (!trans)
         return NS_ERROR_OUT_OF_MEMORY;
     NS_ADDREF(*result = trans);
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsStreamTransportService::CreateOutputTransport(nsIOutputStream *stream,
-                                                int64_t offset,
-                                                int64_t limit,
-                                                bool closeWhenDone,
-                                                nsITransport **result)
-{
-    nsOutputStreamTransport *trans =
-        new nsOutputStreamTransport(stream, offset, limit, closeWhenDone);
-    if (!trans)
-        return NS_ERROR_OUT_OF_MEMORY;
-    NS_ADDREF(*result = trans);
-    return NS_OK;
-}
-
-NS_IMETHODIMP
 nsStreamTransportService::Observe(nsISupports *subject, const char *topic,
                                   const char16_t *data)
 {
   NS_ASSERTION(strcmp(topic, "xpcom-shutdown-threads") == 0, "oops");
 
   {
     mozilla::MutexAutoLock lock(mShutdownLock);
     mIsShutdown = true;