Commit 07aa6dca authored by shrike's avatar shrike Committed by Commit bot

[Mac] Stop using deprecated IOBluetoothSDPServiceRecordRef APIs.

When compiling against the 10.9 SDK, IOBluetoothAddServiceDict() and
IOBluetoothRemoveServiceWithRecordHandle() generate deprecation errors.
This cl removes the instances of this old API.

R=isherman@chromium.org
BUG=650836

Review-Url: https://codereview.chromium.org/2393723002
Cr-Commit-Position: refs/heads/master@{#427184}
parent 90cf7fc2
...@@ -173,9 +173,9 @@ class BluetoothSocketMac : public BluetoothSocket { ...@@ -173,9 +173,9 @@ class BluetoothSocketMac : public BluetoothSocket {
base::scoped_nsobject<BluetoothL2capConnectionListener> base::scoped_nsobject<BluetoothL2capConnectionListener>
l2cap_connection_listener_; l2cap_connection_listener_;
// A handle to the service record registered in the system SDP server. // The service record registered in the system SDP server, used to
// Used to eventually unregister the service. // eventually unregister the service.
BluetoothSDPServiceRecordHandle service_record_handle_; base::scoped_nsobject<IOBluetoothSDPServiceRecord> service_record_;
// The channel used to issue commands. // The channel used to issue commands.
std::unique_ptr<BluetoothChannelMac> channel_; std::unique_ptr<BluetoothChannelMac> channel_;
......
...@@ -217,12 +217,8 @@ using device::BluetoothSocket; ...@@ -217,12 +217,8 @@ using device::BluetoothSocket;
namespace device { namespace device {
namespace { namespace {
// It's safe to use 0 to represent an unregistered service, as implied by the // It's safe to use 0 to represent invalid channel or PSM port numbers, as both
// documentation at [ http://goo.gl/YRtCkF ]. // are required to be non-zero for valid services.
const BluetoothSDPServiceRecordHandle kInvalidServiceRecordHandle = 0;
// Likewise, it's safe to use 0 to represent invalid channel or PSM port
// numbers, as both are required to be non-zero for valid services.
const BluetoothRFCOMMChannelID kInvalidRfcommChannelId = 0; const BluetoothRFCOMMChannelID kInvalidRfcommChannelId = 0;
const BluetoothL2CAPPSM kInvalidL2capPsm = 0; const BluetoothL2CAPPSM kInvalidL2capPsm = 0;
...@@ -342,41 +338,25 @@ NSDictionary* BuildL2capServiceDefinition( ...@@ -342,41 +338,25 @@ NSDictionary* BuildL2capServiceDefinition(
} }
// Registers a Bluetooth service with the specified |service_definition| in the // Registers a Bluetooth service with the specified |service_definition| in the
// system SDP server. Returns a handle to the registered service on success. If // system SDP server. Returns the registered service on success. If the service
// the service could not be registered, or if |verify_service_callback| // could not be registered, or if |verify_service_callback| indicates that the
// indicates that the to-be-registered service is not configured correctly, // to-be-registered service was not configured correctly, returns nil.
// returns |kInvalidServiceRecordHandle|. IOBluetoothSDPServiceRecord* RegisterService(
BluetoothSDPServiceRecordHandle RegisterService(
NSDictionary* service_definition, NSDictionary* service_definition,
const base::Callback<bool(IOBluetoothSDPServiceRecord*)>& const base::Callback<bool(IOBluetoothSDPServiceRecord*)>&
verify_service_callback) { verify_service_callback) {
// Attempt to register the service. // Attempt to register the service.
IOBluetoothSDPServiceRecordRef service_record_ref; IOBluetoothSDPServiceRecord* service_record = [IOBluetoothSDPServiceRecord
IOReturn result = publishedServiceRecordWithDictionary:service_definition];
IOBluetoothAddServiceDict((CFDictionaryRef)service_definition,
&service_record_ref);
if (result != kIOReturnSuccess)
return kInvalidServiceRecordHandle;
// Transfer ownership to a scoped object, to simplify memory management.
base::ScopedCFTypeRef<IOBluetoothSDPServiceRecordRef>
scoped_service_record_ref(service_record_ref);
// Extract the service record handle.
BluetoothSDPServiceRecordHandle service_record_handle;
IOBluetoothSDPServiceRecord* service_record =
[IOBluetoothSDPServiceRecord withSDPServiceRecordRef:service_record_ref];
result = [service_record getServiceRecordHandle:&service_record_handle];
if (result != kIOReturnSuccess)
return kInvalidServiceRecordHandle;
// Verify that the registered service was configured correctly. If not, // Verify that the registered service was configured correctly. If not,
// withdraw the service. // withdraw the service.
if (!verify_service_callback.Run(service_record)) { if (!service_record || !verify_service_callback.Run(service_record)) {
IOBluetoothRemoveServiceWithRecordHandle(service_record_handle); [service_record removeServiceRecord];
return kInvalidServiceRecordHandle; service_record = nil;
} }
return service_record_handle; return service_record;
} }
// Returns true iff the |requested_channel_id| was registered in the RFCOMM // Returns true iff the |requested_channel_id| was registered in the RFCOMM
...@@ -403,9 +383,9 @@ bool VerifyRfcommService(const int* requested_channel_id, ...@@ -403,9 +383,9 @@ bool VerifyRfcommService(const int* requested_channel_id,
// and |options.name| in the system SDP server. Automatically allocates a // and |options.name| in the system SDP server. Automatically allocates a
// channel if |options.channel_id| is null. Does not specify a name if // channel if |options.channel_id| is null. Does not specify a name if
// |options.name| is null. Returns a handle to the registered service and // |options.name| is null. Returns a handle to the registered service and
// updates |registered_channel_id| to the actual channel id, or returns // updates |registered_channel_id| to the actual channel id, or returns nil if
// |kInvalidServiceRecordHandle| if the service could not be registered. // the service could not be registered.
BluetoothSDPServiceRecordHandle RegisterRfcommService( IOBluetoothSDPServiceRecord* RegisterRfcommService(
const BluetoothUUID& uuid, const BluetoothUUID& uuid,
const BluetoothAdapter::ServiceOptions& options, const BluetoothAdapter::ServiceOptions& options,
BluetoothRFCOMMChannelID* registered_channel_id) { BluetoothRFCOMMChannelID* registered_channel_id) {
...@@ -439,9 +419,8 @@ bool VerifyL2capService(const int* requested_psm, ...@@ -439,9 +419,8 @@ bool VerifyL2capService(const int* requested_psm,
// |options.name| in the system SDP server. Automatically allocates a PSM if // |options.name| in the system SDP server. Automatically allocates a PSM if
// |options.psm| is null. Does not register a name if |options.name| is null. // |options.psm| is null. Does not register a name if |options.name| is null.
// Returns a handle to the registered service and updates |registered_psm| to // Returns a handle to the registered service and updates |registered_psm| to
// the actual PSM, or returns |kInvalidServiceRecordHandle| if the service could // the actual PSM, or returns nil if the service could not be registered.
// not be registered. IOBluetoothSDPServiceRecord* RegisterL2capService(
BluetoothSDPServiceRecordHandle RegisterL2capService(
const BluetoothUUID& uuid, const BluetoothUUID& uuid,
const BluetoothAdapter::ServiceOptions& options, const BluetoothAdapter::ServiceOptions& options,
BluetoothL2CAPPSM* registered_psm) { BluetoothL2CAPPSM* registered_psm) {
...@@ -493,9 +472,9 @@ void BluetoothSocketMac::ListenUsingRfcomm( ...@@ -493,9 +472,9 @@ void BluetoothSocketMac::ListenUsingRfcomm(
DVLOG(1) << uuid_.canonical_value() << ": Registering RFCOMM service."; DVLOG(1) << uuid_.canonical_value() << ": Registering RFCOMM service.";
BluetoothRFCOMMChannelID registered_channel_id; BluetoothRFCOMMChannelID registered_channel_id;
service_record_handle_ = service_record_.reset(
RegisterRfcommService(uuid, options, &registered_channel_id); RegisterRfcommService(uuid, options, &registered_channel_id));
if (service_record_handle_ == kInvalidServiceRecordHandle) { if (!service_record_.get()) {
error_callback.Run(kInvalidOrUsedChannel); error_callback.Run(kInvalidOrUsedChannel);
return; return;
} }
...@@ -521,8 +500,8 @@ void BluetoothSocketMac::ListenUsingL2cap( ...@@ -521,8 +500,8 @@ void BluetoothSocketMac::ListenUsingL2cap(
DVLOG(1) << uuid_.canonical_value() << ": Registering L2CAP service."; DVLOG(1) << uuid_.canonical_value() << ": Registering L2CAP service.";
BluetoothL2CAPPSM registered_psm; BluetoothL2CAPPSM registered_psm;
service_record_handle_ = RegisterL2capService(uuid, options, &registered_psm); service_record_.reset(RegisterL2capService(uuid, options, &registered_psm));
if (service_record_handle_ == kInvalidServiceRecordHandle) { if (!service_record_.get()) {
error_callback.Run(kInvalidOrUsedPsm); error_callback.Run(kInvalidOrUsedPsm);
return; return;
} }
...@@ -664,7 +643,7 @@ void BluetoothSocketMac::Close() { ...@@ -664,7 +643,7 @@ void BluetoothSocketMac::Close() {
if (channel_) if (channel_)
ReleaseChannel(); ReleaseChannel();
else if (service_record_handle_ != kInvalidServiceRecordHandle) else if (service_record_.get())
ReleaseListener(); ReleaseListener();
} }
...@@ -909,9 +888,7 @@ BluetoothSocketMac::ConnectCallbacks::ConnectCallbacks() {} ...@@ -909,9 +888,7 @@ BluetoothSocketMac::ConnectCallbacks::ConnectCallbacks() {}
BluetoothSocketMac::ConnectCallbacks::~ConnectCallbacks() {} BluetoothSocketMac::ConnectCallbacks::~ConnectCallbacks() {}
BluetoothSocketMac::BluetoothSocketMac() BluetoothSocketMac::BluetoothSocketMac() {}
: service_record_handle_(kInvalidServiceRecordHandle) {
}
BluetoothSocketMac::~BluetoothSocketMac() { BluetoothSocketMac::~BluetoothSocketMac() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
...@@ -933,9 +910,10 @@ void BluetoothSocketMac::ReleaseChannel() { ...@@ -933,9 +910,10 @@ void BluetoothSocketMac::ReleaseChannel() {
void BluetoothSocketMac::ReleaseListener() { void BluetoothSocketMac::ReleaseListener() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_NE(service_record_handle_, kInvalidServiceRecordHandle); DCHECK(service_record_.get());
IOBluetoothRemoveServiceWithRecordHandle(service_record_handle_); [service_record_ removeServiceRecord];
service_record_.reset();
rfcomm_connection_listener_.reset(); rfcomm_connection_listener_.reset();
l2cap_connection_listener_.reset(); l2cap_connection_listener_.reset();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment