2003-01-18 04:27:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-01-18 04:27:53 +03:00
|
|
|
|
|
|
|
#ifndef nsInputStreamPump_h__
|
|
|
|
#define nsInputStreamPump_h__
|
|
|
|
|
|
|
|
#include "nsIInputStreamPump.h"
|
|
|
|
#include "nsIAsyncInputStream.h"
|
2013-07-09 05:45:25 +04:00
|
|
|
#include "nsIThreadRetargetableRequest.h"
|
2003-01-18 04:27:53 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2012-06-06 07:18:25 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-24 21:53:35 +04:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2003-01-18 04:27:53 +03:00
|
|
|
|
2013-09-22 07:04:57 +04:00
|
|
|
class nsIInputStream;
|
|
|
|
class nsILoadGroup;
|
|
|
|
class nsIStreamListener;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsInputStreamPump final : public nsIInputStreamPump
|
2015-03-27 21:52:19 +03:00
|
|
|
, public nsIInputStreamCallback
|
|
|
|
, public nsIThreadRetargetableRequest
|
2003-01-18 04:27:53 +03:00
|
|
|
{
|
2014-06-24 20:36:44 +04:00
|
|
|
~nsInputStreamPump();
|
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
public:
|
2013-09-24 21:53:35 +04:00
|
|
|
typedef mozilla::ReentrantMonitorAutoEnter ReentrantMonitorAutoEnter;
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2003-01-18 04:27:53 +03:00
|
|
|
NS_DECL_NSIREQUEST
|
|
|
|
NS_DECL_NSIINPUTSTREAMPUMP
|
2003-10-06 05:46:31 +04:00
|
|
|
NS_DECL_NSIINPUTSTREAMCALLBACK
|
2013-07-09 05:45:25 +04:00
|
|
|
NS_DECL_NSITHREADRETARGETABLEREQUEST
|
2003-01-18 04:27:53 +03:00
|
|
|
|
|
|
|
nsInputStreamPump();
|
|
|
|
|
2014-06-02 16:08:21 +04:00
|
|
|
static nsresult
|
2006-03-04 00:06:53 +03:00
|
|
|
Create(nsInputStreamPump **result,
|
|
|
|
nsIInputStream *stream,
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t streamPos = -1,
|
|
|
|
int64_t streamLen = -1,
|
|
|
|
uint32_t segsize = 0,
|
|
|
|
uint32_t segcount = 0,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool closeWhenDone = false);
|
2006-03-04 00:06:53 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
typedef void (*PeekSegmentFun)(void *closure, const uint8_t *buf,
|
|
|
|
uint32_t bufLen);
|
2006-02-17 19:54:27 +03:00
|
|
|
/**
|
|
|
|
* Peek into the first chunk of data that's in the stream. Note that this
|
|
|
|
* method will not call the callback when there is no data in the stream.
|
|
|
|
* The callback will be called at most once.
|
|
|
|
*
|
|
|
|
* The data from the stream will not be consumed, i.e. the pump's listener
|
|
|
|
* can still read all the data.
|
|
|
|
*
|
|
|
|
* Do not call before asyncRead. Do not call after onStopRequest.
|
|
|
|
*/
|
2014-06-02 16:08:21 +04:00
|
|
|
nsresult PeekStream(PeekSegmentFun callback, void *closure);
|
2006-02-17 19:54:27 +03:00
|
|
|
|
2013-07-09 05:45:25 +04:00
|
|
|
/**
|
2013-09-06 04:07:04 +04:00
|
|
|
* Dispatched (to the main thread) by OnStateStop if it's called off main
|
|
|
|
* thread. Updates mState based on return value of OnStateStop.
|
2013-07-09 05:45:25 +04:00
|
|
|
*/
|
2013-09-06 04:07:04 +04:00
|
|
|
nsresult CallOnStateStop();
|
2013-07-09 05:45:25 +04:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
protected:
|
|
|
|
|
|
|
|
enum {
|
|
|
|
STATE_IDLE,
|
|
|
|
STATE_START,
|
|
|
|
STATE_TRANSFER,
|
|
|
|
STATE_STOP
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult EnsureWaiting();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t OnStateStart();
|
|
|
|
uint32_t OnStateTransfer();
|
|
|
|
uint32_t OnStateStop();
|
2003-01-18 04:27:53 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mState;
|
2003-01-18 04:27:53 +03:00
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
|
|
|
nsCOMPtr<nsISupports> mListenerContext;
|
2013-07-09 05:45:25 +04:00
|
|
|
nsCOMPtr<nsIEventTarget> mTargetThread;
|
2003-01-18 04:27:53 +03:00
|
|
|
nsCOMPtr<nsIInputStream> mStream;
|
|
|
|
nsCOMPtr<nsIAsyncInputStream> mAsyncStream;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t mStreamOffset;
|
|
|
|
uint64_t mStreamLength;
|
|
|
|
uint32_t mSegSize;
|
|
|
|
uint32_t mSegCount;
|
2003-01-18 04:27:53 +03:00
|
|
|
nsresult mStatus;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mSuspendCount;
|
|
|
|
uint32_t mLoadFlags;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsPending;
|
2013-09-24 21:53:35 +04:00
|
|
|
// True while in OnInputStreamReady, calling OnStateStart, OnStateTransfer
|
|
|
|
// and OnStateStop. Used to prevent calls to AsyncWait during callbacks.
|
|
|
|
bool mProcessingCallbacks;
|
|
|
|
// True if waiting on the "input stream ready" callback.
|
|
|
|
bool mWaitingForInputStreamReady;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mCloseWhenDone;
|
2013-07-09 05:45:25 +04:00
|
|
|
bool mRetargeting;
|
2013-09-24 21:53:35 +04:00
|
|
|
// Protects state/member var accesses across multiple threads.
|
|
|
|
mozilla::ReentrantMonitor mMonitor;
|
2003-01-18 04:27:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // !nsInputStreamChannel_h__
|