diff options
author | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-05 23:27:59 +0000 |
---|---|---|
committer | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-05 23:27:59 +0000 |
commit | 5b5ca009377b2ce5a99ce5a81aeaca8eaaff2320 (patch) | |
tree | 7e60c32308a78f6c04a7ba1d984ec1285979be52 /device | |
parent | 3e3250c714b0de96f021ba4d59d51f1700b72644 (diff) | |
download | chromium_src-5b5ca009377b2ce5a99ce5a81aeaca8eaaff2320.zip chromium_src-5b5ca009377b2ce5a99ce5a81aeaca8eaaff2320.tar.gz chromium_src-5b5ca009377b2ce5a99ce5a81aeaca8eaaff2320.tar.bz2 |
Delayload bluetooth imports on Windows.
Some systems (e.g., Windows Server 2012) do not have a bluetooth stack, so the corresponding dll (bthprops.cpl) isn't present. If neither delayload nor explicit runtime binding is used, then binaries linking in the device_bluetooth target will fail to load on such systems.
BUG=135470
Review URL: https://chromiumcodereview.appspot.com/11299332
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171353 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
-rw-r--r-- | device/bluetooth/bluetooth_adapter_win.cc | 45 | ||||
-rw-r--r-- | device/device.gyp | 13 |
2 files changed, 57 insertions, 1 deletions
diff --git a/device/bluetooth/bluetooth_adapter_win.cc b/device/bluetooth/bluetooth_adapter_win.cc index 5924cd9a..26a9fc5 100644 --- a/device/bluetooth/bluetooth_adapter_win.cc +++ b/device/bluetooth/bluetooth_adapter_win.cc @@ -7,20 +7,58 @@ #include "device/bluetooth/bluetooth_adapter_win.h" #include <BluetoothAPIs.h> +#if defined(_WIN32_WINNT_WIN8) +// The Windows 8 SDK defines FACILITY_VISUALCPP in winerror.h. +#undef FACILITY_VISUALCPP +#endif +#include <delayimp.h> #include <string> #include "base/bind.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/stringprintf.h" #include "base/sys_string_conversions.h" +#include "base/threading/thread_restrictions.h" -# pragma comment(lib, "Bthprops.lib") +#pragma comment(lib, "Bthprops.lib") +#pragma comment(lib, "delayimp.lib") namespace { const BLUETOOTH_FIND_RADIO_PARAMS bluetooth_adapter_param = { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) }; +// 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; +} + +// Returns true if the machine has a bluetooth stack available. The first call +// to this function will involve file IO, so it should be done on an +// appropriate thread. This function is not threadsafe. +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 namespace device { @@ -94,6 +132,11 @@ void BluetoothAdapterWin::ReadLocalOutOfBandPairingData( } void BluetoothAdapterWin::UpdateAdapterState() { + // TODO(youngki): Move this check to the earliest point reasonable so that no + // attempts are made to do any bluetooth processing if no BT stack is present. + if (!HasBluetoothStack()) + return; + HBLUETOOTH_RADIO_FIND bluetooth_adapter_handle = NULL; BLUETOOTH_RADIO_INFO bluetooth_adapter_info = { sizeof(BLUETOOTH_RADIO_INFO), 0 }; diff --git a/device/device.gyp b/device/device.gyp index 08cac92..25db3cb 100644 --- a/device/device.gyp +++ b/device/device.gyp @@ -49,6 +49,19 @@ '../dbus/dbus.gyp:dbus', ] }], + ['OS=="win"', { + 'all_dependent_settings': { + 'msvs_settings': { + 'VCLinkerTool': { + 'DelayLoadDLLs': [ + # Despite MSDN stating that Bthprops.dll contains the + # symbols declared by bthprops.lib, they actually reside here: + 'Bthprops.cpl', + ], + }, + }, + }, + }], ], }, { |