tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsIncrementalStreamLoader.h (1761B)


      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 
      6 #ifndef nsIncrementalStreamLoader_h__
      7 #define nsIncrementalStreamLoader_h__
      8 
      9 #include "nsIThreadRetargetableStreamListener.h"
     10 #include "nsIIncrementalStreamLoader.h"
     11 #include "nsCOMPtr.h"
     12 #include "mozilla/Atomics.h"
     13 #include "mozilla/Vector.h"
     14 
     15 class nsIRequest;
     16 
     17 class nsIncrementalStreamLoader final : public nsIIncrementalStreamLoader {
     18 public:
     19  NS_DECL_THREADSAFE_ISUPPORTS
     20  NS_DECL_NSIINCREMENTALSTREAMLOADER
     21  NS_DECL_NSIREQUESTOBSERVER
     22  NS_DECL_NSISTREAMLISTENER
     23  NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
     24 
     25  nsIncrementalStreamLoader();
     26 
     27  static nsresult Create(REFNSIID aIID, void** aResult);
     28 
     29 protected:
     30  ~nsIncrementalStreamLoader() = default;
     31 
     32  static nsresult WriteSegmentFun(nsIInputStream*, void*, const char*, uint32_t,
     33                                  uint32_t, uint32_t*);
     34 
     35  // Utility method to free mData, if present, and update other state to
     36  // reflect that no data has been allocated.
     37  void ReleaseData();
     38 
     39  nsCOMPtr<nsIIncrementalStreamLoaderObserver> mObserver;
     40  nsCOMPtr<nsISupports> mContext;  // the observer's context
     41  nsCOMPtr<nsIRequest> mRequest;
     42 
     43  // Buffer to accumulate incoming data. We preallocate if contentSize is
     44  // available.
     45  mozilla::Vector<uint8_t, 0> mData;
     46 
     47  // Number of bytes read, which may not match the number of bytes in mData at
     48  // all, as we incrementally remove from there.
     49  mozilla::Atomic<uint32_t, mozilla::MemoryOrdering::Relaxed> mBytesRead;
     50 };
     51 
     52 #endif  // nsIncrementalStreamLoader_h__