Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1583)

Unified Diff: chrome/browser/chromeos/cros/network_library.cc

Issue 2853001: Fix bug where auto-connect setting is not immediately saved.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/cros/network_library.cc
===================================================================
--- chrome/browser/chromeos/cros/network_library.cc (revision 50012)
+++ chrome/browser/chromeos/cros/network_library.cc (working copy)
@@ -18,6 +18,7 @@
namespace chromeos {
+static const std::string kGoogleWifi = "Google";
static const std::string kGoogleAWifi = "Google-A";
// Helper function to wrap Html with <th> tag.
@@ -257,32 +258,38 @@
// TODO(chocobo): Add the concept of preferred network to libcros.
// So that we don't have to hard-code Google-A here.
if (CrosLibrary::Get()->EnsureLoaded()) {
- LOG(INFO) << "Attempting to auto-connect to Google-A wifi.";
+ LOG(INFO) << "Attempting to auto-connect to Google wifi.";
// First force a refresh of the system info.
UpdateSystemInfo();
// If ethernet is connected, then don't bother.
if (ethernet_connected()) {
- LOG(INFO) << "Ethernet connected, so don't need Google-A.";
+ LOG(INFO) << "Ethernet connected, so don't need Google wifi.";
return false;
}
- // Find Google-A network.
- WifiNetwork wifi;
- bool found = GetWifiNetworkByName(kGoogleAWifi, &wifi);
- if (!found) {
- LOG(INFO) << "Google-A wifi not found.";
- return false;
+ // First look for Google-A then look for Google.
+ // Only care if set to auto-connect.
+ WifiNetwork* wifi = GetWifiNetworkByName(kGoogleAWifi);
+ // If wifi found and set to not auto-connect, then ignore it.
+ if (wifi && !wifi->auto_connect())
+ wifi = NULL;
+
+ if (!wifi) {
+ wifi = GetWifiNetworkByName(kGoogleWifi);
+ // If wifi found and set to not auto-connect, then ignore it.
+ if (wifi && !wifi->auto_connect())
+ wifi = NULL;
}
- // Make sure we want to auto-connect.
- // Since auto-connect is true, we assume the identity and certificate
- // is setup propertly. If it's not, the connection will fail.
- if (!wifi.auto_connect()) {
- LOG(INFO) << "Google-A wifi is set to not auto-connect.";
+ if (!wifi) {
+ LOG(INFO) << "Google-A/Google wifi not found or set to not auto-connect.";
return false;
}
+ // Save the wifi path, so we know which one we want to auto-connect to.
+ const std::string wifi_path = wifi->service_path();
+
// It takes some time for the enterprise daemon to start up and populate the
// certificate and identity. So we wait at most 3 seconds here. And every
// 100ms, we refetch the system info and check the cert and identify on the
@@ -291,10 +298,10 @@
for (int i = 0; i < 30; i++) {
// Update the system and refetch the network.
UpdateSystemInfo();
- GetWifiNetworkByName(kGoogleAWifi, &wifi);
+ wifi = GetWifiNetworkByPath(wifi_path);
// See if identity and certpath are available.
- if (!wifi.identity().empty() && !wifi.cert_path().empty()) {
- LOG(INFO) << "Google-A wifi set up after " << (i*0.1) << " seconds.";
+ if (wifi && !wifi->identity().empty() && !wifi->cert_path().empty()) {
+ LOG(INFO) << "Google wifi set up after " << (i*0.1) << " seconds.";
setup = true;
break;
}
@@ -302,27 +309,25 @@
}
if (!setup) {
- LOG(INFO) << "Google-A wifi not set up after 3 seconds.";
+ LOG(INFO) << "Google wifi not set up after 3 seconds.";
return false;
}
- // Now that we have a setup Google-A, we can connect to it.
- ConnectToNetwork(wifi.service_path().c_str(), NULL);
+ // Now that we have a setup Google wifi, we can connect to it.
+ ConnectToNetwork(wifi_path.c_str(), NULL);
return true;
}
return false;
}
bool NetworkLibraryImpl::PreferredNetworkConnected() {
- WifiNetwork wifi;
- bool found = GetWifiNetworkByName(kGoogleAWifi, &wifi);
- return found && wifi.connected();
+ WifiNetwork* wifi = GetWifiNetworkByName(kGoogleAWifi);
+ return wifi && wifi->connected();
}
bool NetworkLibraryImpl::PreferredNetworkFailed() {
- WifiNetwork wifi;
- bool found = GetWifiNetworkByName(kGoogleAWifi, &wifi);
- return !found || wifi.failed();
+ WifiNetwork* wifi = GetWifiNetworkByName(kGoogleAWifi);
+ return !wifi || wifi->failed();
}
void NetworkLibraryImpl::ConnectToWifiNetwork(WifiNetwork network,
@@ -378,6 +383,12 @@
}
void NetworkLibraryImpl::SaveWifiNetwork(const WifiNetwork& network) {
+ // Update the wifi network in the local cache.
+ WifiNetwork* wifi = GetWifiNetworkByPath(network.service_path());
+ if (wifi)
+ *wifi = network;
+
+ // Update the wifi network with libcros.
if (CrosLibrary::Get()->EnsureLoaded()) {
SetPassphrase(network.service_path().c_str(), network.passphrase().c_str());
SetIdentity(network.service_path().c_str(), network.identity().c_str());
@@ -580,17 +591,24 @@
}
}
-bool NetworkLibraryImpl::GetWifiNetworkByName(const std::string& name,
- WifiNetwork* wifi) {
+WifiNetwork* NetworkLibraryImpl::GetWifiNetworkByName(const std::string& name) {
for (size_t i = 0; i < wifi_networks_.size(); ++i) {
if (wifi_networks_[i].name().compare(name) == 0) {
- *wifi = wifi_networks_[i];
- return true;
+ return &wifi_networks_[i];
}
}
- return false;
+ return NULL;
}
+WifiNetwork* NetworkLibraryImpl::GetWifiNetworkByPath(const std::string& path) {
+ for (size_t i = 0; i < wifi_networks_.size(); ++i) {
+ if (wifi_networks_[i].service_path().compare(path) == 0) {
+ return &wifi_networks_[i];
+ }
+ }
+ return NULL;
+}
+
void NetworkLibraryImpl::EnableNetworkDeviceType(ConnectionType device,
bool enable) {
if (!CrosLibrary::Get()->EnsureLoaded())
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698