tor-browser

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

ActiveResource.h (1301B)


      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_LAYERS_ACTIVERESOURCE
      8 #define MOZILLA_LAYERS_ACTIVERESOURCE
      9 
     10 #include "nsExpirationTracker.h"
     11 
     12 namespace mozilla::layers {
     13 
     14 /**
     15 * See ActiveResourceTracker below.
     16 */
     17 class ActiveResource {
     18 public:
     19  virtual void NotifyInactive() = 0;
     20  nsExpirationState* GetExpirationState() { return &mExpirationState; }
     21  bool IsActivityTracked() { return mExpirationState.IsTracked(); }
     22 
     23 private:
     24  nsExpirationState mExpirationState;
     25 };
     26 
     27 /**
     28 * A convenience class on top of nsExpirationTracker
     29 */
     30 class ActiveResourceTracker final
     31    : public nsExpirationTracker<ActiveResource, 3> {
     32 public:
     33  ActiveResourceTracker(uint32_t aExpirationCycle, const nsACString& aName,
     34                        nsIEventTarget* aEventTarget)
     35      : nsExpirationTracker(aExpirationCycle, aName, aEventTarget) {}
     36 
     37  void NotifyExpired(ActiveResource* aResource) override {
     38    RemoveObject(aResource);
     39    aResource->NotifyInactive();
     40  }
     41 };
     42 
     43 }  // namespace mozilla::layers
     44 
     45 #endif