Files
tubestation/netwerk/protocol/http/BackgroundChannelRegistrar.h
Andrew McCreight 4394a576d4 Bug 1760018 - Clean up networking registrars earlier to avoid leaks. r=necko-reviewers,kershaw
These registrars can hold channels alive, which can hold listeners alive,
which can hold cycle collected things alive. By clearing the registrars
before the final CC instead of after the final CC, we can avoid spurious
leaks.

It would make more logical sense to do this earlier, at net teardown,
but I've made the minimal change to try to avoid stirring up weird
shutdown issues.

Differential Revision: https://phabricator.services.mozilla.com/D177182
2023-05-05 15:04:46 +00:00

56 lines
1.8 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_net_BackgroundChannelRegistrar_h__
#define mozilla_net_BackgroundChannelRegistrar_h__
#include "nsIBackgroundChannelRegistrar.h"
#include "nsRefPtrHashtable.h"
#include "mozilla/AlreadyAddRefed.h"
namespace mozilla {
namespace net {
class HttpBackgroundChannelParent;
class HttpChannelParent;
class BackgroundChannelRegistrar final : public nsIBackgroundChannelRegistrar {
using ChannelHashtable =
nsRefPtrHashtable<nsUint64HashKey, HttpChannelParent>;
using BackgroundChannelHashtable =
nsRefPtrHashtable<nsUint64HashKey, HttpBackgroundChannelParent>;
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIBACKGROUNDCHANNELREGISTRAR
explicit BackgroundChannelRegistrar();
// Singleton accessor
static already_AddRefed<nsIBackgroundChannelRegistrar> GetOrCreate();
private:
virtual ~BackgroundChannelRegistrar();
// A helper function for BackgroundChannelRegistrar itself to callback
// HttpChannelParent and HttpBackgroundChannelParent when both objects are
// ready. aChannelParent and aBgParent is the pair of HttpChannelParent and
// HttpBackgroundChannelParent that should be linked together.
void NotifyChannelLinked(HttpChannelParent* aChannelParent,
HttpBackgroundChannelParent* aBgParent);
// Store unlinked HttpChannelParent objects.
ChannelHashtable mChannels;
// Store unlinked HttpBackgroundChannelParent objects.
BackgroundChannelHashtable mBgChannels;
};
} // namespace net
} // namespace mozilla
#endif // mozilla_net_BackgroundChannelRegistrar_h__