|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * vim: sw=2 ts=8 et : |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #ifndef mozilla_plugins_ChildTimer_h |
|
9 #define mozilla_plugins_ChildTimer_h |
|
10 |
|
11 #include "PluginMessageUtils.h" |
|
12 #include "npapi.h" |
|
13 #include "base/timer.h" |
|
14 |
|
15 namespace mozilla { |
|
16 namespace plugins { |
|
17 |
|
18 class PluginInstanceChild; |
|
19 typedef void (*TimerFunc)(NPP npp, uint32_t timerID); |
|
20 |
|
21 class ChildTimer |
|
22 { |
|
23 public: |
|
24 /** |
|
25 * If initialization failed, ID() will return 0. |
|
26 */ |
|
27 ChildTimer(PluginInstanceChild* instance, |
|
28 uint32_t interval, |
|
29 bool repeat, |
|
30 TimerFunc func); |
|
31 ~ChildTimer() { } |
|
32 |
|
33 uint32_t ID() const { return mID; } |
|
34 |
|
35 class IDComparator |
|
36 { |
|
37 public: |
|
38 bool Equals(ChildTimer* t, uint32_t id) const { |
|
39 return t->ID() == id; |
|
40 } |
|
41 }; |
|
42 |
|
43 private: |
|
44 PluginInstanceChild* mInstance; |
|
45 TimerFunc mFunc; |
|
46 bool mRepeating; |
|
47 uint32_t mID; |
|
48 base::RepeatingTimer<ChildTimer> mTimer; |
|
49 |
|
50 void Run(); |
|
51 |
|
52 static uint32_t gNextTimerID; |
|
53 }; |
|
54 |
|
55 } // namespace plugins |
|
56 } // namespace mozilla |
|
57 |
|
58 #endif // mozilla_plugins_ChildTimer_h |