1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/base/src/nsInputStreamPump.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,104 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsInputStreamPump_h__ 1.10 +#define nsInputStreamPump_h__ 1.11 + 1.12 +#include "nsIInputStreamPump.h" 1.13 +#include "nsIAsyncInputStream.h" 1.14 +#include "nsIThreadRetargetableRequest.h" 1.15 +#include "nsCOMPtr.h" 1.16 +#include "mozilla/Attributes.h" 1.17 +#include "mozilla/ReentrantMonitor.h" 1.18 + 1.19 +class nsIInputStream; 1.20 +class nsILoadGroup; 1.21 +class nsIStreamListener; 1.22 + 1.23 +class nsInputStreamPump MOZ_FINAL : public nsIInputStreamPump 1.24 + , public nsIInputStreamCallback 1.25 + , public nsIThreadRetargetableRequest 1.26 +{ 1.27 +public: 1.28 + typedef mozilla::ReentrantMonitorAutoEnter ReentrantMonitorAutoEnter; 1.29 + NS_DECL_THREADSAFE_ISUPPORTS 1.30 + NS_DECL_NSIREQUEST 1.31 + NS_DECL_NSIINPUTSTREAMPUMP 1.32 + NS_DECL_NSIINPUTSTREAMCALLBACK 1.33 + NS_DECL_NSITHREADRETARGETABLEREQUEST 1.34 + 1.35 + nsInputStreamPump(); 1.36 + ~nsInputStreamPump(); 1.37 + 1.38 + static NS_HIDDEN_(nsresult) 1.39 + Create(nsInputStreamPump **result, 1.40 + nsIInputStream *stream, 1.41 + int64_t streamPos = -1, 1.42 + int64_t streamLen = -1, 1.43 + uint32_t segsize = 0, 1.44 + uint32_t segcount = 0, 1.45 + bool closeWhenDone = false); 1.46 + 1.47 + typedef void (*PeekSegmentFun)(void *closure, const uint8_t *buf, 1.48 + uint32_t bufLen); 1.49 + /** 1.50 + * Peek into the first chunk of data that's in the stream. Note that this 1.51 + * method will not call the callback when there is no data in the stream. 1.52 + * The callback will be called at most once. 1.53 + * 1.54 + * The data from the stream will not be consumed, i.e. the pump's listener 1.55 + * can still read all the data. 1.56 + * 1.57 + * Do not call before asyncRead. Do not call after onStopRequest. 1.58 + */ 1.59 + NS_HIDDEN_(nsresult) PeekStream(PeekSegmentFun callback, void *closure); 1.60 + 1.61 + /** 1.62 + * Dispatched (to the main thread) by OnStateStop if it's called off main 1.63 + * thread. Updates mState based on return value of OnStateStop. 1.64 + */ 1.65 + nsresult CallOnStateStop(); 1.66 + 1.67 +protected: 1.68 + 1.69 + enum { 1.70 + STATE_IDLE, 1.71 + STATE_START, 1.72 + STATE_TRANSFER, 1.73 + STATE_STOP 1.74 + }; 1.75 + 1.76 + nsresult EnsureWaiting(); 1.77 + uint32_t OnStateStart(); 1.78 + uint32_t OnStateTransfer(); 1.79 + uint32_t OnStateStop(); 1.80 + 1.81 + uint32_t mState; 1.82 + nsCOMPtr<nsILoadGroup> mLoadGroup; 1.83 + nsCOMPtr<nsIStreamListener> mListener; 1.84 + nsCOMPtr<nsISupports> mListenerContext; 1.85 + nsCOMPtr<nsIEventTarget> mTargetThread; 1.86 + nsCOMPtr<nsIInputStream> mStream; 1.87 + nsCOMPtr<nsIAsyncInputStream> mAsyncStream; 1.88 + uint64_t mStreamOffset; 1.89 + uint64_t mStreamLength; 1.90 + uint32_t mSegSize; 1.91 + uint32_t mSegCount; 1.92 + nsresult mStatus; 1.93 + uint32_t mSuspendCount; 1.94 + uint32_t mLoadFlags; 1.95 + bool mIsPending; 1.96 + // True while in OnInputStreamReady, calling OnStateStart, OnStateTransfer 1.97 + // and OnStateStop. Used to prevent calls to AsyncWait during callbacks. 1.98 + bool mProcessingCallbacks; 1.99 + // True if waiting on the "input stream ready" callback. 1.100 + bool mWaitingForInputStreamReady; 1.101 + bool mCloseWhenDone; 1.102 + bool mRetargeting; 1.103 + // Protects state/member var accesses across multiple threads. 1.104 + mozilla::ReentrantMonitor mMonitor; 1.105 +}; 1.106 + 1.107 +#endif // !nsInputStreamChannel_h__