| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import <CoreWLAN/CoreWLAN.h> | 7 #import <CoreWLAN/CoreWLAN.h> |
| 8 #import <netinet/in.h> | 8 #import <netinet/in.h> |
| 9 #import <SystemConfiguration/SystemConfiguration.h> | 9 #import <SystemConfiguration/SystemConfiguration.h> |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 std::string* error) override; | 64 std::string* error) override; |
| 65 | 65 |
| 66 void StartDisconnect(const std::string& network_guid, | 66 void StartDisconnect(const std::string& network_guid, |
| 67 std::string* error) override; | 67 std::string* error) override; |
| 68 | 68 |
| 69 void GetKeyFromSystem(const std::string& network_guid, | 69 void GetKeyFromSystem(const std::string& network_guid, |
| 70 std::string* key_data, | 70 std::string* key_data, |
| 71 std::string* error) override; | 71 std::string* error) override; |
| 72 | 72 |
| 73 void SetEventObservers( | 73 void SetEventObservers( |
| 74 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 74 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 75 const NetworkGuidListCallback& networks_changed_observer, | 75 const NetworkGuidListCallback& networks_changed_observer, |
| 76 const NetworkGuidListCallback& network_list_changed_observer) override; | 76 const NetworkGuidListCallback& network_list_changed_observer) override; |
| 77 | 77 |
| 78 void RequestConnectedNetworkUpdate() override; | 78 void RequestConnectedNetworkUpdate() override; |
| 79 | 79 |
| 80 void GetConnectedNetworkSSID(std::string* ssid, std::string* error) override; | 80 void GetConnectedNetworkSSID(std::string* ssid, std::string* error) override; |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 // Checks |ns_error| and if is not |nil|, then stores |error_name| | 83 // Checks |ns_error| and if is not |nil|, then stores |error_name| |
| 84 // into |error|. | 84 // into |error|. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 // Default interface. | 134 // Default interface. |
| 135 base::scoped_nsobject<CWInterface> interface_; | 135 base::scoped_nsobject<CWInterface> interface_; |
| 136 // WLAN Notifications observer. |this| doesn't own this reference. | 136 // WLAN Notifications observer. |this| doesn't own this reference. |
| 137 id wlan_observer_; | 137 id wlan_observer_; |
| 138 | 138 |
| 139 // Observer to get notified when network(s) have changed (e.g. connect). | 139 // Observer to get notified when network(s) have changed (e.g. connect). |
| 140 NetworkGuidListCallback networks_changed_observer_; | 140 NetworkGuidListCallback networks_changed_observer_; |
| 141 // Observer to get notified when network list has changed. | 141 // Observer to get notified when network list has changed. |
| 142 NetworkGuidListCallback network_list_changed_observer_; | 142 NetworkGuidListCallback network_list_changed_observer_; |
| 143 // MessageLoopProxy to which events should be posted. | 143 // Task runner to which events should be posted. |
| 144 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 144 scoped_refptr<base::SingleThreadTaskRunner> event_task_runner_; |
| 145 // Task runner for worker tasks. | 145 // Task runner for worker tasks. |
| 146 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 146 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 147 // Cached list of visible networks. Updated by |UpdateNetworks|. | 147 // Cached list of visible networks. Updated by |UpdateNetworks|. |
| 148 NetworkList networks_; | 148 NetworkList networks_; |
| 149 // Guid of last known connected network. | 149 // Guid of last known connected network. |
| 150 std::string connected_network_guid_; | 150 std::string connected_network_guid_; |
| 151 // Temporary storage of network properties indexed by |network_guid|. | 151 // Temporary storage of network properties indexed by |network_guid|. |
| 152 base::DictionaryValue network_properties_; | 152 base::DictionaryValue network_properties_; |
| 153 | 153 |
| 154 DISALLOW_COPY_AND_ASSIGN(WiFiServiceMac); | 154 DISALLOW_COPY_AND_ASSIGN(WiFiServiceMac); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 } | 377 } |
| 378 | 378 |
| 379 if (password_data) { | 379 if (password_data) { |
| 380 *key_data = std::string(reinterpret_cast<char*>(password_data), | 380 *key_data = std::string(reinterpret_cast<char*>(password_data), |
| 381 password_length); | 381 password_length); |
| 382 keychain.ItemFreeContent(NULL, password_data); | 382 keychain.ItemFreeContent(NULL, password_data); |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 | 385 |
| 386 void WiFiServiceMac::SetEventObservers( | 386 void WiFiServiceMac::SetEventObservers( |
| 387 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 387 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 388 const NetworkGuidListCallback& networks_changed_observer, | 388 const NetworkGuidListCallback& networks_changed_observer, |
| 389 const NetworkGuidListCallback& network_list_changed_observer) { | 389 const NetworkGuidListCallback& network_list_changed_observer) { |
| 390 message_loop_proxy_.swap(message_loop_proxy); | 390 event_task_runner_.swap(task_runner); |
| 391 networks_changed_observer_ = networks_changed_observer; | 391 networks_changed_observer_ = networks_changed_observer; |
| 392 network_list_changed_observer_ = network_list_changed_observer; | 392 network_list_changed_observer_ = network_list_changed_observer; |
| 393 | 393 |
| 394 // Remove previous OS notifications observer. | 394 // Remove previous OS notifications observer. |
| 395 if (wlan_observer_) { | 395 if (wlan_observer_) { |
| 396 [[NSNotificationCenter defaultCenter] removeObserver:wlan_observer_]; | 396 [[NSNotificationCenter defaultCenter] removeObserver:wlan_observer_]; |
| 397 wlan_observer_ = nil; | 397 wlan_observer_ = nil; |
| 398 } | 398 } |
| 399 | 399 |
| 400 // Subscribe to OS notifications. | 400 // Subscribe to OS notifications. |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 if (network_list_changed_observer_.is_null()) | 635 if (network_list_changed_observer_.is_null()) |
| 636 return; | 636 return; |
| 637 | 637 |
| 638 NetworkGuidList current_networks; | 638 NetworkGuidList current_networks; |
| 639 for (NetworkList::const_iterator it = networks.begin(); | 639 for (NetworkList::const_iterator it = networks.begin(); |
| 640 it != networks.end(); | 640 it != networks.end(); |
| 641 ++it) { | 641 ++it) { |
| 642 current_networks.push_back(it->guid); | 642 current_networks.push_back(it->guid); |
| 643 } | 643 } |
| 644 | 644 |
| 645 message_loop_proxy_->PostTask( | 645 event_task_runner_->PostTask( |
| 646 FROM_HERE, | 646 FROM_HERE, base::Bind(network_list_changed_observer_, current_networks)); |
| 647 base::Bind(network_list_changed_observer_, current_networks)); | |
| 648 } | 647 } |
| 649 | 648 |
| 650 void WiFiServiceMac::NotifyNetworkChanged(const std::string& network_guid) { | 649 void WiFiServiceMac::NotifyNetworkChanged(const std::string& network_guid) { |
| 651 if (networks_changed_observer_.is_null()) | 650 if (networks_changed_observer_.is_null()) |
| 652 return; | 651 return; |
| 653 | 652 |
| 654 DVLOG(1) << "NotifyNetworkChanged: " << network_guid; | 653 DVLOG(1) << "NotifyNetworkChanged: " << network_guid; |
| 655 NetworkGuidList changed_networks(1, network_guid); | 654 NetworkGuidList changed_networks(1, network_guid); |
| 656 message_loop_proxy_->PostTask( | 655 event_task_runner_->PostTask( |
| 657 FROM_HERE, | 656 FROM_HERE, base::Bind(networks_changed_observer_, changed_networks)); |
| 658 base::Bind(networks_changed_observer_, changed_networks)); | |
| 659 } | 657 } |
| 660 | 658 |
| 661 // static | 659 // static |
| 662 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } | 660 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } |
| 663 | 661 |
| 664 } // namespace wifi | 662 } // namespace wifi |
| OLD | NEW |