nsTemporaryFileInputStream.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsTemporaryFileInputStream_h__
  6. #define nsTemporaryFileInputStream_h__
  7. #include "mozilla/Mutex.h"
  8. #include "nsAutoPtr.h"
  9. #include "nsIInputStream.h"
  10. #include "nsIIPCSerializableInputStream.h"
  11. #include "nsISeekableStream.h"
  12. #include "prio.h"
  13. class nsTemporaryFileInputStream : public nsIInputStream
  14. , public nsISeekableStream
  15. , public nsIIPCSerializableInputStream
  16. {
  17. public:
  18. //used to release a PRFileDesc
  19. class FileDescOwner
  20. {
  21. friend class nsTemporaryFileInputStream;
  22. public:
  23. NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FileDescOwner)
  24. explicit FileDescOwner(PRFileDesc* aFD)
  25. : mFD(aFD),
  26. mMutex("FileDescOwner::mMutex")
  27. {
  28. MOZ_ASSERT(aFD);
  29. }
  30. private:
  31. ~FileDescOwner()
  32. {
  33. PR_Close(mFD);
  34. }
  35. public:
  36. mozilla::Mutex& FileMutex() { return mMutex; }
  37. private:
  38. PRFileDesc* mFD;
  39. mozilla::Mutex mMutex;
  40. };
  41. nsTemporaryFileInputStream(FileDescOwner* aFileDescOwner, uint64_t aStartPos, uint64_t aEndPos);
  42. nsTemporaryFileInputStream();
  43. NS_DECL_THREADSAFE_ISUPPORTS
  44. NS_DECL_NSIINPUTSTREAM
  45. NS_DECL_NSISEEKABLESTREAM
  46. NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM
  47. private:
  48. virtual ~nsTemporaryFileInputStream() { }
  49. RefPtr<FileDescOwner> mFileDescOwner;
  50. uint64_t mStartPos;
  51. uint64_t mCurPos;
  52. uint64_t mEndPos;
  53. bool mClosed;
  54. };
  55. #endif // nsTemporaryFileInputStream_h__