| OLD | NEW |
| 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 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 } | 696 } |
| 697 | 697 |
| 698 // Did not find passphrase in the profile. | 698 // Did not find passphrase in the profile. |
| 699 *error = kWiFiServiceError; | 699 *error = kWiFiServiceError; |
| 700 } | 700 } |
| 701 | 701 |
| 702 void WiFiServiceImpl::SetEventObservers( | 702 void WiFiServiceImpl::SetEventObservers( |
| 703 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 703 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 704 const NetworkGuidListCallback& networks_changed_observer, | 704 const NetworkGuidListCallback& networks_changed_observer, |
| 705 const NetworkGuidListCallback& network_list_changed_observer) { | 705 const NetworkGuidListCallback& network_list_changed_observer) { |
| 706 DWORD error_code = EnsureInitialized(); |
| 707 if (error_code != ERROR_SUCCESS) |
| 708 return; |
| 706 message_loop_proxy_.swap(message_loop_proxy); | 709 message_loop_proxy_.swap(message_loop_proxy); |
| 710 if (!networks_changed_observer_.is_null() || |
| 711 !network_list_changed_observer_.is_null()) { |
| 712 // Stop listening to WLAN notifications. |
| 713 WlanRegisterNotification_function_(client_, |
| 714 WLAN_NOTIFICATION_SOURCE_NONE, |
| 715 FALSE, |
| 716 OnWlanNotificationCallback, |
| 717 this, |
| 718 NULL, |
| 719 NULL); |
| 720 } |
| 707 networks_changed_observer_ = networks_changed_observer; | 721 networks_changed_observer_ = networks_changed_observer; |
| 708 network_list_changed_observer_ = network_list_changed_observer; | 722 network_list_changed_observer_ = network_list_changed_observer; |
| 723 if (!networks_changed_observer_.is_null() || |
| 724 !network_list_changed_observer_.is_null()) { |
| 725 // Start listening to WLAN notifications. |
| 726 WlanRegisterNotification_function_(client_, |
| 727 WLAN_NOTIFICATION_SOURCE_ALL, |
| 728 FALSE, |
| 729 OnWlanNotificationCallback, |
| 730 this, |
| 731 NULL, |
| 732 NULL); |
| 733 } |
| 709 } | 734 } |
| 710 | 735 |
| 711 void WiFiServiceImpl::OnWlanNotificationCallback( | 736 void WiFiServiceImpl::OnWlanNotificationCallback( |
| 712 PWLAN_NOTIFICATION_DATA wlan_notification_data, | 737 PWLAN_NOTIFICATION_DATA wlan_notification_data, |
| 713 PVOID context) { | 738 PVOID context) { |
| 714 WiFiServiceImpl* service = reinterpret_cast<WiFiServiceImpl*>(context); | 739 WiFiServiceImpl* service = reinterpret_cast<WiFiServiceImpl*>(context); |
| 715 service->OnWlanNotification(wlan_notification_data); | 740 service->OnWlanNotification(wlan_notification_data); |
| 716 } | 741 } |
| 717 | 742 |
| 718 void WiFiServiceImpl::OnWlanNotification( | 743 void WiFiServiceImpl::OnWlanNotification( |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 interface_guid_ = interface_list->InterfaceInfo[0].InterfaceGuid; | 961 interface_guid_ = interface_list->InterfaceInfo[0].InterfaceGuid; |
| 937 // Try to find a connected interface. | 962 // Try to find a connected interface. |
| 938 for (DWORD itf = 0; itf < interface_list->dwNumberOfItems; ++itf) { | 963 for (DWORD itf = 0; itf < interface_list->dwNumberOfItems; ++itf) { |
| 939 if (interface_list->InterfaceInfo[itf].isState == | 964 if (interface_list->InterfaceInfo[itf].isState == |
| 940 wlan_interface_state_connected) { | 965 wlan_interface_state_connected) { |
| 941 // Found connected interface, remember it! | 966 // Found connected interface, remember it! |
| 942 interface_guid_ = interface_list->InterfaceInfo[itf].InterfaceGuid; | 967 interface_guid_ = interface_list->InterfaceInfo[itf].InterfaceGuid; |
| 943 break; | 968 break; |
| 944 } | 969 } |
| 945 } | 970 } |
| 946 WlanRegisterNotification_function_(client_, | |
| 947 WLAN_NOTIFICATION_SOURCE_ALL, | |
| 948 FALSE, | |
| 949 OnWlanNotificationCallback, | |
| 950 this, | |
| 951 NULL, | |
| 952 NULL); | |
| 953 } else { | 971 } else { |
| 954 error = ERROR_NOINTERFACE; | 972 error = ERROR_NOINTERFACE; |
| 955 } | 973 } |
| 956 } | 974 } |
| 957 // Clean up.. | 975 // Clean up.. |
| 958 if (interface_list != NULL) | 976 if (interface_list != NULL) |
| 959 WlanFreeMemory_function_(interface_list); | 977 WlanFreeMemory_function_(interface_list); |
| 960 } | 978 } |
| 961 return error; | 979 return error; |
| 962 } | 980 } |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1644 NetworkGuidList changed_networks(1, network_guid); | 1662 NetworkGuidList changed_networks(1, network_guid); |
| 1645 message_loop_proxy_->PostTask( | 1663 message_loop_proxy_->PostTask( |
| 1646 FROM_HERE, | 1664 FROM_HERE, |
| 1647 base::Bind(networks_changed_observer_, changed_networks)); | 1665 base::Bind(networks_changed_observer_, changed_networks)); |
| 1648 } | 1666 } |
| 1649 } | 1667 } |
| 1650 | 1668 |
| 1651 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } | 1669 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } |
| 1652 | 1670 |
| 1653 } // namespace wifi | 1671 } // namespace wifi |
| OLD | NEW |