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

Side by Side Diff: device/bluetooth/public/interfaces/bluetooth_uuid_struct_traits.h

Issue 2136733002: Mojo C++ bindings: add a new mode to generator to use native STL/WTF types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@67_new
Patch Set: . Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | mojo/mojo_public.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_ 5 #ifndef DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_
6 #define DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_ 6 #define DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/optional.h"
11 #include "base/strings/string_piece.h"
12 #include "device/bluetooth/bluetooth_uuid.h" 10 #include "device/bluetooth/bluetooth_uuid.h"
13 #include "device/bluetooth/public/interfaces/bluetooth_uuid.mojom.h" 11 #include "device/bluetooth/public/interfaces/bluetooth_uuid.mojom.h"
14 12
15 namespace mojo { 13 namespace mojo {
16 14
17 template <> 15 template <>
18 struct StructTraits<device::mojom::BluetoothUUID, 16 struct StructTraits<device::mojom::BluetoothUUID, device::BluetoothUUID> {
19 base::Optional<device::BluetoothUUID>> { 17 static const std::string& uuid(const device::BluetoothUUID& uuid) {
20 static bool IsNull(const base::Optional<device::BluetoothUUID>& uuid) { 18 return uuid.canonical_value();
21 return !uuid;
22 }
23
24 static void SetToNull(base::Optional<device::BluetoothUUID>* output) {
25 *output = base::nullopt;
26 }
27
28 static std::string uuid(const base::Optional<device::BluetoothUUID>& uuid) {
29 DCHECK(uuid);
30 return uuid->canonical_value();
31 } 19 }
32 20
33 static bool Read(device::mojom::BluetoothUUIDDataView input, 21 static bool Read(device::mojom::BluetoothUUIDDataView input,
34 base::Optional<device::BluetoothUUID>* output) { 22 device::BluetoothUUID* output) {
35 std::string result; 23 std::string result;
36 if (!input.ReadUuid(&result)) 24 if (!input.ReadUuid(&result))
37 return false; 25 return false;
38 *output = base::make_optional(device::BluetoothUUID(result)); 26 *output = device::BluetoothUUID(result);
39 27
40 // If the format isn't 128-bit, .value() would return a different answer 28 // If the format isn't 128-bit, .value() would return a different answer
41 // than .canonical_value(). Then if browser-side code accidentally checks 29 // than .canonical_value(). Then if browser-side code accidentally checks
42 // .value() against a 128-bit string literal, a hostile renderer could use 30 // .value() against a 128-bit string literal, a hostile renderer could use
43 // the 16- or 32-bit format and evade the check. 31 // the 16- or 32-bit format and evade the check.
44 return output->value().IsValid() && 32 return output->IsValid() &&
45 output->value().format() == device::BluetoothUUID::kFormat128Bit; 33 output->format() == device::BluetoothUUID::kFormat128Bit;
46 } 34 }
47 }; 35 };
48 36
49 } // namespace mojo 37 } // namespace mojo
50 38
51 #endif // DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_ 39 #endif // DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/mojo_public.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698