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

Side by Side Diff: content/common/bluetooth/bluetooth_device_id.h

Issue 2019853002: bluetooth: Use WebBluetoothDeviceId instead of string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-uuid-typemap
Patch Set: Lint 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
(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 CONTENT_COMMON_BLUETOOTH_BLUETOOTH_DEVICE_ID_H_
6 #define CONTENT_COMMON_BLUETOOTH_BLUETOOTH_DEVICE_ID_H_
7
8 #include <string>
9
10 #include "content/common/content_export.h"
11
12 namespace content {
13
14 // Used to uniquely identify a Bluetooth Device for an Origin.
15 // A BluetoothDeviceId is generated by base64-encoding a 128bit
16 // string.
17 class CONTENT_EXPORT BluetoothDeviceId {
Jeffrey Yasskin 2016/06/03 17:22:05 I wish I could think of a way to make it clear tha
ortuno 2016/06/06 22:22:59 Ack.
18 public:
19 // Default constructor that does nothing. We implement it so that instances
Jeffrey Yasskin 2016/06/03 17:22:05 s/does nothing/creates an invalid Id/
ortuno 2016/06/06 22:22:59 Done.
20 // of this class in a container, e.g. std::unordered_map, can be accessed
21 // through the [] operator. Trying to call any function of the resulting
22 // object will DCHECK-fail.
23 BluetoothDeviceId();
24
25 // DCHEKS that |device_id| is valid.
26 explicit BluetoothDeviceId(const std::string& device_id);
27 ~BluetoothDeviceId();
28
29 // Returns the string that represents this BluetoothDeviceId.
30 const std::string& str() const;
31
32 // The returned BluetoothDeviceId is generated by creating a random 128bit
33 // string and base64-enconding it.
Jeffrey Yasskin 2016/06/03 17:22:05 sp: enconding
ortuno 2016/06/06 22:22:59 Done.
34 static BluetoothDeviceId Create();
35
36 // Returns true if base64-decoding |device_id| results in a 128bit string.
37 static bool IsValid(const std::string& device_id);
38
39 bool operator==(const BluetoothDeviceId& device_id) const;
40 bool operator!=(const BluetoothDeviceId& device_id) const;
41
42 private:
43 std::string device_id_;
44 };
45
46 // This is required by gtest to print a readable output on test failures.
47 void CONTENT_EXPORT PrintTo(const BluetoothDeviceId& device_id,
Jeffrey Yasskin 2016/06/03 17:22:05 I'd prefer to just define operator<< so that we ca
ortuno 2016/06/06 22:22:59 Done.
48 std::ostream* out);
49
50 } // namespace content
51
52 namespace std {
53
54 template <>
55 struct hash<content::BluetoothDeviceId> {
56 size_t operator()(const content::BluetoothDeviceId& device_id) const {
57 return std::hash<std::string>()(device_id.str());
58 }
59 };
60
61 } // namespace std
62
63 #endif // CONTENT_COMMON_BLUETOOTH_BLUETOOTH_DEVICE_ID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698