OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef DEVICE_BLUETOOTH_MOJO_BLUETOOTH_UUID_STRUCT_TRAITS_H_ | |
6 #define DEVICE_BLUETOOTH_MOJO_BLUETOOTH_UUID_STRUCT_TRAITS_H_ | |
7 | |
8 #include "base/strings/string_piece.h" | |
9 #include "device/bluetooth/bluetooth_uuid.h" | |
10 #include "device/bluetooth/mojo/bluetooth_uuid.mojom.h" | |
11 | |
12 namespace mojo { | |
13 | |
14 template <> | |
15 struct StructTraits<device::mojom::BluetoothUUID, | |
16 std::unique_ptr<device::BluetoothUUID>> { | |
17 static bool IsNull(const std::unique_ptr<device::BluetoothUUID>& uuid) { | |
18 return !uuid.get(); | |
Ken Rockot(use gerrit already)
2016/05/26 21:05:07
nit: !uuid should be sufficient
ortuno
2016/05/27 14:38:36
Done.
| |
19 } | |
20 | |
21 static void SetToNull(std::unique_ptr<device::BluetoothUUID>* output) { | |
22 *output = nullptr; | |
Ken Rockot(use gerrit already)
2016/05/26 21:05:07
optional style/opinion nit: perhaps output->reset(
ortuno
2016/05/27 14:38:36
Done.
| |
23 } | |
24 | |
25 static base::StringPiece uuid( | |
26 const std::unique_ptr<device::BluetoothUUID>& uuid) { | |
27 DCHECK(uuid.get()); | |
Ken Rockot(use gerrit already)
2016/05/26 21:05:07
nit: DCHECK(uuid) should be sufficient
ortuno
2016/05/27 14:38:36
Done.
| |
28 return base::StringPiece(uuid->canonical_value().c_str(), | |
29 uuid->canonical_value().length()); | |
30 } | |
31 | |
32 static bool Read(device::mojom::BluetoothUUIDDataView input, | |
33 std::unique_ptr<device::BluetoothUUID>* output) { | |
34 base::StringPiece result; | |
35 if (!input.ReadUuid(&result)) | |
36 return false; | |
37 *output = base::WrapUnique(new device::BluetoothUUID(result.as_string())); | |
38 | |
39 // If the format isn't 128-bit, .value() would return a different answer | |
40 // than .canonical_value(). Then if browser-side code accidentally checks | |
41 // .value() against a 128-bit string literal, a hostile renderer could use | |
42 // the 16- or 32-bit format and evade the check. | |
43 return (*output)->IsValid() && | |
44 (*output)->format() == device::BluetoothUUID::kFormat128Bit; | |
45 } | |
46 }; | |
47 } | |
48 | |
49 #endif // DEVICE_BLUETOOTH_MOJO_BLUETOOTH_UUID_STRUCT_TRAITS_H_ | |
OLD | NEW |