tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

EarlyHintRegistrar.h (2680B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      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/. */
      6 
      7 #ifndef mozilla_net_EarlyHintRegistrar_h__
      8 #define mozilla_net_EarlyHintRegistrar_h__
      9 
     10 #include "mozilla/RefCounted.h"
     11 #include "mozilla/dom/ipc/IdType.h"
     12 #include "nsRefPtrHashtable.h"
     13 #include "mozilla/AlreadyAddRefed.h"
     14 
     15 class nsIParentChannel;
     16 
     17 namespace mozilla::net {
     18 
     19 class EarlyHintPreloader;
     20 
     21 /*
     22 * Registrar for pairing EarlyHintPreloader and HttpChannelParent via
     23 * earlyHintPreloaderId. EarlyHintPreloader has to be registered first.
     24 * EarlyHintPreloader::OnParentReady will be invoked to notify the
     25 * EarlyHintpreloader about the existence of the associated HttpChannelParent.
     26 */
     27 class EarlyHintRegistrar final : public RefCounted<EarlyHintRegistrar> {
     28  using EarlyHintHashtable =
     29      nsRefPtrHashtable<nsUint64HashKey, EarlyHintPreloader>;
     30 
     31 public:
     32  MOZ_DECLARE_REFCOUNTED_TYPENAME(EarlyHintRegistrar)
     33 
     34  EarlyHintRegistrar();
     35  ~EarlyHintRegistrar();
     36 
     37  /*
     38   * Store EarlyHintPreloader for the HttpChannelParent to connect back to.
     39   *
     40   * @param aEarlyHintPreloaderId identifying the EarlyHintPreloader
     41   * @param aEhp the EarlyHintPreloader to store
     42   */
     43  void RegisterEarlyHint(uint64_t aEarlyHintPreloaderId,
     44                         EarlyHintPreloader* aEhp);
     45 
     46  /*
     47   * Link the provided nsIParentChannel with the associated EarlyHintPreloader.
     48   *
     49   * @param aEarlyHintPreloaderId identifying the EarlyHintPreloader
     50   * @param aParent the nsIParentChannel to be paired
     51   * @param aChannelId the id of the nsIChannel connecting to the
     52   *        EarlyHintPreloader.
     53   */
     54  bool LinkParentChannel(dom::ContentParentId aCpId,
     55                         uint64_t aEarlyHintPreloaderId,
     56                         nsIParentChannel* aParent);
     57 
     58  /*
     59   * Delete previous stored EarlyHintPreloader
     60   *
     61   * @param aEarlyHintPreloaderId identifying the EarlyHintPreloader
     62   */
     63  void DeleteEntry(dom::ContentParentId aCpId, uint64_t aEarlyHintPreloaderId);
     64 
     65  /*
     66   * This is called when "profile-change-net-teardown" is observed. We use this
     67   * to cancel the ongoing preload and clear the linked EarlyHintPreloader
     68   * objects.
     69   */
     70  static void CleanUp();
     71 
     72  // Singleton accessor
     73  static already_AddRefed<EarlyHintRegistrar> GetOrCreate();
     74 
     75 private:
     76  // Store unlinked EarlyHintPreloader objects.
     77  EarlyHintHashtable mEarlyHint;
     78 };
     79 
     80 }  // namespace mozilla::net
     81 
     82 #endif  // mozilla_net_EarlyHintRegistrar_h__