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 #include "gin/modules/timer.h" | 5 #include "gin/modules/timer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "gin/object_template_builder.h" | 8 #include "gin/object_template_builder.h" |
9 #include "gin/per_context_data.h" | 9 #include "gin/per_context_data.h" |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 // be alive when these methods are called. | 34 // be alive when these methods are called. |
35 return Wrappable<Timer>::GetObjectTemplateBuilder(isolate) | 35 return Wrappable<Timer>::GetObjectTemplateBuilder(isolate) |
36 .SetMethod("cancel", | 36 .SetMethod("cancel", |
37 base::Bind(&base::Timer::Stop, base::Unretained(&timer_))) | 37 base::Bind(&base::Timer::Stop, base::Unretained(&timer_))) |
38 .SetMethod("reset", | 38 .SetMethod("reset", |
39 base::Bind(&base::Timer::Reset, base::Unretained(&timer_))); | 39 base::Bind(&base::Timer::Reset, base::Unretained(&timer_))); |
40 } | 40 } |
41 | 41 |
42 Timer::Timer(v8::Isolate* isolate, bool repeating, int delay_ms, | 42 Timer::Timer(v8::Isolate* isolate, bool repeating, int delay_ms, |
43 v8::Handle<v8::Function> function) | 43 v8::Handle<v8::Function> function) |
44 : weak_factory_(this), | 44 : timer_(false, repeating), |
45 timer_(false, repeating), | |
46 runner_(PerContextData::From( | 45 runner_(PerContextData::From( |
47 isolate->GetCurrentContext())->runner()->GetWeakPtr()) { | 46 isolate->GetCurrentContext())->runner()->GetWeakPtr()), |
| 47 weak_factory_(this) { |
48 GetWrapper(runner_->GetContextHolder()->isolate())->SetHiddenValue( | 48 GetWrapper(runner_->GetContextHolder()->isolate())->SetHiddenValue( |
49 GetHiddenPropertyName(isolate), function); | 49 GetHiddenPropertyName(isolate), function); |
50 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(delay_ms), | 50 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(delay_ms), |
51 base::Bind(&Timer::OnTimerFired, weak_factory_.GetWeakPtr())); | 51 base::Bind(&Timer::OnTimerFired, weak_factory_.GetWeakPtr())); |
52 } | 52 } |
53 | 53 |
54 Timer::~Timer() { | 54 Timer::~Timer() { |
55 } | 55 } |
56 | 56 |
57 void Timer::OnTimerFired() { | 57 void Timer::OnTimerFired() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 ObjectTemplateBuilder TimerModule::GetObjectTemplateBuilder( | 94 ObjectTemplateBuilder TimerModule::GetObjectTemplateBuilder( |
95 v8::Isolate* isolate) { | 95 v8::Isolate* isolate) { |
96 return Wrappable<TimerModule>::GetObjectTemplateBuilder(isolate) | 96 return Wrappable<TimerModule>::GetObjectTemplateBuilder(isolate) |
97 .SetMethod("createOneShot", | 97 .SetMethod("createOneShot", |
98 base::Bind(&Timer::Create, Timer::TYPE_ONE_SHOT)) | 98 base::Bind(&Timer::Create, Timer::TYPE_ONE_SHOT)) |
99 .SetMethod("createRepeating", | 99 .SetMethod("createRepeating", |
100 base::Bind(&Timer::Create, Timer::TYPE_REPEATING)); | 100 base::Bind(&Timer::Create, Timer::TYPE_REPEATING)); |
101 } | 101 } |
102 | 102 |
103 } // namespace gin | 103 } // namespace gin |
OLD | NEW |