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..df0865c4aaf6ad50ebbeb568a60ba4824fdd113b 100644 |
--- a/device/bluetooth/bluetooth_adapter_win.cc |
+++ b/device/bluetooth/bluetooth_adapter_win.cc |
@@ -6,34 +6,22 @@ |
#include "device/bluetooth/bluetooth_adapter_win.h" |
-#include <BluetoothAPIs.h> |
#include <string> |
-#include "base/bind.h" |
#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 = |
- { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) }; |
- |
-} // namespace |
namespace device { |
-const int BluetoothAdapterWin::kPollIntervalMs = 500; |
- |
BluetoothAdapterWin::BluetoothAdapterWin() |
: BluetoothAdapter(), |
powered_(false), |
+ thread_(new BluetoothPollingThreadWin()), |
+ adapter_handle_(NULL), |
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
+ thread_->AddObserver(this); |
} |
BluetoothAdapterWin::~BluetoothAdapterWin() { |
+ thread_->RemoveObserver(this); |
} |
void BluetoothAdapterWin::AddObserver(BluetoothAdapter::Observer* observer) { |
@@ -93,49 +81,20 @@ 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); |
- 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::AdapterPropertyChanged( |
+ const BluetoothPollingThreadWin::Properties& properties) { |
bryeung
2012/11/23 13:32:22
CHECK the thread here
youngki
2012/11/23 18:26:38
Done.
|
+ name_ = properties.name; |
+ address_ = properties.address; |
+ powered_ = properties.powered; |
} |
void BluetoothAdapterWin::TrackDefaultAdapter() { |
- PollAdapterState(); |
+ thread_->Init(); |
} |
-void BluetoothAdapterWin::PollAdapterState() { |
- UpdateAdapterState(); |
- |
- MessageLoop::current()->PostDelayedTask( |
- FROM_HERE, |
- base::Bind(&BluetoothAdapterWin::PollAdapterState, |
- weak_ptr_factory_.GetWeakPtr()), |
- base::TimeDelta::FromMilliseconds(kPollIntervalMs)); |
+void BluetoothAdapterWin::SetBluetoothPollingThreadForTest( |
+ BluetoothPollingThreadWin* thread) { |
+ thread_.reset(thread); |
} |
} // namespace device |