Chromium Code Reviews| 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 "mojo/apps/js/bindings/threading.h" | 5 #include "mojo/apps/js/bindings/monotonic_clock.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/time/time.h" |
| 8 #include "gin/object_template_builder.h" | 8 #include "gin/object_template_builder.h" |
| 9 #include "gin/per_isolate_data.h" | 9 #include "gin/per_isolate_data.h" |
| 10 #include "mojo/apps/js/bindings/handle.h" | 10 #include "gin/public/wrapper_info.h" |
| 11 | 11 |
| 12 namespace mojo { | 12 namespace mojo { |
| 13 namespace apps { | 13 namespace apps { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 void Quit() { | 17 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; |
| 18 base::MessageLoop::current()->QuitNow(); | 18 |
| 19 double GetMonotonicSeconds() { | |
| 20 return static_cast<double>( | |
| 21 (base::TimeTicks::Now() - | |
| 22 base::TimeTicks::UnixEpoch()).InMicroseconds()) / | |
| 23 (base::Time::kMicrosecondsPerMillisecond * | |
| 24 base::Time::kMillisecondsPerSecond); | |
|
abarth-chromium
2014/01/09 00:20:46
You don't want to call the mojo API?
Aaron Boodman
2014/01/09 22:34:38
done. was worried about relying on it being micros
| |
| 19 } | 25 } |
| 20 | 26 |
| 21 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; | |
| 22 | |
| 23 } // namespace | 27 } // namespace |
| 24 | 28 |
| 25 const char Threading::kModuleName[] = "mojo/apps/js/bindings/threading"; | 29 const char MonotonicClock::kModuleName[] = "monotonic_clock"; |
| 26 | 30 |
| 27 v8::Local<v8::Value> Threading::GetModule(v8::Isolate* isolate) { | 31 v8::Local<v8::Value> MonotonicClock::GetModule(v8::Isolate* isolate) { |
| 28 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | 32 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); |
| 29 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( | 33 v8::Local<v8::ObjectTemplate> templ = |
| 30 &g_wrapper_info); | 34 data->GetObjectTemplate(&g_wrapper_info); |
| 31 | |
| 32 if (templ.IsEmpty()) { | 35 if (templ.IsEmpty()) { |
| 33 templ = gin::ObjectTemplateBuilder(isolate) | 36 templ = gin::ObjectTemplateBuilder(isolate) |
| 34 .SetMethod("quit", Quit) | 37 .SetMethod("seconds", GetMonotonicSeconds) |
| 35 .Build(); | 38 .Build(); |
| 36 | |
| 37 data->SetObjectTemplate(&g_wrapper_info, templ); | 39 data->SetObjectTemplate(&g_wrapper_info, templ); |
| 38 } | 40 } |
| 39 | |
| 40 return templ->NewInstance(); | 41 return templ->NewInstance(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 Threading::Threading() { | |
| 44 } | |
| 45 | |
| 46 } // namespace apps | 44 } // namespace apps |
| 47 } // namespace mojo | 45 } // namespace mojo |
| OLD | NEW |