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

Side by Side Diff: chrome/browser/geolocation/wifi_data_provider_win.cc

Issue 552250: Port the gears geolocation network provider to Chromium... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 months 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // Windows Vista uses the Native Wifi (WLAN) API for accessing WiFi cards. See 5 // Windows Vista uses the Native Wifi (WLAN) API for accessing WiFi cards. See
6 // http://msdn.microsoft.com/en-us/library/ms705945(VS.85).aspx. Windows XP 6 // http://msdn.microsoft.com/en-us/library/ms705945(VS.85).aspx. Windows XP
7 // Service Pack 3 (and Windows XP Service Pack 2, if upgraded with a hot fix) 7 // Service Pack 3 (and Windows XP Service Pack 2, if upgraded with a hot fix)
8 // also support a limited version of the WLAN API. See 8 // also support a limited version of the WLAN API. See
9 // http://msdn.microsoft.com/en-us/library/bb204766.aspx. The WLAN API uses 9 // http://msdn.microsoft.com/en-us/library/bb204766.aspx. The WLAN API uses
10 // wlanapi.h, which is not part of the SDK used by Gears, so is replicated 10 // wlanapi.h, which is not part of the SDK used by Gears, so is replicated
(...skipping 12 matching lines...) Expand all
23 23
24 #include "chrome/browser/geolocation/wifi_data_provider_win.h" 24 #include "chrome/browser/geolocation/wifi_data_provider_win.h"
25 25
26 #include <windows.h> 26 #include <windows.h>
27 #include <winioctl.h> 27 #include <winioctl.h>
28 #include <wlanapi.h> 28 #include <wlanapi.h>
29 #include "base/utf_string_conversions.h" 29 #include "base/utf_string_conversions.h"
30 #include "chrome/browser/geolocation/wifi_data_provider_common.h" 30 #include "chrome/browser/geolocation/wifi_data_provider_common.h"
31 #include "chrome/browser/geolocation/wifi_data_provider_common_win.h" 31 #include "chrome/browser/geolocation/wifi_data_provider_common_win.h"
32 32
33 #ifdef _MSC_VER
34 #pragma warning(disable:4355) // 'this' : used in base member initializer list
35 #endif
36
37 // Taken from ndis.h for WinCE. 33 // Taken from ndis.h for WinCE.
38 #define NDIS_STATUS_INVALID_LENGTH ((NDIS_STATUS)0xC0010014L) 34 #define NDIS_STATUS_INVALID_LENGTH ((NDIS_STATUS)0xC0010014L)
39 #define NDIS_STATUS_BUFFER_TOO_SHORT ((NDIS_STATUS)0xC0010016L) 35 #define NDIS_STATUS_BUFFER_TOO_SHORT ((NDIS_STATUS)0xC0010016L)
40 36
41 namespace { 37 namespace {
42 // The limits on the size of the buffer used for the OID query. 38 // The limits on the size of the buffer used for the OID query.
43 const int kInitialBufferSize = 2 << 12; // Good for about 50 APs. 39 const int kInitialBufferSize = 2 << 12; // Good for about 50 APs.
44 const int kMaximumBufferSize = 2 << 20; // 2MB 40 const int kMaximumBufferSize = 2 << 20; // 2MB
45 41
46 // Length for generic string buffers passed to Win32 APIs. 42 // Length for generic string buffers passed to Win32 APIs.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } // namespace 155 } // namespace
160 156
161 template<> 157 template<>
162 WifiDataProviderImplBase *WifiDataProvider::DefaultFactoryFunction() { 158 WifiDataProviderImplBase *WifiDataProvider::DefaultFactoryFunction() {
163 return new Win32WifiDataProvider(); 159 return new Win32WifiDataProvider();
164 } 160 }
165 161
166 Win32WifiDataProvider::Win32WifiDataProvider() 162 Win32WifiDataProvider::Win32WifiDataProvider()
167 : Thread(__FILE__), 163 : Thread(__FILE__),
168 is_first_scan_complete_(false), 164 is_first_scan_complete_(false),
169 task_factory_(this) { 165 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) {
170 } 166 }
171 167
172 Win32WifiDataProvider::~Win32WifiDataProvider() { 168 Win32WifiDataProvider::~Win32WifiDataProvider() {
173 // Base class auto-stops the thread, however we need to do it here so our 169 // Base class auto-stops the thread, however we need to do it here so our
174 // override of CleanUp still exists whilst the thread is shutting down. 170 // override of CleanUp still exists whilst the thread is shutting down.
175 Stop(); 171 Stop();
176 } 172 }
177 173
178 void Win32WifiDataProvider::inject_mock_wlan_api(WlanApiInterface* wlan_api) { 174 void Win32WifiDataProvider::inject_mock_wlan_api(WlanApiInterface* wlan_api) {
179 assert(wlan_api_ == NULL); 175 DCHECK(wlan_api_ == NULL);
180 assert(wlan_api); 176 DCHECK(wlan_api);
181 wlan_api_.reset(wlan_api); 177 wlan_api_.reset(wlan_api);
182 } 178 }
183 179
184 void Win32WifiDataProvider::inject_mock_polling_policy( 180 void Win32WifiDataProvider::inject_mock_polling_policy(
185 PollingPolicyInterface* policy) { 181 PollingPolicyInterface* policy) {
186 assert(polling_policy_ == NULL); 182 DCHECK(polling_policy_ == NULL);
187 assert(policy); 183 DCHECK(policy);
188 polling_policy_.reset(policy); 184 polling_policy_.reset(policy);
189 } 185 }
190 186
191 bool Win32WifiDataProvider::StartDataProvider() { 187 bool Win32WifiDataProvider::StartDataProvider() {
192 return base::Thread::Start(); 188 return base::Thread::Start();
193 } 189 }
194 190
195 bool Win32WifiDataProvider::GetData(WifiData *data) { 191 bool Win32WifiDataProvider::GetData(WifiData *data) {
196 assert(data); 192 DCHECK(data);
197 AutoLock lock(data_mutex_); 193 AutoLock lock(data_mutex_);
198 *data = wifi_data_; 194 *data = wifi_data_;
199 // If we've successfully completed a scan, indicate that we have all of the 195 // If we've successfully completed a scan, indicate that we have all of the
200 // data we can get. 196 // data we can get.
201 return is_first_scan_complete_; 197 return is_first_scan_complete_;
202 } 198 }
203 199
204 // Thread implementation 200 // Thread implementation
205 void Win32WifiDataProvider::Init() { 201 void Win32WifiDataProvider::Init() {
206 // Use the WLAN interface if we're on Vista and if it's available. Otherwise, 202 // Use the WLAN interface if we're on Vista and if it's available. Otherwise,
207 // use NDIS. 203 // use NDIS.
208 if (wlan_api_ == NULL) { 204 if (wlan_api_ == NULL) {
209 wlan_api_.reset(WindowsWlanApi::Create()); 205 wlan_api_.reset(WindowsWlanApi::Create());
210 } 206 }
211 if (wlan_api_ == NULL) { 207 if (wlan_api_ == NULL) {
212 wlan_api_.reset(WindowsNdisApi::Create()); 208 wlan_api_.reset(WindowsNdisApi::Create());
213 } 209 }
214 if (wlan_api_ == NULL) { 210 if (wlan_api_ == NULL) {
215 // Error! Can't do scans, so don't try and schedule one. 211 // Error! Can't do scans, so don't try and schedule one.
216 is_first_scan_complete_ = true; 212 is_first_scan_complete_ = true;
217 return; 213 return;
218 } 214 }
219 215
220 if (polling_policy_ == NULL) { 216 if (polling_policy_ == NULL) {
221 polling_policy_.reset( 217 polling_policy_.reset(
222 new GenericPollingPolicy<kDefaultPollingInterval, 218 new GenericPollingPolicy<kDefaultPollingInterval,
223 kNoChangePollingInterval, 219 kNoChangePollingInterval,
224 kTwoNoChangePollingInterval>); 220 kTwoNoChangePollingInterval>);
225 } 221 }
226 assert(polling_policy_ != NULL); 222 DCHECK(polling_policy_ != NULL);
227 223
228 ScheduleNextScan(); 224 ScheduleNextScan();
229 } 225 }
230 226
231 void Win32WifiDataProvider::CleanUp() { 227 void Win32WifiDataProvider::CleanUp() {
232 // Destroy the wlan api instance in the thread in which it was created. 228 // Destroy the wlan api instance in the thread in which it was created.
233 wlan_api_.reset(NULL); 229 wlan_api_.reset();
234 } 230 }
235 231
236 void Win32WifiDataProvider::DoWifiScanTask() { 232 void Win32WifiDataProvider::DoWifiScanTask() {
233 // TODO(joth): Almost all of this is shareable across platforms.
237 WifiData new_data; 234 WifiData new_data;
238 if (wlan_api_->GetAccessPointData(&new_data.access_point_data)) { 235 if (wlan_api_->GetAccessPointData(&new_data.access_point_data)) {
239 bool update_available; 236 bool update_available;
240 data_mutex_.Acquire(); 237 data_mutex_.Acquire();
241 update_available = wifi_data_.DiffersSignificantly(new_data); 238 update_available = wifi_data_.DiffersSignificantly(new_data);
242 wifi_data_ = new_data; 239 wifi_data_ = new_data;
243 data_mutex_.Release(); 240 data_mutex_.Release();
244 polling_policy_->UpdatePollingInterval(update_available); 241 polling_policy_->UpdatePollingInterval(update_available);
245 if (update_available) { 242 if (update_available || !is_first_scan_complete_) {
246 is_first_scan_complete_ = true; 243 is_first_scan_complete_ = true;
247 NotifyListeners(); 244 NotifyListeners();
248 } 245 }
249 } 246 }
250 ScheduleNextScan(); 247 ScheduleNextScan();
251 } 248 }
252 249
253 void Win32WifiDataProvider::ScheduleNextScan() { 250 void Win32WifiDataProvider::ScheduleNextScan() {
254 message_loop()->PostDelayedTask(FROM_HERE, 251 message_loop()->PostDelayedTask(FROM_HERE,
255 task_factory_.NewRunnableMethod(&Win32WifiDataProvider::DoWifiScanTask), 252 task_factory_.NewRunnableMethod(&Win32WifiDataProvider::DoWifiScanTask),
(...skipping 15 matching lines...) Expand all
271 268
272 WindowsWlanApi* WindowsWlanApi::Create() { 269 WindowsWlanApi* WindowsWlanApi::Create() {
273 // We use an absolute path to load the DLL to avoid DLL preloading attacks. 270 // We use an absolute path to load the DLL to avoid DLL preloading attacks.
274 string16 system_directory; 271 string16 system_directory;
275 if (!IsRunningOnVistaOrNewer()) { 272 if (!IsRunningOnVistaOrNewer()) {
276 return NULL; 273 return NULL;
277 } 274 }
278 if (!GetSystemDirectory(&system_directory)) { 275 if (!GetSystemDirectory(&system_directory)) {
279 return NULL; 276 return NULL;
280 } 277 }
281 assert(!system_directory.empty()); 278 DCHECK(!system_directory.empty());
282 string16 dll_path = system_directory + L"wlanapi.dll"; 279 string16 dll_path = system_directory + L"wlanapi.dll";
283 HINSTANCE library = LoadLibraryEx(dll_path.c_str(), 280 HINSTANCE library = LoadLibraryEx(dll_path.c_str(),
284 NULL, 281 NULL,
285 LOAD_WITH_ALTERED_SEARCH_PATH); 282 LOAD_WITH_ALTERED_SEARCH_PATH);
286 if (!library) { 283 if (!library) {
287 return NULL; 284 return NULL;
288 } 285 }
289 return new WindowsWlanApi(library); 286 return new WindowsWlanApi(library);
290 } 287 }
291 288
292 void WindowsWlanApi::GetWLANFunctions(HINSTANCE wlan_library) { 289 void WindowsWlanApi::GetWLANFunctions(HINSTANCE wlan_library) {
293 assert(wlan_library); 290 DCHECK(wlan_library);
294 WlanOpenHandle_function_ = reinterpret_cast<WlanOpenHandleFunction>( 291 WlanOpenHandle_function_ = reinterpret_cast<WlanOpenHandleFunction>(
295 GetProcAddress(wlan_library, "WlanOpenHandle")); 292 GetProcAddress(wlan_library, "WlanOpenHandle"));
296 WlanEnumInterfaces_function_ = reinterpret_cast<WlanEnumInterfacesFunction>( 293 WlanEnumInterfaces_function_ = reinterpret_cast<WlanEnumInterfacesFunction>(
297 GetProcAddress(wlan_library, "WlanEnumInterfaces")); 294 GetProcAddress(wlan_library, "WlanEnumInterfaces"));
298 WlanGetNetworkBssList_function_ = 295 WlanGetNetworkBssList_function_ =
299 reinterpret_cast<WlanGetNetworkBssListFunction>( 296 reinterpret_cast<WlanGetNetworkBssListFunction>(
300 GetProcAddress(wlan_library, "WlanGetNetworkBssList")); 297 GetProcAddress(wlan_library, "WlanGetNetworkBssList"));
301 WlanFreeMemory_function_ = reinterpret_cast<WlanFreeMemoryFunction>( 298 WlanFreeMemory_function_ = reinterpret_cast<WlanFreeMemoryFunction>(
302 GetProcAddress(wlan_library, "WlanFreeMemory")); 299 GetProcAddress(wlan_library, "WlanFreeMemory"));
303 WlanCloseHandle_function_ = reinterpret_cast<WlanCloseHandleFunction>( 300 WlanCloseHandle_function_ = reinterpret_cast<WlanCloseHandleFunction>(
304 GetProcAddress(wlan_library, "WlanCloseHandle")); 301 GetProcAddress(wlan_library, "WlanCloseHandle"));
305 assert(WlanOpenHandle_function_ && 302 DCHECK(WlanOpenHandle_function_ &&
306 WlanEnumInterfaces_function_ && 303 WlanEnumInterfaces_function_ &&
307 WlanGetNetworkBssList_function_ && 304 WlanGetNetworkBssList_function_ &&
308 WlanFreeMemory_function_ && 305 WlanFreeMemory_function_ &&
309 WlanCloseHandle_function_); 306 WlanCloseHandle_function_);
310 } 307 }
311 308
312 bool WindowsWlanApi::GetAccessPointData( 309 bool WindowsWlanApi::GetAccessPointData(
313 WifiData::AccessPointDataSet *data) { 310 WifiData::AccessPointDataSet *data) {
314 assert(data); 311 DCHECK(data);
315 312
316 // Get the handle to the WLAN API. 313 // Get the handle to the WLAN API.
317 DWORD negotiated_version; 314 DWORD negotiated_version;
318 HANDLE wlan_handle = NULL; 315 HANDLE wlan_handle = NULL;
319 // We could be executing on either Windows XP or Windows Vista, so use the 316 // We could be executing on either Windows XP or Windows Vista, so use the
320 // lower version of the client WLAN API. It seems that the negotiated version 317 // lower version of the client WLAN API. It seems that the negotiated version
321 // is the Vista version irrespective of what we pass! 318 // is the Vista version irrespective of what we pass!
322 static const int kXpWlanClientVersion = 1; 319 static const int kXpWlanClientVersion = 1;
323 if ((*WlanOpenHandle_function_)(kXpWlanClientVersion, 320 if ((*WlanOpenHandle_function_)(kXpWlanClientVersion,
324 NULL, 321 NULL,
325 &negotiated_version, 322 &negotiated_version,
326 &wlan_handle) != ERROR_SUCCESS) { 323 &wlan_handle) != ERROR_SUCCESS) {
327 return false; 324 return false;
328 } 325 }
329 assert(wlan_handle); 326 DCHECK(wlan_handle);
330 327
331 // Get the list of interfaces. WlanEnumInterfaces allocates interface_list. 328 // Get the list of interfaces. WlanEnumInterfaces allocates interface_list.
332 WLAN_INTERFACE_INFO_LIST *interface_list = NULL; 329 WLAN_INTERFACE_INFO_LIST *interface_list = NULL;
333 if ((*WlanEnumInterfaces_function_)(wlan_handle, NULL, &interface_list) != 330 if ((*WlanEnumInterfaces_function_)(wlan_handle, NULL, &interface_list) !=
334 ERROR_SUCCESS) { 331 ERROR_SUCCESS) {
335 return false; 332 return false;
336 } 333 }
337 assert(interface_list); 334 DCHECK(interface_list);
338 335
339 // Go through the list of interfaces and get the data for each. 336 // Go through the list of interfaces and get the data for each.
340 for (int i = 0; i < static_cast<int>(interface_list->dwNumberOfItems); ++i) { 337 for (int i = 0; i < static_cast<int>(interface_list->dwNumberOfItems); ++i) {
341 GetInterfaceDataWLAN(wlan_handle, 338 GetInterfaceDataWLAN(wlan_handle,
342 interface_list->InterfaceInfo[i].InterfaceGuid, 339 interface_list->InterfaceInfo[i].InterfaceGuid,
343 data); 340 data);
344 } 341 }
345 342
346 // Free interface_list. 343 // Free interface_list.
347 (*WlanFreeMemory_function_)(interface_list); 344 (*WlanFreeMemory_function_)(interface_list);
348 345
349 // Close the handle. 346 // Close the handle.
350 if ((*WlanCloseHandle_function_)(wlan_handle, NULL) != ERROR_SUCCESS) { 347 if ((*WlanCloseHandle_function_)(wlan_handle, NULL) != ERROR_SUCCESS) {
351 return false; 348 return false;
352 } 349 }
353 350
354 return true; 351 return true;
355 } 352 }
356 353
357 // Appends the data for a single interface to the data vector. Returns the 354 // Appends the data for a single interface to the data vector. Returns the
358 // number of access points found, or -1 on error. 355 // number of access points found, or -1 on error.
359 int WindowsWlanApi::GetInterfaceDataWLAN( 356 int WindowsWlanApi::GetInterfaceDataWLAN(
360 const HANDLE wlan_handle, 357 const HANDLE wlan_handle,
361 const GUID &interface_id, 358 const GUID &interface_id,
362 WifiData::AccessPointDataSet *data) { 359 WifiData::AccessPointDataSet *data) {
363 assert(data); 360 DCHECK(data);
364 // WlanGetNetworkBssList allocates bss_list. 361 // WlanGetNetworkBssList allocates bss_list.
365 WLAN_BSS_LIST *bss_list; 362 WLAN_BSS_LIST *bss_list;
366 if ((*WlanGetNetworkBssList_function_)(wlan_handle, 363 if ((*WlanGetNetworkBssList_function_)(wlan_handle,
367 &interface_id, 364 &interface_id,
368 NULL, // Use all SSIDs. 365 NULL, // Use all SSIDs.
369 dot11_BSS_type_any, 366 dot11_BSS_type_any,
370 false, // bSecurityEnabled - unused 367 false, // bSecurityEnabled - unused
371 NULL, // reserved 368 NULL, // reserved
372 &bss_list) != ERROR_SUCCESS) { 369 &bss_list) != ERROR_SUCCESS) {
373 return -1; 370 return -1;
(...skipping 10 matching lines...) Expand all
384 381
385 (*WlanFreeMemory_function_)(bss_list); 382 (*WlanFreeMemory_function_)(bss_list);
386 383
387 return found; 384 return found;
388 } 385 }
389 386
390 // WindowsNdisApi 387 // WindowsNdisApi
391 WindowsNdisApi::WindowsNdisApi( 388 WindowsNdisApi::WindowsNdisApi(
392 std::vector<string16>* interface_service_names) 389 std::vector<string16>* interface_service_names)
393 : oid_buffer_size_(kInitialBufferSize) { 390 : oid_buffer_size_(kInitialBufferSize) {
394 assert(!interface_service_names->empty()); 391 DCHECK(!interface_service_names->empty());
395 interface_service_names_.swap(*interface_service_names); 392 interface_service_names_.swap(*interface_service_names);
396 } 393 }
397 394
398 WindowsNdisApi::~WindowsNdisApi() { 395 WindowsNdisApi::~WindowsNdisApi() {
399 } 396 }
400 397
401 WindowsNdisApi* WindowsNdisApi::Create() { 398 WindowsNdisApi* WindowsNdisApi::Create() {
402 std::vector<string16> interface_service_names; 399 std::vector<string16> interface_service_names;
403 if (GetInterfacesNDIS(&interface_service_names)) { 400 if (GetInterfacesNDIS(&interface_service_names)) {
404 return new WindowsNdisApi(&interface_service_names); 401 return new WindowsNdisApi(&interface_service_names);
405 } 402 }
406 return NULL; 403 return NULL;
407 } 404 }
408 405
409 bool WindowsNdisApi::GetAccessPointData(WifiData::AccessPointDataSet *data) { 406 bool WindowsNdisApi::GetAccessPointData(WifiData::AccessPointDataSet *data) {
410 assert(data); 407 DCHECK(data);
411 int interfaces_failed = 0; 408 int interfaces_failed = 0;
412 int interfaces_succeeded = 0; 409 int interfaces_succeeded = 0;
413 410
414 for (int i = 0; i < static_cast<int>(interface_service_names_.size()); ++i) { 411 for (int i = 0; i < static_cast<int>(interface_service_names_.size()); ++i) {
415 // First, check that we have a DOS device for this adapter. 412 // First, check that we have a DOS device for this adapter.
416 if (!DefineDosDeviceIfNotExists(interface_service_names_[i])) { 413 if (!DefineDosDeviceIfNotExists(interface_service_names_[i])) {
417 continue; 414 continue;
418 } 415 }
419 416
420 // Get the handle to the device. This will fail if the named device is not 417 // Get the handle to the device. This will fail if the named device is not
(...skipping 24 matching lines...) Expand all
445 std::vector<string16>* interface_service_names_out) { 442 std::vector<string16>* interface_service_names_out) {
446 HKEY network_cards_key = NULL; 443 HKEY network_cards_key = NULL;
447 if (RegOpenKeyEx( 444 if (RegOpenKeyEx(
448 HKEY_LOCAL_MACHINE, 445 HKEY_LOCAL_MACHINE,
449 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards", 446 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards",
450 0, 447 0,
451 KEY_READ, 448 KEY_READ,
452 &network_cards_key) != ERROR_SUCCESS) { 449 &network_cards_key) != ERROR_SUCCESS) {
453 return false; 450 return false;
454 } 451 }
455 assert(network_cards_key); 452 DCHECK(network_cards_key);
456 453
457 for (int i = 0; ; ++i) { 454 for (int i = 0; ; ++i) {
458 TCHAR name[kStringLength]; 455 TCHAR name[kStringLength];
459 DWORD name_size = kStringLength; 456 DWORD name_size = kStringLength;
460 FILETIME time; 457 FILETIME time;
461 if (RegEnumKeyEx(network_cards_key, 458 if (RegEnumKeyEx(network_cards_key,
462 i, 459 i,
463 name, 460 name,
464 &name_size, 461 &name_size,
465 NULL, 462 NULL,
466 NULL, 463 NULL,
467 NULL, 464 NULL,
468 &time) != ERROR_SUCCESS) { 465 &time) != ERROR_SUCCESS) {
469 break; 466 break;
470 } 467 }
471 HKEY hardware_key = NULL; 468 HKEY hardware_key = NULL;
472 if (RegOpenKeyEx(network_cards_key, name, 0, KEY_READ, &hardware_key) != 469 if (RegOpenKeyEx(network_cards_key, name, 0, KEY_READ, &hardware_key) !=
473 ERROR_SUCCESS) { 470 ERROR_SUCCESS) {
474 break; 471 break;
475 } 472 }
476 assert(hardware_key); 473 DCHECK(hardware_key);
477 474
478 TCHAR service_name[kStringLength]; 475 TCHAR service_name[kStringLength];
479 DWORD service_name_size = kStringLength; 476 DWORD service_name_size = kStringLength;
480 DWORD type = 0; 477 DWORD type = 0;
481 if (RegQueryValueEx(hardware_key, 478 if (RegQueryValueEx(hardware_key,
482 L"ServiceName", 479 L"ServiceName",
483 NULL, 480 NULL,
484 &type, 481 &type,
485 reinterpret_cast<LPBYTE>(service_name), 482 reinterpret_cast<LPBYTE>(service_name),
486 &service_name_size) == ERROR_SUCCESS) { 483 &service_name_size) == ERROR_SUCCESS) {
487 interface_service_names_out->push_back(service_name); 484 interface_service_names_out->push_back(service_name);
488 } 485 }
489 RegCloseKey(hardware_key); 486 RegCloseKey(hardware_key);
490 } 487 }
491 488
492 RegCloseKey(network_cards_key); 489 RegCloseKey(network_cards_key);
493 return true; 490 return true;
494 } 491 }
495 492
496 493
497 bool WindowsNdisApi::GetInterfaceDataNDIS(HANDLE adapter_handle, 494 bool WindowsNdisApi::GetInterfaceDataNDIS(HANDLE adapter_handle,
498 WifiData::AccessPointDataSet *data) { 495 WifiData::AccessPointDataSet *data) {
499 assert(data); 496 DCHECK(data);
500 497
501 scoped_ptr_malloc<BYTE> buffer( 498 scoped_ptr_malloc<BYTE> buffer(
502 reinterpret_cast<BYTE*>(malloc(oid_buffer_size_))); 499 reinterpret_cast<BYTE*>(malloc(oid_buffer_size_)));
503 if (buffer == NULL) { 500 if (buffer == NULL) {
504 return false; 501 return false;
505 } 502 }
506 503
507 DWORD bytes_out; 504 DWORD bytes_out;
508 int result; 505 int result;
509 506
(...skipping 15 matching lines...) Expand all
525 } 522 }
526 if (!ResizeBuffer(oid_buffer_size_, &buffer)) { 523 if (!ResizeBuffer(oid_buffer_size_, &buffer)) {
527 oid_buffer_size_ = kInitialBufferSize; // Reset for next time. 524 oid_buffer_size_ = kInitialBufferSize; // Reset for next time.
528 return false; 525 return false;
529 } 526 }
530 } else { 527 } else {
531 // The buffer is not too small. 528 // The buffer is not too small.
532 break; 529 break;
533 } 530 }
534 } 531 }
535 assert(buffer.get()); 532 DCHECK(buffer.get());
536 533
537 if (result == ERROR_SUCCESS) { 534 if (result == ERROR_SUCCESS) {
538 NDIS_802_11_BSSID_LIST* bssid_list = 535 NDIS_802_11_BSSID_LIST* bssid_list =
539 reinterpret_cast<NDIS_802_11_BSSID_LIST*>(buffer.get()); 536 reinterpret_cast<NDIS_802_11_BSSID_LIST*>(buffer.get());
540 GetDataFromBssIdList(*bssid_list, oid_buffer_size_, data); 537 GetDataFromBssIdList(*bssid_list, oid_buffer_size_, data);
541 } 538 }
542 539
543 return true; 540 return true;
544 } 541 }
545 542
546 bool IsRunningOnVistaOrNewer() { 543 bool IsRunningOnVistaOrNewer() {
547 OSVERSIONINFO info = {0}; 544 OSVERSIONINFO info = {0};
548 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 545 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
549 GetVersionEx(&info); 546 GetVersionEx(&info);
550 return (info.dwMajorVersion >=6); 547 return (info.dwMajorVersion >=6);
551 } 548 }
552 549
553 bool GetNetworkData(const WLAN_BSS_ENTRY &bss_entry, 550 bool GetNetworkData(const WLAN_BSS_ENTRY &bss_entry,
554 AccessPointData *access_point_data) { 551 AccessPointData *access_point_data) {
555 // Currently we get only MAC address, signal strength and SSID. 552 // Currently we get only MAC address, signal strength and SSID.
556 assert(access_point_data); 553 DCHECK(access_point_data);
557 access_point_data->mac_address = MacAddressAsString16(bss_entry.dot11Bssid); 554 access_point_data->mac_address = MacAddressAsString16(bss_entry.dot11Bssid);
558 access_point_data->radio_signal_strength = bss_entry.lRssi; 555 access_point_data->radio_signal_strength = bss_entry.lRssi;
559 // bss_entry.dot11Ssid.ucSSID is not null-terminated. 556 // bss_entry.dot11Ssid.ucSSID is not null-terminated.
560 UTF8ToUTF16(reinterpret_cast<const char*>(bss_entry.dot11Ssid.ucSSID), 557 UTF8ToUTF16(reinterpret_cast<const char*>(bss_entry.dot11Ssid.ucSSID),
561 static_cast<ULONG>(bss_entry.dot11Ssid.uSSIDLength), 558 static_cast<ULONG>(bss_entry.dot11Ssid.uSSIDLength),
562 &access_point_data->ssid); 559 &access_point_data->ssid);
563 // TODO(steveblock): Is it possible to get the following? 560 // TODO(steveblock): Is it possible to get the following?
564 // access_point_data->signal_to_noise 561 // access_point_data->signal_to_noise
565 // access_point_data->age 562 // access_point_data->age
566 // access_point_data->channel 563 // access_point_data->channel
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 buffer, 625 buffer,
629 buffer_size, 626 buffer_size,
630 bytes_out, 627 bytes_out,
631 NULL)) { 628 NULL)) {
632 return GetLastError(); 629 return GetLastError();
633 } 630 }
634 return ERROR_SUCCESS; 631 return ERROR_SUCCESS;
635 } 632 }
636 633
637 bool ResizeBuffer(int requested_size, scoped_ptr_malloc<BYTE>* buffer) { 634 bool ResizeBuffer(int requested_size, scoped_ptr_malloc<BYTE>* buffer) {
638 assert(requested_size > 0); 635 DCHECK(requested_size > 0);
639 assert(buffer); 636 DCHECK(buffer);
640 if (requested_size > kMaximumBufferSize) { 637 if (requested_size > kMaximumBufferSize) {
641 buffer->reset(NULL); 638 buffer->reset();
642 return false; 639 return false;
643 } 640 }
644 641
645 buffer->reset(reinterpret_cast<BYTE*>( 642 buffer->reset(reinterpret_cast<BYTE*>(
646 realloc(buffer->release(), requested_size))); 643 realloc(buffer->release(), requested_size)));
647 return buffer != NULL; 644 return buffer != NULL;
648 } 645 }
649 646
650 bool GetSystemDirectory(string16 *path) { 647 bool GetSystemDirectory(string16 *path) {
651 assert(path); 648 DCHECK(path);
652 // Return value includes terminating NULL. 649 // Return value includes terminating NULL.
653 int buffer_size = ::GetSystemDirectory(NULL, 0); 650 int buffer_size = ::GetSystemDirectory(NULL, 0);
654 if (buffer_size == 0) { 651 if (buffer_size == 0) {
655 return false; 652 return false;
656 } 653 }
657 char16 *buffer = new char16[buffer_size]; 654 char16 *buffer = new char16[buffer_size];
658 655
659 // Return value excludes terminating NULL. 656 // Return value excludes terminating NULL.
660 int characters_written = ::GetSystemDirectory(buffer, buffer_size); 657 int characters_written = ::GetSystemDirectory(buffer, buffer_size);
661 if (characters_written == 0) { 658 if (characters_written == 0) {
662 return false; 659 return false;
663 } 660 }
664 assert(characters_written == buffer_size - 1); 661 DCHECK(characters_written == buffer_size - 1);
665 662
666 path->assign(buffer); 663 path->assign(buffer);
667 delete[] buffer; 664 delete[] buffer;
668 665
669 if (path->at(path->length() - 1) != L'\\') { 666 if (path->at(path->length() - 1) != L'\\') {
670 path->append(L"\\"); 667 path->append(L"\\");
671 } 668 }
672 return true; 669 return true;
673 } 670 }
674 } // namespace 671 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/wifi_data_provider_unittest_win.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698