diff options
author | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-20 19:11:57 +0000 |
---|---|---|
committer | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-20 19:11:57 +0000 |
commit | 9bf562c43f1890642d1d58b4acbfed43deb0805c (patch) | |
tree | 9a498473aec292c1b1e24bcb23ffaa7923b1c159 | |
parent | 6e6a46c54e75acc9d3fdf8837f4e483e2a35da02 (diff) | |
download | chromium_src-9bf562c43f1890642d1d58b4acbfed43deb0805c.zip chromium_src-9bf562c43f1890642d1d58b4acbfed43deb0805c.tar.gz chromium_src-9bf562c43f1890642d1d58b4acbfed43deb0805c.tar.bz2 |
Bluetooth: replace "profiles" with "uuids"
The set of UUIDs for a given device will, in future, consist of not just
the traditional Profiles found via SDP but also GATT Services found via
primary service discovery as well as profile, protocol and service class
UUIDs advertised in EIR data (classic) or AD (Low Energy).
It therefore makes sense to just refer to these as "uuids" everywhere,
especially since the specific UUID identifies exactly what is meant to
the application developer.
Since EIR and AD are passively received, rather than actively fetched,
make this a property of a device rather than a polled function
Specific changes to the C++ API:
- Renamed BluetoothDevice::GetServices() to GetUUIDs()
- Removed BluetoothDevice::GetServiceRecords()
- Removed BluetoothDevice::ProvicesServiceWithName()
- Removed BluetoothDevice::ProvidesServiceWithUUID()
Specific changes to the JavaScript API:
- Manifest entry changed from "profiles" to "uuids".
- New "uuids" array added to Device object.
- Removed chrome.bluetooth.getProfiles() and getServices().
BUG=339217
TEST=Updated tests included
TBR=mkearney@chromium.org
Review URL: https://codereview.chromium.org/196383033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258368 0039d316-1c4b-4281-b951-d872f2087c98
31 files changed, 129 insertions, 477 deletions
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc index 02a3653..d556a1b 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc @@ -56,7 +56,6 @@ const char kProfileAlreadyRegistered[] = "This profile has already been registered"; const char kProfileNotFound[] = "Profile not found: invalid uuid"; const char kProfileRegistrationFailed[] = "Profile registration failed"; -const char kServiceDiscoveryFailed[] = "Service discovery failed"; const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; const char kStartDiscoveryFailed[] = "Starting discovery failed"; const char kStopDiscoveryFailed[] = "Failed to stop discovery"; @@ -69,8 +68,6 @@ namespace Connect = extensions::api::bluetooth::Connect; namespace Disconnect = extensions::api::bluetooth::Disconnect; namespace GetDevice = extensions::api::bluetooth::GetDevice; namespace GetDevices = extensions::api::bluetooth::GetDevices; -namespace GetProfiles = extensions::api::bluetooth::GetProfiles; -namespace GetServices = extensions::api::bluetooth::GetServices; namespace Read = extensions::api::bluetooth::Read; namespace RemoveProfile = extensions::api::bluetooth::RemoveProfile; namespace SetOutOfBandPairingData = @@ -239,37 +236,6 @@ bool BluetoothRemoveProfileFunction::RunImpl() { return true; } -// TODO(youngki): Implement. -bool BluetoothGetProfilesFunction::DoWork( - scoped_refptr<device::BluetoothAdapter> adapter) { - scoped_ptr<GetProfiles::Params> params(GetProfiles::Params::Create(*args_)); - EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); - const bluetooth::GetProfilesOptions& options = params->options; - - BluetoothDevice* device = adapter->GetDevice(options.device.address); - if (!device) { - SetError(kInvalidDevice); - SendResponse(false); - return false; - } - - BluetoothDevice::ServiceList service_list = device->GetServices(); - - base::ListValue* profiles = new base::ListValue; - for (BluetoothDevice::ServiceList::const_iterator iter = service_list.begin(); - iter != service_list.end(); - ++iter) { - bluetooth::Profile api_profile; - api_profile.uuid = *iter; - profiles->Append(api_profile.ToValue().release()); - } - - SetResult(profiles); - SendResponse(true); - - return true; -} - bool BluetoothGetAdapterStateFunction::DoWork( scoped_refptr<BluetoothAdapter> adapter) { bluetooth::AdapterState state; @@ -326,53 +292,6 @@ bool BluetoothGetDeviceFunction::DoWork( return false; } -void BluetoothGetServicesFunction::GetServiceRecordsCallback( - base::ListValue* services, - const BluetoothDevice::ServiceRecordList& records) { - for (BluetoothDevice::ServiceRecordList::const_iterator i = records.begin(); - i != records.end(); ++i) { - const BluetoothServiceRecord& record = **i; - bluetooth::ServiceRecord api_record; - api_record.name = record.name(); - if (!record.uuid().empty()) - api_record.uuid.reset(new std::string(record.uuid())); - services->Append(api_record.ToValue().release()); - } - - SendResponse(true); -} - -void BluetoothGetServicesFunction::OnErrorCallback() { - SetError(kServiceDiscoveryFailed); - SendResponse(false); -} - -bool BluetoothGetServicesFunction::DoWork( - scoped_refptr<BluetoothAdapter> adapter) { - scoped_ptr<GetServices::Params> params(GetServices::Params::Create(*args_)); - EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); - const bluetooth::GetServicesOptions& options = params->options; - - BluetoothDevice* device = adapter->GetDevice(options.device_address); - if (!device) { - SetError(kInvalidDevice); - SendResponse(false); - return false; - } - - base::ListValue* services = new base::ListValue; - SetResult(services); - - device->GetServiceRecords( - base::Bind(&BluetoothGetServicesFunction::GetServiceRecordsCallback, - this, - services), - base::Bind(&BluetoothGetServicesFunction::OnErrorCallback, - this)); - - return true; -} - void BluetoothConnectFunction::OnSuccessCallback() { SendResponse(true); } diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.h b/chrome/browser/extensions/api/bluetooth/bluetooth_api.h index 87b9ce1..1c405c3 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.h +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.h @@ -101,17 +101,6 @@ class BluetoothRemoveProfileFunction : public SyncExtensionFunction { virtual bool RunImpl() OVERRIDE; }; -class BluetoothGetProfilesFunction : public BluetoothExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("bluetooth.getProfiles", BLUETOOTH_GETPROFILES) - - protected: - virtual ~BluetoothGetProfilesFunction() {} - - // BluetoothExtensionFunction: - virtual bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) OVERRIDE; -}; - class BluetoothGetAdapterStateFunction : public BluetoothExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("bluetooth.getAdapterState", @@ -146,23 +135,6 @@ class BluetoothGetDeviceFunction : public BluetoothExtensionFunction { virtual bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) OVERRIDE; }; -class BluetoothGetServicesFunction : public BluetoothExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("bluetooth.getServices", BLUETOOTH_GETSERVICES) - - protected: - virtual ~BluetoothGetServicesFunction() {} - - // BluetoothExtensionFunction: - virtual bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) OVERRIDE; - - private: - void GetServiceRecordsCallback( - base::ListValue* services, - const device::BluetoothDevice::ServiceRecordList& records); - void OnErrorCallback(); -}; - class BluetoothConnectFunction : public BluetoothExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("bluetooth.connect", BLUETOOTH_CONNECT) diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc index cdbdb39..931dbca 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc @@ -111,6 +111,8 @@ 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())); } 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 8d729bf..0d9062c 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc @@ -569,31 +569,6 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, OnConnection) { event_router()->RemoveProfile("1234"); } -IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetProfiles) { - ResultCatcher catcher; - catcher.RestrictToProfile(browser()->profile()); - - BluetoothDevice::ServiceList service_list; - service_list.push_back("1234"); - service_list.push_back("5678"); - - EXPECT_CALL(*device1_, GetServices()) - .WillOnce(testing::Return(service_list)); - - EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress())) - .WillOnce(testing::Return(device1_.get())); - - // Load and wait for setup - ExtensionTestMessageListener listener("ready", true); - ASSERT_TRUE( - LoadExtension(test_data_dir_.AppendASCII("bluetooth/get_profiles"))); - EXPECT_TRUE(listener.WaitUntilSatisfied()); - - listener.Reply("go"); - - EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); -} - IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); @@ -664,6 +639,13 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DeviceInfo) { EXPECT_CALL(*device1_.get(), GetDeviceID()) .WillRepeatedly(testing::Return(0x0400)); + BluetoothDevice::UUIDList uuids; + uuids.push_back("00001105-0000-1000-8000-00805f9b34fb"); + uuids.push_back("00001106-0000-1000-8000-00805f9b34fb"); + + EXPECT_CALL(*device1_.get(), GetUUIDs()) + .WillOnce(testing::Return(uuids)); + devices.push_back(device1_.get()); // Leave the second largely empty so we can check a device without 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 4d759da..a444d63 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc @@ -220,9 +220,9 @@ TEST_F(ExtensionBluetoothEventRouterTest, DispatchConnectionEvent) { base::DictionaryValue* profile_value = NULL; ASSERT_TRUE(socket_value->GetDictionary("profile", &profile_value)); - std::string profile_uuid; - ASSERT_TRUE(profile_value->GetString("uuid", &profile_uuid)); - EXPECT_STREQ(kAudioProfileUuid, profile_uuid.c_str()); + std::string uuid; + ASSERT_TRUE(profile_value->GetString("uuid", &uuid)); + EXPECT_STREQ(kAudioProfileUuid, uuid.c_str()); EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); router_.ReleaseSocket(socket_id); diff --git a/chrome/common/extensions/api/bluetooth.idl b/chrome/common/extensions/api/bluetooth.idl index 747df71..e66cda1 100644 --- a/chrome/common/extensions/api/bluetooth.idl +++ b/chrome/common/extensions/api/bluetooth.idl @@ -58,6 +58,13 @@ namespace bluetooth { // Indicates whether the device is currently connected to the system. boolean? connected; + + // UUIDs of protocols, profiles and services advertised by the device. + // For classic Bluetooth devices, this list is obtained from EIR data and + // SDP tables. For Low Energy devices, this list is obtained from AD and + // GATT primary services. For dual mode devices this may be obtained from + // both. + DOMString[]? uuids; }; dictionary Profile { @@ -132,25 +139,10 @@ namespace bluetooth { callback DevicesCallback = void(Device[] result); callback NameCallback = void(DOMString result); callback OutOfBandPairingDataCallback = void(OutOfBandPairingData data); - callback ProfilesCallback = void(Profile[] result); callback ResultCallback = void(); - callback ServicesCallback = void(ServiceRecord[] result); callback SizeCallback = void(long result); callback SocketCallback = void(Socket result); - // Options for the getProfiles function. - dictionary GetProfilesOptions { - // The remote Bluetooth device to retrieve the exported profiles list from. - Device device; - }; - - // Options for the getServices function. - dictionary GetServicesOptions { - // The address of the device to inquire about. |deviceAddress| should be - // in the format 'XX:XX:XX:XX:XX:XX'. - DOMString deviceAddress; - }; - // Options for the connect function. dictionary ConnectOptions { // The connection is made to |device|. @@ -218,15 +210,6 @@ namespace bluetooth { // |callback| : Called with the Device object describing the device. static void getDevice(DOMString deviceAddress, DeviceCallback callback); - // Returns the set of exported profiles for the device specified in options. - // This function will not initiate a connection to the remote device. - static void getProfiles(GetProfilesOptions options, - ProfilesCallback callback); - - // Get a list of services provided by a device. - static void getServices(GetServicesOptions options, - ServicesCallback callback); - // Connect to a service on a device. // |options| : The options for the connection. // |callback| : Called to indicate success or failure. diff --git a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.cc b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.cc index 237dddb..0b0bb58 100644 --- a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.cc +++ b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.cc @@ -45,8 +45,8 @@ scoped_ptr<BluetoothManifestData> BluetoothManifestData::FromValue( } BluetoothPermissionRequest::BluetoothPermissionRequest( - const std::string& profile_uuid) - : profile_uuid(profile_uuid) {} + const std::string& uuid) + : uuid(uuid) {} BluetoothPermissionRequest::~BluetoothPermissionRequest() {} diff --git a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h index db7f108..f009be8 100644 --- a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h +++ b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h @@ -47,10 +47,10 @@ class BluetoothManifestData : public Extension::ManifestData { // Used for checking bluetooth permission. struct BluetoothPermissionRequest { - explicit BluetoothPermissionRequest(const std::string& profile_uuid); + explicit BluetoothPermissionRequest(const std::string& uuid); ~BluetoothPermissionRequest(); - std::string profile_uuid; + std::string uuid; }; } // namespace extensions diff --git a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.cc b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.cc index 4588b6a..4b46256 100644 --- a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.cc +++ b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.cc @@ -21,7 +21,7 @@ namespace extensions { namespace bluetooth_errors { -const char kErrorInvalidProfileUuid[] = "Invalid UUID '*'"; +const char kErrorInvalidUuid[] = "Invalid UUID '*'"; } namespace errors = bluetooth_errors; @@ -29,24 +29,23 @@ namespace errors = bluetooth_errors; namespace { bool ParseUuid(BluetoothManifestPermission* permission, - const std::string& profile_uuid, + const std::string& uuid, base::string16* error) { - std::string canonical_uuid = - device::bluetooth_utils::CanonicalUuid(profile_uuid); + std::string canonical_uuid = device::bluetooth_utils::CanonicalUuid(uuid); if (canonical_uuid.empty()) { *error = ErrorUtils::FormatErrorMessageUTF16( - errors::kErrorInvalidProfileUuid, profile_uuid); + errors::kErrorInvalidUuid, uuid); return false; } - permission->AddPermission(profile_uuid); + permission->AddPermission(uuid); return true; } bool ParseUuidArray(BluetoothManifestPermission* permission, - const scoped_ptr<std::vector<std::string> >& profiles, + const scoped_ptr<std::vector<std::string> >& uuids, base::string16* error) { - for (std::vector<std::string>::const_iterator it = profiles->begin(); - it != profiles->end(); + for (std::vector<std::string>::const_iterator it = uuids->begin(); + it != uuids->end(); ++it) { if (!ParseUuid(permission, *it, error)) { return false; @@ -72,8 +71,8 @@ scoped_ptr<BluetoothManifestPermission> BluetoothManifestPermission::FromValue( scoped_ptr<BluetoothManifestPermission> result( new BluetoothManifestPermission()); - if (bluetooth->profiles) { - if (!ParseUuidArray(result.get(), bluetooth->profiles, error)) { + if (bluetooth->uuids) { + if (!ParseUuidArray(result.get(), bluetooth->uuids, error)) { return scoped_ptr<BluetoothManifestPermission>(); } } @@ -85,9 +84,9 @@ bool BluetoothManifestPermission::CheckRequest( const BluetoothPermissionRequest& request) const { std::string canonical_param_uuid = - device::bluetooth_utils::CanonicalUuid(request.profile_uuid); - for (BluetoothProfileUuidSet::const_iterator it = profile_uuids_.begin(); - it != profile_uuids_.end(); + device::bluetooth_utils::CanonicalUuid(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) @@ -112,7 +111,7 @@ PermissionMessages BluetoothManifestPermission::GetMessages() const { PermissionMessage::kBluetooth, l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH))); - if (!profile_uuids_.empty()) { + if (!uuids_.empty()) { result.push_back( PermissionMessage(PermissionMessage::kBluetoothDevices, l10n_util::GetStringUTF16( @@ -132,21 +131,21 @@ bool BluetoothManifestPermission::FromValue(const base::Value* value) { if (!manifest_permission) return false; - profile_uuids_ = manifest_permission->profile_uuids_; + uuids_ = manifest_permission->uuids_; return true; } scoped_ptr<base::Value> BluetoothManifestPermission::ToValue() const { api::manifest_types::Bluetooth bluetooth; - bluetooth.profiles.reset(new std::vector<std::string>(profile_uuids_.begin(), - profile_uuids_.end())); + bluetooth.uuids.reset(new std::vector<std::string>(uuids_.begin(), + uuids_.end())); return bluetooth.ToValue().PassAs<base::Value>(); } ManifestPermission* BluetoothManifestPermission::Clone() const { scoped_ptr<BluetoothManifestPermission> result( new BluetoothManifestPermission()); - result->profile_uuids_ = profile_uuids_; + result->uuids_ = uuids_; return result.release(); } @@ -157,8 +156,8 @@ ManifestPermission* BluetoothManifestPermission::Diff( scoped_ptr<BluetoothManifestPermission> result( new BluetoothManifestPermission()); - result->profile_uuids_ = base::STLSetDifference<BluetoothProfileUuidSet>( - profile_uuids_, other->profile_uuids_); + result->uuids_ = base::STLSetDifference<BluetoothUuidSet>( + uuids_, other->uuids_); return result.release(); } @@ -169,8 +168,8 @@ ManifestPermission* BluetoothManifestPermission::Union( scoped_ptr<BluetoothManifestPermission> result( new BluetoothManifestPermission()); - result->profile_uuids_ = base::STLSetUnion<BluetoothProfileUuidSet>( - profile_uuids_, other->profile_uuids_); + result->uuids_ = base::STLSetUnion<BluetoothUuidSet>( + uuids_, other->uuids_); return result.release(); } @@ -181,8 +180,8 @@ ManifestPermission* BluetoothManifestPermission::Intersect( scoped_ptr<BluetoothManifestPermission> result( new BluetoothManifestPermission()); - result->profile_uuids_ = base::STLSetIntersection<BluetoothProfileUuidSet>( - profile_uuids_, other->profile_uuids_); + result->uuids_ = base::STLSetIntersection<BluetoothUuidSet>( + uuids_, other->uuids_); return result.release(); } @@ -191,32 +190,31 @@ bool BluetoothManifestPermission::Contains(const ManifestPermission* rhs) const BluetoothManifestPermission* other = static_cast<const BluetoothManifestPermission*>(rhs); - return base::STLIncludes(profile_uuids_, other->profile_uuids_); + return base::STLIncludes(uuids_, other->uuids_); } bool BluetoothManifestPermission::Equal(const ManifestPermission* rhs) const { const BluetoothManifestPermission* other = static_cast<const BluetoothManifestPermission*>(rhs); - return (profile_uuids_ == other->profile_uuids_); + return (uuids_ == other->uuids_); } void BluetoothManifestPermission::Write(IPC::Message* m) const { - IPC::WriteParam(m, profile_uuids_); + IPC::WriteParam(m, uuids_); } bool BluetoothManifestPermission::Read(const IPC::Message* m, PickleIterator* iter) { - return IPC::ReadParam(m, iter, &profile_uuids_); + return IPC::ReadParam(m, iter, &uuids_); } void BluetoothManifestPermission::Log(std::string* log) const { - IPC::LogParam(profile_uuids_, log); + IPC::LogParam(uuids_, log); } -void BluetoothManifestPermission::AddPermission( - const std::string& profile_uuid) { - profile_uuids_.insert(profile_uuid); +void BluetoothManifestPermission::AddPermission(const std::string& uuid) { + uuids_.insert(uuid); } } // namespace extensions diff --git a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.h b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.h index f9b7603..b4d997c 100644 --- a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.h +++ b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.h @@ -23,7 +23,7 @@ namespace extensions { class BluetoothManifestPermission : public ManifestPermission { public: - typedef std::set<std::string> BluetoothProfileUuidSet; + typedef std::set<std::string> BluetoothUuidSet; BluetoothManifestPermission(); virtual ~BluetoothManifestPermission(); @@ -36,7 +36,7 @@ class BluetoothManifestPermission : public ManifestPermission { bool CheckRequest(const Extension* extension, const BluetoothPermissionRequest& request) const; - void AddPermission(const std::string& profile_uuid); + void AddPermission(const std::string& uuid); // extensions::ManifestPermission overrides. virtual std::string name() const OVERRIDE; @@ -58,12 +58,12 @@ class BluetoothManifestPermission : public ManifestPermission { virtual bool Read(const IPC::Message* m, PickleIterator* iter) OVERRIDE; virtual void Log(std::string* log) const OVERRIDE; - const BluetoothProfileUuidSet& profile_uuids() const { - return profile_uuids_; + const BluetoothUuidSet& uuids() const { + return uuids_; } private: - BluetoothProfileUuidSet profile_uuids_; + BluetoothUuidSet uuids_; }; } // namespace extensions diff --git a/chrome/common/extensions/api/manifest_types.json b/chrome/common/extensions/api/manifest_types.json index ff0352f..d5f19d9 100644 --- a/chrome/common/extensions/api/manifest_types.json +++ b/chrome/common/extensions/api/manifest_types.json @@ -240,14 +240,14 @@ { "id": "bluetooth", "type": "object", - "description": "The <code>bluetooth</code> manifest property give permission to an app to use the $ref:bluetooth API. A list of profile IDs can be optionally specified to enable communication with specific device types", + "description": "The <code>bluetooth</code> manifest property give permission to an app to use the $ref:bluetooth API. A list of UUIDs can be optionally specified to enable communication with devices.", "properties": { - "profiles": { - "description": "The <code>profiles</code> manifest property declares the list of profiles an app can register.", + "uuids": { + "description": "The <code>uuids</code> manifest property declares the list of protocols, profiles and services that an app can communicate using.", "optional": true, "type": "array", "items": { - "description": "<p>The list of profiles specified as UUID strings.</p>", + "description": "<p>The list specified as UUID strings.</p>", "type": "string" } } diff --git a/chrome/common/extensions/docs/templates/articles/app_bluetooth.html b/chrome/common/extensions/docs/templates/articles/app_bluetooth.html index 4cdeac47..2c24ded 100644 --- a/chrome/common/extensions/docs/templates/articles/app_bluetooth.html +++ b/chrome/common/extensions/docs/templates/articles/app_bluetooth.html @@ -15,19 +15,20 @@ <p> For Chrome Apps that use Bluetooth, add the <a href="manifest/bluetooth.html">bluetooth</a> entry to the manifest - and specify, if appropriate, the UUIDs of profiles you wish to implement. + and specify, if appropriate, the UUIDs of profiles, protocols or services + you wish to implement. For example: </p> <pre data-filename="manifest.json"> "bluetooth": { - "profiles": [ "1105", "1106" ] + "uuids": [ "1105", "1106" ] } </pre> <p> To only access adapter state, discover nearby devices, and obtain basic - information about devices, omit the <code>profiles</code> list. + information about devices, omit the <code>uuids</code> list. </p> <h2 id="adapter_state">Obtaining adapter state</h2> diff --git a/chrome/common/extensions/docs/templates/articles/manifest/bluetooth.html b/chrome/common/extensions/docs/templates/articles/manifest/bluetooth.html index cc1796d..a40f860 100644 --- a/chrome/common/extensions/docs/templates/articles/manifest/bluetooth.html +++ b/chrome/common/extensions/docs/templates/articles/manifest/bluetooth.html @@ -11,10 +11,10 @@ available for the $ref:bluetooth API. "name": "My Bluetooth {{platform}}", "bluetooth": { // Permission for chrome.bluetooth.addProfile: - // The application is allowed to make and receive connections - // implementing the profiles identified by the UUIDs + // The application is allowed to communicate with devices using the + // protocols, profiles or services identified by the UUIDs // 0x1105 and 0x1106. - "profiles": [ "1105", "1106" ] + "uuids": [ "1105", "1106" ] }, ... } diff --git a/chrome/common/extensions/docs/templates/json/manifest.json b/chrome/common/extensions/docs/templates/json/manifest.json index 2c098c6..18c94b0 100644 --- a/chrome/common/extensions/docs/templates/json/manifest.json +++ b/chrome/common/extensions/docs/templates/json/manifest.json @@ -19,7 +19,7 @@ "bluetooth": { "documentation": "manifest/bluetooth.html", "example": { - "profiles": [ "1105", "1006" ] + "uuids": [ "1105", "1006" ] } }, "browser_action": { diff --git a/chrome/test/data/extensions/api_test/bluetooth/device_info/runtest.js b/chrome/test/data/extensions/api_test/bluetooth/device_info/runtest.js index 6e1feea..be22e16 100644 --- a/chrome/test/data/extensions/api_test/bluetooth/device_info/runtest.js +++ b/chrome/test/data/extensions/api_test/bluetooth/device_info/runtest.js @@ -13,6 +13,12 @@ function testDeviceInfo() { chrome.test.assertEq(0x0400, devices[0].deviceId); chrome.test.assertEq('computer', devices[0].type); + chrome.test.assertEq(2, devices[0].uuids.length); + chrome.test.assertEq('00001105-0000-1000-8000-00805f9b34fb', + devices[0].uuids[0]); + chrome.test.assertEq('00001106-0000-1000-8000-00805f9b34fb', + devices[0].uuids[1]); + chrome.test.assertEq('d2', devices[1].name); chrome.test.assertEq(0, devices[1].deviceClass); chrome.test.assertEq(undefined, devices[1].vendorIdSource); @@ -20,6 +26,7 @@ function testDeviceInfo() { chrome.test.assertEq(undefined, devices[1].productId); chrome.test.assertEq(undefined, devices[1].deviceId); chrome.test.assertEq(undefined, devices[1].type); + chrome.test.assertEq(0, devices[1].uuids.length); chrome.test.succeed(); } diff --git a/chrome/test/data/extensions/api_test/bluetooth/get_profiles/manifest.json b/chrome/test/data/extensions/api_test/bluetooth/get_profiles/manifest.json deleted file mode 100644 index def4ade..0000000 --- a/chrome/test/data/extensions/api_test/bluetooth/get_profiles/manifest.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "manifest_version": 2, - "name": "Test the Bluetooth getProfiles API", - "version": "1.0", - "app": { - "background": { - "scripts": ["runtest.js"] - } - }, - "bluetooth": {} -} diff --git a/chrome/test/data/extensions/api_test/bluetooth/get_profiles/runtest.js b/chrome/test/data/extensions/api_test/bluetooth/get_profiles/runtest.js deleted file mode 100644 index f221231..0000000 --- a/chrome/test/data/extensions/api_test/bluetooth/get_profiles/runtest.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2013 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. - -function testGetProfiles() { - chrome.test.assertEq(2, profiles.length); - chrome.test.assertEq('1234', profiles[0].uuid); - chrome.test.assertEq('5678', profiles[1].uuid); - chrome.test.succeed(); -} - -var profiles = []; - -function failOnError() { - if (chrome.runtime.lastError) { - chrome.test.fail(chrome.runtime.lastError.message); - } -} - -chrome.bluetooth.getProfiles( - { - device: { - address: '11:12:13:14:15:16' - } - }, - function(results) { - failOnError(); - profiles = results; - chrome.test.sendMessage('ready', - function(message) { - chrome.test.runTests([testGetProfiles]); - }); - }); diff --git a/chrome/test/data/extensions/api_test/bluetooth/on_connection/manifest.json b/chrome/test/data/extensions/api_test/bluetooth/on_connection/manifest.json index cc70491..e02c787 100644 --- a/chrome/test/data/extensions/api_test/bluetooth/on_connection/manifest.json +++ b/chrome/test/data/extensions/api_test/bluetooth/on_connection/manifest.json @@ -8,5 +8,5 @@ "scripts": ["runtest.js"] } }, - "bluetooth": { "profiles": ["1234"] } + "bluetooth": { "uuids": ["1234"] } } diff --git a/chrome/test/data/extensions/api_test/bluetooth/profiles/manifest.json b/chrome/test/data/extensions/api_test/bluetooth/profiles/manifest.json index 58f3ccb..9d56ec3 100644 --- a/chrome/test/data/extensions/api_test/bluetooth/profiles/manifest.json +++ b/chrome/test/data/extensions/api_test/bluetooth/profiles/manifest.json @@ -9,7 +9,7 @@ } }, "bluetooth": { - "profiles": [ + "uuids": [ "1234", "5678" ] diff --git a/device/bluetooth/bluetooth_chromeos_unittest.cc b/device/bluetooth/bluetooth_chromeos_unittest.cc index ca5ff03..b7733dd 100644 --- a/device/bluetooth/bluetooth_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_chromeos_unittest.cc @@ -1446,7 +1446,7 @@ TEST_F(BluetoothChromeOSTest, DeviceProperties) { // Non HID devices are always connectable. EXPECT_TRUE(devices[0]->IsConnectable()); - BluetoothDevice::ServiceList uuids = devices[0]->GetServices(); + 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"); @@ -1521,7 +1521,7 @@ TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) { ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, devices[0]->GetAddress()); - BluetoothDevice::ServiceList uuids = devices[0]->GetServices(); + 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"); @@ -1544,7 +1544,7 @@ TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) { EXPECT_EQ(devices[0], observer.last_device_); // Fetching the value should give the new one. - uuids = devices[0]->GetServices(); + 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"); @@ -1698,7 +1698,7 @@ TEST_F(BluetoothChromeOSTest, ConnectUnpairableDevice) { EXPECT_TRUE(properties->trusted.value()); // Verify is a HID device and is not connectable. - BluetoothDevice::ServiceList uuids = device->GetServices(); + BluetoothDevice::UUIDList uuids = device->GetUUIDs(); ASSERT_EQ(1U, uuids.size()); EXPECT_EQ(uuids[0], "00001124-0000-1000-8000-00805f9b34fb"); EXPECT_FALSE(device->IsConnectable()); @@ -1888,7 +1888,7 @@ TEST_F(BluetoothChromeOSTest, PairLegacyAutopair) { EXPECT_TRUE(device->IsPaired()); // Verify is a HID device and is connectable. - BluetoothDevice::ServiceList uuids = device->GetServices(); + BluetoothDevice::UUIDList uuids = device->GetUUIDs(); ASSERT_EQ(1U, uuids.size()); EXPECT_EQ(uuids[0], "00001124-0000-1000-8000-00805f9b34fb"); EXPECT_TRUE(device->IsConnectable()); @@ -1944,7 +1944,7 @@ TEST_F(BluetoothChromeOSTest, PairDisplayPinCode) { EXPECT_TRUE(device->IsPaired()); // Verify is a HID device and is connectable. - BluetoothDevice::ServiceList uuids = device->GetServices(); + BluetoothDevice::UUIDList uuids = device->GetUUIDs(); ASSERT_EQ(1U, uuids.size()); EXPECT_EQ(uuids[0], "00001124-0000-1000-8000-00805f9b34fb"); EXPECT_TRUE(device->IsConnectable()); @@ -2020,7 +2020,7 @@ TEST_F(BluetoothChromeOSTest, PairDisplayPasskey) { EXPECT_TRUE(device->IsPaired()); // Verify is a HID device. - BluetoothDevice::ServiceList uuids = device->GetServices(); + BluetoothDevice::UUIDList uuids = device->GetUUIDs(); ASSERT_EQ(1U, uuids.size()); EXPECT_EQ(uuids[0], "00001124-0000-1000-8000-00805f9b34fb"); @@ -2078,7 +2078,7 @@ TEST_F(BluetoothChromeOSTest, PairRequestPinCode) { EXPECT_TRUE(device->IsPaired()); // Verify is not a HID device. - BluetoothDevice::ServiceList uuids = device->GetServices(); + BluetoothDevice::UUIDList uuids = device->GetUUIDs(); ASSERT_EQ(0U, uuids.size()); // Non HID devices are always connectable. diff --git a/device/bluetooth/bluetooth_device.cc b/device/bluetooth/bluetooth_device.cc index 7c100ec..6916f8b 100644 --- a/device/bluetooth/bluetooth_device.cc +++ b/device/bluetooth/bluetooth_device.cc @@ -174,17 +174,4 @@ bool BluetoothDevice::IsPairable() const { return true; } -bool BluetoothDevice::ProvidesServiceWithUUID( - const std::string& uuid) const { - std::string canonical_uuid = bluetooth_utils::CanonicalUuid(uuid); - BluetoothDevice::ServiceList services = GetServices(); - for (BluetoothDevice::ServiceList::const_iterator iter = services.begin(); - iter != services.end(); - ++iter) { - if (bluetooth_utils::CanonicalUuid(*iter) == canonical_uuid) - return true; - } - return false; -} - } // namespace device diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h index cb1e7ec..fce46b1 100644 --- a/device/bluetooth/bluetooth_device.h +++ b/device/bluetooth/bluetooth_device.h @@ -15,7 +15,6 @@ namespace device { class BluetoothProfile; -class BluetoothServiceRecord; class BluetoothSocket; struct BluetoothOutOfBandPairingData; @@ -233,10 +232,14 @@ class BluetoothDevice { // were called after the corresponding call to Connect(). virtual bool IsConnecting() const = 0; - // Returns the services (as UUID strings) that this device provides. - // TODO(youngki): Rename this to GetProfiles(). - typedef std::vector<std::string> ServiceList; - virtual ServiceList GetServices() const = 0; + // Returns the set of UUIDs that this device supports. For classic Bluetooth + // 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; + virtual UUIDList GetUUIDs() const = 0; // The ErrorCallback is used for methods that can fail in which case it // is called, in the success case the callback is simply not called. @@ -247,25 +250,6 @@ class BluetoothDevice { // In the success case this callback is not called. typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; - // Returns the services (as BluetoothServiceRecord objects) that this device - // provides. - typedef ScopedVector<BluetoothServiceRecord> ServiceRecordList; - typedef base::Callback<void(const ServiceRecordList&)> ServiceRecordsCallback; - virtual void GetServiceRecords(const ServiceRecordsCallback& callback, - const ErrorCallback& error_callback) = 0; - - // Indicates whether this device provides the given service. - virtual bool ProvidesServiceWithUUID(const std::string& uuid) const; - - // The ProvidesServiceCallback is used by ProvidesServiceWithName to indicate - // whether or not a matching service was found. - typedef base::Callback<void(bool)> ProvidesServiceCallback; - - // Indicates whether this device provides the given service. - virtual void ProvidesServiceWithName( - const std::string& name, - const ProvidesServiceCallback& callback) = 0; - // Indicates whether the device is currently pairing and expecting a // PIN Code to be returned. virtual bool ExpectingPinCode() const = 0; diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc index aa1d66b..a7c7b83 100644 --- a/device/bluetooth/bluetooth_device_chromeos.cc +++ b/device/bluetooth/bluetooth_device_chromeos.cc @@ -213,8 +213,7 @@ bool BluetoothDeviceChromeOS::IsConnecting() const { return num_connecting_calls_ > 0; } -BluetoothDeviceChromeOS::ServiceList BluetoothDeviceChromeOS::GetServices() - const { +BluetoothDeviceChromeOS::UUIDList BluetoothDeviceChromeOS::GetUUIDs() const { BluetoothDeviceClient::Properties* properties = DBusThreadManager::Get()->GetBluetoothDeviceClient()-> GetProperties(object_path_); @@ -223,20 +222,6 @@ BluetoothDeviceChromeOS::ServiceList BluetoothDeviceChromeOS::GetServices() return properties->uuids.value(); } -void BluetoothDeviceChromeOS::GetServiceRecords( - const ServiceRecordsCallback& callback, - const ErrorCallback& error_callback) { - // TODO(keybuk): not implemented; remove - error_callback.Run(); -} - -void BluetoothDeviceChromeOS::ProvidesServiceWithName( - const std::string& name, - const ProvidesServiceCallback& callback) { - // TODO(keybuk): not implemented; remove - callback.Run(false); -} - bool BluetoothDeviceChromeOS::ExpectingPinCode() const { return pairing_.get() && pairing_->ExpectingPinCode(); } diff --git a/device/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h index bc94c3c..d31bae7 100644 --- a/device/bluetooth/bluetooth_device_chromeos.h +++ b/device/bluetooth/bluetooth_device_chromeos.h @@ -34,13 +34,7 @@ class BluetoothDeviceChromeOS virtual bool IsConnected() const OVERRIDE; virtual bool IsConnectable() const OVERRIDE; virtual bool IsConnecting() const OVERRIDE; - virtual ServiceList GetServices() const OVERRIDE; - virtual void GetServiceRecords( - const ServiceRecordsCallback& callback, - const ErrorCallback& error_callback) OVERRIDE; - virtual void ProvidesServiceWithName( - const std::string& name, - const ProvidesServiceCallback& callback) OVERRIDE; + virtual UUIDList GetUUIDs() const OVERRIDE; virtual bool ExpectingPinCode() const OVERRIDE; virtual bool ExpectingPasskey() const OVERRIDE; virtual bool ExpectingConfirmation() const OVERRIDE; diff --git a/device/bluetooth/bluetooth_device_mac.h b/device/bluetooth/bluetooth_device_mac.h index bc3ce19..a953749 100644 --- a/device/bluetooth/bluetooth_device_mac.h +++ b/device/bluetooth/bluetooth_device_mac.h @@ -34,13 +34,7 @@ class BluetoothDeviceMac : public BluetoothDevice { virtual bool IsConnected() const OVERRIDE; virtual bool IsConnectable() const OVERRIDE; virtual bool IsConnecting() const OVERRIDE; - virtual ServiceList GetServices() const OVERRIDE; - virtual void GetServiceRecords( - const ServiceRecordsCallback& callback, - const ErrorCallback& error_callback) OVERRIDE; - virtual void ProvidesServiceWithName( - const std::string& name, - const ProvidesServiceCallback& callback) OVERRIDE; + virtual UUIDList GetUUIDs() const OVERRIDE; virtual bool ExpectingPinCode() const OVERRIDE; virtual bool ExpectingPasskey() const OVERRIDE; virtual bool ExpectingConfirmation() const OVERRIDE; diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm index 50762d2..5d37a54 100644 --- a/device/bluetooth/bluetooth_device_mac.mm +++ b/device/bluetooth/bluetooth_device_mac.mm @@ -115,37 +115,15 @@ bool BluetoothDeviceMac::IsConnecting() const { return false; } -// TODO(youngki): BluetoothServiceRecord is deprecated; implement this method +// TODO(keybuk): BluetoothServiceRecord is deprecated; implement this method // without using BluetoothServiceRecord. -BluetoothDevice::ServiceList BluetoothDeviceMac::GetServices() const { - ServiceList service_uuids; +BluetoothDevice::UUIDList BluetoothDeviceMac::GetUUIDs() const { + UUIDList uuids; for (IOBluetoothSDPServiceRecord* service in [device_ services]) { BluetoothServiceRecordMac service_record(service); - service_uuids.push_back(service_record.uuid()); + uuids.push_back(service_record.uuid()); } - return service_uuids; -} - -// NOTE(youngki): This method is deprecated; it will be removed soon. -void BluetoothDeviceMac::GetServiceRecords( - const ServiceRecordsCallback& callback, - const ErrorCallback& error_callback) { - ServiceRecordList service_record_list; - for (IOBluetoothSDPServiceRecord* service in [device_ services]) { - BluetoothServiceRecord* service_record = - new BluetoothServiceRecordMac(service); - service_record_list.push_back(service_record); - } - - callback.Run(service_record_list); -} - -// NOTE(youngki): This method is deprecated; it will be removed soon. -void BluetoothDeviceMac::ProvidesServiceWithName( - const std::string& name, - const ProvidesServiceCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(false); + return uuids; } bool BluetoothDeviceMac::ExpectingPinCode() const { diff --git a/device/bluetooth/bluetooth_device_win.cc b/device/bluetooth/bluetooth_device_win.cc index 3f95efd..da016f7 100644 --- a/device/bluetooth/bluetooth_device_win.cc +++ b/device/bluetooth/bluetooth_device_win.cc @@ -48,7 +48,7 @@ BluetoothDeviceWin::BluetoothDeviceWin( (*iter)->sdp_bytes.size(), sdp_bytes_buffer); service_record_list_.push_back(service_record); - service_uuids_.push_back(service_record->uuid()); + uuids_.push_back(service_record->uuid()); } } @@ -104,28 +104,8 @@ bool BluetoothDeviceWin::IsConnecting() const { return false; } -BluetoothDevice::ServiceList BluetoothDeviceWin::GetServices() const { - return service_uuids_; -} - -void BluetoothDeviceWin::GetServiceRecords( - const ServiceRecordsCallback& callback, - const ErrorCallback& error_callback) { - callback.Run(service_record_list_); -} - -void BluetoothDeviceWin::ProvidesServiceWithName( - const std::string& name, - const ProvidesServiceCallback& callback) { - for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); - iter != service_record_list_.end(); - ++iter) { - if ((*iter)->name() == name) { - callback.Run(true); - return; - } - } - callback.Run(false); +BluetoothDevice::UUIDList BluetoothDeviceWin::GetUUIDs() const { + return uuids_; } bool BluetoothDeviceWin::ExpectingPinCode() const { diff --git a/device/bluetooth/bluetooth_device_win.h b/device/bluetooth/bluetooth_device_win.h index 274364b..80c8206 100644 --- a/device/bluetooth/bluetooth_device_win.h +++ b/device/bluetooth/bluetooth_device_win.h @@ -34,13 +34,7 @@ class BluetoothDeviceWin : public BluetoothDevice { virtual bool IsConnected() const OVERRIDE; virtual bool IsConnectable() const OVERRIDE; virtual bool IsConnecting() const OVERRIDE; - virtual ServiceList GetServices() const OVERRIDE; - virtual void GetServiceRecords( - const ServiceRecordsCallback& callback, - const ErrorCallback& error_callback) OVERRIDE; - virtual void ProvidesServiceWithName( - const std::string& name, - const ProvidesServiceCallback& callback) OVERRIDE; + virtual UUIDList GetUUIDs() const OVERRIDE; virtual bool ExpectingPinCode() const OVERRIDE; virtual bool ExpectingPasskey() const OVERRIDE; virtual bool ExpectingConfirmation() const OVERRIDE; @@ -72,7 +66,10 @@ class BluetoothDeviceWin : public BluetoothDevice { const base::Closure& callback, const ErrorCallback& error_callback) OVERRIDE; - const BluetoothServiceRecord* GetServiceRecord(const std::string& uuid) const; + // Used by BluetoothProfileWin to retrieve the service record for the given + // |uuid|. + const BluetoothServiceRecord* GetServiceRecord( + const std::string& uuid) const; protected: // BluetoothDevice override @@ -105,7 +102,10 @@ class BluetoothDeviceWin : public BluetoothDevice { bool visible_; // The services (identified by UUIDs) that this device provides. - ServiceList service_uuids_; + UUIDList uuids_; + + // The service records retrieved from SDP. + typedef ScopedVector<BluetoothServiceRecord> ServiceRecordList; ServiceRecordList service_record_list_; DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceWin); diff --git a/device/bluetooth/bluetooth_device_win_unittest.cc b/device/bluetooth/bluetooth_device_win_unittest.cc index 20be2ad..651bfd7 100644 --- a/device/bluetooth/bluetooth_device_win_unittest.cc +++ b/device/bluetooth/bluetooth_device_win_unittest.cc @@ -39,9 +39,7 @@ namespace device { class BluetoothDeviceWinTest : public testing::Test { public: - BluetoothDeviceWinTest() - : error_called_(false), - provides_service_with_name_(false) { + BluetoothDeviceWinTest() { BluetoothTaskManagerWin::DeviceState device_state; device_state.name = kDeviceName; device_state.address = kDeviceAddress; @@ -63,81 +61,20 @@ class BluetoothDeviceWinTest : public testing::Test { device_.reset(new BluetoothDeviceWin(device_state)); } - void GetServiceRecords( - const BluetoothDevice::ServiceRecordList& service_record_list) { - service_records_ = &service_record_list; - } - - void OnError() { - error_called_ = true; - } - - void SetProvidesServiceWithName(bool provides_service_with_name) { - provides_service_with_name_ = provides_service_with_name; - } - protected: scoped_ptr<BluetoothDevice> device_; scoped_ptr<BluetoothDevice> empty_device_; - const BluetoothDevice::ServiceRecordList* service_records_; - bool error_called_; - bool provides_service_with_name_; }; -TEST_F(BluetoothDeviceWinTest, GetServices) { - BluetoothDevice::ServiceList service_list = device_->GetServices(); - - EXPECT_EQ(2, service_list.size()); - EXPECT_STREQ(kTestAudioSdpUuid, service_list[0].c_str()); - EXPECT_STREQ(kTestVideoSdpUuid, service_list[1].c_str()); -} +TEST_F(BluetoothDeviceWinTest, GetUUIDs) { + BluetoothDevice::UUIDList uuids = device_->GetUUIDs(); -TEST_F(BluetoothDeviceWinTest, GetServiceRecords) { - device_->GetServiceRecords( - base::Bind(&BluetoothDeviceWinTest::GetServiceRecords, - base::Unretained(this)), - BluetoothDevice::ErrorCallback()); - ASSERT_TRUE(service_records_ != NULL); - EXPECT_EQ(2, service_records_->size()); - EXPECT_STREQ(kTestAudioSdpUuid, (*service_records_)[0]->uuid().c_str()); - EXPECT_STREQ(kTestVideoSdpUuid, (*service_records_)[1]->uuid().c_str()); - - BluetoothDeviceWin* device_win = - reinterpret_cast<BluetoothDeviceWin*>(device_.get()); - - const BluetoothServiceRecord* audio_device = - device_win->GetServiceRecord(kTestAudioSdpUuid); - ASSERT_TRUE(audio_device != NULL); - EXPECT_EQ((*service_records_)[0], audio_device); - - const BluetoothServiceRecord* video_device = - device_win->GetServiceRecord(kTestVideoSdpUuid); - ASSERT_TRUE(video_device != NULL); - EXPECT_EQ((*service_records_)[1], video_device); - - const BluetoothServiceRecord* invalid_device = - device_win->GetServiceRecord(kTestVideoSdpAddress); - EXPECT_TRUE(invalid_device == NULL); -} + EXPECT_EQ(2, uuids.size()); + EXPECT_STREQ(kTestAudioSdpUuid, uuids[0].c_str()); + EXPECT_STREQ(kTestVideoSdpUuid, uuids[1].c_str()); -TEST_F(BluetoothDeviceWinTest, ProvidesServiceWithName) { - device_->ProvidesServiceWithName( - kTestAudioSdpName, - base::Bind(&BluetoothDeviceWinTest::SetProvidesServiceWithName, - base::Unretained(this))); - EXPECT_TRUE(provides_service_with_name_); - - device_->ProvidesServiceWithName( - kTestVideoSdpName, - base::Bind(&BluetoothDeviceWinTest::SetProvidesServiceWithName, - base::Unretained(this))); - EXPECT_TRUE(provides_service_with_name_); - - device_->ProvidesServiceWithName( - "name that does not exist", - base::Bind(&BluetoothDeviceWinTest::SetProvidesServiceWithName, - base::Unretained(this))); - EXPECT_FALSE(provides_service_with_name_); + uuids = empty_device_->GetUUIDs(); + EXPECT_EQ(0, uuids.size()); } -} // namespace device
\ No newline at end of file +} // namespace device diff --git a/device/bluetooth/test/mock_bluetooth_device.cc b/device/bluetooth/test/mock_bluetooth_device.cc index 4804dc0..5235d5b 100644 --- a/device/bluetooth/test/mock_bluetooth_device.cc +++ b/device/bluetooth/test/mock_bluetooth_device.cc @@ -50,8 +50,8 @@ MockBluetoothDevice::MockBluetoothDevice(MockBluetoothAdapter* adapter, .WillByDefault(testing::Return(false)); ON_CALL(*this, ExpectingConfirmation()) .WillByDefault(testing::Return(false)); - ON_CALL(*this, GetServices()) - .WillByDefault(testing::Return(service_list_)); + ON_CALL(*this, GetUUIDs()) + .WillByDefault(testing::Return(uuids_)); } MockBluetoothDevice::~MockBluetoothDevice() {} diff --git a/device/bluetooth/test/mock_bluetooth_device.h b/device/bluetooth/test/mock_bluetooth_device.h index bc028e5..7c20c00 100644 --- a/device/bluetooth/test/mock_bluetooth_device.h +++ b/device/bluetooth/test/mock_bluetooth_device.h @@ -39,14 +39,7 @@ class MockBluetoothDevice : public BluetoothDevice { MOCK_CONST_METHOD0(IsConnected, bool()); MOCK_CONST_METHOD0(IsConnectable, bool()); MOCK_CONST_METHOD0(IsConnecting, bool()); - MOCK_CONST_METHOD0(GetServices, ServiceList()); - MOCK_METHOD2(GetServiceRecords, - void(const BluetoothDevice::ServiceRecordsCallback&, - const BluetoothDevice::ErrorCallback&)); - MOCK_CONST_METHOD1(ProvidesServiceWithUUID, bool(const std::string&)); - MOCK_METHOD2(ProvidesServiceWithName, - void(const std::string&, - const BluetoothDevice::ProvidesServiceCallback&)); + MOCK_CONST_METHOD0(GetUUIDs, UUIDList()); MOCK_CONST_METHOD0(ExpectingPinCode, bool()); MOCK_CONST_METHOD0(ExpectingPasskey, bool()); MOCK_CONST_METHOD0(ExpectingConfirmation, bool()); @@ -84,7 +77,7 @@ class MockBluetoothDevice : public BluetoothDevice { uint32 bluetooth_class_; std::string name_; std::string address_; - BluetoothDevice::ServiceList service_list_; + BluetoothDevice::UUIDList uuids_; }; } // namespace device |