Chromium Code Reviews| 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..9b33c6ac105033138b719eaf4f5d3a2b5c354831 |
| --- /dev/null |
| +++ b/content/common/bluetooth/bluetooth_device_id.h |
| @@ -0,0 +1,63 @@ |
| +// 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 { |
|
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.
|
| + public: |
| + // 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.
|
| + // 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(const 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-enconding it. |
|
Jeffrey Yasskin
2016/06/03 17:22:05
sp: enconding
ortuno
2016/06/06 22:22:59
Done.
|
| + 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_; |
| +}; |
| + |
| +// This is required by gtest to print a readable output on test failures. |
| +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.
|
| + std::ostream* out); |
| + |
| +} // 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_ |