diff options
-rw-r--r-- | chrome/browser/chromeos/cros/network_library.cc | 83 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/network_library.h | 49 |
2 files changed, 57 insertions, 75 deletions
diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc index 8222de3..afab041 100644 --- a/chrome/browser/chromeos/cros/network_library.cc +++ b/chrome/browser/chromeos/cros/network_library.cc @@ -87,50 +87,28 @@ void NetworkLibrary::RemoveObserver(Observer* observer) { observers_.RemoveObserver(observer); } -static const char* GetEncryptionString(chromeos::EncryptionType encryption) { - switch (encryption) { - case chromeos::NONE: - return "none"; - case chromeos::RSN: - return "rsn"; - case chromeos::WEP: - return "wep"; - case chromeos::WPA: - return "wpa"; - } - return "none"; -} - void NetworkLibrary::ConnectToWifiNetwork(WifiNetwork network, const string16& password) { if (CrosLibrary::EnsureLoaded()) { - // This call kicks off a request to connect to this network, the results of - // which we'll hear about through the monitoring we've set up in Init(); - chromeos::ConnectToWifiNetwork( - network.ssid.c_str(), - password.empty() ? NULL : UTF16ToUTF8(password).c_str(), - GetEncryptionString(network.encryption)); + chromeos::ConnectToNetwork(network.service_path.c_str(), + password.empty() ? NULL : UTF16ToUTF8(password).c_str()); } } void NetworkLibrary::ConnectToWifiNetwork(const string16& ssid, const string16& password) { if (CrosLibrary::EnsureLoaded()) { - // This call kicks off a request to connect to this network, the results of - // which we'll hear about through the monitoring we've set up in Init(); - chromeos::ConnectToWifiNetwork( - UTF16ToUTF8(ssid).c_str(), - password.empty() ? NULL : UTF16ToUTF8(password).c_str(), - "rsn"); - // TODO(chocobo): Make it support other encryptions. + // TODO(chocobo): Implement connect to hidden network. + // First create a service from hidden network. + // Now connect to that service.. +// chromeos::ConnectToNetwork(service_path, +// password.empty() ? NULL : UTF16ToUTF8(password).c_str()); } } void NetworkLibrary::ConnectToCellularNetwork(CellularNetwork network) { if (CrosLibrary::EnsureLoaded()) { - // This call kicks off a request to connect to this network, the results of - // which we'll hear about through the monitoring we've set up in Init(); - chromeos::ConnectToWifiNetwork(network.name.c_str(), NULL, NULL); + chromeos::ConnectToNetwork(network.service_path.c_str(), NULL); } } @@ -207,11 +185,16 @@ void NetworkLibrary::ParseNetworks( for (int i = 0; i < service_status.size; i++) { const chromeos::ServiceInfo& service = service_status.services[i]; DLOG(INFO) << " (" << service.type << - ") " << service.ssid << - " sta=" << service.state << - " pas=" << service.needs_passphrase << - " enc=" << service.encryption << - " sig=" << service.signal_strength; + ") " << service.name << + " mode=" << service.mode << + " state=" << service.state << + " sec=" << service.security << + " req=" << service.passphrase_required << + " pass=" << service.passphrase << + " str=" << service.strength << + " fav=" << service.favorite << + " auto=" << service.auto_connect << + " error=" << service.error; bool connecting = service.state == chromeos::STATE_ASSOCIATION || service.state == chromeos::STATE_CONFIGURATION || service.state == chromeos::STATE_CARRIER; @@ -247,22 +230,12 @@ void NetworkLibrary::ParseNetworks( std::string(); ethernet->ip_address = ip_address; } else if (service.type == chromeos::TYPE_WIFI) { - wifi_networks->push_back(WifiNetwork(service.device_path ? - service.device_path : - std::string(), - service.ssid, - service.needs_passphrase, - service.encryption, - service.signal_strength, + wifi_networks->push_back(WifiNetwork(service, connecting, connected, ip_address)); } else if (service.type == chromeos::TYPE_CELLULAR) { - cellular_networks->push_back(CellularNetwork(service.device_path ? - service.device_path : - std::string(), - service.ssid, - service.signal_strength, + cellular_networks->push_back(CellularNetwork(service, connecting, connected, ip_address)); @@ -304,22 +277,22 @@ void NetworkLibrary::EnableNetworkDevice(chromeos::ConnectionType device, return; // If network device is already enabled/disabled, then don't do anything. - if (enable && (network_devices_ & device)) { - LOG(INFO) << "Trying to enable a network device that's already enabled: " - << device; + if (enable && (network_devices_ & (1 << device))) { + LOG(WARNING) << "Trying to enable a device that's already enabled: " + << device; return; } - if (!enable && !(network_devices_ & device)) { - LOG(INFO) << "Trying to disable a network device that's already disabled: " - << device; + if (!enable && !(network_devices_ & (1 << device))) { + LOG(WARNING) << "Trying to disable a device that's already disabled: " + << device; return; } if (chromeos::EnableNetworkDevice(device, enable)) { if (enable) - network_devices_ |= device; + network_devices_ |= (1 << device); else - network_devices_ &= ~device; + network_devices_ &= ~(1 << device); } } diff --git a/chrome/browser/chromeos/cros/network_library.h b/chrome/browser/chromeos/cros/network_library.h index 8e9a7ad..595b128 100644 --- a/chrome/browser/chromeos/cros/network_library.h +++ b/chrome/browser/chromeos/cros/network_library.h @@ -32,18 +32,19 @@ struct EthernetNetwork { struct WifiNetwork { WifiNetwork() : encrypted(false), - encryption(chromeos::NONE), + encryption(chromeos::SECURITY_UNKNOWN), strength(0), connecting(false), - connected(false) {} - WifiNetwork(const std::string& device_path, const std::string& ssid, - bool encrypted, chromeos::EncryptionType encryption, int strength, - bool connecting, bool connected, const std::string& ip_address) - : device_path(device_path), - ssid(ssid), - encrypted(encrypted), - encryption(encryption), - strength(strength), + connected(false), + auto_connect(false) {} + WifiNetwork(ServiceInfo service, bool connecting, bool connected, + const std::string& ip_address) + : service_path(service.service_path), + device_path(service.device_path), + ssid(service.name), + encrypted(service.passphrase_required), + encryption(service.security), + strength(service.strength), connecting(connecting), connected(connected), ip_address(ip_address) {} @@ -53,13 +54,15 @@ struct WifiNetwork { return ssid < other.ssid; } + std::string service_path; std::string device_path; std::string ssid; bool encrypted; - chromeos::EncryptionType encryption; + chromeos::ConnectionSecurity encryption; int strength; bool connecting; bool connected; + bool auto_connect; std::string ip_address; }; typedef std::vector<WifiNetwork> WifiNetworkVector; @@ -68,13 +71,14 @@ struct CellularNetwork { CellularNetwork() : strength(strength), connecting(false), - connected(false) {} - CellularNetwork(const std::string& device_path, const std::string& name, - int strength, bool connecting, bool connected, + connected(false), + auto_connect(false) {} + CellularNetwork(ServiceInfo service, bool connecting, bool connected, const std::string& ip_address) - : device_path(device_path), - name(name), - strength(strength), + : service_path(service.service_path), + device_path(service.device_path), + name(service.name), + strength(service.strength), connecting(connecting), connected(connected), ip_address(ip_address) {} @@ -84,11 +88,13 @@ struct CellularNetwork { return name < other.name; } + std::string service_path; std::string device_path; std::string name; int strength; bool connecting; bool connected; + bool auto_connect; std::string ip_address; }; typedef std::vector<CellularNetwork> CellularNetworkVector; @@ -197,9 +203,12 @@ class NetworkLibrary : public URLRequestJobTracker::JobObserver { // Connect to the specified cellular network. void ConnectToCellularNetwork(CellularNetwork network); - bool ethernet_enabled() const { return network_devices_ & TYPE_ETHERNET; } - bool wifi_enabled() const { return network_devices_ & TYPE_WIFI; } - bool cellular_enabled() const { return network_devices_ & TYPE_CELLULAR; } + bool ethernet_enabled() const { + return network_devices_ & (1 << TYPE_ETHERNET); } + bool wifi_enabled() const { + return network_devices_ & (1 << TYPE_WIFI); } + bool cellular_enabled() const { + return network_devices_ & (1 << TYPE_CELLULAR); } bool offline_mode() const { return offline_mode_; } // Enables/disables the ethernet network device. |