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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/common/bluetooth/bluetooth_device_id.h
diff --git a/content/common/bluetooth/bluetooth_device_id.h b/content/common/bluetooth/bluetooth_device_id.h
new file mode 100644
index 0000000000000000000000000000000000000000..ec2aa86ac7621eb0d694c9431c6539940fd0ed50
--- /dev/null
+++ b/content/common/bluetooth/bluetooth_device_id.h
@@ -0,0 +1,62 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_COMMON_BLUETOOTH_BLUETOOTH_DEVICE_ID_H_
+#define CONTENT_COMMON_BLUETOOTH_BLUETOOTH_DEVICE_ID_H_
+
+#include <string>
+
+#include "content/common/content_export.h"
+
+namespace content {
+
+// Used to uniquely identify a Bluetooth Device for an Origin.
+// A BluetoothDeviceId is generated by base64-encoding a 128bit
+// string.
+class CONTENT_EXPORT BluetoothDeviceId {
+ public:
+ // Default constructor that creates an invalid id. We implement it so that
+ // instances of this class in a container, e.g. std::unordered_map, can be
+ // accessed through the [] operator. Trying to call any function of the
+ // resulting object will DCHECK-fail.
+ BluetoothDeviceId();
+
+ // DCHEKS that |device_id| is valid.
+ explicit BluetoothDeviceId(std::string device_id);
+ ~BluetoothDeviceId();
+
+ // Returns the string that represents this BluetoothDeviceId.
+ const std::string& str() const;
+
+ // The returned BluetoothDeviceId is generated by creating a random 128bit
+ // string and base64-encoding it.
+ static BluetoothDeviceId Create();
+
+ // Returns true if base64-decoding |device_id| results in a 128bit string.
+ static bool IsValid(const std::string& device_id);
+
+ bool operator==(const BluetoothDeviceId& device_id) const;
+ bool operator!=(const BluetoothDeviceId& device_id) const;
+
+ private:
+ std::string device_id_;
+};
+
+CONTENT_EXPORT std::ostream& operator<<(std::ostream& out,
+ const BluetoothDeviceId& device_id);
+
+} // namespace content
+
+namespace std {
+
+template <>
+struct hash<content::BluetoothDeviceId> {
+ size_t operator()(const content::BluetoothDeviceId& device_id) const {
+ return std::hash<std::string>()(device_id.str());
+ }
+};
+
+} // namespace std
+
+#endif // CONTENT_COMMON_BLUETOOTH_BLUETOOTH_DEVICE_ID_H_

Powered by Google App Engine
This is Rietveld 408576698