Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: gin/modules/timer.cc

Issue 179803007: Refactors parts of gin: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix gin_shell Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gin/modules/module_runner_delegate.cc ('k') | gin/modules/timer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
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 : weak_factory_(this),
45 timer_(false, repeating), 45 timer_(false, repeating),
46 runner_(PerContextData::From( 46 runner_(PerContextData::From(
47 isolate->GetCurrentContext())->runner()->GetWeakPtr()) { 47 isolate->GetCurrentContext())->runner()->GetWeakPtr()) {
48 GetWrapper(runner_->isolate())->SetHiddenValue(GetHiddenPropertyName(isolate), 48 GetWrapper(runner_->GetContextHolder()->isolate())->SetHiddenValue(
49 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() {
58 // This can happen in spite of the weak callback because it is possible for 58 // This can happen in spite of the weak callback because it is possible for
59 // a gin::Handle<> to keep this object alive past when the isolate it is part 59 // a gin::Handle<> to keep this object alive past when the isolate it is part
60 // of is destroyed. 60 // of is destroyed.
61 if (!runner_.get()) { 61 if (!runner_.get()) {
62 return; 62 return;
63 } 63 }
64 64
65 Runner::Scope scope(runner_.get()); 65 Runner::Scope scope(runner_.get());
66 v8::Isolate* isolate = runner_->GetContextHolder()->isolate();
66 v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast( 67 v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(
67 GetWrapper(runner_->isolate())->GetHiddenValue( 68 GetWrapper(isolate)->GetHiddenValue(GetHiddenPropertyName(isolate)));
68 GetHiddenPropertyName(runner_->isolate()))); 69 runner_->Call(function, v8::Undefined(isolate), 0, NULL);
69 runner_->Call(function, v8::Undefined(runner_->isolate()), 0, NULL);
70 } 70 }
71 71
72 72
73 // TimerModule ================================================================= 73 // TimerModule =================================================================
74 74
75 const char TimerModule::kName[] = "timer"; 75 const char TimerModule::kName[] = "timer";
76 WrapperInfo TimerModule::kWrapperInfo = { kEmbedderNativeGin }; 76 WrapperInfo TimerModule::kWrapperInfo = { kEmbedderNativeGin };
77 77
78 // static 78 // static
79 Handle<TimerModule> TimerModule::Create(v8::Isolate* isolate) { 79 Handle<TimerModule> TimerModule::Create(v8::Isolate* isolate) {
(...skipping 14 matching lines...) Expand all
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
OLDNEW
« no previous file with comments | « gin/modules/module_runner_delegate.cc ('k') | gin/modules/timer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698