Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / gin / modules / timer.h
blobe2bed2e56fbee24cbed89949c97a9e0f6630be7b
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
3 // found in the LICENSE file.
5 #ifndef GIN_MODULES_TIMER_H_
6 #define GIN_MODULES_TIMER_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/timer/timer.h"
10 #include "gin/gin_export.h"
11 #include "gin/handle.h"
12 #include "gin/runner.h"
13 #include "gin/wrappable.h"
14 #include "v8/include/v8.h"
16 namespace gin {
18 class ObjectTemplateBuilder;
20 // A simple scriptable timer that can work in one-shot or repeating mode.
21 class GIN_EXPORT Timer : public Wrappable<Timer> {
22 public:
23 enum TimerType {
24 TYPE_ONE_SHOT,
25 TYPE_REPEATING
28 static WrapperInfo kWrapperInfo;
29 static Handle<Timer> Create(TimerType type, v8::Isolate* isolate,
30 int delay_ms, v8::Handle<v8::Function> function);
32 virtual ObjectTemplateBuilder GetObjectTemplateBuilder(
33 v8::Isolate* isolate) OVERRIDE;
35 private:
36 Timer(v8::Isolate* isolate, bool repeating, int delay_ms,
37 v8::Handle<v8::Function> function);
38 virtual ~Timer();
39 void OnTimerFired();
41 base::WeakPtrFactory<Timer> weak_factory_;
42 base::Timer timer_;
43 base::WeakPtr<gin::Runner> runner_;
47 class GIN_EXPORT TimerModule : public Wrappable<TimerModule> {
48 public:
49 static const char kName[];
50 static WrapperInfo kWrapperInfo;
51 static Handle<TimerModule> Create(v8::Isolate* isolate);
52 static v8::Local<v8::Value> GetModule(v8::Isolate* isolate);
54 private:
55 TimerModule();
56 virtual ~TimerModule();
58 virtual ObjectTemplateBuilder GetObjectTemplateBuilder(
59 v8::Isolate* isolate) OVERRIDE;
62 } // namespace gin
64 #endif // GIN_MODULES_TIMER_H_