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

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

Issue 2253293002: Mojo C++ bindings: change the first template parameter of StructTraits and UnionTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@91_extra
Patch Set: rebase Created 4 years, 4 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
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 "device/bluetooth/bluetooth_uuid.h" 10 #include "device/bluetooth/bluetooth_uuid.h"
11 #include "device/bluetooth/public/interfaces/bluetooth_uuid.mojom.h" 11 #include "device/bluetooth/public/interfaces/bluetooth_uuid.mojom.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 14
15 template <> 15 template <>
16 struct StructTraits<device::mojom::BluetoothUUID, device::BluetoothUUID> { 16 struct StructTraits<device::mojom::BluetoothUUIDDataView,
17 device::BluetoothUUID> {
17 static const std::string& uuid(const device::BluetoothUUID& uuid) { 18 static const std::string& uuid(const device::BluetoothUUID& uuid) {
18 return uuid.canonical_value(); 19 return uuid.canonical_value();
19 } 20 }
20 21
21 static bool Read(device::mojom::BluetoothUUIDDataView input, 22 static bool Read(device::mojom::BluetoothUUIDDataView input,
22 device::BluetoothUUID* output) { 23 device::BluetoothUUID* output) {
23 std::string result; 24 std::string result;
24 if (!input.ReadUuid(&result)) 25 if (!input.ReadUuid(&result))
25 return false; 26 return false;
26 *output = device::BluetoothUUID(result); 27 *output = device::BluetoothUUID(result);
27 28
28 // If the format isn't 128-bit, .value() would return a different answer 29 // If the format isn't 128-bit, .value() would return a different answer
29 // than .canonical_value(). Then if browser-side code accidentally checks 30 // than .canonical_value(). Then if browser-side code accidentally checks
30 // .value() against a 128-bit string literal, a hostile renderer could use 31 // .value() against a 128-bit string literal, a hostile renderer could use
31 // the 16- or 32-bit format and evade the check. 32 // the 16- or 32-bit format and evade the check.
32 return output->IsValid() && 33 return output->IsValid() &&
33 output->format() == device::BluetoothUUID::kFormat128Bit; 34 output->format() == device::BluetoothUUID::kFormat128Bit;
34 } 35 }
35 }; 36 };
36 37
37 } // namespace mojo 38 } // namespace mojo
38 39
39 #endif // DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_ 40 #endif // DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698