Bug 1729952 [wpt PR 30477] - Fix timeout in grid-positioned-item-dynamic-change-006...
[gecko.git] / netwerk / base / ThrottleQueue.h
blob0623c05e6bae9aaa84a0efe9d94b09d02e864eb7
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"
15 namespace mozilla {
16 namespace net {
18 class ThrottleInputStream;
20 /**
21 * An implementation of nsIInputChannelThrottleQueue that can be used
22 * to throttle uploads. This class is not thread-safe.
23 * Initialization and calls to WrapStream may be done on any thread;
24 * but otherwise, after creation, it can only be used on the socket
25 * thread. It currently throttles with a one second granularity, so
26 * may be a bit choppy.
29 class ThrottleQueue : public nsIInputChannelThrottleQueue,
30 public nsITimerCallback,
31 public nsINamed {
32 public:
33 static already_AddRefed<nsIInputChannelThrottleQueue> Create();
35 NS_DECL_THREADSAFE_ISUPPORTS
36 NS_DECL_NSIINPUTCHANNELTHROTTLEQUEUE
37 NS_DECL_NSITIMERCALLBACK
38 NS_DECL_NSINAMED
40 void QueueStream(ThrottleInputStream* aStream);
41 void DequeueStream(ThrottleInputStream* aStream);
43 protected:
44 ThrottleQueue();
45 virtual ~ThrottleQueue();
47 struct ThrottleEntry {
48 TimeStamp mTime;
49 uint32_t mBytesRead = 0;
52 nsTArray<ThrottleEntry> mReadEvents;
53 uint32_t mMeanBytesPerSecond{0};
54 uint32_t mMaxBytesPerSecond{0};
55 uint64_t mBytesProcessed{0};
57 nsTArray<RefPtr<ThrottleInputStream>> mAsyncEvents;
58 nsCOMPtr<nsITimer> mTimer;
59 bool mTimerArmed{false};
62 } // namespace net
63 } // namespace mozilla
65 #endif // mozilla_net_ThrottleQueue_h