Bug 1904139 - Don't re-initialize platform font list from GetDefaultFont. r=jfkthame
[gecko.git] / netwerk / base / ThrottleQueue.h
blob4d06af8e6437ba1456f3fa2ed8cfb33f971ad415
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_net_ThrottleQueue_h
8 #define mozilla_net_ThrottleQueue_h
10 #include "mozilla/TimeStamp.h"
11 #include "nsINamed.h"
12 #include "nsIThrottledInputChannel.h"
13 #include "nsITimer.h"
14 #include "nsTArray.h"
16 namespace mozilla {
17 namespace net {
19 class ThrottleInputStream;
21 /**
22 * An implementation of nsIInputChannelThrottleQueue that can be used
23 * to throttle uploads. This class is not thread-safe.
24 * Initialization and calls to WrapStream may be done on any thread;
25 * but otherwise, after creation, it can only be used on the socket
26 * thread. It currently throttles with a one second granularity, so
27 * may be a bit choppy.
30 class ThrottleQueue : public nsIInputChannelThrottleQueue,
31 public nsITimerCallback,
32 public nsINamed {
33 public:
34 static already_AddRefed<nsIInputChannelThrottleQueue> Create();
36 NS_DECL_THREADSAFE_ISUPPORTS
37 NS_DECL_NSIINPUTCHANNELTHROTTLEQUEUE
38 NS_DECL_NSITIMERCALLBACK
39 NS_DECL_NSINAMED
41 void QueueStream(ThrottleInputStream* aStream);
42 void DequeueStream(ThrottleInputStream* aStream);
44 protected:
45 ThrottleQueue();
46 virtual ~ThrottleQueue();
48 struct ThrottleEntry {
49 TimeStamp mTime;
50 uint32_t mBytesRead = 0;
53 nsTArray<ThrottleEntry> mReadEvents;
54 uint32_t mMeanBytesPerSecond{0};
55 uint32_t mMaxBytesPerSecond{0};
56 uint64_t mBytesProcessed{0};
58 nsTArray<RefPtr<ThrottleInputStream>> mAsyncEvents;
59 nsCOMPtr<nsITimer> mTimer;
60 bool mTimerArmed{false};
63 } // namespace net
64 } // namespace mozilla
66 #endif // mozilla_net_ThrottleQueue_h