Chromium Code Reviews| Index: net/base/network_interfaces_win.cc |
| diff --git a/net/base/network_interfaces_win.cc b/net/base/network_interfaces_win.cc |
| index ec9aeeb19f713f4a3b2a6ed474e02184cc8279cf..bb58a16f648e0b58b3c02d36788ecf6cec2ce674 100644 |
| --- a/net/base/network_interfaces_win.cc |
| +++ b/net/base/network_interfaces_win.cc |
| @@ -200,10 +200,12 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) { |
| return internal::GetNetworkListImpl(networks, policy, is_xp, adapters); |
| } |
| -WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| +// Returns true if WLAN connection attributes are available and populates |
| +// |conn_info_ptr|. |
| +bool GetConnectionAttributesPtr(WLAN_CONNECTION_ATTRIBUTES** conn_info_ptr) { |
|
pauljensen
2015/07/29 12:09:20
Let's not give back a raw pointer that has explici
tbansal1
2015/07/30 02:05:25
IIUC, pointer to scoped_ptr is strongly discourage
|
| const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance(); |
| if (!wlanapi.initialized) |
| - return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + return false; |
| internal::WlanHandle client; |
| DWORD cur_version = 0; |
| @@ -215,14 +217,14 @@ WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 OpenHandle()")); |
| DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client); |
| if (result != ERROR_SUCCESS) |
| - return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + return false; |
| } |
| WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; |
| DWORD result = |
| wlanapi.enum_interfaces_func(client.Get(), NULL, &interface_list_ptr); |
| if (result != ERROR_SUCCESS) |
| - return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + return false; |
| scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list( |
| interface_list_ptr); |
| @@ -237,17 +239,27 @@ WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| } |
| if (info == NULL) |
| - return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + return false; |
| - WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr; |
| DWORD conn_info_size = 0; |
| WLAN_OPCODE_VALUE_TYPE op_code; |
| result = wlanapi.query_interface_func( |
| client.Get(), &info->InterfaceGuid, wlan_intf_opcode_current_connection, |
| - NULL, &conn_info_size, reinterpret_cast<VOID**>(&conn_info_ptr), |
| - &op_code); |
| + NULL, &conn_info_size, reinterpret_cast<VOID**>(conn_info_ptr), &op_code); |
| if (result != ERROR_SUCCESS) |
|
pauljensen
2015/07/29 12:09:20
how about combining these lines into "return resul
tbansal1
2015/07/30 02:05:25
After moving DCHECK up, this becomes obsolete.
|
| - return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| +WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| + WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = NULL; |
|
pauljensen
2015/07/29 12:09:20
nullptr?
tbansal1
2015/07/30 02:05:25
Done.
|
| + if (!GetConnectionAttributesPtr(&conn_info_ptr)) { |
| + DCHECK(!conn_info_ptr); |
|
pauljensen
2015/07/29 12:09:20
I don't think WlanQueryInterface is guaranteed to
tbansal1
2015/07/30 02:05:25
Done.
|
| + return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + } |
| + DCHECK(conn_info_ptr); |
|
pauljensen
2015/07/29 12:09:20
Can we move this into GetConnectionAttributesPtr?
tbansal1
2015/07/30 02:05:25
Done.
|
| + |
| scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info( |
| conn_info_ptr); |
| @@ -328,8 +340,18 @@ scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) { |
| } |
| std::string GetWifiSSID() { |
| - NOTIMPLEMENTED(); |
| - return ""; |
| + WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = NULL; |
|
pauljensen
2015/07/29 12:09:20
nullptr?
tbansal1
2015/07/30 02:05:25
Done.
|
| + if (!GetConnectionAttributesPtr(&conn_info_ptr)) { |
| + DCHECK(!conn_info_ptr); |
| + return ""; |
| + } |
| + DCHECK(conn_info_ptr); |
| + |
| + scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info( |
| + conn_info_ptr); |
| + const DOT11_SSID dot11_ssid = conn_info->wlanAssociationAttributes.dot11Ssid; |
| + return std::string(reinterpret_cast<const char*>(dot11_ssid.ucSSID), |
| + dot11_ssid.uSSIDLength); |
| } |
| } // namespace net |