Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1937)

Unified Diff: device/bluetooth/bluetooth_adapter_win.cc

Issue 11411130: Implemented BluetoothTaskManagerWin class. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Renamed properties to adapter state Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..36f03e7d67ebc17017be83c268b137164140896a 100644
--- a/device/bluetooth/bluetooth_adapter_win.cc
+++ b/device/bluetooth/bluetooth_adapter_win.cc
@@ -6,34 +6,23 @@
#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
+#include "base/threading/thread_checker.h"
namespace device {
-const int BluetoothAdapterWin::kPollIntervalMs = 500;
-
BluetoothAdapterWin::BluetoothAdapterWin()
: BluetoothAdapter(),
powered_(false),
+ thread_(new BluetoothPollingThreadWin()),
+ thread_checker_(new base::ThreadChecker()),
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 +82,21 @@ 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::AdapterStateChanged(
+ const BluetoothPollingThreadWin::AdapterState& state) {
+ DCHECK(thread_checker_->CalledOnValidThread());
+ name_ = state.name;
+ address_ = state.address;
+ powered_ = state.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

Powered by Google App Engine
This is Rietveld 408576698