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

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: Turned adapter_callbacks to a lazy instance. 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 144682f61c66578a91b5c69eb8c841413399cd71..ddb051e9d0cd1282d659aa6fc165daa50f0dc723 100644
--- a/device/bluetooth/bluetooth_task_manager_win.cc
+++ b/device/bluetooth/bluetooth_task_manager_win.cc
@@ -13,22 +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"
-#include "device/bluetooth/bluetooth_includes_win.h"
+#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) {
@@ -61,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),
@@ -128,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)));
}
}
@@ -215,4 +195,4 @@ void BluetoothTaskManagerWin::SetPowered(
}
}
-} // namespace device
+} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_task_manager_win.h ('k') | device/bluetooth/bluetooth_task_manager_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698