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

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: changed to const char[] Created 7 years, 11 months 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
« no previous file with comments | « device/bluetooth/bluetooth_adapter_win.h ('k') | device/bluetooth/bluetooth_adapter_win_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_adapter_win.cc
diff --git a/device/bluetooth/bluetooth_adapter_win.cc b/device/bluetooth/bluetooth_adapter_win.cc
index 0df985cb141a575c29aade8f6fb705206e3efe80..1f0efceb5521cc58ee0b064ca1861141ca489939 100644
--- a/device/bluetooth/bluetooth_adapter_win.cc
+++ b/device/bluetooth/bluetooth_adapter_win.cc
@@ -6,65 +6,14 @@
#include "device/bluetooth/bluetooth_adapter_win.h"
-#include <BluetoothAPIs.h>
-#if defined(_WIN32_WINNT_WIN8) && _MSC_VER < 1700
-// The Windows 8 SDK defines FACILITY_VISUALCPP in winerror.h.
-#undef FACILITY_VISUALCPP
-#endif
-#include <delayimp.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"
-#include "base/threading/thread_restrictions.h"
-
-#pragma comment(lib, "Bthprops.lib")
-#pragma comment(lib, "delayimp.lib")
-
-namespace {
-
-const BLUETOOTH_FIND_RADIO_PARAMS bluetooth_adapter_param =
- { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) };
-
-// A frame-based exception handler filter function for a handler for exceptions
-// generated by the Visual C++ delay loader helper function.
-int FilterVisualCPPExceptions(DWORD exception_code) {
- return HRESULT_FACILITY(exception_code) == FACILITY_VISUALCPP ?
- EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
-}
-
-// Returns true if the machine has a bluetooth stack available. The first call
-// to this function will involve file IO, so it should be done on an
-// appropriate thread. This function is not threadsafe.
-bool HasBluetoothStack() {
- static enum {
- HBS_UNKNOWN,
- HBS_YES,
- HBS_NO,
- } has_bluetooth_stack = HBS_UNKNOWN;
-
- if (has_bluetooth_stack == HBS_UNKNOWN) {
- base::ThreadRestrictions::AssertIOAllowed();
- HRESULT hr = E_FAIL;
- __try {
- hr = __HrLoadAllImportsForDll("bthprops.cpl");
- } __except(FilterVisualCPPExceptions(::GetExceptionCode())) {
- hr = E_FAIL;
- }
- has_bluetooth_stack = SUCCEEDED(hr) ? HBS_YES : HBS_NO;
- }
-
- return has_bluetooth_stack == HBS_YES;
-}
-
-} // namespace
+#include "base/sequenced_task_runner.h"
+#include "base/single_thread_task_runner.h"
+#include "base/thread_task_runner_handle.h"
namespace device {
-const int BluetoothAdapterWin::kPollIntervalMs = 500;
-
BluetoothAdapterWin::BluetoothAdapterWin()
: BluetoothAdapter(),
powered_(false),
@@ -72,6 +21,10 @@ BluetoothAdapterWin::BluetoothAdapterWin()
}
BluetoothAdapterWin::~BluetoothAdapterWin() {
+ if (task_manager_) {
+ task_manager_->RemoveObserver(this);
+ task_manager_->Shutdown();
+ }
}
void BluetoothAdapterWin::AddObserver(BluetoothAdapter::Observer* observer) {
@@ -131,54 +84,19 @@ void BluetoothAdapterWin::ReadLocalOutOfBandPairingData(
NOTIMPLEMENTED();
}
-void BluetoothAdapterWin::UpdateAdapterState() {
- // TODO(youngki): Move this check to the earliest point reasonable so that no
- // attempts are made to do any bluetooth processing if no BT stack is present.
- if (!HasBluetoothStack())
- return;
-
- 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_ =
+ new BluetoothTaskManagerWin(base::ThreadTaskRunnerHandle::Get());
+ task_manager_->AddObserver(this);
+ task_manager_->Initialize();
}
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_adapter_win.h ('k') | device/bluetooth/bluetooth_adapter_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698