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

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: Address jyasskin's comments 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 {
18 public:
19 // Default constructor that creates an invalid id. We implement it so that
20 // instances of this class in a container, e.g. std::unordered_map, can be
21 // accessed through the [] operator. Trying to call any function of the
22 // resulting object will DCHECK-fail.
23 BluetoothDeviceId();
24
25 // DCHEKS that |device_id| is valid.
26 explicit BluetoothDeviceId(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-encoding it.
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 CONTENT_EXPORT std::ostream& operator<<(std::ostream& out,
47 const BluetoothDeviceId& device_id);
48
49 } // namespace content
50
51 namespace std {
52
53 template <>
54 struct hash<content::BluetoothDeviceId> {
55 size_t operator()(const content::BluetoothDeviceId& device_id) const {
56 return std::hash<std::string>()(device_id.str());
57 }
58 };
59
60 } // namespace std
61
62 #endif // CONTENT_COMMON_BLUETOOTH_BLUETOOTH_DEVICE_ID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698