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

Side by Side Diff: device/bluetooth/bluetooth_adapter_win.cc

Issue 11299332: Delayload bluetooth imports on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | device/device.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // TODO(youngki): Implement this file. 5 // TODO(youngki): Implement this file.
6 6
7 #include "device/bluetooth/bluetooth_adapter_win.h" 7 #include "device/bluetooth/bluetooth_adapter_win.h"
8 8
9 #include <BluetoothAPIs.h> 9 #include <BluetoothAPIs.h>
10 #if defined(_WIN32_WINNT_WIN8)
11 // The Windows 8 SDK defines FACILITY_VISUALCPP in winerror.h.
12 #undef FACILITY_VISUALCPP
13 #endif
14 #include <delayimp.h>
10 #include <string> 15 #include <string>
11 #include "base/bind.h" 16 #include "base/bind.h"
12 #include "base/logging.h" 17 #include "base/logging.h"
13 #include "base/message_loop.h" 18 #include "base/message_loop.h"
14 #include "base/stringprintf.h" 19 #include "base/stringprintf.h"
15 #include "base/sys_string_conversions.h" 20 #include "base/sys_string_conversions.h"
21 #include "base/threading/thread_restrictions.h"
16 22
17 # pragma comment(lib, "Bthprops.lib") 23 #pragma comment(lib, "Bthprops.lib")
24 #pragma comment(lib, "delayimp.lib")
18 25
19 namespace { 26 namespace {
20 27
21 const BLUETOOTH_FIND_RADIO_PARAMS bluetooth_adapter_param = 28 const BLUETOOTH_FIND_RADIO_PARAMS bluetooth_adapter_param =
22 { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) }; 29 { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) };
23 30
31 // A frame-based exception handler filter function for a handler for exceptions
32 // generated by the Visual C++ delay loader helper function.
33 int FilterVisualCPPExceptions(DWORD exception_code) {
34 return HRESULT_FACILITY(exception_code) == FACILITY_VISUALCPP ?
35 EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
36 }
37
38 // Returns true if the machine has a bluetooth stack available. The first call
39 // to this function will involve file IO, so it should be done on an
40 // appropriate thread. This function is not threadsafe.
41 bool HasBluetoothStack() {
42 static enum {
43 HBS_UNKNOWN,
44 HBS_YES,
45 HBS_NO,
46 } has_bluetooth_stack = HBS_UNKNOWN;
47
48 if (has_bluetooth_stack == HBS_UNKNOWN) {
49 base::ThreadRestrictions::AssertIOAllowed();
50 HRESULT hr = E_FAIL;
51 __try {
52 hr = __HrLoadAllImportsForDll("bthprops.cpl");
53 } __except(FilterVisualCPPExceptions(::GetExceptionCode())) {
54 hr = E_FAIL;
55 }
56 has_bluetooth_stack = SUCCEEDED(hr) ? HBS_YES : HBS_NO;
57 }
58
59 return has_bluetooth_stack == HBS_YES;
60 }
61
24 } // namespace 62 } // namespace
25 63
26 namespace device { 64 namespace device {
27 65
28 const int BluetoothAdapterWin::kPollIntervalMs = 500; 66 const int BluetoothAdapterWin::kPollIntervalMs = 500;
29 67
30 BluetoothAdapterWin::BluetoothAdapterWin() 68 BluetoothAdapterWin::BluetoothAdapterWin()
31 : BluetoothAdapter(), 69 : BluetoothAdapter(),
32 powered_(false), 70 powered_(false),
33 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 71 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 return NULL; 125 return NULL;
88 } 126 }
89 127
90 void BluetoothAdapterWin::ReadLocalOutOfBandPairingData( 128 void BluetoothAdapterWin::ReadLocalOutOfBandPairingData(
91 const BluetoothOutOfBandPairingDataCallback& callback, 129 const BluetoothOutOfBandPairingDataCallback& callback,
92 const ErrorCallback& error_callback) { 130 const ErrorCallback& error_callback) {
93 NOTIMPLEMENTED(); 131 NOTIMPLEMENTED();
94 } 132 }
95 133
96 void BluetoothAdapterWin::UpdateAdapterState() { 134 void BluetoothAdapterWin::UpdateAdapterState() {
135 // TODO(youngki): Move this check to the earliest point reasonable so that no
136 // attempts are made to do any bluetooth processing if no BT stack is present.
137 if (!HasBluetoothStack())
138 return;
139
97 HBLUETOOTH_RADIO_FIND bluetooth_adapter_handle = NULL; 140 HBLUETOOTH_RADIO_FIND bluetooth_adapter_handle = NULL;
98 BLUETOOTH_RADIO_INFO bluetooth_adapter_info = 141 BLUETOOTH_RADIO_INFO bluetooth_adapter_info =
99 { sizeof(BLUETOOTH_RADIO_INFO), 0 }; 142 { sizeof(BLUETOOTH_RADIO_INFO), 0 };
100 HBLUETOOTH_RADIO_FIND bluetooth_handle = BluetoothFindFirstRadio( 143 HBLUETOOTH_RADIO_FIND bluetooth_handle = BluetoothFindFirstRadio(
101 &bluetooth_adapter_param, &bluetooth_adapter_handle); 144 &bluetooth_adapter_param, &bluetooth_adapter_handle);
102 145
103 if (bluetooth_adapter_handle) { 146 if (bluetooth_adapter_handle) {
104 if (ERROR_SUCCESS == BluetoothGetRadioInfo(bluetooth_adapter_handle, 147 if (ERROR_SUCCESS == BluetoothGetRadioInfo(bluetooth_adapter_handle,
105 &bluetooth_adapter_info)) { 148 &bluetooth_adapter_info)) {
106 name_ = base::SysWideToUTF8(bluetooth_adapter_info.szName); 149 name_ = base::SysWideToUTF8(bluetooth_adapter_info.szName);
(...skipping 25 matching lines...) Expand all
132 UpdateAdapterState(); 175 UpdateAdapterState();
133 176
134 MessageLoop::current()->PostDelayedTask( 177 MessageLoop::current()->PostDelayedTask(
135 FROM_HERE, 178 FROM_HERE,
136 base::Bind(&BluetoothAdapterWin::PollAdapterState, 179 base::Bind(&BluetoothAdapterWin::PollAdapterState,
137 weak_ptr_factory_.GetWeakPtr()), 180 weak_ptr_factory_.GetWeakPtr()),
138 base::TimeDelta::FromMilliseconds(kPollIntervalMs)); 181 base::TimeDelta::FromMilliseconds(kPollIntervalMs));
139 } 182 }
140 183
141 } // namespace device 184 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/device.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698