Bug 1876335 - use GRADLE_MAVEN_REPOSITORIES in more places. r=owlish,geckoview-review...
[gecko.git] / netwerk / ipc / InputChannelThrottleQueueParent.cpp
blobd1e6e82f9f5b20ac04d22559bbfff35f09ff1aed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:set ts=4 sw=4 sts=4 et cin: */
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 #include "InputChannelThrottleQueueParent.h"
8 #include "mozilla/net/SocketProcessParent.h"
9 #include "nsIOService.h"
11 namespace mozilla {
12 namespace net {
14 NS_IMPL_ADDREF(InputChannelThrottleQueueParent)
15 NS_INTERFACE_MAP_BEGIN(InputChannelThrottleQueueParent)
16 NS_INTERFACE_MAP_ENTRY(nsIInputChannelThrottleQueue)
17 NS_INTERFACE_MAP_ENTRY(nsISupports)
18 NS_INTERFACE_MAP_ENTRY_CONCRETE(InputChannelThrottleQueueParent)
19 NS_INTERFACE_MAP_END
21 NS_IMETHODIMP_(MozExternalRefCountType)
22 InputChannelThrottleQueueParent::Release(void) {
23 MOZ_ASSERT(NS_IsMainThread());
24 MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");
26 if (!nsAutoRefCnt::isThreadSafe) {
27 NS_ASSERT_OWNINGTHREAD(InputChannelThrottleQueueParent);
30 nsrefcnt count = --mRefCnt;
31 NS_LOG_RELEASE(this, count, "InputChannelThrottleQueueParent");
33 if (count == 0) {
34 if (!nsAutoRefCnt::isThreadSafe) {
35 NS_ASSERT_OWNINGTHREAD(InputChannelThrottleQueueParent);
38 mRefCnt = 1; /* stabilize */
39 delete (this);
40 return 0;
43 // When ref count goes down to 1 (held internally by IPDL), it means that
44 // we are done with this ThrottleQueue. We should send a delete message
45 // to delete the InputChannelThrottleQueueChild in socket process.
46 if (count == 1 && CanSend()) {
47 mozilla::Unused << Send__delete__(this);
48 return 1;
50 return count;
53 mozilla::ipc::IPCResult InputChannelThrottleQueueParent::RecvRecordRead(
54 const uint32_t& aBytesRead) {
55 mBytesProcessed += aBytesRead;
56 return IPC_OK();
59 NS_IMETHODIMP
60 InputChannelThrottleQueueParent::RecordRead(uint32_t aBytesRead) {
61 return NS_ERROR_NOT_IMPLEMENTED;
64 NS_IMETHODIMP
65 InputChannelThrottleQueueParent::Available(uint32_t aRemaining,
66 uint32_t* aAvailable) {
67 return NS_ERROR_NOT_IMPLEMENTED;
70 NS_IMETHODIMP
71 InputChannelThrottleQueueParent::Init(uint32_t aMeanBytesPerSecond,
72 uint32_t aMaxBytesPerSecond) {
73 // Can be called on any thread.
74 if (aMeanBytesPerSecond == 0 || aMaxBytesPerSecond == 0 ||
75 aMaxBytesPerSecond < aMeanBytesPerSecond) {
76 return NS_ERROR_ILLEGAL_VALUE;
79 mMeanBytesPerSecond = aMeanBytesPerSecond;
80 mMaxBytesPerSecond = aMaxBytesPerSecond;
82 RefPtr<InputChannelThrottleQueueParent> self = this;
83 gIOService->CallOrWaitForSocketProcess(
84 [self, meanBytesPerSecond(mMeanBytesPerSecond),
85 maxBytesPerSecond(mMaxBytesPerSecond)] {
86 Unused << SocketProcessParent::GetSingleton()
87 ->SendPInputChannelThrottleQueueConstructor(
88 self, meanBytesPerSecond, maxBytesPerSecond);
89 });
91 return NS_OK;
94 NS_IMETHODIMP
95 InputChannelThrottleQueueParent::BytesProcessed(uint64_t* aResult) {
96 *aResult = mBytesProcessed;
97 return NS_OK;
100 NS_IMETHODIMP
101 InputChannelThrottleQueueParent::WrapStream(nsIInputStream* aInputStream,
102 nsIAsyncInputStream** aResult) {
103 return NS_ERROR_NOT_IMPLEMENTED;
106 NS_IMETHODIMP
107 InputChannelThrottleQueueParent::GetMeanBytesPerSecond(
108 uint32_t* aMeanBytesPerSecond) {
109 NS_ENSURE_ARG(aMeanBytesPerSecond);
111 *aMeanBytesPerSecond = mMeanBytesPerSecond;
112 return NS_OK;
115 NS_IMETHODIMP
116 InputChannelThrottleQueueParent::GetMaxBytesPerSecond(
117 uint32_t* aMaxBytesPerSecond) {
118 NS_ENSURE_ARG(aMaxBytesPerSecond);
120 *aMaxBytesPerSecond = mMaxBytesPerSecond;
121 return NS_OK;
124 } // namespace net
125 } // namespace mozilla