Chromium Code Reviews| Index: net/base/net_util_win.cc |
| diff --git a/net/base/net_util_win.cc b/net/base/net_util_win.cc |
| index cac92e39d54bbb391814190d1faf0ed440c61848..448bf85e9688d7ff86b9ce0bf6da45db4e32e1ba 100644 |
| --- a/net/base/net_util_win.cc |
| +++ b/net/base/net_util_win.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/files/file_path.h" |
| #include "base/lazy_instance.h" |
| +#include "base/memory/lifetime_interface.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/strings/string_piece.h" |
| #include "base/strings/string_util.h" |
| @@ -36,6 +37,8 @@ struct WlanApi { |
| typedef DWORD (WINAPI *WlanQueryInterfaceFunc)( |
| HANDLE, const GUID*, WLAN_INTF_OPCODE, VOID*, DWORD*, VOID**, |
| WLAN_OPCODE_VALUE_TYPE*); |
| + typedef DWORD (WINAPI *WlanSetInterfaceFunc)( |
| + HANDLE, const GUID*, WLAN_INTF_OPCODE, DWORD, const VOID*, VOID*); |
| typedef VOID (WINAPI *WlanFreeMemoryFunc)(VOID*); |
| typedef DWORD (WINAPI *WlanCloseHandleFunc)(HANDLE, VOID*); |
| @@ -54,6 +57,8 @@ struct WlanApi { |
| ::GetProcAddress(module, "WlanEnumInterfaces")); |
| query_interface_func = reinterpret_cast<WlanQueryInterfaceFunc>( |
| ::GetProcAddress(module, "WlanQueryInterface")); |
| + set_interface_func = reinterpret_cast<WlanSetInterfaceFunc>( |
| + ::GetProcAddress(module, "WlanSetInterface")); |
| free_memory_func = reinterpret_cast<WlanFreeMemoryFunc>( |
| ::GetProcAddress(module, "WlanFreeMemory")); |
| close_handle_func = reinterpret_cast<WlanCloseHandleFunc>( |
| @@ -78,6 +83,7 @@ struct WlanApi { |
| WlanOpenHandleFunc open_handle_func; |
| WlanEnumInterfacesFunc enum_interfaces_func; |
| WlanQueryInterfaceFunc query_interface_func; |
| + WlanSetInterfaceFunc set_interface_func; |
| WlanFreeMemoryFunc free_memory_func; |
| WlanCloseHandleFunc close_handle_func; |
| bool initialized; |
| @@ -215,9 +221,9 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) { |
| return true; |
| } |
| -WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| - static base::LazyInstance<WlanApi>::Leaky lazy_wlanapi = |
| - LAZY_INSTANCE_INITIALIZER; |
| +namespace { |
|
pauljensen
2014/09/16 15:01:18
I think moving this up into the anonymous namespac
hubbe
2014/09/16 21:06:50
Done.
|
| +base::LazyInstance<WlanApi>::Leaky lazy_wlanapi = |
| + LAZY_INSTANCE_INITIALIZER; |
| struct WlanApiHandleTraits { |
| typedef HANDLE Handle; |
| @@ -243,7 +249,9 @@ WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| lazy_wlanapi.Get().free_memory_func(ptr); |
| } |
| }; |
| +}; |
|
pauljensen
2014/09/16 15:01:18
// namespace
hubbe
2014/09/16 21:06:51
No longer relevant.
|
| +WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| const WlanApi& wlanapi = lazy_wlanapi.Get(); |
| if (!wlanapi.initialized) |
| return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| @@ -306,4 +314,58 @@ WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| } |
| } |
| +class WifiOptionSetter : public base::LifetimeInterface { |
| + public: |
| + WifiOptionSetter(int options) { |
|
pauljensen
2014/09/16 15:01:18
indent
hubbe
2014/09/16 21:06:50
Done (finally configured emacs on my windows box,
|
| + const WlanApi& wlanapi = lazy_wlanapi.Get(); |
| + if (!wlanapi.initialized) |
| + return; |
| + |
| + DWORD cur_version = 0; |
| + const DWORD kMaxClientVersion = 2; |
|
pauljensen
2014/09/16 15:01:18
Please add a comment about where this 0 and 2 come
hubbe
2014/09/16 21:06:50
Gladly, but I don't know. I copied this from line
|
| + DWORD result = wlanapi.OpenHandle( |
| + kMaxClientVersion, &cur_version, &client_); |
| + if (result != ERROR_SUCCESS) |
| + return; |
| + |
| + WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; |
| + result = wlanapi.enum_interfaces_func(client_, NULL, &interface_list_ptr); |
| + if (result != ERROR_SUCCESS) |
| + return; |
| + scoped_ptr<WLAN_INTERFACE_INFO_LIST, WlanApiDeleter> interface_list( |
| + interface_list_ptr); |
| + |
| + // Assume at most one connected wifi interface. |
|
pauljensen
2014/09/16 15:01:18
"at most one"? This function appears to loop thro
hubbe
2014/09/16 21:06:50
Oops, removed.
|
| + WLAN_INTERFACE_INFO* info = NULL; |
| + for (unsigned i = 0; i < interface_list->dwNumberOfItems; ++i) { |
| + if (options & WIFI_OPTIONS_DISABLE_SCAN) { |
| + BOOL data = false; |
| + wlanapi.set_interface_func(client_, |
| + &info->InterfaceGuid, |
| + wlan_intf_opcode_background_scan_enabled, |
| + sizeof(data), |
| + &data, |
| + NULL); |
| + } |
| + if (options & WIFI_OPTIONS_MEDIA_STREAMING_MODE) { |
| + BOOL data = true; |
| + wlanapi.set_interface_func(client_, |
| + &info->InterfaceGuid, |
| + wlan_intf_opcode_media_streaming_mode, |
| + sizeof(data), |
| + &data, |
| + NULL); |
| + } |
| + } |
| + } |
| + |
|
pauljensen
2014/09/16 15:01:18
Maybe I'm missing something, but shouldn't there b
hubbe
2014/09/16 21:06:51
If I'm reading the documentation correctly, the OS
|
| +private: |
| + WlanHandle client_; |
| +}; |
| + |
| +scoped_ptr<base::LifetimeInterface> SetWifiOptions(int options) { |
| + return scoped_ptr<base::LifetimeInterface>( |
| + new WifiOptionSetter(options)); |
| +} |
| + |
| } // namespace net |