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. 4 5#include "device/bluetooth/bluetooth_init_win.h" 6 7#include "base/threading/thread_restrictions.h" 8 9namespace { 10 11// A frame-based exception handler filter function for a handler for exceptions 12// generated by the Visual C++ delay loader helper function. 13int FilterVisualCPPExceptions(DWORD exception_code) { 14 return HRESULT_FACILITY(exception_code) == FACILITY_VISUALCPP ? 15 EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH; 16} 17 18} // namespace 19 20namespace device { 21namespace bluetooth_init_win { 22 23bool HasBluetoothStack() { 24 static enum { 25 HBS_UNKNOWN, 26 HBS_YES, 27 HBS_NO, 28 } has_bluetooth_stack = HBS_UNKNOWN; 29 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; 37 } 38 has_bluetooth_stack = SUCCEEDED(hr) ? HBS_YES : HBS_NO; 39 } 40 41 return has_bluetooth_stack == HBS_YES; 42} 43 44} // namespace bluetooth_init_win 45} // namespace device