2012-05-21 11:12:37 +00: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 01:27:53 +00:00
|
|
|
|
|
|
|
#ifndef nsAsyncStreamCopier_h__
|
|
|
|
#define nsAsyncStreamCopier_h__
|
|
|
|
|
|
|
|
#include "nsIAsyncStreamCopier.h"
|
2014-04-09 00:26:00 +00:00
|
|
|
#include "nsIAsyncStreamCopier2.h"
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2003-10-06 01:46:31 +00:00
|
|
|
#include "nsStreamUtils.h"
|
2003-01-18 01:27:53 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
2013-09-22 03:04:57 +00:00
|
|
|
class nsIRequestObserver;
|
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsAsyncStreamCopier final : public nsIAsyncStreamCopier,
|
2015-03-27 18:52:19 +00:00
|
|
|
nsIAsyncStreamCopier2
|
2003-01-18 01:27:53 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-07-19 02:24:13 +00:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2003-01-18 01:27:53 +00:00
|
|
|
NS_DECL_NSIREQUEST
|
|
|
|
NS_DECL_NSIASYNCSTREAMCOPIER
|
|
|
|
|
2014-04-09 00:26:00 +00:00
|
|
|
// nsIAsyncStreamCopier2
|
|
|
|
// We declare it by hand instead of NS_DECL_NSIASYNCSTREAMCOPIER2
|
|
|
|
// as nsIAsyncStreamCopier2 duplicates methods of nsIAsyncStreamCopier
|
|
|
|
NS_IMETHOD Init(nsIInputStream *aSource,
|
|
|
|
nsIOutputStream *aSink,
|
|
|
|
nsIEventTarget *aTarget,
|
|
|
|
uint32_t aChunkSize,
|
|
|
|
bool aCloseSource,
|
2015-03-21 16:28:04 +00:00
|
|
|
bool aCloseSink) override;
|
2014-04-09 00:26:00 +00:00
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
nsAsyncStreamCopier();
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// these methods may be called on any thread
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
bool IsComplete(nsresult *status = nullptr);
|
2003-01-18 01:27:53 +00:00
|
|
|
void Complete(nsresult status);
|
|
|
|
|
2003-10-06 01:46:31 +00:00
|
|
|
private:
|
2014-06-24 16:36:44 +00:00
|
|
|
virtual ~nsAsyncStreamCopier();
|
|
|
|
|
2014-04-09 00:26:00 +00:00
|
|
|
nsresult InitInternal(nsIInputStream *source,
|
|
|
|
nsIOutputStream *sink,
|
|
|
|
nsIEventTarget *target,
|
|
|
|
uint32_t chunkSize,
|
|
|
|
bool closeSource,
|
|
|
|
bool closeSink);
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2003-10-06 01:46:31 +00:00
|
|
|
static void OnAsyncCopyComplete(void *, nsresult);
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2014-04-09 00:26:00 +00:00
|
|
|
void AsyncCopyInternal();
|
|
|
|
nsresult ApplyBufferingPolicy();
|
|
|
|
nsIRequest* AsRequest();
|
|
|
|
|
2003-10-06 01:46:31 +00:00
|
|
|
nsCOMPtr<nsIInputStream> mSource;
|
|
|
|
nsCOMPtr<nsIOutputStream> mSink;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRequestObserver> mObserver;
|
|
|
|
|
2003-10-06 01:46:31 +00:00
|
|
|
nsCOMPtr<nsIEventTarget> mTarget;
|
|
|
|
|
2009-03-30 19:10:13 +00:00
|
|
|
nsCOMPtr<nsISupports> mCopierCtx;
|
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
mozilla::Mutex mLock;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2003-10-06 01:46:31 +00:00
|
|
|
nsAsyncCopyMode mMode;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mChunkSize;
|
2003-01-18 01:27:53 +00:00
|
|
|
nsresult mStatus;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mIsPending;
|
|
|
|
bool mCloseSource;
|
|
|
|
bool mCloseSink;
|
2014-04-09 00:26:00 +00:00
|
|
|
bool mShouldSniffBuffering;
|
|
|
|
|
|
|
|
friend class ProceedWithAsyncCopy;
|
|
|
|
friend class AsyncApplyBufferingPolicyEvent;
|
2003-01-18 01:27:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // !nsAsyncStreamCopier_h__
|