Index: device/bluetooth/bluetooth_adapter_win.cc |
diff --git a/device/bluetooth/bluetooth_adapter_win.cc b/device/bluetooth/bluetooth_adapter_win.cc |
index 5924cd9a433ae428154de364d46c10b43093bb5a..9d8c21710c3b7a265ebde8531f68b9beddfa455d 100644 |
--- a/device/bluetooth/bluetooth_adapter_win.cc |
+++ b/device/bluetooth/bluetooth_adapter_win.cc |
@@ -13,6 +13,7 @@ |
#include "base/message_loop.h" |
#include "base/stringprintf.h" |
#include "base/sys_string_conversions.h" |
+#include "device/bluetooth/bluetooth_manager_win.h" |
# pragma comment(lib, "Bthprops.lib") |
@@ -30,6 +31,8 @@ const int BluetoothAdapterWin::kPollIntervalMs = 500; |
BluetoothAdapterWin::BluetoothAdapterWin() |
: BluetoothAdapter(), |
powered_(false), |
+ manager_(new BluetoothManagerWin()), |
+ adapter_handle_(NULL), |
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
} |
@@ -93,49 +96,56 @@ void BluetoothAdapterWin::ReadLocalOutOfBandPairingData( |
NOTIMPLEMENTED(); |
} |
-void BluetoothAdapterWin::UpdateAdapterState() { |
- HBLUETOOTH_RADIO_FIND bluetooth_adapter_handle = NULL; |
- BLUETOOTH_RADIO_INFO bluetooth_adapter_info = |
- { sizeof(BLUETOOTH_RADIO_INFO), 0 }; |
- HBLUETOOTH_RADIO_FIND bluetooth_handle = BluetoothFindFirstRadio( |
- &bluetooth_adapter_param, &bluetooth_adapter_handle); |
- |
- if (bluetooth_adapter_handle) { |
- if (ERROR_SUCCESS == BluetoothGetRadioInfo(bluetooth_adapter_handle, |
- &bluetooth_adapter_info)) { |
- name_ = base::SysWideToUTF8(bluetooth_adapter_info.szName); |
+void BluetoothAdapterWin::UpdateAdapterState(HANDLE adapter_handle) { |
+ adapter_handle_ = adapter_handle; |
+ BLUETOOTH_RADIO_INFO adapter_info = { sizeof(BLUETOOTH_RADIO_INFO), 0 }; |
+ if (adapter_handle_) { |
+ if (ERROR_SUCCESS == BluetoothGetRadioInfo(adapter_handle_, |
bryeung
2012/11/22 18:13:25
I think we should move all of the code to interfac
youngki
2012/11/23 01:50:47
Done. Now all the Windows specific API calls are m
|
+ &adapter_info)) { |
+ name_ = base::SysWideToUTF8(adapter_info.szName); |
address_ = base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X", |
- bluetooth_adapter_info.address.rgBytes[5], |
- bluetooth_adapter_info.address.rgBytes[4], |
- bluetooth_adapter_info.address.rgBytes[3], |
- bluetooth_adapter_info.address.rgBytes[2], |
- bluetooth_adapter_info.address.rgBytes[1], |
- bluetooth_adapter_info.address.rgBytes[0]); |
- powered_ = BluetoothIsConnectable(bluetooth_adapter_handle) || |
- BluetoothIsDiscoverable(bluetooth_adapter_handle); |
+ adapter_info.address.rgBytes[5], |
+ adapter_info.address.rgBytes[4], |
+ adapter_info.address.rgBytes[3], |
+ adapter_info.address.rgBytes[2], |
+ adapter_info.address.rgBytes[1], |
+ adapter_info.address.rgBytes[0]); |
+ powered_ = BluetoothIsConnectable(adapter_handle_) ? true : false; |
bryeung
2012/11/22 18:13:25
what happened to the check for BluetoothIsDiscover
youngki
2012/11/23 01:50:47
BluetoothIsConnectable() does not exactly return b
|
} else { |
name_.clear(); |
address_.clear(); |
powered_ = false; |
} |
} |
- |
- if (bluetooth_handle) |
- BluetoothFindRadioClose(bluetooth_handle); |
} |
void BluetoothAdapterWin::TrackDefaultAdapter() { |
- PollAdapterState(); |
+ if (!manager_->message_loop()) |
+ manager_->Start(); |
+ |
+ manager_->message_loop()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&BluetoothManagerWin::FindAdapterHandleAndReply, |
+ base::Unretained(manager_.get()), |
+ weak_ptr_factory_.GetWeakPtr())); |
} |
-void BluetoothAdapterWin::PollAdapterState() { |
- UpdateAdapterState(); |
+void BluetoothAdapterWin::OnAdapterHandleAvailable(HANDLE handle) { |
+ UpdateAdapterState(handle); |
- MessageLoop::current()->PostDelayedTask( |
+ // Post another task to BluetoothManagerWin thread to update the adapter |
+ // handle. |
+ manager_->message_loop()->PostDelayedTask( |
FROM_HERE, |
- base::Bind(&BluetoothAdapterWin::PollAdapterState, |
+ base::Bind(&BluetoothManagerWin::FindAdapterHandleAndReply, |
+ base::Unretained(manager_.get()), |
weak_ptr_factory_.GetWeakPtr()), |
base::TimeDelta::FromMilliseconds(kPollIntervalMs)); |
} |
+void BluetoothAdapterWin::SetBluetoothManagerForTest( |
+ BluetoothManagerWin* manager) { |
+ manager_.reset(manager); |
+} |
+ |
} // namespace device |