Bug 1643382 - P1: BackgroundDataBridgeChild and HttpBackgroundChannelChild don't need to be a cycle r=dragana
Differential Revision: https://phabricator.services.mozilla.com/D79254
This commit is contained in:
@@ -176,6 +176,11 @@ void SocketProcessChild::CleanUp() {
|
||||
iter.Data()->Close();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
mBackgroundDataBridgeMap.Clear();
|
||||
}
|
||||
NS_ShutdownXPCOM(nullptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,27 +10,27 @@ namespace net {
|
||||
|
||||
BackgroundDataBridgeChild::BackgroundDataBridgeChild(
|
||||
HttpBackgroundChannelChild* aBgChild)
|
||||
: mBgChild(aBgChild), mBackgroundThread(NS_GetCurrentThread()) {
|
||||
: mBgChild(aBgChild) {
|
||||
MOZ_ASSERT(aBgChild);
|
||||
}
|
||||
|
||||
BackgroundDataBridgeChild::~BackgroundDataBridgeChild() = default;
|
||||
|
||||
void BackgroundDataBridgeChild::Destroy() {
|
||||
RefPtr<BackgroundDataBridgeChild> self = this;
|
||||
MOZ_ALWAYS_SUCCEEDS(mBackgroundThread->Dispatch(
|
||||
NS_NewRunnableFunction("BackgroundDataBridgeParent::Destroy",
|
||||
[self]() {
|
||||
if (self->CanSend()) {
|
||||
Unused << self->Send__delete__(self);
|
||||
}
|
||||
}),
|
||||
NS_DISPATCH_NORMAL));
|
||||
void BackgroundDataBridgeChild::ActorDestroy(ActorDestroyReason aWhy) {
|
||||
mBgChild = nullptr;
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult BackgroundDataBridgeChild::RecvOnTransportAndData(
|
||||
const uint64_t& offset, const uint32_t& count, const nsCString& data) {
|
||||
MOZ_ASSERT(mBgChild);
|
||||
if (!mBgChild) {
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
if (mBgChild->ChannelClosed()) {
|
||||
Unused << Send__delete__(this);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
return mBgChild->RecvOnTransportAndData(NS_OK, NS_NET_STATUS_RECEIVING_FROM,
|
||||
offset, count, data, true);
|
||||
}
|
||||
|
||||
@@ -17,13 +17,12 @@ class BackgroundDataBridgeChild final : public PBackgroundDataBridgeChild {
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BackgroundDataBridgeChild, override)
|
||||
|
||||
explicit BackgroundDataBridgeChild(HttpBackgroundChannelChild* aBgChild);
|
||||
void Destroy();
|
||||
|
||||
protected:
|
||||
virtual ~BackgroundDataBridgeChild();
|
||||
void ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
RefPtr<HttpBackgroundChannelChild> mBgChild;
|
||||
nsCOMPtr<nsIThread> mBackgroundThread;
|
||||
|
||||
public:
|
||||
mozilla::ipc::IPCResult RecvOnTransportAndData(const uint64_t& offset,
|
||||
|
||||
@@ -49,17 +49,21 @@ nsresult HttpBackgroundChannelChild::Init(HttpChannelChild* aChannelChild) {
|
||||
|
||||
void HttpBackgroundChannelChild::CreateDataBridge() {
|
||||
MOZ_ASSERT(OnSocketThread());
|
||||
|
||||
if (!mChannelChild) {
|
||||
return;
|
||||
}
|
||||
|
||||
PBackgroundChild* actorChild =
|
||||
BackgroundChild::GetOrCreateSocketActorForCurrentThread();
|
||||
if (NS_WARN_IF(!actorChild)) {
|
||||
return;
|
||||
}
|
||||
|
||||
mDataBridgeChild = new BackgroundDataBridgeChild(this);
|
||||
if (!actorChild->SendPBackgroundDataBridgeConstructor(
|
||||
mDataBridgeChild, mChannelChild->ChannelId())) {
|
||||
mDataBridgeChild = nullptr;
|
||||
}
|
||||
RefPtr<BackgroundDataBridgeChild> dataBridgeChild =
|
||||
new BackgroundDataBridgeChild(this);
|
||||
Unused << actorChild->SendPBackgroundDataBridgeConstructor(
|
||||
dataBridgeChild, mChannelChild->ChannelId());
|
||||
}
|
||||
|
||||
void HttpBackgroundChannelChild::OnChannelClosed() {
|
||||
@@ -71,11 +75,12 @@ void HttpBackgroundChannelChild::OnChannelClosed() {
|
||||
|
||||
// Remove pending IPC messages as well.
|
||||
mQueuedRunnables.Clear();
|
||||
|
||||
if (mDataBridgeChild) {
|
||||
mDataBridgeChild->Destroy();
|
||||
mDataBridgeChild = nullptr;
|
||||
}
|
||||
|
||||
bool HttpBackgroundChannelChild::ChannelClosed() {
|
||||
MOZ_ASSERT(OnSocketThread());
|
||||
|
||||
return !mChannelChild;
|
||||
}
|
||||
|
||||
void HttpBackgroundChannelChild::OnStartRequestReceived() {
|
||||
|
||||
@@ -39,6 +39,9 @@ class HttpBackgroundChannelChild final : public PHttpBackgroundChannelChild {
|
||||
// handle any incoming messages over background channel.
|
||||
void OnChannelClosed();
|
||||
|
||||
// Return true if OnChannelClosed has been called.
|
||||
bool ChannelClosed();
|
||||
|
||||
// Callback when OnStartRequest is received and handled by HttpChannelChild.
|
||||
// Enqueued messages in background channel will be flushed.
|
||||
void OnStartRequestReceived();
|
||||
@@ -110,8 +113,6 @@ class HttpBackgroundChannelChild final : public PHttpBackgroundChannelChild {
|
||||
// Should be flushed after OnStartRequest is received and handled.
|
||||
// Should only access on STS thread.
|
||||
nsTArray<nsCOMPtr<nsIRunnable>> mQueuedRunnables;
|
||||
|
||||
RefPtr<BackgroundDataBridgeChild> mDataBridgeChild;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
|
||||
Reference in New Issue
Block a user