OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GIN_MODULES_TIMER_H_ | 5 #ifndef GIN_MODULES_TIMER_H_ |
6 #define GIN_MODULES_TIMER_H_ | 6 #define GIN_MODULES_TIMER_H_ |
7 | 7 |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 #include "gin/gin_export.h" | 10 #include "gin/gin_export.h" |
11 #include "gin/handle.h" | 11 #include "gin/handle.h" |
12 #include "gin/runner.h" | 12 #include "gin/runner.h" |
13 #include "gin/wrappable.h" | 13 #include "gin/wrappable.h" |
14 #include "v8/include/v8.h" | 14 #include "v8/include/v8.h" |
15 | 15 |
16 namespace gin { | 16 namespace gin { |
17 | 17 |
18 class ObjectTemplateBuilder; | 18 class ObjectTemplateBuilder; |
19 | 19 |
20 // A simple scriptable timer that can work in one-shot or repeating mode. | 20 // A simple scriptable timer that can work in one-shot or repeating mode. |
21 class GIN_EXPORT Timer : public Wrappable<Timer> { | 21 class GIN_EXPORT Timer : public Wrappable<Timer> { |
22 public: | 22 public: |
23 enum TimerType { | 23 enum TimerType { |
24 TYPE_ONE_SHOT, | 24 TYPE_ONE_SHOT, |
25 TYPE_REPEATING | 25 TYPE_REPEATING |
26 }; | 26 }; |
27 | 27 |
28 static WrapperInfo kWrapperInfo; | 28 static WrapperInfo kWrapperInfo; |
29 static Handle<Timer> Create(TimerType type, v8::Isolate* isolate, | 29 static Handle<Timer> Create(TimerType type, v8::Isolate* isolate, |
30 int delay_ms, v8::Handle<v8::Function> function); | 30 int delay_ms, v8::Local<v8::Function> function); |
31 | 31 |
32 ObjectTemplateBuilder GetObjectTemplateBuilder(v8::Isolate* isolate) override; | 32 ObjectTemplateBuilder GetObjectTemplateBuilder(v8::Isolate* isolate) override; |
33 | 33 |
34 private: | 34 private: |
35 Timer(v8::Isolate* isolate, bool repeating, int delay_ms, | 35 Timer(v8::Isolate* isolate, bool repeating, int delay_ms, |
36 v8::Handle<v8::Function> function); | 36 v8::Local<v8::Function> function); |
37 ~Timer() override; | 37 ~Timer() override; |
38 void OnTimerFired(); | 38 void OnTimerFired(); |
39 | 39 |
40 base::Timer timer_; | 40 base::Timer timer_; |
41 base::WeakPtr<gin::Runner> runner_; | 41 base::WeakPtr<gin::Runner> runner_; |
42 base::WeakPtrFactory<Timer> weak_factory_; | 42 base::WeakPtrFactory<Timer> weak_factory_; |
43 | 43 |
44 DISALLOW_COPY_AND_ASSIGN(Timer); | 44 DISALLOW_COPY_AND_ASSIGN(Timer); |
45 }; | 45 }; |
46 | 46 |
47 | 47 |
48 class GIN_EXPORT TimerModule : public Wrappable<TimerModule> { | 48 class GIN_EXPORT TimerModule : public Wrappable<TimerModule> { |
49 public: | 49 public: |
50 static const char kName[]; | 50 static const char kName[]; |
51 static WrapperInfo kWrapperInfo; | 51 static WrapperInfo kWrapperInfo; |
52 static Handle<TimerModule> Create(v8::Isolate* isolate); | 52 static Handle<TimerModule> Create(v8::Isolate* isolate); |
53 static v8::Local<v8::Value> GetModule(v8::Isolate* isolate); | 53 static v8::Local<v8::Value> GetModule(v8::Isolate* isolate); |
54 | 54 |
55 private: | 55 private: |
56 TimerModule(); | 56 TimerModule(); |
57 ~TimerModule() override; | 57 ~TimerModule() override; |
58 | 58 |
59 ObjectTemplateBuilder GetObjectTemplateBuilder(v8::Isolate* isolate) override; | 59 ObjectTemplateBuilder GetObjectTemplateBuilder(v8::Isolate* isolate) override; |
60 }; | 60 }; |
61 | 61 |
62 } // namespace gin | 62 } // namespace gin |
63 | 63 |
64 #endif // GIN_MODULES_TIMER_H_ | 64 #endif // GIN_MODULES_TIMER_H_ |
OLD | NEW |