Backed out 2 changesets (bug 1943998) for causing wd failures @ phases.py CLOSED...
[gecko.git] / netwerk / ipc / InputChannelThrottleQueueParent.cpp
blob625100394016b06dfea04f82c3c850f889f02738
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 RefPtr<SocketProcessParent> socketParent =
87 SocketProcessParent::GetSingleton();
88 Unused << socketParent->SendPInputChannelThrottleQueueConstructor(
89 self, meanBytesPerSecond, maxBytesPerSecond);
90 });
92 return NS_OK;
95 NS_IMETHODIMP
96 InputChannelThrottleQueueParent::BytesProcessed(uint64_t* aResult) {
97 *aResult = mBytesProcessed;
98 return NS_OK;
101 NS_IMETHODIMP
102 InputChannelThrottleQueueParent::WrapStream(nsIInputStream* aInputStream,
103 nsIAsyncInputStream** aResult) {
104 return NS_ERROR_NOT_IMPLEMENTED;
107 NS_IMETHODIMP
108 InputChannelThrottleQueueParent::GetMeanBytesPerSecond(
109 uint32_t* aMeanBytesPerSecond) {
110 NS_ENSURE_ARG(aMeanBytesPerSecond);
112 *aMeanBytesPerSecond = mMeanBytesPerSecond;
113 return NS_OK;
116 NS_IMETHODIMP
117 InputChannelThrottleQueueParent::GetMaxBytesPerSecond(
118 uint32_t* aMaxBytesPerSecond) {
119 NS_ENSURE_ARG(aMaxBytesPerSecond);
121 *aMaxBytesPerSecond = mMaxBytesPerSecond;
122 return NS_OK;
125 } // namespace net
126 } // namespace mozilla