diff options
author | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-25 09:26:01 +0000 |
---|---|---|
committer | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-25 09:26:01 +0000 |
commit | 063d9430289fdf33106cc23d7225391ec56c9e93 (patch) | |
tree | cb13ee8851648ec5fa3fdfb7efb6056612dd86ed /device/bluetooth/bluetooth_init_win.cc | |
parent | 6dcc0079d3b89d46b6f3a68570c0eca538aff32d (diff) | |
download | chromium_src-063d9430289fdf33106cc23d7225391ec56c9e93.zip chromium_src-063d9430289fdf33106cc23d7225391ec56c9e93.tar.gz chromium_src-063d9430289fdf33106cc23d7225391ec56c9e93.tar.bz2 |
Resubmitting asynchronous bluetooth adapter init CL with fix.
The original CL: https://chromiumcodereview.appspot.com/12018024/ was reverted because it violated the style guide that the struct-level global variable is prohibited and it failed the static analyzer test, in bluetooth_adapter_factory.cc. In order to resolve the issue, I changed adapter_callbacks to a lazy instance.
BUG=135470
Review URL: https://chromiumcodereview.appspot.com/12045051
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178798 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device/bluetooth/bluetooth_init_win.cc')
-rw-r--r-- | device/bluetooth/bluetooth_init_win.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/device/bluetooth/bluetooth_init_win.cc b/device/bluetooth/bluetooth_init_win.cc new file mode 100644 index 0000000..54d0b20 --- /dev/null +++ b/device/bluetooth/bluetooth_init_win.cc @@ -0,0 +1,45 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "device/bluetooth/bluetooth_init_win.h" + +#include "base/threading/thread_restrictions.h" + +namespace { + +// 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 + +namespace device { +namespace bluetooth_init_win { + +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 bluetooth_init_win +} // namespace device
\ No newline at end of file |