OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/cros/network_library.h" | 5 #include "chrome/browser/chromeos/cros/network_library.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 208 |
209 NetworkLibraryImpl::NetworkLibraryImpl() | 209 NetworkLibraryImpl::NetworkLibraryImpl() |
210 : traffic_type_(0), | 210 : traffic_type_(0), |
211 network_status_connection_(NULL), | 211 network_status_connection_(NULL), |
212 available_devices_(0), | 212 available_devices_(0), |
213 enabled_devices_(0), | 213 enabled_devices_(0), |
214 connected_devices_(0), | 214 connected_devices_(0), |
215 offline_mode_(false) { | 215 offline_mode_(false) { |
216 if (CrosLibrary::Get()->EnsureLoaded()) { | 216 if (CrosLibrary::Get()->EnsureLoaded()) { |
217 Init(); | 217 Init(); |
| 218 } else { |
| 219 InitTestData(); |
218 } | 220 } |
219 g_url_request_job_tracker.AddObserver(this); | 221 g_url_request_job_tracker.AddObserver(this); |
220 } | 222 } |
221 | 223 |
222 NetworkLibraryImpl::~NetworkLibraryImpl() { | 224 NetworkLibraryImpl::~NetworkLibraryImpl() { |
223 if (network_status_connection_) { | 225 if (network_status_connection_) { |
224 DisconnectMonitorNetwork(network_status_connection_); | 226 DisconnectMonitorNetwork(network_status_connection_); |
225 } | 227 } |
226 g_url_request_job_tracker.RemoveObserver(this); | 228 g_url_request_job_tracker.RemoveObserver(this); |
227 } | 229 } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 455 |
454 // Update the wifi network with libcros. | 456 // Update the wifi network with libcros. |
455 if (CrosLibrary::Get()->EnsureLoaded()) { | 457 if (CrosLibrary::Get()->EnsureLoaded()) { |
456 SetPassphrase(network.service_path().c_str(), network.passphrase().c_str()); | 458 SetPassphrase(network.service_path().c_str(), network.passphrase().c_str()); |
457 SetIdentity(network.service_path().c_str(), network.identity().c_str()); | 459 SetIdentity(network.service_path().c_str(), network.identity().c_str()); |
458 SetCertPath(network.service_path().c_str(), network.cert_path().c_str()); | 460 SetCertPath(network.service_path().c_str(), network.cert_path().c_str()); |
459 SetAutoConnect(network.service_path().c_str(), network.auto_connect()); | 461 SetAutoConnect(network.service_path().c_str(), network.auto_connect()); |
460 } | 462 } |
461 } | 463 } |
462 | 464 |
463 void NetworkLibraryImpl::ForgetWirelessNetwork(const WirelessNetwork& network) { | 465 void NetworkLibraryImpl::ForgetWirelessNetwork( |
| 466 const std::string& service_path) { |
464 if (CrosLibrary::Get()->EnsureLoaded()) { | 467 if (CrosLibrary::Get()->EnsureLoaded()) { |
465 DeleteRememberedService(network.service_path().c_str()); | 468 DeleteRememberedService(service_path.c_str()); |
466 } | 469 } |
467 } | 470 } |
468 | 471 |
469 void NetworkLibraryImpl::EnableEthernetNetworkDevice(bool enable) { | 472 void NetworkLibraryImpl::EnableEthernetNetworkDevice(bool enable) { |
470 EnableNetworkDeviceType(TYPE_ETHERNET, enable); | 473 EnableNetworkDeviceType(TYPE_ETHERNET, enable); |
471 } | 474 } |
472 | 475 |
473 void NetworkLibraryImpl::EnableWifiNetworkDevice(bool enable) { | 476 void NetworkLibraryImpl::EnableWifiNetworkDevice(bool enable) { |
474 EnableNetworkDeviceType(TYPE_WIFI, enable); | 477 EnableNetworkDeviceType(TYPE_WIFI, enable); |
475 } | 478 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 // on the connman side, so the call should be quick. | 641 // on the connman side, so the call should be quick. |
639 LOG(INFO) << "Getting initial CrOS network info."; | 642 LOG(INFO) << "Getting initial CrOS network info."; |
640 UpdateSystemInfo(); | 643 UpdateSystemInfo(); |
641 | 644 |
642 LOG(INFO) << "Registering for network status updates."; | 645 LOG(INFO) << "Registering for network status updates."; |
643 // Now, register to receive updates on network status. | 646 // Now, register to receive updates on network status. |
644 network_status_connection_ = MonitorNetwork(&NetworkStatusChangedHandler, | 647 network_status_connection_ = MonitorNetwork(&NetworkStatusChangedHandler, |
645 this); | 648 this); |
646 } | 649 } |
647 | 650 |
| 651 void NetworkLibraryImpl::InitTestData() { |
| 652 ethernet_.Clear(); |
| 653 ethernet_.set_connected(true); |
| 654 |
| 655 wifi_networks_.clear(); |
| 656 WifiNetwork wifi1 = WifiNetwork(); |
| 657 wifi1.set_service_path("fw1"); |
| 658 wifi1.set_name("Fake Wifi 1"); |
| 659 wifi1.set_strength(90); |
| 660 wifi1.set_connected(false); |
| 661 wifi1.set_encryption(SECURITY_NONE); |
| 662 wifi_networks_.push_back(wifi1); |
| 663 |
| 664 WifiNetwork wifi2 = WifiNetwork(); |
| 665 wifi2.set_service_path("fw2"); |
| 666 wifi2.set_name("Fake Wifi 2"); |
| 667 wifi2.set_strength(70); |
| 668 wifi2.set_connected(true); |
| 669 wifi2.set_encryption(SECURITY_WEP); |
| 670 wifi_networks_.push_back(wifi2); |
| 671 |
| 672 WifiNetwork wifi3 = WifiNetwork(); |
| 673 wifi3.set_service_path("fw3"); |
| 674 wifi3.set_name("Fake Wifi 3"); |
| 675 wifi3.set_strength(50); |
| 676 wifi3.set_connected(false); |
| 677 wifi3.set_encryption(SECURITY_WEP); |
| 678 wifi_networks_.push_back(wifi3); |
| 679 |
| 680 wifi_ = wifi2; |
| 681 |
| 682 cellular_networks_.clear(); |
| 683 |
| 684 cellular_networks_.clear(); |
| 685 CellularNetwork cellular1 = CellularNetwork(); |
| 686 cellular1.set_service_path("fc1"); |
| 687 cellular1.set_name("Fake Cellular 1"); |
| 688 cellular1.set_strength(90); |
| 689 cellular1.set_connected(false); |
| 690 cellular_networks_.push_back(cellular1); |
| 691 |
| 692 CellularNetwork cellular2 = CellularNetwork(); |
| 693 cellular2.set_service_path("fc2"); |
| 694 cellular2.set_name("Fake Cellular 2"); |
| 695 cellular2.set_strength(70); |
| 696 cellular2.set_connected(true); |
| 697 cellular_networks_.push_back(cellular2); |
| 698 |
| 699 CellularNetwork cellular3 = CellularNetwork(); |
| 700 cellular3.set_service_path("fc3"); |
| 701 cellular3.set_name("Fake Cellular 3"); |
| 702 cellular3.set_strength(50); |
| 703 cellular3.set_connected(false); |
| 704 cellular_networks_.push_back(cellular3); |
| 705 |
| 706 cellular_ = cellular2; |
| 707 |
| 708 remembered_wifi_networks_.clear(); |
| 709 remembered_wifi_networks_.push_back(wifi2); |
| 710 |
| 711 remembered_cellular_networks_.clear(); |
| 712 remembered_cellular_networks_.push_back(cellular2); |
| 713 |
| 714 int devices = (1 << TYPE_ETHERNET) | (1 << TYPE_WIFI) | |
| 715 (1 << TYPE_CELLULAR); |
| 716 available_devices_ = devices; |
| 717 enabled_devices_ = devices; |
| 718 connected_devices_ = devices; |
| 719 offline_mode_ = false; |
| 720 } |
| 721 |
648 void NetworkLibraryImpl::UpdateSystemInfo() { | 722 void NetworkLibraryImpl::UpdateSystemInfo() { |
649 if (CrosLibrary::Get()->EnsureLoaded()) { | 723 if (CrosLibrary::Get()->EnsureLoaded()) { |
650 UpdateNetworkStatus(); | 724 UpdateNetworkStatus(); |
651 } | 725 } |
652 } | 726 } |
653 | 727 |
654 WifiNetwork* NetworkLibraryImpl::GetPreferredNetwork() { | 728 WifiNetwork* NetworkLibraryImpl::GetPreferredNetwork() { |
655 // First look for Google-A then look for Google. | 729 // First look for Google-A then look for Google. |
656 // Only care if set to auto-connect. | 730 // Only care if set to auto-connect. |
657 WifiNetwork* wifi = GetWifiNetworkByName(kGoogleAWifi); | 731 WifiNetwork* wifi = GetWifiNetworkByName(kGoogleAWifi); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 if (ethernet_connected()) | 888 if (ethernet_connected()) |
815 return ethernet_.ip_address(); | 889 return ethernet_.ip_address(); |
816 if (wifi_connected()) | 890 if (wifi_connected()) |
817 return wifi_.ip_address(); | 891 return wifi_.ip_address(); |
818 if (cellular_connected()) | 892 if (cellular_connected()) |
819 return cellular_.ip_address(); | 893 return cellular_.ip_address(); |
820 return ethernet_.ip_address(); | 894 return ethernet_.ip_address(); |
821 } | 895 } |
822 | 896 |
823 } // namespace chromeos | 897 } // namespace chromeos |
OLD | NEW |