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"
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
)
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");
34 if (!nsAutoRefCnt::isThreadSafe
) {
35 NS_ASSERT_OWNINGTHREAD(InputChannelThrottleQueueParent
);
38 mRefCnt
= 1; /* stabilize */
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);
53 mozilla::ipc::IPCResult
InputChannelThrottleQueueParent::RecvRecordRead(
54 const uint32_t& aBytesRead
) {
55 mBytesProcessed
+= aBytesRead
;
60 InputChannelThrottleQueueParent::RecordRead(uint32_t aBytesRead
) {
61 return NS_ERROR_NOT_IMPLEMENTED
;
65 InputChannelThrottleQueueParent::Available(uint32_t aRemaining
,
66 uint32_t* aAvailable
) {
67 return NS_ERROR_NOT_IMPLEMENTED
;
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
);
96 InputChannelThrottleQueueParent::BytesProcessed(uint64_t* aResult
) {
97 *aResult
= mBytesProcessed
;
102 InputChannelThrottleQueueParent::WrapStream(nsIInputStream
* aInputStream
,
103 nsIAsyncInputStream
** aResult
) {
104 return NS_ERROR_NOT_IMPLEMENTED
;
108 InputChannelThrottleQueueParent::GetMeanBytesPerSecond(
109 uint32_t* aMeanBytesPerSecond
) {
110 NS_ENSURE_ARG(aMeanBytesPerSecond
);
112 *aMeanBytesPerSecond
= mMeanBytesPerSecond
;
117 InputChannelThrottleQueueParent::GetMaxBytesPerSecond(
118 uint32_t* aMaxBytesPerSecond
) {
119 NS_ENSURE_ARG(aMaxBytesPerSecond
);
121 *aMaxBytesPerSecond
= mMaxBytesPerSecond
;
126 } // namespace mozilla