michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsTemporaryFileInputStream_h__ michael@0: #define nsTemporaryFileInputStream_h__ michael@0: michael@0: #include "mozilla/Mutex.h" michael@0: #include "nsIInputStream.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "prio.h" michael@0: michael@0: class nsTemporaryFileInputStream : public nsIInputStream michael@0: { michael@0: public: michael@0: //used to release a PRFileDesc michael@0: class FileDescOwner michael@0: { michael@0: friend class nsTemporaryFileInputStream; michael@0: public: michael@0: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FileDescOwner) michael@0: FileDescOwner(PRFileDesc* aFD) michael@0: : mFD(aFD), michael@0: mMutex("FileDescOwner::mMutex") michael@0: { michael@0: MOZ_ASSERT(aFD); michael@0: } michael@0: ~FileDescOwner() michael@0: { michael@0: PR_Close(mFD); michael@0: } michael@0: mozilla::Mutex& FileMutex() { return mMutex; } michael@0: michael@0: private: michael@0: PRFileDesc* mFD; michael@0: mozilla::Mutex mMutex; michael@0: }; michael@0: michael@0: nsTemporaryFileInputStream(FileDescOwner* aFileDescOwner, uint64_t aStartPos, uint64_t aEndPos); michael@0: michael@0: virtual ~nsTemporaryFileInputStream() { } michael@0: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIINPUTSTREAM michael@0: michael@0: private: michael@0: nsRefPtr mFileDescOwner; michael@0: uint64_t mStartPos; michael@0: uint64_t mEndPos; michael@0: bool mClosed; michael@0: }; michael@0: michael@0: #endif // nsTemporaryFileInputStream_h__