netwerk/base/src/nsAsyncStreamCopier.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef nsAsyncStreamCopier_h__
     6 #define nsAsyncStreamCopier_h__
     8 #include "nsIAsyncStreamCopier.h"
     9 #include "nsIAsyncStreamCopier2.h"
    10 #include "mozilla/Mutex.h"
    11 #include "nsStreamUtils.h"
    12 #include "nsCOMPtr.h"
    14 class nsIRequestObserver;
    16 //-----------------------------------------------------------------------------
    18 class nsAsyncStreamCopier : public nsIAsyncStreamCopier, nsIAsyncStreamCopier2
    19 {
    20 public:
    21     NS_DECL_THREADSAFE_ISUPPORTS
    22     NS_DECL_NSIREQUEST
    23     NS_DECL_NSIASYNCSTREAMCOPIER
    25     // nsIAsyncStreamCopier2
    26     // We declare it by hand instead of NS_DECL_NSIASYNCSTREAMCOPIER2
    27     // as nsIAsyncStreamCopier2 duplicates methods of nsIAsyncStreamCopier
    28     NS_IMETHOD Init(nsIInputStream *aSource,
    29                     nsIOutputStream *aSink,
    30                     nsIEventTarget *aTarget,
    31                     uint32_t aChunkSize,
    32                     bool aCloseSource,
    33                     bool aCloseSink);
    35     nsAsyncStreamCopier();
    36     virtual ~nsAsyncStreamCopier();
    38     //-------------------------------------------------------------------------
    39     // these methods may be called on any thread
    41     bool IsComplete(nsresult *status = nullptr);
    42     void   Complete(nsresult status);
    44 private:
    45     nsresult InitInternal(nsIInputStream *source,
    46                           nsIOutputStream *sink,
    47                           nsIEventTarget *target,
    48                           uint32_t chunkSize,
    49                           bool closeSource,
    50                           bool closeSink);
    52     static void OnAsyncCopyComplete(void *, nsresult);
    54     void AsyncCopyInternal();
    55     nsresult ApplyBufferingPolicy();
    56     nsIRequest* AsRequest();
    58     nsCOMPtr<nsIInputStream>       mSource;
    59     nsCOMPtr<nsIOutputStream>      mSink;
    61     nsCOMPtr<nsIRequestObserver>   mObserver;
    63     nsCOMPtr<nsIEventTarget>       mTarget;
    65     nsCOMPtr<nsISupports>          mCopierCtx;
    67     mozilla::Mutex                 mLock;
    69     nsAsyncCopyMode                mMode;
    70     uint32_t                       mChunkSize;
    71     nsresult                       mStatus;
    72     bool                           mIsPending;
    73     bool                           mCloseSource;
    74     bool                           mCloseSink;
    75     bool                           mShouldSniffBuffering;
    77     friend class ProceedWithAsyncCopy;
    78     friend class AsyncApplyBufferingPolicyEvent;
    79 };
    81 #endif // !nsAsyncStreamCopier_h__

mercurial