Windows precompiled header support in GN.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_init_win.cc
blob54d0b20ae69cbf6daa87a266b65e00fe5f2e6b25
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "device/bluetooth/bluetooth_init_win.h"
7 #include "base/threading/thread_restrictions.h"
9 namespace {
11 // A frame-based exception handler filter function for a handler for exceptions
12 // generated by the Visual C++ delay loader helper function.
13 int FilterVisualCPPExceptions(DWORD exception_code) {
14 return HRESULT_FACILITY(exception_code) == FACILITY_VISUALCPP ?
15 EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
18 } // namespace
20 namespace device {
21 namespace bluetooth_init_win {
23 bool HasBluetoothStack() {
24 static enum {
25 HBS_UNKNOWN,
26 HBS_YES,
27 HBS_NO,
28 } has_bluetooth_stack = HBS_UNKNOWN;
30 if (has_bluetooth_stack == HBS_UNKNOWN) {
31 base::ThreadRestrictions::AssertIOAllowed();
32 HRESULT hr = E_FAIL;
33 __try {
34 hr = __HrLoadAllImportsForDll("bthprops.cpl");
35 } __except(FilterVisualCPPExceptions(::GetExceptionCode())) {
36 hr = E_FAIL;
38 has_bluetooth_stack = SUCCEEDED(hr) ? HBS_YES : HBS_NO;
41 return has_bluetooth_stack == HBS_YES;
44 } // namespace bluetooth_init_win
45 } // namespace device