diff options
author | Luis Hector Chavez <lhchavez@google.com> | 2017-12-08 13:12:57 -0800 |
---|---|---|
committer | Luis Hector Chavez <lhchavez@google.com> | 2017-12-08 13:13:47 -0800 |
commit | c96e5aa6f5f1f6df03ef539b4b85c78bf7c292e5 (patch) | |
tree | 7d81cd532025d5d68cf6764a96767eacc7b311b9 | |
parent | bed7ec80d106ea11bb6a67a9a3d8c24dea5f7284 (diff) | |
download | libmojo-c96e5aa6f5f1f6df03ef539b4b85c78bf7c292e5.tar.gz |
libmojo: Add Time-related type mappings
This change enables the use of Time-related types in mojo.
Bug: None
Test: m -j42
Change-Id: I48a507ab14dd3637bb629cba9b0b1d5b5e34e3f2
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | gen/mojo/common/common_custom_types__type_mappings | 43 | ||||
-rw-r--r-- | mojo/common/BUILD.gn | 1 | ||||
-rw-r--r-- | mojo/common/common_custom_types.mojom | 9 | ||||
-rw-r--r-- | mojo/common/common_custom_types_struct_traits.h | 43 | ||||
-rw-r--r-- | mojo/common/time.mojom | 21 | ||||
-rw-r--r-- | mojo/common/time.typemap | 17 |
7 files changed, 96 insertions, 39 deletions
@@ -16,6 +16,7 @@ LOCAL_CPP_EXTENSION := .cc LOCAL_MOJOM_FILES := \ mojo/common/common_custom_types.mojom \ mojo/common/string16.mojom \ + mojo/common/time.mojom \ mojo/public/interfaces/bindings/interface_control_messages.mojom \ mojo/public/interfaces/bindings/pipe_control_messages.mojom \ diff --git a/gen/mojo/common/common_custom_types__type_mappings b/gen/mojo/common/common_custom_types__type_mappings index 2adbcc7..4602371 100644 --- a/gen/mojo/common/common_custom_types__type_mappings +++ b/gen/mojo/common/common_custom_types__type_mappings @@ -3,15 +3,13 @@ "mojo.common.mojom.ListValue": { "typename": "base::ListValue", "traits_headers": [ - "ipc/ipc_message_utils.h" + "ipc/ipc_message_utils.h", + "mojo/common/common_custom_types_struct_traits.h" ], "copyable_pass_by_value": false, "move_only": false, "nullable_is_same_type": false, "public_headers": [ - "base/files/file_path.h", - "base/strings/string16.h", - "base/time/time.h", "base/values.h" ] }, @@ -25,55 +23,46 @@ "move_only": false, "nullable_is_same_type": false, "public_headers": [ - "base/files/file_path.h", - "base/strings/string16.h", - "base/time/time.h", - "base/values.h" + "base/strings/string16.h" ] }, "mojo.common.mojom.Time": { "typename": "base::Time", "traits_headers": [ - "ipc/ipc_message_utils.h" + "ipc/ipc_message_utils.h", + "mojo/common/common_custom_types_struct_traits.h" ], "copyable_pass_by_value": true, "move_only": false, "nullable_is_same_type": false, "public_headers": [ - "base/files/file_path.h", - "base/strings/string16.h", - "base/time/time.h", - "base/values.h" + "base/time/time.h" ] }, "mojo.common.mojom.TimeDelta": { "typename": "base::TimeDelta", "traits_headers": [ - "ipc/ipc_message_utils.h" + "ipc/ipc_message_utils.h", + "mojo/common/common_custom_types_struct_traits.h" ], "copyable_pass_by_value": true, "move_only": false, "nullable_is_same_type": false, "public_headers": [ - "base/files/file_path.h", - "base/strings/string16.h", - "base/time/time.h", - "base/values.h" + "base/time/time.h" ] }, "mojo.common.mojom.TimeTicks": { "typename": "base::TimeTicks", "traits_headers": [ - "ipc/ipc_message_utils.h" + "ipc/ipc_message_utils.h", + "mojo/common/common_custom_types_struct_traits.h" ], "copyable_pass_by_value": true, "move_only": false, "nullable_is_same_type": false, "public_headers": [ - "base/files/file_path.h", - "base/strings/string16.h", - "base/time/time.h", - "base/values.h" + "base/time/time.h" ] }, "mojo.common.mojom.FilePath": { @@ -85,10 +74,7 @@ "move_only": false, "nullable_is_same_type": false, "public_headers": [ - "base/files/file_path.h", - "base/strings/string16.h", - "base/time/time.h", - "base/values.h" + "base/files/file_path.h" ] }, "mojo.common.mojom.DictionaryValue": { @@ -100,9 +86,6 @@ "move_only": false, "nullable_is_same_type": false, "public_headers": [ - "base/files/file_path.h", - "base/strings/string16.h", - "base/time/time.h", "base/values.h" ] } diff --git a/mojo/common/BUILD.gn b/mojo/common/BUILD.gn index 57c85d5..6dfed8e 100644 --- a/mojo/common/BUILD.gn +++ b/mojo/common/BUILD.gn @@ -17,6 +17,7 @@ mojom("common_custom_types") { sources = [ "common_custom_types.mojom", "string16.mojom", + "time.mojom", ] } diff --git a/mojo/common/common_custom_types.mojom b/mojo/common/common_custom_types.mojom index aa87106..4a04dbc 100644 --- a/mojo/common/common_custom_types.mojom +++ b/mojo/common/common_custom_types.mojom @@ -12,12 +12,3 @@ struct ListValue; [Native] struct DictionaryValue; - -[Native] -struct Time; - -[Native] -struct TimeDelta; - -[Native] -struct TimeTicks; diff --git a/mojo/common/common_custom_types_struct_traits.h b/mojo/common/common_custom_types_struct_traits.h index 22afdb6..4cbb3f9 100644 --- a/mojo/common/common_custom_types_struct_traits.h +++ b/mojo/common/common_custom_types_struct_traits.h @@ -8,7 +8,10 @@ #include <stdint.h> #include <vector> +#include "base/strings/string16.h" +#include "base/time/time.h" #include "mojo/common/string16.mojom.h" +#include "mojo/common/time.mojom.h" #include "mojo/public/cpp/bindings/struct_traits.h" namespace mojo { @@ -22,6 +25,46 @@ struct StructTraits<common::mojom::String16, base::string16> { static bool Read(common::mojom::String16DataView data, base::string16* output); }; +template <> +struct StructTraits<common::mojom::Time, base::Time> { + static int64_t internal_value(const base::Time& time) { + return time.ToInternalValue(); + } + + 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::TimeDelta, 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::TimeTicks, base::TimeTicks> { + static int64_t internal_value(const base::TimeTicks& time) { + return time.ToInternalValue(); + } + + static bool Read(common::mojom::TimeTicksDataView data, + base::TimeTicks* time) { + *time = base::TimeTicks() + + base::TimeDelta::FromMicroseconds(data.internal_value()); + return true; + } +}; + } // mojo #endif // MOJO_COMMON_COMMON_CUSTOM_TYPES_STRUCT_TRAITS_H_ diff --git a/mojo/common/time.mojom b/mojo/common/time.mojom new file mode 100644 index 0000000..b403bca --- /dev/null +++ b/mojo/common/time.mojom @@ -0,0 +1,21 @@ +// Copyright 2016 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. + +module mojo.common.mojom; + +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; +}; + +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.typemap b/mojo/common/time.typemap new file mode 100644 index 0000000..20661f6 --- /dev/null +++ b/mojo/common/time.typemap @@ -0,0 +1,17 @@ +# Copyright 2016 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. + +mojom = "//mojo/common/time.mojom" +public_headers = [ "//base/time/time.h" ] +traits_headers = [ "//mojo/common/time_struct_traits.h" ] +public_deps = [ + "//base", + "//mojo/common:struct_traits", +] + +type_mappings = [ + "mojo.common.mojom.Time=base::Time[copyable_pass_by_value]", + "mojo.common.mojom.TimeDelta=base::TimeDelta[copyable_pass_by_value]", + "mojo.common.mojom.TimeTicks=base::TimeTicks[copyable_pass_by_value]", +] |