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

Unified Diff: device/bluetooth/bluetooth_task_manager_win.cc

Issue 12018024: Implemented Asynchronous Initialization of BluetoothAdapter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed RunCallbackOnAdapterReady to GetAdapter. 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
Index: device/bluetooth/bluetooth_task_manager_win.cc
diff --git a/device/bluetooth/bluetooth_task_manager_win.cc b/device/bluetooth/bluetooth_task_manager_win.cc
index b124139774d7886cf21903608b48c9b433ebd3a4..c1cfbd33a423da481c156ad9b029c35796f3bf8c 100644
--- a/device/bluetooth/bluetooth_task_manager_win.cc
+++ b/device/bluetooth/bluetooth_task_manager_win.cc
@@ -4,12 +4,6 @@
#include "device/bluetooth/bluetooth_task_manager_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"
@@ -19,23 +13,14 @@
#include "base/stringprintf.h"
#include "base/sys_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
-#include "base/threading/thread_restrictions.h"
#include "base/win/scoped_handle.h"
-
-#pragma comment(lib, "Bthprops.lib")
+#include "device/bluetooth/bluetooth_init_win.h"
namespace {
const int kNumThreadsInWorkerPool = 3;
const char kBluetoothThreadName[] = "BluetoothPollingThreadWin";
-// 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;
-} // namespace
-
// Populates bluetooth adapter state using adapter_handle.
void GetAdapterState(HANDLE adapter_handle,
device::BluetoothTaskManagerWin::AdapterState* state) {
@@ -68,28 +53,6 @@ namespace device {
// static
const int BluetoothTaskManagerWin::kPollIntervalMs = 500;
-// static
-bool BluetoothTaskManagerWin::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;
-}
-
BluetoothTaskManagerWin::BluetoothTaskManagerWin(
scoped_refptr<base::SequencedTaskRunner> ui_task_runner)
: ui_task_runner_(ui_task_runner),
@@ -135,8 +98,18 @@ void BluetoothTaskManagerWin::StartPolling() {
DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread());
// TODO(youngki): Handle this check where BluetoothAdapter is initialized.
- if (HasBluetoothStack()) {
+ if (device::bluetooth_init_win::HasBluetoothStack()) {
PollAdapter();
+ } else {
+ // IF the bluetooth stack is not available, we still send an empty state
+ // to BluetoothAdapter so that it is marked initialized, but the adapter
+ // will not be present.
+ AdapterState* state = new AdapterState();
+ ui_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&BluetoothTaskManagerWin::OnAdapterStateChanged,
+ this,
+ base::Owned(state)));
}
}

Powered by Google App Engine
This is Rietveld 408576698