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

Unified Diff: mojo/apps/js/bindings/monotonic_clock.cc

Issue 129633005: Introduce a monotonic_clock module for Mojo.js. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/apps/js/bindings/monotonic_clock.h ('k') | mojo/apps/js/main.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/apps/js/bindings/monotonic_clock.cc
diff --git a/mojo/apps/js/bindings/threading.cc b/mojo/apps/js/bindings/monotonic_clock.cc
similarity index 51%
copy from mojo/apps/js/bindings/threading.cc
copy to mojo/apps/js/bindings/monotonic_clock.cc
index 4b10bff0d170836002ef0501ee5561b6ad58f958..9a2c326c6457e107b085b1cf143f1af56b7d4609 100644
--- a/mojo/apps/js/bindings/threading.cc
+++ b/mojo/apps/js/bindings/monotonic_clock.cc
@@ -2,46 +2,44 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/apps/js/bindings/threading.h"
+#include "mojo/apps/js/bindings/monotonic_clock.h"
-#include "base/message_loop/message_loop.h"
+#include "base/time/time.h"
#include "gin/object_template_builder.h"
#include "gin/per_isolate_data.h"
-#include "mojo/apps/js/bindings/handle.h"
+#include "gin/public/wrapper_info.h"
namespace mojo {
namespace apps {
namespace {
-void Quit() {
- base::MessageLoop::current()->QuitNow();
-}
-
gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin };
+double GetMonotonicSeconds() {
+ return static_cast<double>(
+ (base::TimeTicks::Now() -
+ base::TimeTicks::UnixEpoch()).InMicroseconds()) /
+ (base::Time::kMicrosecondsPerMillisecond *
+ 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
+}
+
} // namespace
-const char Threading::kModuleName[] = "mojo/apps/js/bindings/threading";
+const char MonotonicClock::kModuleName[] = "monotonic_clock";
-v8::Local<v8::Value> Threading::GetModule(v8::Isolate* isolate) {
+v8::Local<v8::Value> MonotonicClock::GetModule(v8::Isolate* isolate) {
gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
- v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(
- &g_wrapper_info);
-
+ v8::Local<v8::ObjectTemplate> templ =
+ data->GetObjectTemplate(&g_wrapper_info);
if (templ.IsEmpty()) {
templ = gin::ObjectTemplateBuilder(isolate)
- .SetMethod("quit", Quit)
+ .SetMethod("seconds", GetMonotonicSeconds)
.Build();
-
data->SetObjectTemplate(&g_wrapper_info, templ);
}
-
return templ->NewInstance();
}
-Threading::Threading() {
-}
-
} // namespace apps
} // namespace mojo
« no previous file with comments | « mojo/apps/js/bindings/monotonic_clock.h ('k') | mojo/apps/js/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698