summaryrefslogtreecommitdiffstats
path: root/device
diff options
context:
space:
mode:
authoryoungki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-05 03:37:09 +0000
committeryoungki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-05 03:37:09 +0000
commite55a50f5803110f145d3a81173de7f96d5e26302 (patch)
tree0d0ea32147c5b19336cdc5ca601f097be43fc0b0 /device
parentc0b1877384ba2e5f7b79ddbf3013b2a69c5e2691 (diff)
downloadchromium_src-e55a50f5803110f145d3a81173de7f96d5e26302.zip
chromium_src-e55a50f5803110f145d3a81173de7f96d5e26302.tar.gz
chromium_src-e55a50f5803110f145d3a81173de7f96d5e26302.tar.bz2
Implemented BluetoothDeviceWin::ConnectToProfile()
I mostly reused BluetoothServiceRecordWin to implement this method (for now). Even if we deprecate BluetoothServiceRecord, I think we could keep BluetoothServiceRecordWin for Windows platform. After I submit this I will send out cleanup CLs to delete the unused code. BUG=229636 Review URL: https://chromiumcodereview.appspot.com/14582010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198350 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
-rw-r--r--device/bluetooth/bluetooth_device_win.cc36
-rw-r--r--device/bluetooth/bluetooth_device_win.h14
-rw-r--r--device/bluetooth/bluetooth_profile.cc4
-rw-r--r--device/bluetooth/bluetooth_profile_mac.mm3
-rw-r--r--device/bluetooth/bluetooth_profile_win.cc47
-rw-r--r--device/bluetooth/bluetooth_profile_win.h38
-rw-r--r--device/device.gyp2
7 files changed, 110 insertions, 34 deletions
diff --git a/device/bluetooth/bluetooth_device_win.cc b/device/bluetooth/bluetooth_device_win.cc
index 7779166..11dc529 100644
--- a/device/bluetooth/bluetooth_device_win.cc
+++ b/device/bluetooth/bluetooth_device_win.cc
@@ -7,11 +7,11 @@
#include <string>
#include "base/basictypes.h"
-#include "base/hash.h"
#include "base/logging.h"
#include "base/memory/scoped_vector.h"
#include "base/stringprintf.h"
#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
+#include "device/bluetooth/bluetooth_profile_win.h"
#include "device/bluetooth/bluetooth_service_record_win.h"
#include "device/bluetooth/bluetooth_socket_win.h"
#include "device/bluetooth/bluetooth_task_manager_win.h"
@@ -26,7 +26,7 @@ namespace device {
BluetoothDeviceWin::BluetoothDeviceWin(
const BluetoothTaskManagerWin::DeviceState& state)
- : BluetoothDevice(), device_fingerprint_(ComputeDeviceFingerprint(state)) {
+ : BluetoothDevice() {
name_ = state.name;
address_ = state.address;
bluetooth_class_ = state.bluetooth_class;
@@ -197,7 +197,10 @@ void BluetoothDeviceWin::ConnectToProfile(
device::BluetoothProfile* profile,
const base::Closure& callback,
const ErrorCallback& error_callback) {
- // TODO(keybuk): implement
+ if (static_cast<BluetoothProfileWin*>(profile)->Connect(this))
+ callback.Run();
+ else
+ error_callback.Run();
}
void BluetoothDeviceWin::SetOutOfBandPairingData(
@@ -213,27 +216,14 @@ void BluetoothDeviceWin::ClearOutOfBandPairingData(
NOTIMPLEMENTED();
}
-// static
-uint32 BluetoothDeviceWin::ComputeDeviceFingerprint(
- const BluetoothTaskManagerWin::DeviceState& state) {
- std::string device_string = base::StringPrintf("%s%s%u%s%s%s",
- state.name.c_str(),
- state.address.c_str(),
- state.bluetooth_class,
- state.visible ? "true" : "false",
- state.connected ? "true" : "false",
- state.authenticated ? "true" : "false");
- for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
- iter = state.service_record_states.begin();
- iter != state.service_record_states.end();
- ++iter) {
- base::StringAppendF(&device_string,
- "%s%s%d",
- (*iter)->name.c_str(),
- (*iter)->address.c_str(),
- (*iter)->sdp_bytes.size());
+const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord(
+ const std::string& uuid) const {
+ for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
+ iter != service_record_list_.end();
+ ++iter) {
+ return *iter;
}
- return base::Hash(device_string);
+ return NULL;
}
} // namespace device
diff --git a/device/bluetooth/bluetooth_device_win.h b/device/bluetooth/bluetooth_device_win.h
index 6bfdf92..7e208ed 100644
--- a/device/bluetooth/bluetooth_device_win.h
+++ b/device/bluetooth/bluetooth_device_win.h
@@ -15,6 +15,7 @@
namespace device {
class BluetoothAdapterWin;
+class BluetoothServiceRecord;
class BluetoothDeviceWin : public BluetoothDevice {
public:
@@ -70,6 +71,8 @@ class BluetoothDeviceWin : public BluetoothDevice {
const base::Closure& callback,
const ErrorCallback& error_callback) OVERRIDE;
+ const BluetoothServiceRecord* GetServiceRecord(const std::string& uuid) const;
+
protected:
// BluetoothDevice override
virtual std::string GetDeviceName() const OVERRIDE;
@@ -81,14 +84,6 @@ class BluetoothDeviceWin : public BluetoothDevice {
// discovery.
void SetVisible(bool visible);
- // Computes the fingerprint that can be used to compare the devices.
- static uint32 ComputeDeviceFingerprint(
- const BluetoothTaskManagerWin::DeviceState& state);
-
- uint32 device_fingerprint() const {
- return device_fingerprint_;
- }
-
// The Bluetooth class of the device, a bitmask that may be decoded using
// https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
uint32 bluetooth_class_;
@@ -110,9 +105,6 @@ class BluetoothDeviceWin : public BluetoothDevice {
// The services (identified by UUIDs) that this device provides.
ServiceList service_uuids_;
-
- // Used to compare the devices.
- uint32 device_fingerprint_;
ServiceRecordList service_record_list_;
DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceWin);
diff --git a/device/bluetooth/bluetooth_profile.cc b/device/bluetooth/bluetooth_profile.cc
index 73f1128..2ef9425 100644
--- a/device/bluetooth/bluetooth_profile.cc
+++ b/device/bluetooth/bluetooth_profile.cc
@@ -7,6 +7,8 @@
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
#include "device/bluetooth/bluetooth_profile_mac.h"
+#elif defined(OS_WIN)
+#include "device/bluetooth/bluetooth_profile_win.h"
#endif
#include <string>
@@ -46,6 +48,8 @@ void BluetoothProfile::Register(const std::string& uuid,
#if defined(OS_MACOSX)
if (base::mac::IsOSLionOrLater())
profile = new BluetoothProfileMac(uuid, options.name);
+#elif defined(OS_WIN)
+ profile = new BluetoothProfileWin(uuid, options.name);
#endif
callback.Run(profile);
diff --git a/device/bluetooth/bluetooth_profile_mac.mm b/device/bluetooth/bluetooth_profile_mac.mm
index c0658a9..7829793 100644
--- a/device/bluetooth/bluetooth_profile_mac.mm
+++ b/device/bluetooth/bluetooth_profile_mac.mm
@@ -64,6 +64,9 @@ void BluetoothProfileMac::SetConnectionCallback(
}
bool BluetoothProfileMac::Connect(IOBluetoothDevice* device) {
+ if (connection_callback_.is_null())
+ return false;
+
IOBluetoothSDPServiceRecord* record =
[device getServiceRecordForUUID:GetIOBluetoothSDPUUID(uuid_)];
if (record != nil) {
diff --git a/device/bluetooth/bluetooth_profile_win.cc b/device/bluetooth/bluetooth_profile_win.cc
new file mode 100644
index 0000000..f0729bb
--- /dev/null
+++ b/device/bluetooth/bluetooth_profile_win.cc
@@ -0,0 +1,47 @@
+// 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.
+
+#include "device/bluetooth/bluetooth_profile_win.h"
+
+#include "base/memory/ref_counted.h"
+#include "device/bluetooth/bluetooth_device_win.h"
+#include "device/bluetooth/bluetooth_service_record.h"
+#include "device/bluetooth/bluetooth_socket_win.h"
+
+namespace device {
+
+BluetoothProfileWin::BluetoothProfileWin(const std::string& uuid,
+ const std::string& name)
+ : BluetoothProfile(), uuid_(uuid), name_(name) {
+}
+
+BluetoothProfileWin::~BluetoothProfileWin() {
+}
+
+void BluetoothProfileWin::Unregister() {
+ delete this;
+}
+
+void BluetoothProfileWin::SetConnectionCallback(
+ const ConnectionCallback& callback) {
+ connection_callback_ = callback;
+}
+
+bool BluetoothProfileWin::Connect(const BluetoothDeviceWin* device) {
+ if (connection_callback_.is_null())
+ return false;
+
+ const BluetoothServiceRecord* record = device->GetServiceRecord(uuid_);
+ if (record) {
+ scoped_refptr<BluetoothSocket> socket(
+ BluetoothSocketWin::CreateBluetoothSocket(*record));
+ if (socket.get() != NULL) {
+ connection_callback_.Run(device, socket);
+ return true;
+ }
+ }
+ return false;
+}
+
+} // namespace device
diff --git a/device/bluetooth/bluetooth_profile_win.h b/device/bluetooth/bluetooth_profile_win.h
new file mode 100644
index 0000000..a102bf5
--- /dev/null
+++ b/device/bluetooth/bluetooth_profile_win.h
@@ -0,0 +1,38 @@
+// 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.
+
+#ifndef DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_WIN_H_
+#define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_WIN_H_
+
+#include <string>
+
+#include "device/bluetooth/bluetooth_profile.h"
+
+namespace device {
+
+class BluetoothDeviceWin;
+
+class BluetoothProfileWin : public BluetoothProfile {
+ public:
+ // BluetoothProfile override.
+ virtual void Unregister() OVERRIDE;
+ virtual void SetConnectionCallback(
+ const ConnectionCallback& callback) OVERRIDE;
+
+ bool Connect(const BluetoothDeviceWin* device);
+
+ private:
+ friend BluetoothProfile;
+
+ BluetoothProfileWin(const std::string& uuid, const std::string& name);
+ virtual ~BluetoothProfileWin();
+
+ const std::string uuid_;
+ const std::string name_;
+ ConnectionCallback connection_callback_;
+};
+
+} // namespace device
+
+#endif // DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_WIN_H_
diff --git a/device/device.gyp b/device/device.gyp
index 6afb8a0..12de0c4 100644
--- a/device/device.gyp
+++ b/device/device.gyp
@@ -48,6 +48,8 @@
'bluetooth/bluetooth_profile.h',
'bluetooth/bluetooth_profile_mac.h',
'bluetooth/bluetooth_profile_mac.mm',
+ 'bluetooth/bluetooth_profile_win.cc',
+ 'bluetooth/bluetooth_profile_win.h',
'bluetooth/bluetooth_service_record.cc',
'bluetooth/bluetooth_service_record.h',
'bluetooth/bluetooth_service_record_chromeos.cc',