nsStreamLoader.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  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 nsStreamLoader_h__
  6. #define nsStreamLoader_h__
  7. #include "nsIThreadRetargetableStreamListener.h"
  8. #include "nsIStreamLoader.h"
  9. #include "nsCOMPtr.h"
  10. #include "mozilla/Attributes.h"
  11. #include "mozilla/Vector.h"
  12. class nsIRequest;
  13. namespace mozilla {
  14. namespace net {
  15. class nsStreamLoader final : public nsIStreamLoader
  16. , public nsIThreadRetargetableStreamListener
  17. {
  18. public:
  19. NS_DECL_THREADSAFE_ISUPPORTS
  20. NS_DECL_NSISTREAMLOADER
  21. NS_DECL_NSIREQUESTOBSERVER
  22. NS_DECL_NSISTREAMLISTENER
  23. NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
  24. nsStreamLoader();
  25. static nsresult
  26. Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
  27. protected:
  28. ~nsStreamLoader();
  29. static nsresult WriteSegmentFun(nsIInputStream *, void *, const char *,
  30. uint32_t, uint32_t, uint32_t *);
  31. // Utility method to free mData, if present, and update other state to
  32. // reflect that no data has been allocated.
  33. void ReleaseData();
  34. nsCOMPtr<nsIStreamLoaderObserver> mObserver;
  35. nsCOMPtr<nsISupports> mContext; // the observer's context
  36. nsCOMPtr<nsIRequest> mRequest;
  37. nsCOMPtr<nsIRequestObserver> mRequestObserver;
  38. mozilla::Atomic<uint32_t, mozilla::Relaxed> mBytesRead;
  39. // Buffer to accumulate incoming data. We preallocate if contentSize is
  40. // available.
  41. mozilla::Vector<uint8_t, 0> mData;
  42. };
  43. } // namespace net
  44. } // namespace mozilla
  45. #endif // nsStreamLoader_h__