aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhishek Bhardwaj <abhishekbh@google.com>2018-01-10 21:40:13 +0000
committerandroid-build-merger <android-build-merger@google.com>2018-01-10 21:40:13 +0000
commiteca3e8a8fc785590d207667618801458791aeaff (patch)
tree0f217a95abaad0693419a7f75b045534a4c058d6
parente714b8113a2dd840c595131b96cad96fb2b250d5 (diff)
parent85dd0fbd3af5c5baccc37e0f84edb2465744fb23 (diff)
downloadlibmojo-eca3e8a8fc785590d207667618801458791aeaff.tar.gz
libmojo: Support Time and TimeTicks typemap am: 359ef58a9d
am: 85dd0fbd3a Change-Id: I0ad445799f94b425f28fc850d64775d705149f2d
-rw-r--r--mojo/common/common_custom_types_struct_traits.h13
-rw-r--r--mojo/common/time.mojom14
-rw-r--r--mojo/common/time_struct_traits.h55
3 files changed, 65 insertions, 17 deletions
diff --git a/mojo/common/common_custom_types_struct_traits.h b/mojo/common/common_custom_types_struct_traits.h
index b20c795..85815ff 100644
--- a/mojo/common/common_custom_types_struct_traits.h
+++ b/mojo/common/common_custom_types_struct_traits.h
@@ -63,19 +63,6 @@ struct StructTraits<common::mojom::UnguessableTokenDataView,
};
template <>
-struct StructTraits<common::mojom::TimeDeltaDataView, base::TimeDelta> {
- static int64_t microseconds(const base::TimeDelta& delta) {
- return delta.InMicroseconds();
- }
-
- static bool Read(common::mojom::TimeDeltaDataView data,
- base::TimeDelta* delta) {
- *delta = base::TimeDelta::FromMicroseconds(data.microseconds());
- return true;
- }
-};
-
-template <>
struct StructTraits<common::mojom::FileDataView, base::File> {
static bool IsNull(const base::File& file) { return !file.IsValid(); }
diff --git a/mojo/common/time.mojom b/mojo/common/time.mojom
index 43dfcc8..b403bca 100644
--- a/mojo/common/time.mojom
+++ b/mojo/common/time.mojom
@@ -4,12 +4,18 @@
module mojo.common.mojom;
-[Native]
-struct Time;
+struct Time {
+ // The internal value is expressed in terms of microseconds since a fixed but
+ // intentionally unspecified epoch.
+ int64 internal_value;
+};
struct TimeDelta {
int64 microseconds;
};
-[Native]
-struct TimeTicks;
+struct TimeTicks {
+ // The internal value is expressed in terms of microseconds since a fixed but
+ // intentionally unspecified epoch.
+ int64 internal_value;
+};
diff --git a/mojo/common/time_struct_traits.h b/mojo/common/time_struct_traits.h
new file mode 100644
index 0000000..b480edb
--- /dev/null
+++ b/mojo/common/time_struct_traits.h
@@ -0,0 +1,55 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_COMMON_TIME_STRUCT_TRAITS_H_
+#define MOJO_COMMON_TIME_STRUCT_TRAITS_H_
+
+#include "base/time/time.h"
+#include "mojo/common/time.mojom-shared.h"
+
+namespace mojo {
+
+template <>
+struct StructTraits<common::mojom::TimeDataView, base::Time> {
+ static int64_t internal_value(const base::Time& time) {
+ return time.since_origin().InMicroseconds();
+ }
+
+ static bool Read(common::mojom::TimeDataView data, base::Time* time) {
+ *time =
+ base::Time() + base::TimeDelta::FromMicroseconds(data.internal_value());
+ return true;
+ }
+};
+
+template <>
+struct StructTraits<common::mojom::TimeDeltaDataView, base::TimeDelta> {
+ static int64_t microseconds(const base::TimeDelta& delta) {
+ return delta.InMicroseconds();
+ }
+
+ static bool Read(common::mojom::TimeDeltaDataView data,
+ base::TimeDelta* delta) {
+ *delta = base::TimeDelta::FromMicroseconds(data.microseconds());
+ return true;
+ }
+};
+
+template <>
+struct StructTraits<common::mojom::TimeTicksDataView, base::TimeTicks> {
+ static int64_t internal_value(const base::TimeTicks& time) {
+ return time.since_origin().InMicroseconds();
+ }
+
+ static bool Read(common::mojom::TimeTicksDataView data,
+ base::TimeTicks* time) {
+ *time = base::TimeTicks() +
+ base::TimeDelta::FromMicroseconds(data.internal_value());
+ return true;
+ }
+};
+
+} // namespace mojo
+
+#endif // MOJO_COMMON_TIME_STRUCT_TRAITS_H_