tor-browser

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

GMPTimerParent.h (1492B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef GMPTimerParent_h_
      7 #define GMPTimerParent_h_
      8 
      9 #include "mozilla/Monitor.h"
     10 #include "mozilla/gmp/PGMPTimerParent.h"
     11 #include "nsCOMPtr.h"
     12 #include "nsITimer.h"
     13 #include "nsTHashSet.h"
     14 
     15 namespace mozilla::gmp {
     16 
     17 class GMPTimerParent : public PGMPTimerParent {
     18  friend class PGMPTimerParent;
     19 
     20 public:
     21  NS_INLINE_DECL_REFCOUNTING(GMPTimerParent)
     22  explicit GMPTimerParent(nsISerialEventTarget* aGMPEventTarget);
     23 
     24  void Shutdown();
     25 
     26 protected:
     27  mozilla::ipc::IPCResult RecvSetTimer(const uint32_t& aTimerId,
     28                                       const uint32_t& aTimeoutMs);
     29  void ActorDestroy(ActorDestroyReason aWhy) override;
     30 
     31 private:
     32  ~GMPTimerParent() = default;
     33 
     34  static void GMPTimerExpired(nsITimer* aTimer, void* aClosure);
     35 
     36  struct Context {
     37    Context() : mId(0) { MOZ_COUNT_CTOR(Context); }
     38    MOZ_COUNTED_DTOR(Context)
     39    nsCOMPtr<nsITimer> mTimer;
     40    RefPtr<GMPTimerParent>
     41        mParent;  // Note: live timers keep the GMPTimerParent alive.
     42    uint32_t mId;
     43  };
     44 
     45  void TimerExpired(Context* aContext);
     46 
     47  nsTHashSet<Context*> mTimers;
     48 
     49  nsCOMPtr<nsISerialEventTarget> mGMPEventTarget;
     50 
     51  bool mIsOpen;
     52 };
     53 
     54 }  // namespace mozilla::gmp
     55 
     56 #endif  // GMPTimerParent_h_