2013-07-02 07:00:37 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef nsTemporaryFileInputStream_h__
|
|
|
|
#define nsTemporaryFileInputStream_h__
|
|
|
|
|
|
|
|
#include "mozilla/Mutex.h"
|
2013-09-22 07:04:57 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2015-11-03 18:12:23 +03:00
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsISeekableStream.h"
|
2013-09-22 07:04:57 +04:00
|
|
|
#include "prio.h"
|
2013-07-02 07:00:37 +04:00
|
|
|
|
|
|
|
class nsTemporaryFileInputStream : public nsIInputStream
|
2015-11-03 18:12:23 +03:00
|
|
|
, public nsISeekableStream
|
2013-07-02 07:00:37 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
//used to release a PRFileDesc
|
|
|
|
class FileDescOwner
|
|
|
|
{
|
|
|
|
friend class nsTemporaryFileInputStream;
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FileDescOwner)
|
2014-08-05 17:20:24 +04:00
|
|
|
explicit FileDescOwner(PRFileDesc* aFD)
|
2013-07-02 07:00:37 +04:00
|
|
|
: mFD(aFD),
|
|
|
|
mMutex("FileDescOwner::mMutex")
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aFD);
|
|
|
|
}
|
2014-06-20 15:08:24 +04:00
|
|
|
private:
|
2013-07-02 07:00:37 +04:00
|
|
|
~FileDescOwner()
|
|
|
|
{
|
|
|
|
PR_Close(mFD);
|
|
|
|
}
|
2014-06-20 15:08:24 +04:00
|
|
|
public:
|
2013-07-02 07:00:37 +04:00
|
|
|
mozilla::Mutex& FileMutex() { return mMutex; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
PRFileDesc* mFD;
|
|
|
|
mozilla::Mutex mMutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsTemporaryFileInputStream(FileDescOwner* aFileDescOwner, uint64_t aStartPos, uint64_t aEndPos);
|
|
|
|
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2013-07-02 07:00:37 +04:00
|
|
|
NS_DECL_NSIINPUTSTREAM
|
2015-11-03 18:12:23 +03:00
|
|
|
NS_DECL_NSISEEKABLESTREAM
|
2013-07-02 07:00:37 +04:00
|
|
|
|
|
|
|
private:
|
2014-06-24 20:36:44 +04:00
|
|
|
virtual ~nsTemporaryFileInputStream() { }
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<FileDescOwner> mFileDescOwner;
|
2013-07-02 07:00:37 +04:00
|
|
|
uint64_t mStartPos;
|
2015-11-03 18:12:23 +03:00
|
|
|
uint64_t mCurPos;
|
2013-07-02 07:00:37 +04:00
|
|
|
uint64_t mEndPos;
|
|
|
|
bool mClosed;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsTemporaryFileInputStream_h__
|