diff options
author | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-20 20:56:52 +0000 |
---|---|---|
committer | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-20 20:56:52 +0000 |
commit | fbc7bb6df0f7e9704aaabfce37eadec709f15d7f (patch) | |
tree | f661558529ddfd00153bbb0fd752814d579cb1d7 /device | |
parent | 38c054d58652286914237b19f8b04916df323af1 (diff) | |
download | chromium_src-fbc7bb6df0f7e9704aaabfce37eadec709f15d7f.zip chromium_src-fbc7bb6df0f7e9704aaabfce37eadec709f15d7f.tar.gz chromium_src-fbc7bb6df0f7e9704aaabfce37eadec709f15d7f.tar.bz2 |
Implemented BluetoothAdapterWin::IsPowered().
I didn't include SetPowered() implementation here because SetPowered() requires a reference to bluetooth adapter handle and right now that is only created within the polling method. I will refactor this in the next CL to have BluetoothAdapterWin hold a bluetooth adapter handle pointer so that we can call SetPowered() using it.
BUG=135470
Review URL: https://chromiumcodereview.appspot.com/11420074
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168875 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
-rw-r--r-- | device/bluetooth/bluetooth_adapter_win.cc | 43 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_win.h | 2 |
2 files changed, 28 insertions, 17 deletions
diff --git a/device/bluetooth/bluetooth_adapter_win.cc b/device/bluetooth/bluetooth_adapter_win.cc index 2fe1f58..5924cd9a 100644 --- a/device/bluetooth/bluetooth_adapter_win.cc +++ b/device/bluetooth/bluetooth_adapter_win.cc @@ -29,6 +29,7 @@ const int BluetoothAdapterWin::kPollIntervalMs = 500; BluetoothAdapterWin::BluetoothAdapterWin() : BluetoothAdapter(), + powered_(false), ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { } @@ -48,8 +49,7 @@ bool BluetoothAdapterWin::IsPresent() const { } bool BluetoothAdapterWin::IsPowered() const { - NOTIMPLEMENTED(); - return false; + return powered_; } void BluetoothAdapterWin::SetPowered( @@ -97,22 +97,31 @@ 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(); + 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); + 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); + } else { + name_.clear(); + address_.clear(); + powered_ = false; + } } + + if (bluetooth_handle) + BluetoothFindRadioClose(bluetooth_handle); } void BluetoothAdapterWin::TrackDefaultAdapter() { diff --git a/device/bluetooth/bluetooth_adapter_win.h b/device/bluetooth/bluetooth_adapter_win.h index 61a2e5c..0cad233 100644 --- a/device/bluetooth/bluetooth_adapter_win.h +++ b/device/bluetooth/bluetooth_adapter_win.h @@ -58,6 +58,8 @@ class BluetoothAdapterWin : public BluetoothAdapter { static const int kPollIntervalMs; + bool powered_; + // NOTE: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_; |