diff options
author | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-04 04:10:38 +0000 |
---|---|---|
committer | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-04 04:10:38 +0000 |
commit | 8148ad4c315725f995e52f91113203f0135add1b (patch) | |
tree | c60f826a8201e49537874e8f9ba399af1f3dbcaa | |
parent | b250f01e51eae5377a3419048b0fed2a17d4dea9 (diff) | |
download | chromium_src-8148ad4c315725f995e52f91113203f0135add1b.zip chromium_src-8148ad4c315725f995e52f91113203f0135add1b.tar.gz chromium_src-8148ad4c315725f995e52f91113203f0135add1b.tar.bz2 |
device/bluetooth: Rename device::bluetooth_utils::UUID to device::BluetoothUUID
Moved bluetooth_utils::UUID into its own file called bluetooth_uuid.h/cc as
class BluetoothUUID. This effectively removes the usage of
bluetooth_utils::CanonicalUuid.
This is a post-revert reupload of https://codereview.chromium.org/220323004/.
The CQ didn't run any Mac bots that build and run device_unittests.
BUG=358874
TEST=device_unittests, browser_tests
Review URL: https://codereview.chromium.org/224893002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261663 0039d316-1c4b-4281-b951-d872f2087c98
46 files changed, 309 insertions, 331 deletions
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc index aff3f8e..d520f3d 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc @@ -19,7 +19,6 @@ #include "device/bluetooth/bluetooth_profile.h" #include "device/bluetooth/bluetooth_service_record.h" #include "device/bluetooth/bluetooth_socket.h" -#include "device/bluetooth/bluetooth_utils.h" #include "extensions/browser/event_router.h" #include "extensions/browser/extension_system.h" #include "extensions/common/permissions/permissions_data.h" @@ -134,7 +133,9 @@ bool BluetoothAddProfileFunction::RunImpl() { scoped_ptr<AddProfile::Params> params(AddProfile::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); - if (!BluetoothDevice::IsUUIDValid(params->profile.uuid)) { + device::BluetoothUUID uuid(params->profile.uuid); + + if (!uuid.IsValid()) { SetError(kInvalidUuid); return false; } @@ -145,7 +146,7 @@ bool BluetoothAddProfileFunction::RunImpl() { return false; } - uuid_ = device::bluetooth_utils::CanonicalUuid(params->profile.uuid); + uuid_ = uuid; if (GetEventRouter(browser_context())->HasProfile(uuid_)) { SetError(kProfileAlreadyRegistered); @@ -216,14 +217,13 @@ bool BluetoothRemoveProfileFunction::RunImpl() { scoped_ptr<RemoveProfile::Params> params( RemoveProfile::Params::Create(*args_)); - if (!BluetoothDevice::IsUUIDValid(params->profile.uuid)) { + device::BluetoothUUID uuid(params->profile.uuid); + + if (!uuid.IsValid()) { SetError(kInvalidUuid); return false; } - std::string uuid = - device::bluetooth_utils::CanonicalUuid(params->profile.uuid); - if (!GetEventRouter(browser_context())->HasProfile(uuid)) { SetError(kProfileNotFound); return false; @@ -303,7 +303,9 @@ bool BluetoothConnectFunction::DoWork(scoped_refptr<BluetoothAdapter> adapter) { EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); const bluetooth::ConnectOptions& options = params->options; - if (!BluetoothDevice::IsUUIDValid(options.profile.uuid)) { + device::BluetoothUUID uuid(options.profile.uuid); + + if (!uuid.IsValid()) { SetError(kInvalidUuid); SendResponse(false); return false; @@ -316,9 +318,6 @@ bool BluetoothConnectFunction::DoWork(scoped_refptr<BluetoothAdapter> adapter) { return false; } - std::string uuid = device::bluetooth_utils::CanonicalUuid( - options.profile.uuid); - BluetoothProfile* bluetooth_profile = GetEventRouter(browser_context())->GetProfile(uuid); if (!bluetooth_profile) { diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.h b/chrome/browser/extensions/api/bluetooth/bluetooth_api.h index e33de7f..21e164c 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.h +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.h @@ -12,6 +12,7 @@ #include "chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.h" #include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_profile.h" +#include "device/bluetooth/bluetooth_uuid.h" #include "extensions/browser/api/async_api_function.h" #include "extensions/browser/browser_context_keyed_api_factory.h" #include "extensions/browser/event_router.h" @@ -88,7 +89,7 @@ class BluetoothAddProfileFunction : public UIThreadExtensionFunction { private: void OnProfileRegistered(device::BluetoothProfile* bluetooth_profile); - std::string uuid_; + device::BluetoothUUID uuid_; }; class BluetoothRemoveProfileFunction : public SyncExtensionFunction { diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc index 931dbca..bd7bec3 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc @@ -112,7 +112,12 @@ void BluetoothDeviceToApiDevice(const device::BluetoothDevice& device, out->paired.reset(new bool(device.IsPaired())); out->connected.reset(new bool(device.IsConnected())); - out->uuids.reset(new std::vector<std::string>(device.GetUUIDs())); + std::vector<std::string>* string_uuids = new std::vector<std::string>(); + const device::BluetoothDevice::UUIDList& uuids = device.GetUUIDs(); + for (device::BluetoothDevice::UUIDList::const_iterator iter = uuids.begin(); + iter != uuids.end(); ++iter) + string_uuids->push_back(iter->canonical_value()); + out->uuids.reset(string_uuids); } void PopulateAdapterState(const device::BluetoothAdapter& adapter, diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc index 1df119b..f1113b8 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc @@ -16,6 +16,7 @@ #include "chrome/test/base/ui_test_utils.h" #include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" +#include "device/bluetooth/bluetooth_uuid.h" #include "device/bluetooth/test/mock_bluetooth_adapter.h" #include "device/bluetooth/test/mock_bluetooth_device.h" #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" @@ -28,6 +29,7 @@ using device::BluetoothDevice; using device::BluetoothDiscoverySession; using device::BluetoothOutOfBandPairingData; using device::BluetoothProfile; +using device::BluetoothUUID; using device::MockBluetoothAdapter; using device::MockBluetoothDevice; using device::MockBluetoothDiscoverySession; @@ -560,13 +562,15 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, OnConnection) { scoped_refptr<device::MockBluetoothSocket> socket = new device::MockBluetoothSocket(); - event_router()->AddProfile("1234", extension->id(), profile1_.get()); + event_router()->AddProfile( + BluetoothUUID("1234"), + extension->id(), profile1_.get()); event_router()->DispatchConnectionEvent( - extension->id(), "1234", device1_.get(), socket); + extension->id(), BluetoothUUID("1234"), device1_.get(), socket); listener.Reply("go"); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->RemoveProfile("1234"); + event_router()->RemoveProfile(BluetoothUUID("1234")); } IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { @@ -640,8 +644,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DeviceInfo) { .WillRepeatedly(testing::Return(0x0400)); BluetoothDevice::UUIDList uuids; - uuids.push_back("00001105-0000-1000-8000-00805f9b34fb"); - uuids.push_back("00001106-0000-1000-8000-00805f9b34fb"); + uuids.push_back(BluetoothUUID("1105")); + uuids.push_back(BluetoothUUID("1106")); EXPECT_CALL(*device1_.get(), GetUUIDs()) .WillOnce(testing::Return(uuids)); diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc index 67a19d4..41bba4c 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc @@ -110,7 +110,7 @@ bool BluetoothEventRouter::ReleaseSocket(int id) { } void BluetoothEventRouter::AddProfile( - const std::string& uuid, + const device::BluetoothUUID& uuid, const std::string& extension_id, device::BluetoothProfile* bluetooth_profile) { DCHECK(!HasProfile(uuid)); @@ -118,7 +118,7 @@ void BluetoothEventRouter::AddProfile( bluetooth_profile_map_[uuid] = record; } -void BluetoothEventRouter::RemoveProfile(const std::string& uuid) { +void BluetoothEventRouter::RemoveProfile(const device::BluetoothUUID& uuid) { BluetoothProfileMap::iterator iter = bluetooth_profile_map_.find(uuid); if (iter != bluetooth_profile_map_.end()) { device::BluetoothProfile* bluetooth_profile = iter->second.profile; @@ -127,7 +127,7 @@ void BluetoothEventRouter::RemoveProfile(const std::string& uuid) { } } -bool BluetoothEventRouter::HasProfile(const std::string& uuid) const { +bool BluetoothEventRouter::HasProfile(const device::BluetoothUUID& uuid) const { return bluetooth_profile_map_.find(uuid) != bluetooth_profile_map_.end(); } @@ -176,7 +176,7 @@ void BluetoothEventRouter::StopDiscoverySession( } device::BluetoothProfile* BluetoothEventRouter::GetProfile( - const std::string& uuid) const { + const device::BluetoothUUID& uuid) const { BluetoothProfileMap::const_iterator iter = bluetooth_profile_map_.find(uuid); if (iter != bluetooth_profile_map_.end()) return iter->second.profile; @@ -193,7 +193,7 @@ scoped_refptr<device::BluetoothSocket> BluetoothEventRouter::GetSocket(int id) { void BluetoothEventRouter::DispatchConnectionEvent( const std::string& extension_id, - const std::string& uuid, + const device::BluetoothUUID& uuid, const device::BluetoothDevice* device, scoped_refptr<device::BluetoothSocket> socket) { if (!HasProfile(uuid)) @@ -202,7 +202,7 @@ void BluetoothEventRouter::DispatchConnectionEvent( int socket_id = RegisterSocket(extension_id, socket); bluetooth::Socket result_socket; bluetooth::BluetoothDeviceToApiDevice(*device, &result_socket.device); - result_socket.profile.uuid = uuid; + result_socket.profile.uuid = uuid.canonical_value(); result_socket.id = socket_id; scoped_ptr<base::ListValue> args = diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h index 79828c7..4d86b4f 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h @@ -18,6 +18,7 @@ #include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_socket.h" +#include "device/bluetooth/bluetooth_uuid.h" namespace content { class BrowserContext; @@ -63,17 +64,17 @@ class BluetoothEventRouter : public device::BluetoothAdapter::Observer, // system. This class will hold onto the profile until RemoveProfile is // called for the profile, or until the extension that added the profile // is disabled/reloaded. - void AddProfile(const std::string& uuid, + void AddProfile(const device::BluetoothUUID& uuid, const std::string& extension_id, device::BluetoothProfile* bluetooth_profile); // Unregister the BluetoothProfile corersponding to |uuid| and release the // object from this class. - void RemoveProfile(const std::string& uuid); + void RemoveProfile(const device::BluetoothUUID& uuid); // Returns true if the BluetoothProfile corresponding to |uuid| is already // registered. - bool HasProfile(const std::string& uuid) const; + bool HasProfile(const device::BluetoothUUID& uuid) const; // Requests that a new device discovery session be initiated for extension // with id |extension_id|. |callback| is called, if a session has been @@ -96,7 +97,7 @@ class BluetoothEventRouter : public device::BluetoothAdapter::Observer, // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL // if the BluetoothProfile with |uuid| does not exist. - device::BluetoothProfile* GetProfile(const std::string& uuid) const; + device::BluetoothProfile* GetProfile(const device::BluetoothUUID& uuid) const; // Get the BluetoothSocket corresponding to |id|. scoped_refptr<device::BluetoothSocket> GetSocket(int id); @@ -104,7 +105,7 @@ class BluetoothEventRouter : public device::BluetoothAdapter::Observer, // Dispatch an event that takes a connection socket as a parameter to the // extension that registered the profile that the socket has connected to. void DispatchConnectionEvent(const std::string& extension_id, - const std::string& uuid, + const device::BluetoothUUID& uuid, const device::BluetoothDevice* device, scoped_refptr<device::BluetoothSocket> socket); @@ -187,7 +188,7 @@ class BluetoothEventRouter : public device::BluetoothAdapter::Observer, // Maps uuids to a struct containing a Bluetooth profile and its // associated extension id. - typedef std::map<std::string, ExtensionBluetoothProfileRecord> + typedef std::map<device::BluetoothUUID, ExtensionBluetoothProfileRecord> BluetoothProfileMap; BluetoothProfileMap bluetooth_profile_map_; diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc index e7d9350..98bf071 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc @@ -16,6 +16,7 @@ #include "chrome/test/base/testing_profile.h" #include "content/public/browser/notification_service.h" #include "content/public/test/test_browser_thread.h" +#include "device/bluetooth/bluetooth_uuid.h" #include "device/bluetooth/test/mock_bluetooth_adapter.h" #include "device/bluetooth/test/mock_bluetooth_device.h" #include "device/bluetooth/test/mock_bluetooth_profile.h" @@ -28,8 +29,8 @@ namespace { const char kTestExtensionId[] = "test extension id"; -const char kAudioProfileUuid[] = "audio profile uuid"; -const char kHealthProfileUuid[] = "health profile uuid"; +const device::BluetoothUUID kAudioProfileUuid("1234"); +const device::BluetoothUUID kHealthProfileUuid("4321"); class FakeEventRouter : public extensions::EventRouter { public: @@ -221,7 +222,7 @@ TEST_F(BluetoothEventRouterTest, DispatchConnectionEvent) { ASSERT_TRUE(socket_value->GetDictionary("profile", &profile_value)); std::string uuid; ASSERT_TRUE(profile_value->GetString("uuid", &uuid)); - EXPECT_STREQ(kAudioProfileUuid, uuid.c_str()); + EXPECT_STREQ(kAudioProfileUuid.canonical_value().c_str(), uuid.c_str()); EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); router_.ReleaseSocket(socket_id); diff --git a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.cc b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.cc index 4b46256..c5ead3c 100644 --- a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.cc +++ b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.cc @@ -10,7 +10,7 @@ #include "base/values.h" #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h" #include "chrome/common/extensions/api/manifest_types.h" -#include "device/bluetooth/bluetooth_utils.h" +#include "device/bluetooth/bluetooth_uuid.h" #include "extensions/common/error_utils.h" #include "extensions/common/extension_messages.h" #include "extensions/common/manifest_constants.h" @@ -31,8 +31,8 @@ namespace { bool ParseUuid(BluetoothManifestPermission* permission, const std::string& uuid, base::string16* error) { - std::string canonical_uuid = device::bluetooth_utils::CanonicalUuid(uuid); - if (canonical_uuid.empty()) { + device::BluetoothUUID bt_uuid(uuid); + if (!bt_uuid.IsValid()) { *error = ErrorUtils::FormatErrorMessageUTF16( errors::kErrorInvalidUuid, uuid); return false; @@ -83,13 +83,12 @@ bool BluetoothManifestPermission::CheckRequest( const Extension* extension, const BluetoothPermissionRequest& request) const { - std::string canonical_param_uuid = - device::bluetooth_utils::CanonicalUuid(request.uuid); + device::BluetoothUUID param_uuid(request.uuid); for (BluetoothUuidSet::const_iterator it = uuids_.begin(); it != uuids_.end(); ++it) { - std::string canonical_uuid = device::bluetooth_utils::CanonicalUuid(*it); - if (canonical_uuid == canonical_param_uuid) + device::BluetoothUUID uuid(*it); + if (param_uuid == uuid) return true; } return false; diff --git a/chrome/test/data/extensions/api_test/bluetooth/on_connection/runtest.js b/chrome/test/data/extensions/api_test/bluetooth/on_connection/runtest.js index fca8ec0..1a05349 100644 --- a/chrome/test/data/extensions/api_test/bluetooth/on_connection/runtest.js +++ b/chrome/test/data/extensions/api_test/bluetooth/on_connection/runtest.js @@ -9,7 +9,7 @@ var profileUuid; function testOnConnectionEvent() { chrome.test.assertEq('d1', deviceName); chrome.test.assertEq('11:12:13:14:15:16', deviceAddress); - chrome.test.assertEq('1234', profileUuid); + chrome.test.assertEq('00001234-0000-1000-8000-00805f9b34fb', profileUuid); chrome.test.succeed(); } diff --git a/device/bluetooth/bluetooth.gyp b/device/bluetooth/bluetooth.gyp index 2d70842..c3f8475 100644 --- a/device/bluetooth/bluetooth.gyp +++ b/device/bluetooth/bluetooth.gyp @@ -75,8 +75,8 @@ 'bluetooth_socket_win.h', 'bluetooth_task_manager_win.cc', 'bluetooth_task_manager_win.h', - 'bluetooth_utils.cc', - 'bluetooth_utils.h', + 'bluetooth_uuid.cc', + 'bluetooth_uuid.h', ], 'conditions': [ ['chromeos==1', { diff --git a/device/bluetooth/bluetooth_chromeos_unittest.cc b/device/bluetooth/bluetooth_chromeos_unittest.cc index 924ea3c..ae60eee 100644 --- a/device/bluetooth/bluetooth_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_chromeos_unittest.cc @@ -25,6 +25,7 @@ using device::BluetoothAdapter; using device::BluetoothAdapterFactory; using device::BluetoothDevice; using device::BluetoothDiscoverySession; +using device::BluetoothUUID; namespace chromeos { @@ -1448,8 +1449,8 @@ TEST_F(BluetoothChromeOSTest, DeviceProperties) { BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs(); ASSERT_EQ(2U, uuids.size()); - EXPECT_EQ(uuids[0], "00001800-0000-1000-8000-00805f9b34fb"); - EXPECT_EQ(uuids[1], "00001801-0000-1000-8000-00805f9b34fb"); + EXPECT_EQ(uuids[0], BluetoothUUID("1800")); + EXPECT_EQ(uuids[1], BluetoothUUID("1801")); EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[0]->GetVendorIDSource()); EXPECT_EQ(0x05ac, devices[0]->GetVendorID()); @@ -1523,8 +1524,8 @@ TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) { BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs(); ASSERT_EQ(2U, uuids.size()); - ASSERT_EQ(uuids[0], "00001800-0000-1000-8000-00805f9b34fb"); - ASSERT_EQ(uuids[1], "00001801-0000-1000-8000-00805f9b34fb"); + ASSERT_EQ(uuids[0], BluetoothUUID("1800")); + ASSERT_EQ(uuids[1], BluetoothUUID("1801")); // Install an observer; expect the DeviceChanged method to be called when // we change the class of the device. @@ -1534,11 +1535,14 @@ TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) { fake_bluetooth_device_client_->GetProperties( dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath)); - uuids.push_back("0000110c-0000-1000-8000-00805f9b34fb"); - uuids.push_back("0000110e-0000-1000-8000-00805f9b34fb"); - uuids.push_back("0000110a-0000-1000-8000-00805f9b34fb"); + std::vector<std::string> new_uuids; + new_uuids.push_back(uuids[0].canonical_value()); + new_uuids.push_back(uuids[1].canonical_value()); + new_uuids.push_back("0000110c-0000-1000-8000-00805f9b34fb"); + new_uuids.push_back("0000110e-0000-1000-8000-00805f9b34fb"); + new_uuids.push_back("0000110a-0000-1000-8000-00805f9b34fb"); - properties->uuids.ReplaceValue(uuids); + properties->uuids.ReplaceValue(new_uuids); EXPECT_EQ(1, observer.device_changed_count_); EXPECT_EQ(devices[0], observer.last_device_); @@ -1546,11 +1550,11 @@ TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) { // Fetching the value should give the new one. uuids = devices[0]->GetUUIDs(); ASSERT_EQ(5U, uuids.size()); - EXPECT_EQ(uuids[0], "00001800-0000-1000-8000-00805f9b34fb"); - EXPECT_EQ(uuids[1], "00001801-0000-1000-8000-00805f9b34fb"); - EXPECT_EQ(uuids[2], "0000110c-0000-1000-8000-00805f9b34fb"); - EXPECT_EQ(uuids[3], "0000110e-0000-1000-8000-00805f9b34fb"); - EXPECT_EQ(uuids[4], "0000110a-0000-1000-8000-00805f9b34fb"); + EXPECT_EQ(uuids[0], BluetoothUUID("1800")); + EXPECT_EQ(uuids[1], BluetoothUUID("1801")); + EXPECT_EQ(uuids[2], BluetoothUUID("110c")); + EXPECT_EQ(uuids[3], BluetoothUUID("110e")); + EXPECT_EQ(uuids[4], BluetoothUUID("110a")); } TEST_F(BluetoothChromeOSTest, ForgetDevice) { @@ -1700,7 +1704,7 @@ TEST_F(BluetoothChromeOSTest, ConnectUnpairableDevice) { // Verify is a HID device and is not connectable. BluetoothDevice::UUIDList uuids = device->GetUUIDs(); ASSERT_EQ(1U, uuids.size()); - EXPECT_EQ(uuids[0], "00001124-0000-1000-8000-00805f9b34fb"); + EXPECT_EQ(uuids[0], BluetoothUUID("1124")); EXPECT_FALSE(device->IsConnectable()); } @@ -1890,7 +1894,7 @@ TEST_F(BluetoothChromeOSTest, PairLegacyAutopair) { // Verify is a HID device and is connectable. BluetoothDevice::UUIDList uuids = device->GetUUIDs(); ASSERT_EQ(1U, uuids.size()); - EXPECT_EQ(uuids[0], "00001124-0000-1000-8000-00805f9b34fb"); + EXPECT_EQ(uuids[0], BluetoothUUID("1124")); EXPECT_TRUE(device->IsConnectable()); // Make sure the trusted property has been set to true. @@ -1946,7 +1950,7 @@ TEST_F(BluetoothChromeOSTest, PairDisplayPinCode) { // Verify is a HID device and is connectable. BluetoothDevice::UUIDList uuids = device->GetUUIDs(); ASSERT_EQ(1U, uuids.size()); - EXPECT_EQ(uuids[0], "00001124-0000-1000-8000-00805f9b34fb"); + EXPECT_EQ(uuids[0], BluetoothUUID("1124")); EXPECT_TRUE(device->IsConnectable()); // Make sure the trusted property has been set to true. @@ -2022,7 +2026,7 @@ TEST_F(BluetoothChromeOSTest, PairDisplayPasskey) { // Verify is a HID device. BluetoothDevice::UUIDList uuids = device->GetUUIDs(); ASSERT_EQ(1U, uuids.size()); - EXPECT_EQ(uuids[0], "00001124-0000-1000-8000-00805f9b34fb"); + EXPECT_EQ(uuids[0], BluetoothUUID("1124")); // And usually not connectable. EXPECT_FALSE(device->IsConnectable()); diff --git a/device/bluetooth/bluetooth_device.cc b/device/bluetooth/bluetooth_device.cc index 6916f8b..f8cef4a 100644 --- a/device/bluetooth/bluetooth_device.cc +++ b/device/bluetooth/bluetooth_device.cc @@ -7,17 +7,11 @@ #include <string> #include "base/strings/utf_string_conversions.h" -#include "device/bluetooth/bluetooth_utils.h" #include "grit/device_bluetooth_strings.h" #include "ui/base/l10n/l10n_util.h" namespace device { -// static -bool BluetoothDevice::IsUUIDValid(const std::string& uuid) { - return !bluetooth_utils::CanonicalUuid(uuid).empty(); -} - BluetoothDevice::BluetoothDevice() { } diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h index fce46b1..cfe8d9a 100644 --- a/device/bluetooth/bluetooth_device.h +++ b/device/bluetooth/bluetooth_device.h @@ -11,6 +11,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_vector.h" #include "base/strings/string16.h" +#include "device/bluetooth/bluetooth_uuid.h" namespace device { @@ -169,10 +170,6 @@ class BluetoothDevice { virtual void AuthorizePairing(BluetoothDevice* device) = 0; }; - // Returns true if uuid is in a a valid canonical format - // (see utils::CanonicalUuid). - static bool IsUUIDValid(const std::string& uuid); - virtual ~BluetoothDevice(); // Returns the Bluetooth class of the device, used by GetDeviceType() @@ -236,9 +233,7 @@ class BluetoothDevice { // devices this data is collected from both the EIR data and SDP tables, // for Low Energy devices this data is collected from AD and GATT primary // services, for dual mode devices this may be collected from both./ - // - // All UUIDs are returned in the canonical 128-bit format. - typedef std::vector<std::string> UUIDList; + typedef std::vector<BluetoothUUID> UUIDList; virtual UUIDList GetUUIDs() const = 0; // The ErrorCallback is used for methods that can fail in which case it @@ -333,7 +328,7 @@ class BluetoothDevice { // all references to the BluetoothSocket are released. Note that the // BluetoothSocket object can outlive both this BluetoothDevice and the // BluetoothAdapter for this device. - virtual void ConnectToService(const std::string& service_uuid, + virtual void ConnectToService(const BluetoothUUID& service_uuid, const SocketCallback& callback) = 0; // Attempts to initiate an outgoing connection to this device for the profile diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc index a7c7b83..f42f3ee 100644 --- a/device/bluetooth/bluetooth_device_chromeos.cc +++ b/device/bluetooth/bluetooth_device_chromeos.cc @@ -219,7 +219,15 @@ BluetoothDeviceChromeOS::UUIDList BluetoothDeviceChromeOS::GetUUIDs() const { GetProperties(object_path_); DCHECK(properties); - return properties->uuids.value(); + std::vector<device::BluetoothUUID> uuids; + const std::vector<std::string> &dbus_uuids = properties->uuids.value(); + for (std::vector<std::string>::const_iterator iter = dbus_uuids.begin(); + iter != dbus_uuids.end(); ++iter) { + device::BluetoothUUID uuid(*iter); + DCHECK(uuid.IsValid()); + uuids.push_back(uuid); + } + return uuids; } bool BluetoothDeviceChromeOS::ExpectingPinCode() const { @@ -344,7 +352,7 @@ void BluetoothDeviceChromeOS::Forget(const ErrorCallback& error_callback) { } void BluetoothDeviceChromeOS::ConnectToService( - const std::string& service_uuid, + const device::BluetoothUUID& service_uuid, const SocketCallback& callback) { // TODO(keybuk): implement callback.Run(scoped_refptr<device::BluetoothSocket>()); @@ -357,11 +365,11 @@ void BluetoothDeviceChromeOS::ConnectToProfile( BluetoothProfileChromeOS* profile_chromeos = static_cast<BluetoothProfileChromeOS*>(profile); VLOG(1) << object_path_.value() << ": Connecting profile: " - << profile_chromeos->uuid(); + << profile_chromeos->uuid().canonical_value(); DBusThreadManager::Get()->GetBluetoothDeviceClient()-> ConnectProfile( object_path_, - profile_chromeos->uuid(), + profile_chromeos->uuid().canonical_value(), base::Bind( &BluetoothDeviceChromeOS::OnConnectProfile, weak_ptr_factory_.GetWeakPtr(), @@ -567,7 +575,7 @@ void BluetoothDeviceChromeOS::OnConnectProfile( BluetoothProfileChromeOS* profile_chromeos = static_cast<BluetoothProfileChromeOS*>(profile); VLOG(1) << object_path_.value() << ": Profile connected: " - << profile_chromeos->uuid(); + << profile_chromeos->uuid().canonical_value(); callback.Run(); } @@ -579,7 +587,7 @@ void BluetoothDeviceChromeOS::OnConnectProfileError( BluetoothProfileChromeOS* profile_chromeos = static_cast<BluetoothProfileChromeOS*>(profile); VLOG(1) << object_path_.value() << ": Profile connection failed: " - << profile_chromeos->uuid() << ": " + << profile_chromeos->uuid().canonical_value() << ": " << error_name << ": " << error_message; error_callback.Run(); } diff --git a/device/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h index d31bae7..98475f2 100644 --- a/device/bluetooth/bluetooth_device_chromeos.h +++ b/device/bluetooth/bluetooth_device_chromeos.h @@ -52,7 +52,7 @@ class BluetoothDeviceChromeOS const ErrorCallback& error_callback) OVERRIDE; virtual void Forget(const ErrorCallback& error_callback) OVERRIDE; virtual void ConnectToService( - const std::string& service_uuid, + const device::BluetoothUUID& service_uuid, const SocketCallback& callback) OVERRIDE; virtual void ConnectToProfile( device::BluetoothProfile* profile, diff --git a/device/bluetooth/bluetooth_device_mac.h b/device/bluetooth/bluetooth_device_mac.h index a953749..f610f24 100644 --- a/device/bluetooth/bluetooth_device_mac.h +++ b/device/bluetooth/bluetooth_device_mac.h @@ -52,7 +52,7 @@ class BluetoothDeviceMac : public BluetoothDevice { const ErrorCallback& error_callback) OVERRIDE; virtual void Forget(const ErrorCallback& error_callback) OVERRIDE; virtual void ConnectToService( - const std::string& service_uuid, + const device::BluetoothUUID& service_uuid, const SocketCallback& callback) OVERRIDE; virtual void ConnectToProfile( device::BluetoothProfile* profile, diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm index 5d37a54..6fbad23 100644 --- a/device/bluetooth/bluetooth_device_mac.mm +++ b/device/bluetooth/bluetooth_device_mac.mm @@ -179,10 +179,11 @@ void BluetoothDeviceMac::Forget(const ErrorCallback& error_callback) { } void BluetoothDeviceMac::ConnectToService( - const std::string& service_uuid, + const device::BluetoothUUID& service_uuid, const SocketCallback& callback) { IOBluetoothSDPServiceRecord* record = - [device_ getServiceRecordForUUID:GetIOBluetoothSDPUUID(service_uuid)]; + [device_ getServiceRecordForUUID:GetIOBluetoothSDPUUID( + service_uuid.canonical_value())]; if (record != nil) { BluetoothServiceRecordMac service_record(record); scoped_refptr<BluetoothSocket> socket( diff --git a/device/bluetooth/bluetooth_device_win.cc b/device/bluetooth/bluetooth_device_win.cc index da016f7..312f0e5 100644 --- a/device/bluetooth/bluetooth_device_win.cc +++ b/device/bluetooth/bluetooth_device_win.cc @@ -161,7 +161,7 @@ void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) { } void BluetoothDeviceWin::ConnectToService( - const std::string& service_uuid, + const device::BluetoothUUID& service_uuid, const SocketCallback& callback) { for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); iter != service_record_list_.end(); @@ -202,11 +202,11 @@ void BluetoothDeviceWin::ClearOutOfBandPairingData( } const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord( - const std::string& uuid) const { + const device::BluetoothUUID& uuid) const { for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); iter != service_record_list_.end(); ++iter) { - if ((*iter)->uuid().compare(uuid) == 0) + if ((*iter)->uuid() == uuid) return *iter; } return NULL; diff --git a/device/bluetooth/bluetooth_device_win.h b/device/bluetooth/bluetooth_device_win.h index 80c8206..0ba0796 100644 --- a/device/bluetooth/bluetooth_device_win.h +++ b/device/bluetooth/bluetooth_device_win.h @@ -52,7 +52,7 @@ class BluetoothDeviceWin : public BluetoothDevice { const ErrorCallback& error_callback) OVERRIDE; virtual void Forget(const ErrorCallback& error_callback) OVERRIDE; virtual void ConnectToService( - const std::string& service_uuid, + const device::BluetoothUUID& service_uuid, const SocketCallback& callback) OVERRIDE; virtual void ConnectToProfile( device::BluetoothProfile* profile, @@ -69,7 +69,7 @@ class BluetoothDeviceWin : public BluetoothDevice { // Used by BluetoothProfileWin to retrieve the service record for the given // |uuid|. const BluetoothServiceRecord* GetServiceRecord( - const std::string& uuid) const; + const device::BluetoothUUID& uuid) const; protected: // BluetoothDevice override diff --git a/device/bluetooth/bluetooth_device_win_unittest.cc b/device/bluetooth/bluetooth_device_win_unittest.cc index 651bfd7..45a4a81 100644 --- a/device/bluetooth/bluetooth_device_win_unittest.cc +++ b/device/bluetooth/bluetooth_device_win_unittest.cc @@ -10,6 +10,7 @@ #include "device/bluetooth/bluetooth_device_win.h" #include "device/bluetooth/bluetooth_service_record.h" #include "device/bluetooth/bluetooth_task_manager_win.h" +#include "device/bluetooth/bluetooth_uuid.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -23,7 +24,7 @@ const char kTestAudioSdpBytes[] = "35510900000a00010001090001350319110a09000435103506190100090019350619001909" "010209000535031910020900093508350619110d090102090100250c417564696f20536f75" "726365090311090001"; -const char kTestAudioSdpUuid[] = "0000110a-0000-1000-8000-00805f9b34fb"; +const device::BluetoothUUID kTestAudioSdpUuid("110a"); const char kTestVideoSdpName[] = "Video"; const char kTestVideoSdpAddress[] = "A0:10:0A:03:02:01"; @@ -31,7 +32,7 @@ const char kTestVideoSdpBytes[] = "354b0900000a000100030900013506191112191203090004350c3503190100350519000308" "0b090005350319100209000935083506191108090100090100250d566f6963652047617465" "776179"; -const char kTestVideoSdpUuid[] = "00001112-0000-1000-8000-00805f9b34fb"; +const device::BluetoothUUID kTestVideoSdpUuid("1112"); } // namespace @@ -44,6 +45,7 @@ class BluetoothDeviceWinTest : public testing::Test { device_state.name = kDeviceName; device_state.address = kDeviceAddress; + // Add device with audio/video services. BluetoothTaskManagerWin::ServiceRecordState* audio_state = new BluetoothTaskManagerWin::ServiceRecordState(); audio_state->name = kTestAudioSdpName; @@ -59,6 +61,10 @@ class BluetoothDeviceWinTest : public testing::Test { device_state.service_record_states.push_back(video_state); device_.reset(new BluetoothDeviceWin(device_state)); + + // Add empty device. + device_state.service_record_states.clear(); + empty_device_.reset(new BluetoothDeviceWin(device_state)); } protected: @@ -70,8 +76,8 @@ TEST_F(BluetoothDeviceWinTest, GetUUIDs) { BluetoothDevice::UUIDList uuids = device_->GetUUIDs(); EXPECT_EQ(2, uuids.size()); - EXPECT_STREQ(kTestAudioSdpUuid, uuids[0].c_str()); - EXPECT_STREQ(kTestVideoSdpUuid, uuids[1].c_str()); + EXPECT_EQ(kTestAudioSdpUuid, uuids[0]); + EXPECT_EQ(kTestVideoSdpUuid, uuids[1]); uuids = empty_device_->GetUUIDs(); EXPECT_EQ(0, uuids.size()); diff --git a/device/bluetooth/bluetooth_gatt_characteristic.cc b/device/bluetooth/bluetooth_gatt_characteristic.cc index 49fd3b3..47182a5 100644 --- a/device/bluetooth/bluetooth_gatt_characteristic.cc +++ b/device/bluetooth/bluetooth_gatt_characteristic.cc @@ -16,7 +16,7 @@ BluetoothGattCharacteristic::~BluetoothGattCharacteristic() { // static BluetoothGattCharacteristic* BluetoothGattCharacteristic::Create( - const bluetooth_utils::UUID& uuid, + const BluetoothUUID& uuid, const std::vector<uint8>& value, Properties properties, Permissions permissions) { diff --git a/device/bluetooth/bluetooth_gatt_characteristic.h b/device/bluetooth/bluetooth_gatt_characteristic.h index 00f7a88..3fe5859 100644 --- a/device/bluetooth/bluetooth_gatt_characteristic.h +++ b/device/bluetooth/bluetooth_gatt_characteristic.h @@ -9,7 +9,7 @@ #include "base/basictypes.h" #include "base/callback.h" -#include "device/bluetooth/bluetooth_utils.h" +#include "device/bluetooth/bluetooth_uuid.h" namespace device { @@ -80,7 +80,7 @@ class BluetoothGattCharacteristic { // Called when the UUID of |characteristic| has changed. virtual void UuidChanged( BluetoothGattCharacteristic* characteristic, - const bluetooth_utils::UUID& uuid) {} + const BluetoothUUID& uuid) {} // Called when the current value of |characteristic| has changed. virtual void ValueChanged( @@ -125,13 +125,13 @@ class BluetoothGattCharacteristic { // "Characteristic Extended Properties" descriptor and this will automatically // set the correspoding bit in the characteristic's properties field. If // |properties| has |kPropertyExtendedProperties| set, it will be ignored. - static BluetoothGattCharacteristic* Create(const bluetooth_utils::UUID& uuid, + static BluetoothGattCharacteristic* Create(const BluetoothUUID& uuid, const std::vector<uint8>& value, Properties properties, Permissions permissions); // The Bluetooth-specific UUID of the characteristic. - virtual const bluetooth_utils::UUID& GetUuid() const = 0; + virtual const BluetoothUUID& GetUuid() const = 0; // Returns true, if this characteristic is hosted locally. If false, then this // instance represents a remote GATT characteristic. diff --git a/device/bluetooth/bluetooth_gatt_descriptor.cc b/device/bluetooth/bluetooth_gatt_descriptor.cc index 4746cad..692e258 100644 --- a/device/bluetooth/bluetooth_gatt_descriptor.cc +++ b/device/bluetooth/bluetooth_gatt_descriptor.cc @@ -8,20 +8,18 @@ namespace device { -using bluetooth_utils::UUID; - -const UUID BluetoothGattDescriptor:: - kCharacteristicExtendedPropertiesUuid("0x2900"); -const UUID BluetoothGattDescriptor:: - kCharacteristicUserDescriptionUuid("0x2901"); -const UUID BluetoothGattDescriptor:: - kClientCharacteristicConfigurationUuid("0x2902"); -const UUID BluetoothGattDescriptor:: - kServerCharacteristicConfigurationUuid("0x2903"); -const UUID BluetoothGattDescriptor:: - kCharacteristicPresentationFormatUuid("0x2904"); -const UUID BluetoothGattDescriptor:: - kCharacteristicAggregateFormatUuid("0x2905"); +const BluetoothUUID BluetoothGattDescriptor:: + kCharacteristicExtendedPropertiesUuid("2900"); +const BluetoothUUID BluetoothGattDescriptor:: + kCharacteristicUserDescriptionUuid("2901"); +const BluetoothUUID BluetoothGattDescriptor:: + kClientCharacteristicConfigurationUuid("2902"); +const BluetoothUUID BluetoothGattDescriptor:: + kServerCharacteristicConfigurationUuid("2903"); +const BluetoothUUID BluetoothGattDescriptor:: + kCharacteristicPresentationFormatUuid("2904"); +const BluetoothUUID BluetoothGattDescriptor:: + kCharacteristicAggregateFormatUuid("2905"); BluetoothGattDescriptor::BluetoothGattDescriptor() { } @@ -31,7 +29,7 @@ BluetoothGattDescriptor::~BluetoothGattDescriptor() { // static BluetoothGattDescriptor* BluetoothGattDescriptor::Create( - const bluetooth_utils::UUID& uuid, + const BluetoothUUID& uuid, const std::vector<uint8>& value) { LOG(ERROR) << "Creating local GATT characteristic descriptors currently not " << "supported."; diff --git a/device/bluetooth/bluetooth_gatt_descriptor.h b/device/bluetooth/bluetooth_gatt_descriptor.h index 9c0a1d2..45ea8f8 100644 --- a/device/bluetooth/bluetooth_gatt_descriptor.h +++ b/device/bluetooth/bluetooth_gatt_descriptor.h @@ -9,7 +9,7 @@ #include "base/basictypes.h" #include "base/callback.h" -#include "device/bluetooth/bluetooth_utils.h" +#include "device/bluetooth/bluetooth_uuid.h" namespace device { @@ -36,7 +36,7 @@ class BluetoothGattDescriptor { // - Reliable Write: 0x0001 // - Writable Auxiliaries: 0x0002 // - static const bluetooth_utils::UUID kCharacteristicExtendedPropertiesUuid; + static const BluetoothUUID kCharacteristicExtendedPropertiesUuid; // The "Characteristic User Description" descriptor defines a UTF-8 string of // variable size that is a user textual description of the associated @@ -44,7 +44,7 @@ class BluetoothGattDescriptor { // per characteristic. This descriptor can be written to if the "Writable // Auxiliaries" bit of the Characteristic Properties (via the "Characteristic // Extended Properties" descriptor) has been set. - static const bluetooth_utils::UUID kCharacteristicUserDescriptionUuid; + static const BluetoothUUID kCharacteristicUserDescriptionUuid; // The "Client Characteristic Configuration" descriptor defines how the // characteristic may be configured by a specific client. A server-side @@ -58,7 +58,7 @@ class BluetoothGattDescriptor { // - Notification: 0x0001 // - Indication: 0x0002 // - static const bluetooth_utils::UUID kClientCharacteristicConfigurationUuid; + static const BluetoothUUID kClientCharacteristicConfigurationUuid; // The "Server Characteristic Configuration" descriptor defines how the // characteristic may be configured for the server. There is one instance @@ -71,7 +71,7 @@ class BluetoothGattDescriptor { // - Default: 0x0000 // - Broadcast: 0x0001 // - static const bluetooth_utils::UUID kServerCharacteristicConfigurationUuid; + static const BluetoothUUID kServerCharacteristicConfigurationUuid; // The "Characteristic Presentation Format" declaration defines the format of // the Characteristic Value. The value is composed of 7 octets which are @@ -81,7 +81,7 @@ class BluetoothGattDescriptor { // than one declaration of this descriptor exists for a characteristic, then a // "Characteristic Aggregate Format" descriptor must also exist for that // characteristic. - static const bluetooth_utils::UUID kCharacteristicPresentationFormatUuid; + static const BluetoothUUID kCharacteristicPresentationFormatUuid; // The "Characteristic Aggregate Format" descriptor defines the format of an // aggragated characteristic value. In GATT's underlying protocol, ATT, each @@ -103,7 +103,7 @@ class BluetoothGattDescriptor { // Similarly for local characteristics, implementations DO NOT need to create // an instance of BluetoothGattDescriptor for this descriptor as this will be // handled by the subsystem. - static const bluetooth_utils::UUID kCharacteristicAggregateFormatUuid; + static const BluetoothUUID kCharacteristicAggregateFormatUuid; // Interface for observing changes from a BluetoothGattDescriptor. // Properties of remote characteristic desciptors are received asynchonously. @@ -115,7 +115,7 @@ class BluetoothGattDescriptor { // Called when the UUID of |descriptor| has changed. virtual void UuidChanged( BluetoothGattDescriptor* descriptor, - const bluetooth_utils::UUID& uuid) {} + const BluetoothUUID& uuid) {} // Called when the current value of |descriptor| has changed. virtual void ValueChanged( @@ -153,11 +153,11 @@ class BluetoothGattDescriptor { // |kCharacteristicPresentationFormat| are supported for locally hosted // descriptors. This method will return NULL if |uuid| is any one of the // unsupported predefined descriptor UUIDs. - static BluetoothGattDescriptor* Create(const bluetooth_utils::UUID& uuid, + static BluetoothGattDescriptor* Create(const BluetoothUUID& uuid, const std::vector<uint8>& value); // The Bluetooth-specific UUID of the characteristic descriptor. - virtual const bluetooth_utils::UUID& GetUuid() const = 0; + virtual const BluetoothUUID& GetUuid() const = 0; // Returns true, if this characteristic descriptor is hosted locally. If // false, then this instance represents a remote descriptor. diff --git a/device/bluetooth/bluetooth_gatt_service.cc b/device/bluetooth/bluetooth_gatt_service.cc index dccb06a..461a63c 100644 --- a/device/bluetooth/bluetooth_gatt_service.cc +++ b/device/bluetooth/bluetooth_gatt_service.cc @@ -16,7 +16,7 @@ BluetoothGattService::~BluetoothGattService() { // static BluetoothGattService* BluetoothGattService::Create( - const bluetooth_utils::UUID& uuid, + const BluetoothUUID& uuid, bool is_primary, Delegate* delegate) { LOG(ERROR) << "Creating local GATT services currently not supported."; diff --git a/device/bluetooth/bluetooth_gatt_service.h b/device/bluetooth/bluetooth_gatt_service.h index 963fdd5..4046a00 100644 --- a/device/bluetooth/bluetooth_gatt_service.h +++ b/device/bluetooth/bluetooth_gatt_service.h @@ -9,7 +9,7 @@ #include "base/basictypes.h" #include "base/callback.h" -#include "device/bluetooth/bluetooth_utils.h" +#include "device/bluetooth/bluetooth_uuid.h" namespace device { @@ -133,7 +133,7 @@ class BluetoothGattService { // Called when the UUID of |service| have changed. virtual void UuidChanged( BluetoothGattService* service, - const bluetooth_utils::UUID& uuid) {} + const BluetoothUUID& uuid) {} // Called when the services included by |service| have changed. virtual void IncludedServicesChanged( @@ -157,12 +157,12 @@ class BluetoothGattService { // peripheral role events. If |delegate| is NULL, then this service will // employ a default behavior when responding to read and write requests based // on the cached value of its characteristics and descriptors at a given time. - static BluetoothGattService* Create(const bluetooth_utils::UUID& uuid, + static BluetoothGattService* Create(const BluetoothUUID& uuid, bool is_primary, Delegate* delegate); // The Bluetooth-specific UUID of the service. - virtual const bluetooth_utils::UUID& GetUuid() const = 0; + virtual const BluetoothUUID& GetUuid() const = 0; // Returns true, if this service hosted locally. If false, then this service // represents a remote GATT service. diff --git a/device/bluetooth/bluetooth_profile.cc b/device/bluetooth/bluetooth_profile.cc index 0d9a757..bf70ab8 100644 --- a/device/bluetooth/bluetooth_profile.cc +++ b/device/bluetooth/bluetooth_profile.cc @@ -13,8 +13,6 @@ #include "device/bluetooth/bluetooth_profile_win.h" #endif -#include <string> - namespace device { BluetoothProfile::Options::Options() @@ -42,7 +40,7 @@ BluetoothProfile::~BluetoothProfile() { // static -void BluetoothProfile::Register(const std::string& uuid, +void BluetoothProfile::Register(const BluetoothUUID& uuid, const Options& options, const ProfileCallback& callback) { #if defined(OS_CHROMEOS) diff --git a/device/bluetooth/bluetooth_profile.h b/device/bluetooth/bluetooth_profile.h index 4ff2480..30f2a1a 100644 --- a/device/bluetooth/bluetooth_profile.h +++ b/device/bluetooth/bluetooth_profile.h @@ -9,6 +9,7 @@ #include "base/callback.h" #include "base/memory/ref_counted.h" +#include "device/bluetooth/bluetooth_uuid.h" namespace device { @@ -78,7 +79,7 @@ class BluetoothProfile { // This pointer is not owned by the receiver, but will not be freed unless // its Unregister() method is called. typedef base::Callback<void(BluetoothProfile*)> ProfileCallback; - static void Register(const std::string& uuid, + static void Register(const BluetoothUUID& uuid, const Options& options, const ProfileCallback& callback); diff --git a/device/bluetooth/bluetooth_profile_chromeos.cc b/device/bluetooth/bluetooth_profile_chromeos.cc index 704b68c..7d6b786f 100644 --- a/device/bluetooth/bluetooth_profile_chromeos.cc +++ b/device/bluetooth/bluetooth_profile_chromeos.cc @@ -69,13 +69,13 @@ BluetoothProfileChromeOS::~BluetoothProfileChromeOS() { } void BluetoothProfileChromeOS::Init( - const std::string& uuid, + const device::BluetoothUUID& uuid, const device::BluetoothProfile::Options& options, const ProfileCallback& callback) { DCHECK(object_path_.value().empty()); DCHECK(profile_.get() == NULL); - if (!BluetoothDevice::IsUUIDValid(uuid)) { + if (!uuid.IsValid()) { callback.Run(NULL); return; } @@ -83,7 +83,7 @@ void BluetoothProfileChromeOS::Init( uuid_ = uuid; options_.name = options.name; - options_.service = uuid; + options_.service = uuid.canonical_value(); options_.channel = options.channel; options_.psm = options.psm; options_.require_authentication = options.require_authentication; @@ -95,7 +95,7 @@ void BluetoothProfileChromeOS::Init( // The object path is relatively meaningless, but has to be unique, so we // use the UUID of the profile. std::string uuid_path; - base::ReplaceChars(uuid, ":-", "_", &uuid_path); + base::ReplaceChars(uuid.canonical_value(), ":-", "_", &uuid_path); object_path_ = dbus::ObjectPath("/org/chromium/bluetooth_profile/" + uuid_path); @@ -143,7 +143,7 @@ void BluetoothProfileChromeOS::AdapterPresentChanged(BluetoothAdapter* adapter, DBusThreadManager::Get()->GetBluetoothProfileManagerClient()-> RegisterProfile( object_path_, - uuid_, + uuid_.canonical_value(), options_, base::Bind(&BluetoothProfileChromeOS::OnInternalRegisterProfile, weak_ptr_factory_.GetWeakPtr()), @@ -162,7 +162,7 @@ void BluetoothProfileChromeOS::OnGetAdapter( DBusThreadManager::Get()->GetBluetoothProfileManagerClient()-> RegisterProfile( object_path_, - uuid_, + uuid_.canonical_value(), options_, base::Bind(&BluetoothProfileChromeOS::OnRegisterProfile, weak_ptr_factory_.GetWeakPtr(), diff --git a/device/bluetooth/bluetooth_profile_chromeos.h b/device/bluetooth/bluetooth_profile_chromeos.h index 84b7043..f7974f2 100644 --- a/device/bluetooth/bluetooth_profile_chromeos.h +++ b/device/bluetooth/bluetooth_profile_chromeos.h @@ -17,6 +17,7 @@ #include "dbus/object_path.h" #include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_profile.h" +#include "device/bluetooth/bluetooth_uuid.h" namespace dbus { @@ -39,7 +40,7 @@ class CHROMEOS_EXPORT BluetoothProfileChromeOS const ConnectionCallback& callback) OVERRIDE; // Return the UUID of the profile. - const std::string& uuid() const { return uuid_; } + const device::BluetoothUUID& uuid() const { return uuid_; } private: friend class BluetoothProfile; @@ -50,7 +51,7 @@ class CHROMEOS_EXPORT BluetoothProfileChromeOS // Called by BluetoothProfile::Register to initialize the profile object // asynchronously. |uuid|, |options| and |callback| are the arguments to // BluetoothProfile::Register. - void Init(const std::string& uuid, + void Init(const device::BluetoothUUID& uuid, const device::BluetoothProfile::Options& options, const ProfileCallback& callback); @@ -105,7 +106,7 @@ class CHROMEOS_EXPORT BluetoothProfileChromeOS scoped_ptr<dbus::FileDescriptor> fd); // UUID of the profile passed during initialization. - std::string uuid_; + device::BluetoothUUID uuid_; // Copy of the profile options passed during initialization. BluetoothProfileManagerClient::Options options_; diff --git a/device/bluetooth/bluetooth_profile_chromeos_unittest.cc b/device/bluetooth/bluetooth_profile_chromeos_unittest.cc index da2f659..24061b7 100644 --- a/device/bluetooth/bluetooth_profile_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_profile_chromeos_unittest.cc @@ -19,6 +19,7 @@ #include "device/bluetooth/bluetooth_profile_chromeos.h" #include "device/bluetooth/bluetooth_socket.h" #include "device/bluetooth/bluetooth_socket_chromeos.h" +#include "device/bluetooth/bluetooth_uuid.h" #include "net/base/io_buffer.h" #include "testing/gtest/include/gtest/gtest.h" @@ -26,6 +27,7 @@ using device::BluetoothAdapter; using device::BluetoothDevice; using device::BluetoothProfile; using device::BluetoothSocket; +using device::BluetoothUUID; namespace chromeos { @@ -124,7 +126,7 @@ TEST_F(BluetoothProfileChromeOSTest, L2capEndToEnd) { // callback. BluetoothProfile::Options options; BluetoothProfile::Register( - FakeBluetoothProfileManagerClient::kL2capUuid, + BluetoothUUID(FakeBluetoothProfileManagerClient::kL2capUuid), options, base::Bind(&BluetoothProfileChromeOSTest::ProfileCallback, base::Unretained(this))); @@ -250,7 +252,7 @@ TEST_F(BluetoothProfileChromeOSTest, RfcommEndToEnd) { // callback. BluetoothProfile::Options options; BluetoothProfile::Register( - FakeBluetoothProfileManagerClient::kRfcommUuid, + BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), options, base::Bind(&BluetoothProfileChromeOSTest::ProfileCallback, base::Unretained(this))); diff --git a/device/bluetooth/bluetooth_profile_mac.h b/device/bluetooth/bluetooth_profile_mac.h index 0085efd..bad10ce 100644 --- a/device/bluetooth/bluetooth_profile_mac.h +++ b/device/bluetooth/bluetooth_profile_mac.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "base/callback.h" #include "device/bluetooth/bluetooth_profile.h" +#include "device/bluetooth/bluetooth_uuid.h" #ifdef __OBJC__ @class IOBluetoothDevice; @@ -34,10 +35,10 @@ class BluetoothProfileMac : public BluetoothProfile { private: friend BluetoothProfile; - BluetoothProfileMac(const std::string& uuid, const std::string& name); + BluetoothProfileMac(const BluetoothUUID& uuid, const std::string& name); virtual ~BluetoothProfileMac(); - const std::string uuid_; + const BluetoothUUID uuid_; const std::string name_; ConnectionCallback connection_callback_; }; diff --git a/device/bluetooth/bluetooth_profile_mac.mm b/device/bluetooth/bluetooth_profile_mac.mm index 4956651..54781e4 100644 --- a/device/bluetooth/bluetooth_profile_mac.mm +++ b/device/bluetooth/bluetooth_profile_mac.mm @@ -46,7 +46,7 @@ IOBluetoothSDPUUID* GetIOBluetoothSDPUUID(const std::string& uuid) { namespace device { -BluetoothProfileMac::BluetoothProfileMac(const std::string& uuid, +BluetoothProfileMac::BluetoothProfileMac(const BluetoothUUID& uuid, const std::string& name) : BluetoothProfile(), uuid_(uuid), name_(name) { } @@ -68,7 +68,8 @@ bool BluetoothProfileMac::Connect(IOBluetoothDevice* device) { return false; IOBluetoothSDPServiceRecord* record = - [device getServiceRecordForUUID:GetIOBluetoothSDPUUID(uuid_)]; + [device getServiceRecordForUUID:GetIOBluetoothSDPUUID( + uuid_.canonical_value())]; if (record != nil) { scoped_refptr<BluetoothSocket> socket( BluetoothSocketMac::CreateBluetoothSocket(record)); diff --git a/device/bluetooth/bluetooth_profile_win.cc b/device/bluetooth/bluetooth_profile_win.cc index f0729bb..707afeb 100644 --- a/device/bluetooth/bluetooth_profile_win.cc +++ b/device/bluetooth/bluetooth_profile_win.cc @@ -11,7 +11,7 @@ namespace device { -BluetoothProfileWin::BluetoothProfileWin(const std::string& uuid, +BluetoothProfileWin::BluetoothProfileWin(const BluetoothUUID& uuid, const std::string& name) : BluetoothProfile(), uuid_(uuid), name_(name) { } diff --git a/device/bluetooth/bluetooth_profile_win.h b/device/bluetooth/bluetooth_profile_win.h index a102bf5..b7b5333 100644 --- a/device/bluetooth/bluetooth_profile_win.h +++ b/device/bluetooth/bluetooth_profile_win.h @@ -8,6 +8,7 @@ #include <string> #include "device/bluetooth/bluetooth_profile.h" +#include "device/bluetooth/bluetooth_uuid.h" namespace device { @@ -25,10 +26,10 @@ class BluetoothProfileWin : public BluetoothProfile { private: friend BluetoothProfile; - BluetoothProfileWin(const std::string& uuid, const std::string& name); + BluetoothProfileWin(const BluetoothUUID& uuid, const std::string& name); virtual ~BluetoothProfileWin(); - const std::string uuid_; + const BluetoothUUID uuid_; const std::string name_; ConnectionCallback connection_callback_; }; diff --git a/device/bluetooth/bluetooth_service_record.h b/device/bluetooth/bluetooth_service_record.h index eebdb6a..e4859b1 100644 --- a/device/bluetooth/bluetooth_service_record.h +++ b/device/bluetooth/bluetooth_service_record.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "device/bluetooth/bluetooth_uuid.h" namespace device { @@ -27,7 +28,7 @@ class BluetoothServiceRecord { // The UUID of the service. This field may be empty if no UUID was // specified in the service record. - const std::string& uuid() const { return uuid_; } + const BluetoothUUID& uuid() const { return uuid_; } // Indicates if this service supports HID. bool SupportsHid() const { return supports_hid_; } @@ -52,7 +53,7 @@ class BluetoothServiceRecord { std::string address_; std::string name_; - std::string uuid_; + BluetoothUUID uuid_; bool supports_hid_; bool hid_reconnect_initiate_; diff --git a/device/bluetooth/bluetooth_service_record_mac.mm b/device/bluetooth/bluetooth_service_record_mac.mm index 306d5e5..ee61b97 100644 --- a/device/bluetooth/bluetooth_service_record_mac.mm +++ b/device/bluetooth/bluetooth_service_record_mac.mm @@ -66,7 +66,9 @@ BluetoothServiceRecordMac::BluetoothServiceRecordMac( [record getAttributeDataElement:service_class_id]; if ([service_class_data getTypeDescriptor] == kBluetoothSDPDataElementTypeDataElementSequence) { - ExtractUuid(service_class_data, &uuid_); + std::string uuid_str; + ExtractUuid(service_class_data, &uuid_str); + uuid_ = BluetoothUUID(uuid_str); } } diff --git a/device/bluetooth/bluetooth_service_record_mac_unittest.mm b/device/bluetooth/bluetooth_service_record_mac_unittest.mm index 22e4d1a..b64ea67 100644 --- a/device/bluetooth/bluetooth_service_record_mac_unittest.mm +++ b/device/bluetooth/bluetooth_service_record_mac_unittest.mm @@ -13,6 +13,7 @@ #include "base/basictypes.h" #include "base/strings/string_number_conversions.h" #include "base/strings/sys_string_conversions.h" +#include "device/bluetooth/bluetooth_uuid.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -25,8 +26,9 @@ const BluetoothSDPServiceAttributeID kServiceNameAttributeId = 0x0100; const uint8 kRfcommChannel = 0x0c; const char kServiceName[] = "Headset Audio Gateway"; -const char kExpectedRfcommUuid[] = "01234567-89ab-cdef-0123-456789abcdef"; -const char kExpectedSerialUuid[] = "00001101-0000-1000-8000-00805f9b34fb"; +const device::BluetoothUUID kExpectedRfcommUuid( + "01234567-89ab-cdef-0123-456789abcdef"); +const device::BluetoothUUID kExpectedSerialUuid("1101"); const int kMaxUuidSize = 16; @@ -146,7 +148,7 @@ TEST_F(BluetoothServiceRecordMacTest, UpperCaseUuid) { TEST_F(BluetoothServiceRecordMacTest, InvalidUuid) { BluetoothServiceRecordMac record(GetServiceRecord(nil, false)); - EXPECT_EQ("", record.uuid()); + EXPECT_FALSE(record.uuid().IsValid()); } } // namespace device diff --git a/device/bluetooth/bluetooth_service_record_win.cc b/device/bluetooth/bluetooth_service_record_win.cc index e0ba750..48f8723 100644 --- a/device/bluetooth/bluetooth_service_record_win.cc +++ b/device/bluetooth/bluetooth_service_record_win.cc @@ -10,7 +10,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "device/bluetooth/bluetooth_init_win.h" -#include "device/bluetooth/bluetooth_utils.h" +#include "device/bluetooth/bluetooth_uuid.h" namespace { @@ -61,7 +61,8 @@ void ExtractChannels(const SDP_ELEMENT_DATA& protocol_descriptor_list_data, } } -void ExtractUuid(const SDP_ELEMENT_DATA& uuid_data, std::string* uuid) { +void ExtractUuid(const SDP_ELEMENT_DATA& uuid_data, + device::BluetoothUUID* uuid) { HBLUETOOTH_CONTAINER_ELEMENT inner_uuid_element = NULL; SDP_ELEMENT_DATA inner_uuid_data; if (AdvanceToSdpType(uuid_data, @@ -71,13 +72,13 @@ void ExtractUuid(const SDP_ELEMENT_DATA& uuid_data, std::string* uuid) { if (inner_uuid_data.specificType == SDP_ST_UUID16) { std::string uuid_hex = base::StringPrintf("%04x", inner_uuid_data.data.uuid16); - *uuid = device::bluetooth_utils::CanonicalUuid(uuid_hex); + *uuid = device::BluetoothUUID(uuid_hex); } else if (inner_uuid_data.specificType == SDP_ST_UUID32) { std::string uuid_hex = base::StringPrintf("%08x", inner_uuid_data.data.uuid32); - *uuid = device::bluetooth_utils::CanonicalUuid(uuid_hex); + *uuid = device::BluetoothUUID(uuid_hex); } else if (inner_uuid_data.specificType == SDP_ST_UUID128) { - *uuid = base::StringPrintf( + *uuid = device::BluetoothUUID(base::StringPrintf( "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", inner_uuid_data.data.uuid128.Data1, inner_uuid_data.data.uuid128.Data2, @@ -89,9 +90,9 @@ void ExtractUuid(const SDP_ELEMENT_DATA& uuid_data, std::string* uuid) { inner_uuid_data.data.uuid128.Data4[4], inner_uuid_data.data.uuid128.Data4[5], inner_uuid_data.data.uuid128.Data4[6], - inner_uuid_data.data.uuid128.Data4[7]); + inner_uuid_data.data.uuid128.Data4[7])); } else { - uuid->clear(); + *uuid = device::BluetoothUUID(); } } } @@ -143,8 +144,8 @@ BluetoothServiceRecordWin::BluetoothServiceRecordWin( blob_size, kUuidId, &uuid_data)) { - ExtractUuid(uuid_data, &uuid_); + ExtractUuid(uuid_data, &uuid_); } } -} // namespace device
\ No newline at end of file +} // namespace device diff --git a/device/bluetooth/bluetooth_service_record_win_unittest.cc b/device/bluetooth/bluetooth_service_record_win_unittest.cc index 804b620..c9d44c6 100644 --- a/device/bluetooth/bluetooth_service_record_win_unittest.cc +++ b/device/bluetooth/bluetooth_service_record_win_unittest.cc @@ -5,6 +5,7 @@ #include "base/basictypes.h" #include "base/strings/string_number_conversions.h" #include "device/bluetooth/bluetooth_service_record_win.h" +#include "device/bluetooth/bluetooth_uuid.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -14,14 +15,14 @@ const char kTestNoRfcommSdpBytes[] = "010209000535031910020900093508350619110d090102090100250c417564696f20536f75" "726365090311090001"; const int kTestNoRfcommSdpBytesSize = sizeof(kTestNoRfcommSdpBytes) / 2; -const char kTestNoRfcommSdpUuid[] = "0000110a-0000-1000-8000-00805f9b34fb"; +const device::BluetoothUUID kTestNoRfcommSdpUuid("110a"); const char kTestRfcommSdpBytes[] = "354b0900000a000100030900013506191112191203090004350c3503190100350519000308" "0b090005350319100209000935083506191108090100090100250d566f6963652047617465" "776179"; const int kTestRfcommSdpBytesSize = sizeof(kTestRfcommSdpBytes) / 2; -const char kTestRfcommSdpUuid[] = "00001112-0000-1000-8000-00805f9b34fb"; +const device::BluetoothUUID kTestRfcommSdpUuid("1112"); const int kTestRfcommChannel = 11; } // namespace @@ -46,7 +47,7 @@ TEST_F(BluetoothServiceRecordWinTest, NoRfcommSdp) { "01:02:03:0A:10:A0", kTestNoRfcommSdpBytesSize, sdp_bytes_array); - EXPECT_STREQ(kTestNoRfcommSdpUuid, service_record.uuid().c_str()); + EXPECT_EQ(kTestNoRfcommSdpUuid, service_record.uuid()); EXPECT_FALSE(service_record.SupportsRfcomm()); } @@ -58,7 +59,7 @@ TEST_F(BluetoothServiceRecordWinTest, RfcommSdp) { "01:02:03:0A:10:A0", kTestRfcommSdpBytesSize, sdp_bytes_array); - EXPECT_STREQ(kTestRfcommSdpUuid, service_record.uuid().c_str()); + EXPECT_EQ(kTestRfcommSdpUuid, service_record.uuid()); EXPECT_TRUE(service_record.SupportsRfcomm()); EXPECT_EQ(kTestRfcommChannel, service_record.rfcomm_channel()); } @@ -73,4 +74,4 @@ TEST_F(BluetoothServiceRecordWinTest, BthAddr) { EXPECT_EQ(1108152553632, service_record.bth_addr()); } -} // namespace device
\ No newline at end of file +} // namespace device diff --git a/device/bluetooth/bluetooth_utils_unittest.cc b/device/bluetooth/bluetooth_utils_unittest.cc deleted file mode 100644 index 07c63b5..0000000 --- a/device/bluetooth/bluetooth_utils_unittest.cc +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) 2012 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. - -#include "base/basictypes.h" -#include "device/bluetooth/bluetooth_utils.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace device { -namespace bluetooth_utils { - -TEST(BluetoothUtilsTest, CanonicalUuid) { - // Does nothing for an already canonical UUID - EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", - CanonicalUuid("00001101-0000-1000-8000-00805f9b34fb")); - - // Rejects misformatted - EXPECT_EQ("", CanonicalUuid("1101a")); - EXPECT_EQ("", CanonicalUuid("Z101")); - EXPECT_EQ("", CanonicalUuid("0000-1101")); - EXPECT_EQ("", CanonicalUuid("0000Z101")); - EXPECT_EQ("", CanonicalUuid("0001101-0000-1000-8000-00805f9b34fb")); - EXPECT_EQ("", CanonicalUuid("Z0001101-0000-1000-8000-00805f9b34fb")); - EXPECT_EQ("", CanonicalUuid("00001101 0000-1000-8000-00805f9b34fb")); - EXPECT_EQ("", CanonicalUuid("00001101-0000:1000-8000-00805f9b34fb")); - EXPECT_EQ("", CanonicalUuid("00001101-0000-1000;8000-00805f9b34fb")); - EXPECT_EQ("", CanonicalUuid("00001101-0000-1000-8000000805f9b34fb")); - - // Lower case - EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", - CanonicalUuid("00001101-0000-1000-8000-00805F9B34FB")); - - // Short to full - EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", - CanonicalUuid("1101")); - EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", - CanonicalUuid("0x1101")); - EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", - CanonicalUuid("00001101")); - EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", - CanonicalUuid("0x00001101")); - - // No 0x prefix on 36 character - EXPECT_EQ("", CanonicalUuid("0x00001101-0000-1000-8000-00805f9b34fb")); -} - -TEST(BluetoothUtilsTest, UUID) { - const char kValid128Bit0[] = "12345678-1234-5678-9abc-def123456789"; - const char kValid128Bit1[] = "00001101-0000-1000-8000-00805f9b34fb"; - const char kInvalid36Char[] = "1234567-1234-5678-9abc-def123456789"; - const char kInvalid4Char[] = "Z101"; - const char kValid16Bit[] = "0x1101"; - const char kValid32Bit[] = "00001101"; - - // Valid 128-bit custom UUID. - UUID uuid0(kValid128Bit0); - EXPECT_TRUE(uuid0.IsValid()); - EXPECT_EQ(UUID::kFormat128Bit, uuid0.format()); - EXPECT_EQ(uuid0.value(), uuid0.canonical_value()); - - // Valid 128-bit UUID. - UUID uuid1(kValid128Bit1); - EXPECT_TRUE(uuid1.IsValid()); - EXPECT_EQ(UUID::kFormat128Bit, uuid1.format()); - EXPECT_EQ(uuid1.value(), uuid1.canonical_value()); - - EXPECT_NE(uuid0, uuid1); - - // Invalid 128-bit UUID. - UUID uuid2(kInvalid36Char); - EXPECT_FALSE(uuid2.IsValid()); - EXPECT_EQ(UUID::kFormatInvalid, uuid2.format()); - EXPECT_TRUE(uuid2.value().empty()); - EXPECT_TRUE(uuid2.canonical_value().empty()); - - // Invalid 16-bit UUID. - UUID uuid3(kInvalid4Char); - EXPECT_FALSE(uuid3.IsValid()); - EXPECT_EQ(UUID::kFormatInvalid, uuid3.format()); - EXPECT_TRUE(uuid3.value().empty()); - EXPECT_TRUE(uuid3.canonical_value().empty()); - - // Valid 16-bit UUID. - UUID uuid4(kValid16Bit); - EXPECT_TRUE(uuid4.IsValid()); - EXPECT_EQ(UUID::kFormat16Bit, uuid4.format()); - EXPECT_NE(uuid4.value(), uuid4.canonical_value()); - EXPECT_EQ("1101", uuid4.value()); - EXPECT_EQ(kValid128Bit1, uuid4.canonical_value()); - - // Valid 32-bit UUID. - UUID uuid5(kValid32Bit); - EXPECT_TRUE(uuid5.IsValid()); - EXPECT_EQ(UUID::kFormat32Bit, uuid5.format()); - EXPECT_NE(uuid5.value(), uuid5.canonical_value()); - EXPECT_EQ("00001101", uuid5.value()); - EXPECT_EQ(kValid128Bit1, uuid5.canonical_value()); - - // uuid4, uuid5, and uuid1 are equivalent. - EXPECT_EQ(uuid4, uuid5); - EXPECT_EQ(uuid1, uuid4); - EXPECT_EQ(uuid1, uuid5); -} - -} // namespace bluetooth_utils -} // namespace device diff --git a/device/bluetooth/bluetooth_utils.cc b/device/bluetooth/bluetooth_uuid.cc index b874736..a62da21 100644 --- a/device/bluetooth/bluetooth_utils.cc +++ b/device/bluetooth/bluetooth_uuid.cc @@ -1,17 +1,14 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#include "device/bluetooth/bluetooth_utils.h" - -#include <vector> +#include "device/bluetooth/bluetooth_uuid.h" #include "base/basictypes.h" #include "base/logging.h" #include "base/strings/string_util.h" namespace device { -namespace bluetooth_utils { namespace { @@ -24,11 +21,11 @@ const int kUuidSize = 36; void GetCanonicalUuid(std::string uuid, std::string* canonical, std::string* canonical_128, - UUID::Format* format) { + BluetoothUUID::Format* format) { // Initialize the values for the failure case. canonical->clear(); canonical_128->clear(); - *format = UUID::kFormatInvalid; + *format = BluetoothUUID::kFormatInvalid; if (uuid.empty()) return; @@ -47,12 +44,12 @@ void GetCanonicalUuid(std::string uuid, if (uuid.size() == 4) { canonical->assign(uuid); canonical_128->assign(kCommonUuidPrefix + uuid + kCommonUuidPostfix); - *format = UUID::kFormat16Bit; + *format = BluetoothUUID::kFormat16Bit; return; } canonical->assign(uuid); canonical_128->assign(uuid + kCommonUuidPostfix); - *format = UUID::kFormat32Bit; + *format = BluetoothUUID::kFormat32Bit; return; } @@ -69,42 +66,36 @@ void GetCanonicalUuid(std::string uuid, canonical->assign(uuid); canonical_128->assign(uuid); - *format = UUID::kFormat128Bit; + *format = BluetoothUUID::kFormat128Bit; } } // namespace -UUID::UUID(const std::string& uuid) { +BluetoothUUID::BluetoothUUID(const std::string& uuid) { GetCanonicalUuid(uuid, &value_, &canonical_value_, &format_); } -UUID::~UUID() { +BluetoothUUID::BluetoothUUID() : format_(kFormatInvalid) { +} + +BluetoothUUID::~BluetoothUUID() { } -bool UUID::IsValid() const { +bool BluetoothUUID::IsValid() const { return format_ != kFormatInvalid; } -bool UUID::operator<(const UUID& uuid) const { +bool BluetoothUUID::operator<(const BluetoothUUID& uuid) const { return canonical_value_ < uuid.canonical_value_; } -bool UUID::operator==(const UUID& uuid) const { +bool BluetoothUUID::operator==(const BluetoothUUID& uuid) const { return canonical_value_ == uuid.canonical_value_; } -bool UUID::operator!=(const UUID& uuid) const { +bool BluetoothUUID::operator!=(const BluetoothUUID& uuid) const { return canonical_value_ != uuid.canonical_value_; } -std::string CanonicalUuid(std::string uuid) { - std::string value; - std::string canonical_value; - UUID::Format format; - GetCanonicalUuid(uuid, &value, &canonical_value, &format); - return canonical_value; -} - -} // namespace bluetooth_utils } // namespace device diff --git a/device/bluetooth/bluetooth_utils.h b/device/bluetooth/bluetooth_uuid.h index 1f9a2c9..282c8ba 100644 --- a/device/bluetooth/bluetooth_utils.h +++ b/device/bluetooth/bluetooth_uuid.h @@ -1,23 +1,20 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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 DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_ -#define DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_ +#ifndef DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_ +#define DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_ #include <string> -#include "base/basictypes.h" - namespace device { -namespace bluetooth_utils { // Opaque wrapper around a Bluetooth UUID. Instances of UUID represent the // 128-bit universally unique identifiers (UUIDs) of profiles and attributes // used in Bluetooth based communication, such as a peripheral's services, // characteristics, and characteristic descriptors. An instance are // constructed using a string representing 16, 32, or 128 bit UUID formats. -class UUID { +class BluetoothUUID { public: // Possible representation formats used during construction. enum Format { @@ -41,8 +38,14 @@ class UUID { // should be provided in the 128-bit format. If |uuid| is in an unsupported // format, the result might be invalid. Use IsValid to check for validity // after construction. - explicit UUID(const std::string& uuid); - ~UUID(); + explicit BluetoothUUID(const std::string& uuid); + + // Default constructor does nothing. Since BluetoothUUID is copyable, this + // constructor is useful for initializing member variables and assigning a + // value to them later. The default constructor will initialize an invalid + // UUID by definition and the string accessors will return an empty string. + BluetoothUUID(); + virtual ~BluetoothUUID(); // Returns true, if the UUID is in a valid canonical format. bool IsValid() const; @@ -67,11 +70,11 @@ class UUID { // Permit sufficient comparison to allow a UUID to be used as a key in a // std::map. - bool operator<(const UUID& uuid) const; + bool operator<(const BluetoothUUID& uuid) const; // Equality operators. - bool operator==(const UUID& uuid) const; - bool operator!=(const UUID& uuid) const; + bool operator==(const BluetoothUUID& uuid) const; + bool operator!=(const BluetoothUUID& uuid) const; private: // String representation of the UUID that was used during construction. For @@ -86,21 +89,6 @@ class UUID { std::string canonical_value_; }; -// DEPRECATED. Use bluetooth_utils::UUID instead. -// -// Takes a 4, 8 or 36 character UUID, validates it and returns it in 36 -// character format with all hex digits lower case. If |uuid| is invalid, the -// empty string is returned. -// -// Valid inputs are: -// XXXX -// 0xXXXX -// XXXXXXXX -// 0xXXXXXXXX -// XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -std::string CanonicalUuid(std::string uuid); - -} // namespace bluetooth_utils } // namespace device -#endif // DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_ +#endif // DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_ diff --git a/device/bluetooth/bluetooth_uuid_unittest.cc b/device/bluetooth/bluetooth_uuid_unittest.cc new file mode 100644 index 0000000..d4838bb --- /dev/null +++ b/device/bluetooth/bluetooth_uuid_unittest.cc @@ -0,0 +1,76 @@ +// Copyright 2014 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. + +#include "device/bluetooth/bluetooth_uuid.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace device { + +TEST(BluetoothUUIDTest, MainTest) { + const char kValid128Bit0[] = "12345678-1234-5678-9abc-def123456789"; + const char kValid128Bit1[] = "00001101-0000-1000-8000-00805f9b34fb"; + const char kInvalid36Char0[] = "1234567-1234-5678-9abc-def123456789"; + const char kInvalid36Char1[] = "0x00001101-0000-1000-8000-00805f9b34fb"; + const char kInvalid4Char[] = "Z101"; + const char kValid16Bit[] = "0x1101"; + const char kValid32Bit[] = "00001101"; + + // Valid 128-bit custom UUID. + BluetoothUUID uuid0(kValid128Bit0); + EXPECT_TRUE(uuid0.IsValid()); + EXPECT_EQ(BluetoothUUID::kFormat128Bit, uuid0.format()); + EXPECT_EQ(uuid0.value(), uuid0.canonical_value()); + + // Valid 128-bit UUID. + BluetoothUUID uuid1(kValid128Bit1); + EXPECT_TRUE(uuid1.IsValid()); + EXPECT_EQ(BluetoothUUID::kFormat128Bit, uuid1.format()); + EXPECT_EQ(uuid1.value(), uuid1.canonical_value()); + + EXPECT_NE(uuid0, uuid1); + + // Invalid 128-bit UUID. + BluetoothUUID uuid2(kInvalid36Char0); + EXPECT_FALSE(uuid2.IsValid()); + EXPECT_EQ(BluetoothUUID::kFormatInvalid, uuid2.format()); + EXPECT_TRUE(uuid2.value().empty()); + EXPECT_TRUE(uuid2.canonical_value().empty()); + + // Invalid 128-bit UUID. + BluetoothUUID uuid3(kInvalid36Char1); + EXPECT_FALSE(uuid3.IsValid()); + EXPECT_EQ(BluetoothUUID::kFormatInvalid, uuid3.format()); + EXPECT_TRUE(uuid3.value().empty()); + EXPECT_TRUE(uuid3.canonical_value().empty()); + + // Invalid 16-bit UUID. + BluetoothUUID uuid4(kInvalid4Char); + EXPECT_FALSE(uuid4.IsValid()); + EXPECT_EQ(BluetoothUUID::kFormatInvalid, uuid4.format()); + EXPECT_TRUE(uuid4.value().empty()); + EXPECT_TRUE(uuid4.canonical_value().empty()); + + // Valid 16-bit UUID. + BluetoothUUID uuid5(kValid16Bit); + EXPECT_TRUE(uuid5.IsValid()); + EXPECT_EQ(BluetoothUUID::kFormat16Bit, uuid5.format()); + EXPECT_NE(uuid5.value(), uuid5.canonical_value()); + EXPECT_EQ("1101", uuid5.value()); + EXPECT_EQ(kValid128Bit1, uuid5.canonical_value()); + + // Valid 32-bit UUID. + BluetoothUUID uuid6(kValid32Bit); + EXPECT_TRUE(uuid6.IsValid()); + EXPECT_EQ(BluetoothUUID::kFormat32Bit, uuid6.format()); + EXPECT_NE(uuid6.value(), uuid6.canonical_value()); + EXPECT_EQ("00001101", uuid6.value()); + EXPECT_EQ(kValid128Bit1, uuid6.canonical_value()); + + // uuid5, uuid6, and uuid1 are equivalent. + EXPECT_EQ(uuid5, uuid6); + EXPECT_EQ(uuid1, uuid5); + EXPECT_EQ(uuid1, uuid6); +} + +} // namespace device diff --git a/device/bluetooth/test/mock_bluetooth_device.h b/device/bluetooth/test/mock_bluetooth_device.h index 7c20c00..6bd5707 100644 --- a/device/bluetooth/test/mock_bluetooth_device.h +++ b/device/bluetooth/test/mock_bluetooth_device.h @@ -10,6 +10,7 @@ #include "base/strings/string16.h" #include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" +#include "device/bluetooth/bluetooth_uuid.h" #include "testing/gmock/include/gmock/gmock.h" namespace device { @@ -58,7 +59,7 @@ class MockBluetoothDevice : public BluetoothDevice { const BluetoothDevice::ErrorCallback& error_callback)); MOCK_METHOD1(Forget, void(const BluetoothDevice::ErrorCallback&)); MOCK_METHOD2(ConnectToService, - void(const std::string&, + void(const BluetoothUUID&, const BluetoothDevice::SocketCallback&)); MOCK_METHOD3(ConnectToProfile, void(BluetoothProfile*, diff --git a/device/device_tests.gyp b/device/device_tests.gyp index 0cadffb..36b5826 100644 --- a/device/device_tests.gyp +++ b/device/device_tests.gyp @@ -31,7 +31,7 @@ 'bluetooth/bluetooth_service_record_mac_unittest.mm', 'bluetooth/bluetooth_service_record_win_unittest.cc', 'bluetooth/bluetooth_task_manager_win_unittest.cc', - 'bluetooth/bluetooth_utils_unittest.cc', + 'bluetooth/bluetooth_uuid_unittest.cc', 'nfc/nfc_chromeos_unittest.cc', 'nfc/nfc_ndef_record_unittest.cc', 'usb/usb_ids_unittest.cc', |