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

Side by Side Diff: device/bluetooth/bluetooth_uuid.cc

Issue 2015463004: bluetooth: Use BluetoothUUID instead of string when sending uuids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-mojo-request-device
Patch Set: Include string Created 4 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "device/bluetooth/bluetooth_uuid.h" 5 #include "device/bluetooth/bluetooth_uuid.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "ipc/ipc_message.h"
12 #include "ipc/ipc_message_utils.h"
13 11
14 namespace device { 12 namespace device {
15 13
16 namespace { 14 namespace {
17 15
18 const char* kCommonUuidPostfix = "-0000-1000-8000-00805f9b34fb"; 16 const char* kCommonUuidPostfix = "-0000-1000-8000-00805f9b34fb";
19 const char* kCommonUuidPrefix = "0000"; 17 const char* kCommonUuidPrefix = "0000";
20 18
21 // Returns the canonical, 128-bit canonical, and the format of the UUID 19 // Returns the canonical, 128-bit canonical, and the format of the UUID
22 // in |canonical|, |canonical_128|, and |format| based on |uuid|. 20 // in |canonical|, |canonical_128|, and |format| based on |uuid|.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 87
90 bool BluetoothUUID::operator!=(const BluetoothUUID& uuid) const { 88 bool BluetoothUUID::operator!=(const BluetoothUUID& uuid) const {
91 return canonical_value_ != uuid.canonical_value_; 89 return canonical_value_ != uuid.canonical_value_;
92 } 90 }
93 91
94 void PrintTo(const BluetoothUUID& uuid, std::ostream* out) { 92 void PrintTo(const BluetoothUUID& uuid, std::ostream* out) {
95 *out << uuid.canonical_value(); 93 *out << uuid.canonical_value();
96 } 94 }
97 95
98 } // namespace device 96 } // namespace device
99
100 void IPC::ParamTraits<device::BluetoothUUID>::GetSize(base::PickleSizer* s,
101 const param_type& p) {
102 IPC::GetParamSize(s, p.canonical_value());
103 }
104
105 void IPC::ParamTraits<device::BluetoothUUID>::Write(base::Pickle* m,
106 const param_type& p) {
107 m->WriteString(p.canonical_value());
108 }
109
110 bool IPC::ParamTraits<device::BluetoothUUID>::Read(const base::Pickle* m,
111 base::PickleIterator* iter,
112 param_type* r) {
113 std::string value;
114 if (!iter->ReadString(&value))
115 return false;
116 *r = device::BluetoothUUID(value);
117 // If the format isn't 128-bit, .value() would return a different answer than
118 // .canonical_value(). Then if browser-side code accidentally checks .value()
119 // against a 128-bit string literal, a hostile renderer could use the 16- or
120 // 32-bit format and evade the check.
121 return r->format() == device::BluetoothUUID::kFormat128Bit;
122 }
123
124 void IPC::ParamTraits<device::BluetoothUUID>::Log(const param_type& p,
125 std::string* l) {
126 l->append(p.canonical_value());
127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698