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..5cc3dc20bdffd71a7726a74f885f3b321100de49 100644 |
| --- a/net/base/network_interfaces_win.cc |
| +++ b/net/base/network_interfaces_win.cc |
| @@ -200,10 +200,13 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) { |
| return internal::GetNetworkListImpl(networks, policy, is_xp, adapters); |
| } |
| -WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| +// Returns scoped_ptr to WLAN_CONNECTION_ATTRIBUTES. The scoped_ptr may hold a |
| +// NULL pointer if WLAN_CONNECTION_ATTRIBUTES is unavailable. |
| +scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> |
| +GetConnectionAttributes() { |
|
pauljensen
2015/07/31 12:59:42
Move this function up into the anonymous namespace
tbansal1
2015/07/31 19:49:43
Done.
|
| const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance(); |
| if (!wlanapi.initialized) |
| - return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(); |
| internal::WlanHandle client; |
| DWORD cur_version = 0; |
| @@ -215,14 +218,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 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(); |
| } |
| 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 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(); |
| scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list( |
| interface_list_ptr); |
| @@ -237,9 +240,9 @@ WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| } |
| if (info == NULL) |
| - return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(); |
| - WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr; |
| + WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = nullptr; |
| DWORD conn_info_size = 0; |
| WLAN_OPCODE_VALUE_TYPE op_code; |
| result = wlanapi.query_interface_func( |
| @@ -247,10 +250,21 @@ WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| NULL, &conn_info_size, reinterpret_cast<VOID**>(&conn_info_ptr), |
| &op_code); |
| if (result != ERROR_SUCCESS) |
| - return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; |
| + return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(); |
| scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info( |
| conn_info_ptr); |
| + DCHECK(conn_info.get()); |
| + return conn_info.Pass(); |
|
pauljensen
2015/07/31 12:59:42
Lets change these five lines to:
DCHECK(conn_info_
tbansal1
2015/07/31 19:49:43
Done.
|
| +} |
| + |
| +WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| + scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info = |
|
pauljensen
2015/07/31 12:59:42
I think using auto here might be nice as the type
tbansal1
2015/07/31 19:49:43
Done.
|
| + GetConnectionAttributes(); |
| + |
| + if (!conn_info.get()) |
| + return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + |
| switch (conn_info->wlanAssociationAttributes.dot11PhyType) { |
| case dot11_phy_type_fhss: |
| return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; |
| @@ -328,8 +342,15 @@ scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) { |
| } |
| std::string GetWifiSSID() { |
| - NOTIMPLEMENTED(); |
| - return ""; |
| + scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info = |
| + GetConnectionAttributes(); |
|
pauljensen
2015/07/31 12:59:42
ditto
tbansal1
2015/07/31 19:49:43
Done.
|
| + |
| + if (!conn_info.get()) |
| + return ""; |
| + |
| + const DOT11_SSID dot11_ssid = conn_info->wlanAssociationAttributes.dot11Ssid; |
| + return std::string(reinterpret_cast<const char*>(dot11_ssid.ucSSID), |
| + dot11_ssid.uSSIDLength); |
| } |
| } // namespace net |