Add string16 to Android mojom am: 2a90c28e40 am: 386a50484a
am: f3f2670d71

Change-Id: I32aeab0cfb0d8146504854a860adc6c8c9d0b9ff
diff --git a/Android.mk b/Android.mk
index a3e2083..c54e37e 100644
--- a/Android.mk
+++ b/Android.mk
@@ -15,6 +15,7 @@
 
 LOCAL_MOJOM_FILES := \
 	mojo/common/common_custom_types.mojom \
+	mojo/common/string16.mojom \
 	mojo/public/interfaces/bindings/interface_control_messages.mojom \
 	mojo/public/interfaces/bindings/pipe_control_messages.mojom \
 
@@ -78,6 +79,7 @@
 	mojo/android/system/base_run_loop.cc \
 	mojo/android/system/core_impl.cc \
 	mojo/edk/embedder/embedder.cc \
+	mojo/common/common_custom_types_struct_traits.cc \
 	mojo/edk/embedder/entrypoints.cc \
 	mojo/edk/embedder/platform_channel_pair.cc \
 	mojo/edk/embedder/platform_channel_pair_posix.cc \
diff --git a/gen/mojo/common/common_custom_types__type_mappings b/gen/mojo/common/common_custom_types__type_mappings
index 45c178d..2adbcc7 100644
--- a/gen/mojo/common/common_custom_types__type_mappings
+++ b/gen/mojo/common/common_custom_types__type_mappings
@@ -1,92 +1,108 @@
 {
   "c++": {
     "mojo.common.mojom.ListValue": {
-      "typename": "base::ListValue", 
+      "typename": "base::ListValue",
       "traits_headers": [
         "ipc/ipc_message_utils.h"
-      ], 
-      "copyable_pass_by_value": false, 
-      "move_only": false, 
-      "nullable_is_same_type": false, 
+      ],
+      "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/files/file_path.h",
+        "base/strings/string16.h",
+        "base/time/time.h",
         "base/values.h"
       ]
-    }, 
+    },
+    "mojo.common.mojom.String16": {
+      "typename": "base::string16",
+      "traits_headers": [
+        "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"
+      ]
+    },
     "mojo.common.mojom.Time": {
-      "typename": "base::Time", 
+      "typename": "base::Time",
       "traits_headers": [
         "ipc/ipc_message_utils.h"
-      ], 
-      "copyable_pass_by_value": true, 
-      "move_only": false, 
-      "nullable_is_same_type": false, 
+      ],
+      "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/files/file_path.h",
+        "base/strings/string16.h",
+        "base/time/time.h",
         "base/values.h"
       ]
-    }, 
+    },
     "mojo.common.mojom.TimeDelta": {
-      "typename": "base::TimeDelta", 
+      "typename": "base::TimeDelta",
       "traits_headers": [
         "ipc/ipc_message_utils.h"
-      ], 
-      "copyable_pass_by_value": true, 
-      "move_only": false, 
-      "nullable_is_same_type": false, 
+      ],
+      "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/files/file_path.h",
+        "base/strings/string16.h",
+        "base/time/time.h",
         "base/values.h"
       ]
-    }, 
+    },
     "mojo.common.mojom.TimeTicks": {
-      "typename": "base::TimeTicks", 
+      "typename": "base::TimeTicks",
       "traits_headers": [
         "ipc/ipc_message_utils.h"
-      ], 
-      "copyable_pass_by_value": true, 
-      "move_only": false, 
-      "nullable_is_same_type": false, 
+      ],
+      "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/files/file_path.h",
+        "base/strings/string16.h",
+        "base/time/time.h",
         "base/values.h"
       ]
-    }, 
+    },
     "mojo.common.mojom.FilePath": {
-      "typename": "base::FilePath", 
+      "typename": "base::FilePath",
       "traits_headers": [
         "ipc/ipc_message_utils.h"
-      ], 
-      "copyable_pass_by_value": false, 
-      "move_only": false, 
-      "nullable_is_same_type": false, 
+      ],
+      "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/files/file_path.h",
+        "base/strings/string16.h",
+        "base/time/time.h",
         "base/values.h"
       ]
-    }, 
+    },
     "mojo.common.mojom.DictionaryValue": {
-      "typename": "base::DictionaryValue", 
+      "typename": "base::DictionaryValue",
       "traits_headers": [
         "ipc/ipc_message_utils.h"
-      ], 
-      "copyable_pass_by_value": false, 
-      "move_only": false, 
-      "nullable_is_same_type": false, 
+      ],
+      "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/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 2edfb6d..57c85d5 100644
--- a/mojo/common/BUILD.gn
+++ b/mojo/common/BUILD.gn
@@ -16,6 +16,7 @@
 mojom("common_custom_types") {
   sources = [
     "common_custom_types.mojom",
+    "string16.mojom",
   ]
 }
 
diff --git a/mojo/common/common_custom_types.typemap b/mojo/common/common_custom_types.typemap
index 8d88109..0b63f38 100644
--- a/mojo/common/common_custom_types.typemap
+++ b/mojo/common/common_custom_types.typemap
@@ -17,6 +17,7 @@
   "mojo.common.mojom.FilePath=base::FilePath",
   "mojo.common.mojom.DictionaryValue=base::DictionaryValue",
   "mojo.common.mojom.ListValue=base::ListValue",
+  "mojo.common.mojom.String16=base::string16",
   "mojo.common.mojom.Time=base::Time",
   "mojo.common.mojom.TimeDelta=base::TimeDelta",
   "mojo.common.mojom.TimeTicks=base::TimeTicks",
diff --git a/mojo/common/common_custom_types_struct_traits.cc b/mojo/common/common_custom_types_struct_traits.cc
new file mode 100644
index 0000000..3f9f7d9
--- /dev/null
+++ b/mojo/common/common_custom_types_struct_traits.cc
@@ -0,0 +1,18 @@
+// 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.
+
+#include "mojo/common/common_custom_types_struct_traits.h"
+
+namespace mojo {
+
+// static
+bool StructTraits<common::mojom::String16, base::string16>::Read(
+    common::mojom::String16DataView data, base::string16* out) {
+  std::vector<uint16_t> view;
+  data.ReadData(&view);
+  out->assign(reinterpret_cast<const base::char16*>(view.data()), view.size());
+  return true;
+}
+
+}  // mojo
diff --git a/mojo/common/common_custom_types_struct_traits.h b/mojo/common/common_custom_types_struct_traits.h
new file mode 100644
index 0000000..22afdb6
--- /dev/null
+++ b/mojo/common/common_custom_types_struct_traits.h
@@ -0,0 +1,27 @@
+// 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_COMMON_CUSTOM_TYPES_STRUCT_TRAITS_H_
+#define MOJO_COMMON_COMMON_CUSTOM_TYPES_STRUCT_TRAITS_H_
+
+#include <stdint.h>
+#include <vector>
+
+#include "mojo/common/string16.mojom.h"
+#include "mojo/public/cpp/bindings/struct_traits.h"
+
+namespace mojo {
+
+template <>
+struct StructTraits<common::mojom::String16, base::string16> {
+  static std::vector<uint16_t> data(const base::string16& str) {
+    const uint16_t* base = str.data();
+    return std::vector<uint16_t>(base, base + str.size());
+  }
+  static bool Read(common::mojom::String16DataView data, base::string16* output);
+};
+
+}  // mojo
+
+#endif  // MOJO_COMMON_COMMON_CUSTOM_TYPES_STRUCT_TRAITS_H_
diff --git a/mojo/common/string16.mojom b/mojo/common/string16.mojom
new file mode 100644
index 0000000..eb1ace2
--- /dev/null
+++ b/mojo/common/string16.mojom
@@ -0,0 +1,13 @@
+// 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;
+
+// Corresponds to |base::string16| in base/strings/string16.h
+// Corresponds to |WTF::String| in
+// third_party/WebKit/Source/wtf/text/WTFString.h.
+struct String16 {
+  array<uint16> data;
+};
+