Line data Source code
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/gmp/PGMPTimerParent.h"
10 : #include "nsITimer.h"
11 : #include "nsCOMPtr.h"
12 : #include "nsClassHashtable.h"
13 : #include "nsHashKeys.h"
14 : #include "mozilla/Monitor.h"
15 : #include "nsIThread.h"
16 :
17 : namespace mozilla {
18 : namespace gmp {
19 :
20 : class GMPTimerParent : public PGMPTimerParent {
21 : public:
22 0 : NS_INLINE_DECL_REFCOUNTING(GMPTimerParent)
23 : explicit GMPTimerParent(nsISerialEventTarget* aGMPEventTarget);
24 :
25 : void Shutdown();
26 :
27 : protected:
28 : mozilla::ipc::IPCResult RecvSetTimer(const uint32_t& aTimerId,
29 : const uint32_t& aTimeoutMs) override;
30 : void ActorDestroy(ActorDestroyReason aWhy) override;
31 :
32 : private:
33 0 : ~GMPTimerParent() {}
34 :
35 : static void GMPTimerExpired(nsITimer *aTimer, void *aClosure);
36 :
37 : struct Context {
38 0 : Context() {
39 0 : MOZ_COUNT_CTOR(Context);
40 0 : }
41 0 : ~Context() {
42 0 : MOZ_COUNT_DTOR(Context);
43 0 : }
44 : nsCOMPtr<nsITimer> mTimer;
45 : RefPtr<GMPTimerParent> mParent; // Note: live timers keep the GMPTimerParent alive.
46 : uint32_t mId;
47 : };
48 :
49 : void TimerExpired(Context* aContext);
50 :
51 : nsTHashtable<nsPtrHashKey<Context>> mTimers;
52 :
53 : nsCOMPtr<nsISerialEventTarget> mGMPEventTarget;
54 :
55 : bool mIsOpen;
56 : };
57 :
58 : } // namespace gmp
59 : } // namespace mozilla
60 :
61 : #endif // GMPTimerParent_h_
|