1// Copyright 2014 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. 4 5#include "mojo/apps/js/bindings/monotonic_clock.h" 6 7#include "gin/object_template_builder.h" 8#include "gin/per_isolate_data.h" 9#include "gin/public/wrapper_info.h" 10#include "mojo/public/cpp/system/core.h" 11 12namespace mojo { 13namespace apps { 14 15namespace { 16 17gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; 18 19double GetMonotonicSeconds() { 20 const double kMicrosecondsPerSecond = 1000000; 21 return static_cast<double>(mojo::GetTimeTicksNow()) / kMicrosecondsPerSecond; 22} 23 24} // namespace 25 26const char MonotonicClock::kModuleName[] = "monotonic_clock"; 27 28v8::Local<v8::Value> MonotonicClock::GetModule(v8::Isolate* isolate) { 29 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); 30 v8::Local<v8::ObjectTemplate> templ = 31 data->GetObjectTemplate(&g_wrapper_info); 32 if (templ.IsEmpty()) { 33 templ = gin::ObjectTemplateBuilder(isolate) 34 .SetMethod("seconds", GetMonotonicSeconds) 35 .Build(); 36 data->SetObjectTemplate(&g_wrapper_info, templ); 37 } 38 return templ->NewInstance(); 39} 40 41} // namespace apps 42} // namespace mojo 43