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

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: Added BluetoothTaskManagerWin class 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..def135803d934bdd986a9bf452e094aabf4e2773 100644
--- a/device/bluetooth/bluetooth_adapter_win.cc
+++ b/device/bluetooth/bluetooth_adapter_win.cc
@@ -6,34 +6,25 @@
#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),
+ task_manager_(new BluetoothTaskManagerWin()),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
+ task_manager_->AddObserver(this);
}
BluetoothAdapterWin::~BluetoothAdapterWin() {
+ task_manager_->RemoveObserver(this);
+
+ // We explicitly call StopThread() here; we cannot rely on |task_manager_|
+ // destructor because it is reference counted.
bryeung 2012/12/10 19:51:28 who else would be holding a reference to it?
youngki 2012/12/17 17:17:23 BluetoothPollingThreadWin::PollAdapter() queues ba
+ task_manager_->StopThread();
}
void BluetoothAdapterWin::AddObserver(BluetoothAdapter::Observer* observer) {
@@ -93,49 +84,16 @@ 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 BluetoothTaskManagerWin::AdapterState& state) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ name_ = state.name;
+ address_ = state.address;
+ powered_ = state.powered;
}
void BluetoothAdapterWin::TrackDefaultAdapter() {
- PollAdapterState();
-}
-
-void BluetoothAdapterWin::PollAdapterState() {
- UpdateAdapterState();
-
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&BluetoothAdapterWin::PollAdapterState,
- weak_ptr_factory_.GetWeakPtr()),
- base::TimeDelta::FromMilliseconds(kPollIntervalMs));
+ task_manager_->StartThread();
}
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698