| 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_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 WifiNetwork* wifi = GetPreferredNetwork(); | 398 WifiNetwork* wifi = GetPreferredNetwork(); |
| 399 return wifi && wifi->connected(); | 399 return wifi && wifi->connected(); |
| 400 } | 400 } |
| 401 | 401 |
| 402 bool PreferredNetworkFailed() { | 402 bool PreferredNetworkFailed() { |
| 403 WifiNetwork* wifi = GetPreferredNetwork(); | 403 WifiNetwork* wifi = GetPreferredNetwork(); |
| 404 return !wifi || wifi->failed(); | 404 return !wifi || wifi->failed(); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void ConnectToWifiNetwork(WifiNetwork network, | 407 void ConnectToWifiNetwork(WifiNetwork network, |
| 408 const std::string& password, | 408 const std::string& password, |
| 409 const std::string& identity, | 409 const std::string& identity, |
| 410 const std::string& certpath) { | 410 const std::string& certpath) { |
| 411 if (CrosLibrary::Get()->EnsureLoaded()) { | 411 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 412 ConnectToNetworkWithCertInfo(network.service_path().c_str(), | 412 ConnectToNetworkWithCertInfo(network.service_path().c_str(), |
| 413 password.empty() ? NULL : password.c_str(), | 413 password.empty() ? NULL : password.c_str(), |
| 414 identity.empty() ? NULL : identity.c_str(), | 414 identity.empty() ? NULL : identity.c_str(), |
| 415 certpath.empty() ? NULL : certpath.c_str()); | 415 certpath.empty() ? NULL : certpath.c_str()); |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 | 418 |
| 419 void ConnectToWifiNetwork(const std::string& ssid, | 419 void ConnectToWifiNetwork(const std::string& ssid, |
| 420 const std::string& password, | 420 const std::string& password, |
| 421 const std::string& identity, | 421 const std::string& identity, |
| 422 const std::string& certpath, | 422 const std::string& certpath, |
| 423 bool auto_connect) { | 423 bool auto_connect) { |
| 424 if (CrosLibrary::Get()->EnsureLoaded()) { | 424 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 425 // First create a service from hidden network. | 425 // First create a service from hidden network. |
| 426 ServiceInfo* service = GetWifiService(ssid.c_str(), | 426 ServiceInfo* service = GetWifiService(ssid.c_str(), |
| 427 SECURITY_UNKNOWN); | 427 SECURITY_UNKNOWN); |
| 428 if (service) { | 428 if (service) { |
| 429 // Set auto-connect. | 429 // Set auto-connect. |
| 430 SetAutoConnect(service->service_path, auto_connect); | 430 SetAutoConnect(service->service_path, auto_connect); |
| 431 // Now connect to that service. | 431 // Now connect to that service. |
| 432 ConnectToNetworkWithCertInfo(service->service_path, | 432 ConnectToNetworkWithCertInfo(service->service_path, |
| 433 password.empty() ? NULL : password.c_str(), | 433 password.empty() ? NULL : password.c_str(), |
| 434 identity.empty() ? NULL : identity.c_str(), | 434 identity.empty() ? NULL : identity.c_str(), |
| 435 certpath.empty() ? NULL : certpath.c_str()); | 435 certpath.empty() ? NULL : certpath.c_str()); |
| 436 | 436 |
| 437 // Clean up ServiceInfo object. | 437 // Clean up ServiceInfo object. |
| 438 FreeServiceInfo(service); | 438 FreeServiceInfo(service); |
| 439 } else { | 439 } else { |
| 440 LOG(WARNING) << "Cannot find hidden network: " << ssid; | 440 LOG(WARNING) << "Cannot find hidden network: " << ssid; |
| 441 // TODO(chocobo): Show error message. | 441 // TODO(chocobo): Show error message. |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 | 445 |
| 446 void ConnectToCellularNetwork(CellularNetwork network) { | 446 void ConnectToCellularNetwork(CellularNetwork network) { |
| 447 if (CrosLibrary::Get()->EnsureLoaded()) { | 447 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 448 ConnectToNetwork(network.service_path().c_str(), NULL); | 448 ConnectToNetwork(network.service_path().c_str(), NULL); |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 | 451 |
| 452 void DisconnectFromWirelessNetwork( | 452 void DisconnectFromWirelessNetwork(const WirelessNetwork& network) { |
| 453 const WirelessNetwork& network) { | |
| 454 if (CrosLibrary::Get()->EnsureLoaded()) { | 453 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 455 DisconnectFromNetwork(network.service_path().c_str()); | 454 DisconnectFromNetwork(network.service_path().c_str()); |
| 456 } | 455 } |
| 457 } | 456 } |
| 458 | 457 |
| 459 void SaveCellularNetwork(const CellularNetwork& network) { | 458 void SaveCellularNetwork(const CellularNetwork& network) { |
| 460 // Update the wifi network in the local cache. | 459 // Update the wifi network in the local cache. |
| 461 CellularNetwork* cellular = GetWirelessNetworkByPath( | 460 CellularNetwork* cellular = GetWirelessNetworkByPath( |
| 462 cellular_networks_, | 461 cellular_networks_, |
| 463 network.service_path()); | 462 network.service_path()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 480 // Update the wifi network with libcros. | 479 // Update the wifi network with libcros. |
| 481 if (CrosLibrary::Get()->EnsureLoaded()) { | 480 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 482 SetPassphrase( | 481 SetPassphrase( |
| 483 network.service_path().c_str(), network.passphrase().c_str()); | 482 network.service_path().c_str(), network.passphrase().c_str()); |
| 484 SetIdentity(network.service_path().c_str(), network.identity().c_str()); | 483 SetIdentity(network.service_path().c_str(), network.identity().c_str()); |
| 485 SetCertPath(network.service_path().c_str(), network.cert_path().c_str()); | 484 SetCertPath(network.service_path().c_str(), network.cert_path().c_str()); |
| 486 SetAutoConnect(network.service_path().c_str(), network.auto_connect()); | 485 SetAutoConnect(network.service_path().c_str(), network.auto_connect()); |
| 487 } | 486 } |
| 488 } | 487 } |
| 489 | 488 |
| 490 void ForgetWirelessNetwork( | 489 void ForgetWirelessNetwork(const std::string& service_path) { |
| 491 const std::string& service_path) { | |
| 492 if (CrosLibrary::Get()->EnsureLoaded()) { | 490 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 493 DeleteRememberedService(service_path.c_str()); | 491 DeleteRememberedService(service_path.c_str()); |
| 494 } | 492 } |
| 495 } | 493 } |
| 496 | 494 |
| 497 virtual bool ethernet_available() const { | 495 virtual bool ethernet_available() const { |
| 498 return available_devices_ & (1 << TYPE_ETHERNET); | 496 return available_devices_ & (1 << TYPE_ETHERNET); |
| 499 } | 497 } |
| 500 virtual bool wifi_available() const { | 498 virtual bool wifi_available() const { |
| 501 return available_devices_ & (1 << TYPE_WIFI); | 499 return available_devices_ & (1 << TYPE_WIFI); |
| 502 } | 500 } |
| 503 virtual bool cellular_available() const { | 501 virtual bool cellular_available() const { |
| 504 return available_devices_ & (1 << TYPE_CELLULAR); | 502 return available_devices_ & (1 << TYPE_CELLULAR); |
| 505 } | 503 } |
| 506 | 504 |
| 507 virtual bool ethernet_enabled() const { | 505 virtual bool ethernet_enabled() const { |
| 508 return enabled_devices_ & (1 << TYPE_ETHERNET); | 506 return enabled_devices_ & (1 << TYPE_ETHERNET); |
| 509 } | 507 } |
| 510 virtual bool wifi_enabled() const { | 508 virtual bool wifi_enabled() const { |
| 511 return enabled_devices_ & (1 << TYPE_WIFI); | 509 return enabled_devices_ & (1 << TYPE_WIFI); |
| 512 } | 510 } |
| 513 virtual bool cellular_enabled() const { | 511 virtual bool cellular_enabled() const { |
| 514 return enabled_devices_ & (1 << TYPE_CELLULAR); | 512 return enabled_devices_ & (1 << TYPE_CELLULAR); |
| 515 } | 513 } |
| 516 | 514 |
| 517 virtual bool offline_mode() const { return offline_mode_; } | 515 virtual bool offline_mode() const { return offline_mode_; } |
| 518 | 516 |
| 519 void EnableEthernetNetworkDevice(bool enable) { | 517 void EnableEthernetNetworkDevice(bool enable) { |
| 520 EnableNetworkDeviceType(TYPE_ETHERNET, enable); | 518 EnableNetworkDeviceType(TYPE_ETHERNET, enable); |
| 521 } | 519 } |
| 522 | 520 |
| 523 void EnableWifiNetworkDevice(bool enable) { | 521 void EnableWifiNetworkDevice(bool enable) { |
| 524 EnableNetworkDeviceType(TYPE_WIFI, enable); | 522 EnableNetworkDeviceType(TYPE_WIFI, enable); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 541 LOG(INFO) << | 539 LOG(INFO) << |
| 542 "Trying to disable offline mode when it's already disabled. "; | 540 "Trying to disable offline mode when it's already disabled. "; |
| 543 return; | 541 return; |
| 544 } | 542 } |
| 545 | 543 |
| 546 if (SetOfflineMode(enable)) { | 544 if (SetOfflineMode(enable)) { |
| 547 offline_mode_ = enable; | 545 offline_mode_ = enable; |
| 548 } | 546 } |
| 549 } | 547 } |
| 550 | 548 |
| 551 NetworkIPConfigVector GetIPConfigs( | 549 NetworkIPConfigVector GetIPConfigs(const std::string& device_path) { |
| 552 const std::string& device_path) { | |
| 553 NetworkIPConfigVector ipconfig_vector; | 550 NetworkIPConfigVector ipconfig_vector; |
| 554 if (!device_path.empty()) { | 551 if (!device_path.empty()) { |
| 555 IPConfigStatus* ipconfig_status = ListIPConfigs(device_path.c_str()); | 552 IPConfigStatus* ipconfig_status = ListIPConfigs(device_path.c_str()); |
| 556 if (ipconfig_status) { | 553 if (ipconfig_status) { |
| 557 for (int i = 0; i < ipconfig_status->size; i++) { | 554 for (int i = 0; i < ipconfig_status->size; i++) { |
| 558 IPConfig ipconfig = ipconfig_status->ips[i]; | 555 IPConfig ipconfig = ipconfig_status->ips[i]; |
| 559 ipconfig_vector.push_back( | 556 ipconfig_vector.push_back( |
| 560 NetworkIPConfig(device_path, ipconfig.type, ipconfig.address, | 557 NetworkIPConfig(device_path, ipconfig.type, ipconfig.address, |
| 561 ipconfig.netmask, ipconfig.gateway, | 558 ipconfig.netmask, ipconfig.gateway, |
| 562 ipconfig.name_servers)); | 559 ipconfig.name_servers)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 577 base::IntToString(refresh) + "\"/>"); | 574 base::IntToString(refresh) + "\"/>"); |
| 578 output.append("</head><body>"); | 575 output.append("</head><body>"); |
| 579 if (refresh > 0) { | 576 if (refresh > 0) { |
| 580 output.append("(Auto-refreshing page every " + | 577 output.append("(Auto-refreshing page every " + |
| 581 base::IntToString(refresh) + "s)"); | 578 base::IntToString(refresh) + "s)"); |
| 582 } else { | 579 } else { |
| 583 output.append("(To auto-refresh this page: about:network/<secs>)"); | 580 output.append("(To auto-refresh this page: about:network/<secs>)"); |
| 584 } | 581 } |
| 585 | 582 |
| 586 output.append("<h3>Ethernet:</h3><table border=1>"); | 583 output.append("<h3>Ethernet:</h3><table border=1>"); |
| 587 output.append("<tr>" + ToHtmlTableHeader(ðernet_) + "</tr>"); | 584 if (ethernet_enabled()) { |
| 588 output.append("<tr>" + ToHtmlTableRow(ðernet_) + "</tr>"); | 585 output.append("<tr>" + ToHtmlTableHeader(ðernet_) + "</tr>"); |
| 586 output.append("<tr>" + ToHtmlTableRow(ðernet_) + "</tr>"); |
| 587 } |
| 589 | 588 |
| 590 output.append("</table><h3>Wifi:</h3><table border=1>"); | 589 output.append("</table><h3>Wifi:</h3><table border=1>"); |
| 591 for (size_t i = 0; i < wifi_networks_.size(); ++i) { | 590 for (size_t i = 0; i < wifi_networks_.size(); ++i) { |
| 592 if (i == 0) | 591 if (i == 0) |
| 593 output.append("<tr>" + ToHtmlTableHeader(&wifi_networks_[i]) + "</tr>"); | 592 output.append("<tr>" + ToHtmlTableHeader(&wifi_networks_[i]) + "</tr>"); |
| 594 output.append("<tr>" + ToHtmlTableRow(&wifi_networks_[i]) + "</tr>"); | 593 output.append("<tr>" + ToHtmlTableRow(&wifi_networks_[i]) + "</tr>"); |
| 595 } | 594 } |
| 596 | 595 |
| 597 output.append("</table><h3>Cellular:</h3><table border=1>"); | 596 output.append("</table><h3>Cellular:</h3><table border=1>"); |
| 598 for (size_t i = 0; i < cellular_networks_.size(); ++i) { | 597 for (size_t i = 0; i < cellular_networks_.size(); ++i) { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 | 810 |
| 812 // const version | 811 // const version |
| 813 template<typename T> const T* GetWirelessNetworkByPath( | 812 template<typename T> const T* GetWirelessNetworkByPath( |
| 814 const std::vector<T>& networks, const std::string& path) const { | 813 const std::vector<T>& networks, const std::string& path) const { |
| 815 typedef typename std::vector<T>::const_iterator iter_t; | 814 typedef typename std::vector<T>::const_iterator iter_t; |
| 816 iter_t iter = std::find_if(networks.begin(), networks.end(), | 815 iter_t iter = std::find_if(networks.begin(), networks.end(), |
| 817 WirelessNetwork::ServicePathEq(path)); | 816 WirelessNetwork::ServicePathEq(path)); |
| 818 return (iter != networks.end()) ? &(*iter) : NULL; | 817 return (iter != networks.end()) ? &(*iter) : NULL; |
| 819 } | 818 } |
| 820 | 819 |
| 821 void EnableNetworkDeviceType(ConnectionType device, | 820 void EnableNetworkDeviceType(ConnectionType device, bool enable) { |
| 822 bool enable) { | |
| 823 if (!CrosLibrary::Get()->EnsureLoaded()) | 821 if (!CrosLibrary::Get()->EnsureLoaded()) |
| 824 return; | 822 return; |
| 825 | 823 |
| 826 // If network device is already enabled/disabled, then don't do anything. | 824 // If network device is already enabled/disabled, then don't do anything. |
| 827 if (enable && (enabled_devices_ & (1 << device))) { | 825 if (enable && (enabled_devices_ & (1 << device))) { |
| 828 LOG(WARNING) << "Trying to enable a device that's already enabled: " | 826 LOG(WARNING) << "Trying to enable a device that's already enabled: " |
| 829 << device; | 827 << device; |
| 830 return; | 828 return; |
| 831 } | 829 } |
| 832 if (!enable && !(enabled_devices_ & (1 << device))) { | 830 if (!enable && !(enabled_devices_ & (1 << device))) { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 return new NetworkLibraryStubImpl(); | 1013 return new NetworkLibraryStubImpl(); |
| 1016 else | 1014 else |
| 1017 return new NetworkLibraryImpl(); | 1015 return new NetworkLibraryImpl(); |
| 1018 } | 1016 } |
| 1019 | 1017 |
| 1020 } // namespace chromeos | 1018 } // namespace chromeos |
| 1021 | 1019 |
| 1022 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 1020 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 1023 // won't be deleted until it's last InvokeLater is run. | 1021 // won't be deleted until it's last InvokeLater is run. |
| 1024 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); | 1022 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); |
| OLD | NEW |