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

Side by Side Diff: components/wifi/wifi_service_win.cc

Issue 249683002: Rename WiFiService::GetConnectedProperties into GetCurrentProperties. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "components/wifi/wifi_service.h" 5 #include "components/wifi/wifi_service.h"
6 6
7 #include <iphlpapi.h> 7 #include <iphlpapi.h>
8 #include <objbase.h> 8 #include <objbase.h>
9 #include <wlanapi.h> 9 #include <wlanapi.h>
10 10
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 // Update |properties| based on bss info from |wlan_bss_list|. If |bssid| in 348 // Update |properties| based on bss info from |wlan_bss_list|. If |bssid| in
349 // |properties| is not empty, then it is not changed and |frequency| is set 349 // |properties| is not empty, then it is not changed and |frequency| is set
350 // based on that bssid. 350 // based on that bssid.
351 void UpdateNetworkPropertiesFromBssList(const std::string& network_guid, 351 void UpdateNetworkPropertiesFromBssList(const std::string& network_guid,
352 const WLAN_BSS_LIST& wlan_bss_list, 352 const WLAN_BSS_LIST& wlan_bss_list,
353 NetworkProperties* properties); 353 NetworkProperties* properties);
354 354
355 // Get the list of visible wireless networks. 355 // Get the list of visible wireless networks.
356 DWORD GetVisibleNetworkList(NetworkList* network_list); 356 DWORD GetVisibleNetworkList(NetworkList* network_list);
357 357
358 // Find currently connected network if any. Populate |connected_properties| 358 // Get properties of the network currently used (connected or in transition)
359 // on success. 359 // by interface. Populate |current_properties| on success.
360 DWORD GetConnectedProperties(NetworkProperties* connected_properties); 360 DWORD GetCurrentProperties(NetworkProperties* current_properties);
361 361
362 // Connect to network |network_guid| using previosly stored profile if exists, 362 // Connect to network |network_guid| using previosly stored profile if exists,
363 // or just network sid. If |frequency| is not |kFrequencyUnknown| then 363 // or just network sid. If |frequency| is not |kFrequencyUnknown| then
364 // connects only to BSS which uses that frequency and returns 364 // connects only to BSS which uses that frequency and returns
365 // |ERROR_NOT_FOUND| if such BSS cannot be found. 365 // |ERROR_NOT_FOUND| if such BSS cannot be found.
366 DWORD Connect(const std::string& network_guid, Frequency frequency); 366 DWORD Connect(const std::string& network_guid, Frequency frequency);
367 367
368 // Disconnect from currently connected network if any. 368 // Disconnect from currently connected network if any.
369 DWORD Disconnect(); 369 DWORD Disconnect();
370 370
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 } 508 }
509 509
510 void WiFiServiceImpl::GetProperties(const std::string& network_guid, 510 void WiFiServiceImpl::GetProperties(const std::string& network_guid,
511 base::DictionaryValue* properties, 511 base::DictionaryValue* properties,
512 std::string* error) { 512 std::string* error) {
513 DWORD error_code = EnsureInitialized(); 513 DWORD error_code = EnsureInitialized();
514 if (CheckError(error_code, kWiFiServiceError, error)) 514 if (CheckError(error_code, kWiFiServiceError, error))
515 return; 515 return;
516 516
517 NetworkProperties connected_properties; 517 NetworkProperties connected_properties;
518 error_code = GetConnectedProperties(&connected_properties); 518 error_code = GetCurrentProperties(&connected_properties);
519 if (error_code == ERROR_SUCCESS && 519 if (error_code == ERROR_SUCCESS &&
520 connected_properties.guid == network_guid) { 520 connected_properties.guid == network_guid) {
521 properties->Swap(connected_properties.ToValue(false).get()); 521 properties->Swap(connected_properties.ToValue(false).get());
522 return; 522 return;
523 } 523 }
524 524
525 NetworkList network_list; 525 NetworkList network_list;
526 error_code = GetVisibleNetworkList(&network_list); 526 error_code = GetVisibleNetworkList(&network_list);
527 if (error_code == ERROR_SUCCESS) { 527 if (error_code == ERROR_SUCCESS) {
528 NetworkList::const_iterator it = FindNetwork(network_list, network_guid); 528 NetworkList::const_iterator it = FindNetwork(network_list, network_guid);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 DVLOG(1) << "Start Connect: " << network_guid; 662 DVLOG(1) << "Start Connect: " << network_guid;
663 DWORD error_code = EnsureInitialized(); 663 DWORD error_code = EnsureInitialized();
664 if (error_code == ERROR_SUCCESS) { 664 if (error_code == ERROR_SUCCESS) {
665 std::string connected_network_guid; 665 std::string connected_network_guid;
666 error_code = SaveCurrentConnectedNetwork(&connected_network_guid); 666 error_code = SaveCurrentConnectedNetwork(&connected_network_guid);
667 if (error_code == ERROR_SUCCESS) { 667 if (error_code == ERROR_SUCCESS) {
668 // Check, if the network is already connected on desired frequency. 668 // Check, if the network is already connected on desired frequency.
669 bool already_connected = (network_guid == connected_network_guid); 669 bool already_connected = (network_guid == connected_network_guid);
670 Frequency frequency = GetFrequencyToConnect(network_guid); 670 Frequency frequency = GetFrequencyToConnect(network_guid);
671 if (already_connected && frequency != kFrequencyAny) { 671 if (already_connected && frequency != kFrequencyAny) {
672 NetworkProperties connected_properties; 672 NetworkProperties current_properties;
673 if (GetConnectedProperties(&connected_properties) == ERROR_SUCCESS) { 673 if (GetCurrentProperties(&current_properties) == ERROR_SUCCESS) {
674 already_connected = frequency == connected_properties.frequency && 674 already_connected = current_properties.connection_state ==
675 network_guid == connected_properties.guid; 675 onc::connection_state::kConnected &&
tbarzic 2014/04/23 16:50:20 nit: increasing indent (+4) here would make it eas
mef 2014/04/23 17:04:21 Done.
676 frequency == current_properties.frequency &&
677 network_guid == current_properties.guid;
676 } 678 }
677 } 679 }
678 // Connect only if network |network_guid| is not connected already. 680 // Connect only if network |network_guid| is not connected already.
679 if (!already_connected) 681 if (!already_connected)
680 error_code = Connect(network_guid, frequency); 682 error_code = Connect(network_guid, frequency);
681 if (error_code == ERROR_SUCCESS) { 683 if (error_code == ERROR_SUCCESS) {
682 // Notify that previously connected network has changed. 684 // Notify that previously connected network has changed.
683 NotifyNetworkChanged(connected_network_guid); 685 NotifyNetworkChanged(connected_network_guid);
684 // Start waiting for network connection state change. 686 // Start waiting for network connection state change.
685 if (!networks_changed_observer_.is_null()) { 687 if (!networks_changed_observer_.is_null()) {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 LOG(ERROR) << "Failed to delete created profile for " << network_guid 889 LOG(ERROR) << "Failed to delete created profile for " << network_guid
888 << " error=" << error_code; 890 << " error=" << error_code;
889 } 891 }
890 } 892 }
891 } 893 }
892 // Restore automatic network change notifications and stop waiting. 894 // Restore automatic network change notifications and stop waiting.
893 enable_notify_network_changed_ = true; 895 enable_notify_network_changed_ = true;
894 RestoreNwCategoryWizard(); 896 RestoreNwCategoryWizard();
895 return; 897 return;
896 } 898 }
897 NetworkProperties connected_network_properties; 899 NetworkProperties current_properties;
898 DWORD error = GetConnectedProperties(&connected_network_properties); 900 DWORD error = GetCurrentProperties(&current_properties);
899 if (network_guid == connected_network_properties.guid && 901 if (network_guid == current_properties.guid &&
900 connected_network_properties.connection_state == 902 current_properties.connection_state ==
901 onc::connection_state::kConnected) { 903 onc::connection_state::kConnected) {
902 DVLOG(1) << "WiFi Connected, Reset DHCP: " << network_guid; 904 DVLOG(1) << "WiFi Connected, Reset DHCP: " << network_guid;
903 // Even though wireless network is now connected, it may still be unusable, 905 // Even though wireless network is now connected, it may still be unusable,
904 // e.g. after Chromecast device reset. Reset DHCP on wireless network to 906 // e.g. after Chromecast device reset. Reset DHCP on wireless network to
905 // work around this issue. 907 // work around this issue.
906 error = ResetDHCP(); 908 error = ResetDHCP();
907 // There is no need to keep created profile as network is connected. 909 // There is no need to keep created profile as network is connected.
908 created_profiles_.RemoveWithoutPathExpansion(network_guid, NULL); 910 created_profiles_.RemoveWithoutPathExpansion(network_guid, NULL);
909 // Restore previously suppressed notifications. 911 // Restore previously suppressed notifications.
910 enable_notify_network_changed_ = true; 912 enable_notify_network_changed_ = true;
(...skipping 29 matching lines...) Expand all
940 ++it) { 942 ++it) {
941 if (it->guid == network_guid) 943 if (it->guid == network_guid)
942 return it; 944 return it;
943 } 945 }
944 return networks.end(); 946 return networks.end();
945 } 947 }
946 948
947 DWORD WiFiServiceImpl::SaveCurrentConnectedNetwork( 949 DWORD WiFiServiceImpl::SaveCurrentConnectedNetwork(
948 std::string* connected_network_guid) { 950 std::string* connected_network_guid) {
949 // Find currently connected network. 951 // Find currently connected network.
950 NetworkProperties connected_network_properties; 952 NetworkProperties current_properties;
951 DWORD error = GetConnectedProperties(&connected_network_properties); 953 DWORD error = GetCurrentProperties(&current_properties);
952 if (error == ERROR_SUCCESS && !connected_network_properties.guid.empty()) { 954 if (error == ERROR_SUCCESS && !current_properties.guid.empty() &&
953 *connected_network_guid = connected_network_properties.guid; 955 current_properties.connection_state ==
956 onc::connection_state::kConnected) {
957 *connected_network_guid = current_properties.guid;
954 SaveTempProfile(*connected_network_guid); 958 SaveTempProfile(*connected_network_guid);
955 std::string profile_xml; 959 std::string profile_xml;
956 error = GetProfile(*connected_network_guid, false, &profile_xml); 960 error = GetProfile(*connected_network_guid, false, &profile_xml);
957 if (error == ERROR_SUCCESS) { 961 if (error == ERROR_SUCCESS) {
958 saved_profiles_xml_[*connected_network_guid] = profile_xml; 962 saved_profiles_xml_[*connected_network_guid] = profile_xml;
959 } 963 }
960 } 964 }
961 return error; 965 return error;
962 } 966 }
963 967
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 // Clean up. 1382 // Clean up.
1379 if (available_network_list != NULL) { 1383 if (available_network_list != NULL) {
1380 WlanFreeMemory_function_(available_network_list); 1384 WlanFreeMemory_function_(available_network_list);
1381 } 1385 }
1382 if (bss_list != NULL) { 1386 if (bss_list != NULL) {
1383 WlanFreeMemory_function_(bss_list); 1387 WlanFreeMemory_function_(bss_list);
1384 } 1388 }
1385 return error; 1389 return error;
1386 } 1390 }
1387 1391
1388 DWORD WiFiServiceImpl::GetConnectedProperties(NetworkProperties* properties) { 1392 DWORD WiFiServiceImpl::GetCurrentProperties(NetworkProperties* properties) {
1389 if (client_ == NULL) { 1393 if (client_ == NULL) {
1390 NOTREACHED(); 1394 NOTREACHED();
1391 return ERROR_NOINTERFACE; 1395 return ERROR_NOINTERFACE;
1392 } 1396 }
1393 1397
1394 // TODO(mef): WlanGetNetworkBssList is not available on XP. If XP support is 1398 // TODO(mef): WlanGetNetworkBssList is not available on XP. If XP support is
1395 // needed, then different method of getting BSS (e.g. OID query) will have 1399 // needed, then different method of getting BSS (e.g. OID query) will have
1396 // to be used. 1400 // to be used.
1397 if (WlanGetNetworkBssList_function_ == NULL) 1401 if (WlanGetNetworkBssList_function_ == NULL)
1398 return ERROR_NOINTERFACE; 1402 return ERROR_NOINTERFACE;
1399 1403
1400 Frequency frequency = kFrequencyUnknown;
1401 DWORD error = ERROR_SUCCESS; 1404 DWORD error = ERROR_SUCCESS;
1402 DWORD data_size = 0; 1405 DWORD data_size = 0;
1403 PWLAN_CONNECTION_ATTRIBUTES wlan_connection_attributes = NULL; 1406 PWLAN_CONNECTION_ATTRIBUTES wlan_connection_attributes = NULL;
1404 PWLAN_BSS_LIST bss_list = NULL; 1407 PWLAN_BSS_LIST bss_list = NULL;
1405 error = WlanQueryInterface_function_( 1408 error = WlanQueryInterface_function_(
1406 client_, 1409 client_,
1407 &interface_guid_, 1410 &interface_guid_,
1408 wlan_intf_opcode_current_connection, 1411 wlan_intf_opcode_current_connection,
1409 NULL, 1412 NULL,
1410 &data_size, 1413 &data_size,
1411 reinterpret_cast<PVOID*>(&wlan_connection_attributes), 1414 reinterpret_cast<PVOID*>(&wlan_connection_attributes),
1412 NULL); 1415 NULL);
1413 if (error == ERROR_SUCCESS && 1416 if (error == ERROR_SUCCESS &&
1414 wlan_connection_attributes != NULL) { 1417 wlan_connection_attributes != NULL) {
1415 WLAN_ASSOCIATION_ATTRIBUTES& connected_wlan = 1418 WLAN_ASSOCIATION_ATTRIBUTES& connected_wlan =
1416 wlan_connection_attributes->wlanAssociationAttributes; 1419 wlan_connection_attributes->wlanAssociationAttributes;
1417 1420
1418 properties->connection_state = ConnectionStateFromInterfaceState( 1421 properties->connection_state = ConnectionStateFromInterfaceState(
1419 wlan_connection_attributes->isState); 1422 wlan_connection_attributes->isState);
1420 properties->ssid = GUIDFromSSID(connected_wlan.dot11Ssid); 1423 properties->ssid = GUIDFromSSID(connected_wlan.dot11Ssid);
1421 properties->name = properties->ssid; 1424 properties->name = properties->ssid;
1422 properties->guid = GUIDFromSSID(connected_wlan.dot11Ssid); 1425 properties->guid = GUIDFromSSID(connected_wlan.dot11Ssid);
1423 properties->type = onc::network_type::kWiFi; 1426 properties->type = onc::network_type::kWiFi;
1424 properties->bssid = NetworkProperties::MacAddressAsString( 1427 properties->bssid = NetworkProperties::MacAddressAsString(
1425 connected_wlan.dot11Bssid); 1428 connected_wlan.dot11Bssid);
1426 properties->security = SecurityFromDot11AuthAlg( 1429 properties->security = SecurityFromDot11AuthAlg(
1427 wlan_connection_attributes->wlanSecurityAttributes.dot11AuthAlgorithm); 1430 wlan_connection_attributes->wlanSecurityAttributes.dot11AuthAlgorithm);
1428 properties->signal_strength = connected_wlan.wlanSignalQuality; 1431 properties->signal_strength = connected_wlan.wlanSignalQuality;
1429 1432
1430 // TODO(mef): WlanGetNetworkBssList is not available on XP. If XP support is
1431 // needed, then different method of getting BSS (e.g. OID query) will have
1432 // to be used.
1433 error = WlanGetNetworkBssList_function_(client_, 1433 error = WlanGetNetworkBssList_function_(client_,
1434 &interface_guid_, 1434 &interface_guid_,
1435 &connected_wlan.dot11Ssid, 1435 &connected_wlan.dot11Ssid,
1436 connected_wlan.dot11BssType, 1436 connected_wlan.dot11BssType,
1437 FALSE, 1437 FALSE,
1438 NULL, 1438 NULL,
1439 &bss_list); 1439 &bss_list);
1440 if (error == ERROR_SUCCESS && NULL != bss_list) { 1440 if (error == ERROR_SUCCESS && NULL != bss_list) {
1441 UpdateNetworkPropertiesFromBssList(properties->guid, 1441 UpdateNetworkPropertiesFromBssList(properties->guid,
1442 *bss_list, 1442 *bss_list,
1443 properties); 1443 properties);
1444 } 1444 }
1445 } 1445 }
1446 1446
1447 // Clean up. 1447 // Clean up.
1448 if (wlan_connection_attributes != NULL) 1448 if (wlan_connection_attributes != NULL)
1449 WlanFreeMemory_function_(wlan_connection_attributes); 1449 WlanFreeMemory_function_(wlan_connection_attributes);
1450 1450
1451 if (bss_list != NULL) 1451 if (bss_list != NULL)
1452 WlanFreeMemory_function_(bss_list); 1452 WlanFreeMemory_function_(bss_list);
1453 1453
1454 return frequency; 1454 return error;
1455 } 1455 }
1456 1456
1457 WiFiService::Frequency WiFiServiceImpl::GetFrequencyToConnect( 1457 WiFiService::Frequency WiFiServiceImpl::GetFrequencyToConnect(
1458 const std::string& network_guid) const { 1458 const std::string& network_guid) const {
1459 // Check whether desired frequency is set in |connect_properties_|. 1459 // Check whether desired frequency is set in |connect_properties_|.
1460 const base::DictionaryValue* properties; 1460 const base::DictionaryValue* properties;
1461 const base::DictionaryValue* wifi; 1461 const base::DictionaryValue* wifi;
1462 int frequency; 1462 int frequency;
1463 if (connect_properties_.GetDictionaryWithoutPathExpansion( 1463 if (connect_properties_.GetDictionaryWithoutPathExpansion(
1464 network_guid, &properties) && 1464 network_guid, &properties) &&
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 NetworkGuidList changed_networks(1, network_guid); 1818 NetworkGuidList changed_networks(1, network_guid);
1819 message_loop_proxy_->PostTask( 1819 message_loop_proxy_->PostTask(
1820 FROM_HERE, 1820 FROM_HERE,
1821 base::Bind(networks_changed_observer_, changed_networks)); 1821 base::Bind(networks_changed_observer_, changed_networks));
1822 } 1822 }
1823 } 1823 }
1824 1824
1825 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } 1825 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); }
1826 1826
1827 } // namespace wifi 1827 } // namespace wifi
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698