Chromium Code Reviews| Index: device/bluetooth/bluetooth_adapter_win.cc |
| diff --git a/device/bluetooth/bluetooth_adapter_win.cc b/device/bluetooth/bluetooth_adapter_win.cc |
| index 97eca65763bbdb2245bc9a84cf82ced50b7ab675..b5570be757d1f195e896e2255367f6c160e347b8 100644 |
| --- a/device/bluetooth/bluetooth_adapter_win.cc |
| +++ b/device/bluetooth/bluetooth_adapter_win.cc |
| @@ -6,8 +6,21 @@ |
| #include "device/bluetooth/bluetooth_adapter_win.h" |
| +#include <BluetoothAPIs.h> |
| #include <string> |
| #include "base/logging.h" |
| +#include "base/message_loop.h" |
| +#include "base/stringprintf.h" |
| +#include "base/sys_string_conversions.h" |
| + |
| +# pragma comment(lib, "Bthprops.lib") |
| + |
| +namespace { |
| + const BLUETOOTH_FIND_RADIO_PARAMS bluetooth_adapter_param = |
|
bryeung
2012/10/30 19:58:40
no indent and a blank line after namespace and bef
youngki
2012/10/30 21:50:56
Done.
|
| + { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) }; |
| + |
| + const int kUpdateAdapterStateIntervalMs = 500; |
| +} // namespace |
| namespace device { |
| @@ -28,8 +41,7 @@ void BluetoothAdapterWin::RemoveObserver(BluetoothAdapter::Observer* observer) { |
| } |
| bool BluetoothAdapterWin::IsPresent() const { |
|
bryeung
2012/10/30 19:58:40
This should probably try to update address_ immedi
youngki
2012/10/30 21:50:56
This is a const method.. so I don't think we can u
|
| - NOTIMPLEMENTED(); |
| - return false; |
| + return !address_.empty(); |
| } |
| bool BluetoothAdapterWin::IsPowered() const { |
| @@ -78,4 +90,36 @@ void BluetoothAdapterWin::ReadLocalOutOfBandPairingData( |
| NOTIMPLEMENTED(); |
| } |
| +void BluetoothAdapterWin::TrackDefaultAdapter() { |
| + UpdateAdapterState(); |
|
bryeung
2012/10/30 19:58:40
This is going to start polling before it is necess
youngki
2012/10/30 21:50:56
I will wait for Scott's thoughts here.
keybuk
2012/10/31 18:19:47
TrackDefaultAdapter should only be called when a n
bryeung
2012/10/31 18:46:01
Maybe this is strictly a problem with ExtensionBlu
youngki
2012/10/31 19:42:59
Okay then I will leave this as it is for now.
|
| +} |
| + |
| +void BluetoothAdapterWin::UpdateAdapterState() { |
| + HBLUETOOTH_RADIO_FIND bluetooth_adapter_handle = NULL; |
| + BLUETOOTH_RADIO_INFO bluetooth_adapter_info = |
| + { sizeof(BLUETOOTH_RADIO_INFO), 0 }; |
| + BluetoothFindFirstRadio(&bluetooth_adapter_param, &bluetooth_adapter_handle); |
| + if (bluetooth_adapter_handle && |
| + ERROR_SUCCESS == BluetoothGetRadioInfo(bluetooth_adapter_handle, |
| + &bluetooth_adapter_info)) { |
| + name_ = base::SysWideToUTF8(bluetooth_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]); |
| + } else { |
| + name_.clear(); |
| + address_.clear(); |
| + } |
| + |
| + MessageLoop::current()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&BluetoothAdapterWin::UpdateAdapterState, |
| + weak_ptr_factory_.GetWeakPtr()), |
| + base::TimeDelta::FromMilliseconds(kUpdateAdapterStateIntervalMs)); |
| +} |
| + |
| } // namespace device |