diff options
-rw-r--r-- | chrome/browser/chromeos/cros/network_library.cc | 50 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/network_library.h | 3 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/login_utils.cc | 39 |
3 files changed, 69 insertions, 23 deletions
diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc index 9920308..9af0847 100644 --- a/chrome/browser/chromeos/cros/network_library.cc +++ b/chrome/browser/chromeos/cros/network_library.cc @@ -262,6 +262,8 @@ bool NetworkLibraryImpl::ConnectToPreferredNetworkIfAvailable() { // 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."; + // First force a refresh of the system info. + UpdateSystemInfo(); // If ethernet is connected, then don't bother. if (ethernet_connected()) { @@ -277,19 +279,38 @@ bool NetworkLibraryImpl::ConnectToPreferredNetworkIfAvailable() { return false; } - // See if identity and certpath are available. - if (wifi.identity().empty() || wifi.cert_path().empty()) { - LOG(INFO) << "Google-A wifi not set up."; - return false; - } - // 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."; return false; } - // Connect to Google-A. + // 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 + // wifi. The enterprise daemon takes between 0.4 to 0.9 seconds to setup. + bool setup = false; + for (int i = 0; i < 30; i++) { + // Update the system and refetch the network. + UpdateSystemInfo(); + GetWifiNetworkByName(kGoogleAWifi, &wifi); + // 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."; + setup = true; + break; + } + PlatformThread::Sleep(100); + } + + if (!setup) { + LOG(INFO) << "Google-A 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); return true; } @@ -546,16 +567,21 @@ void NetworkLibraryImpl::ParseSystem(SystemInfo* system, void NetworkLibraryImpl::Init() { // First, get the currently available networks. This data is cached // on the connman side, so the call should be quick. + LOG(INFO) << "Getting initial CrOS network info."; + UpdateSystemInfo(); + + LOG(INFO) << "Registering for network status updates."; + // Now, register to receive updates on network status. + network_status_connection_ = MonitorNetwork(&NetworkStatusChangedHandler, + this); +} + +void NetworkLibraryImpl::UpdateSystemInfo() { SystemInfo* system = GetSystemInfo(); if (system) { - LOG(INFO) << "Getting initial CrOS network info."; UpdateNetworkStatus(system); FreeSystemInfo(system); } - LOG(INFO) << "Registering for network status updates."; - // Now, register to receive updates on network status. - network_status_connection_ = MonitorNetwork(&NetworkStatusChangedHandler, - this); } bool NetworkLibraryImpl::GetWifiNetworkByName(const std::string& name, diff --git a/chrome/browser/chromeos/cros/network_library.h b/chrome/browser/chromeos/cros/network_library.h index 8eb0f89..38917f7 100644 --- a/chrome/browser/chromeos/cros/network_library.h +++ b/chrome/browser/chromeos/cros/network_library.h @@ -432,6 +432,9 @@ class NetworkLibraryImpl : public NetworkLibrary, // monitoring of network changes. void Init(); + // Force an update of the system info. + void UpdateSystemInfo(); + // Gets the WifiNetwork with the given name. Returns whether the wifi network // was found or not. bool GetWifiNetworkByName(const std::string& name, WifiNetwork* wifi); diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index ca59ce7..2273c2c 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -40,7 +40,7 @@ namespace chromeos { namespace { -const int kWifiTimeoutInMS = 15000; +const int kWifiTimeoutInMS = 30000; static char kIncognitoUser[] = "incognito"; // Prefix for Auth token received from ClientLogin request. @@ -111,6 +111,7 @@ class LoginUtilsImpl : public LoginUtils, NotificationRegistrar registrar_; bool wifi_connecting_; + bool wifi_connection_started_; base::Time wifi_connect_start_time_; // Indicates if DoBrowserLaunch will actually launch the browser or not. @@ -150,20 +151,35 @@ bool LoginUtilsImpl::ShouldWaitForWifi() { // wait kWifiTimeoutInMS until connection is made or failed. if (wifi_connecting_) { NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); + bool failed = false; if (cros->PreferredNetworkConnected()) { - LOG(INFO) << "Wifi connection successful."; + base::TimeDelta diff = base::Time::Now() - wifi_connect_start_time_; + LOG(INFO) << "Wifi connection successful after " << diff.InSeconds() << + " seconds."; return false; } else if (cros->PreferredNetworkFailed()) { - LOG(INFO) << "Wifi connection failed."; - return false; - } else { - base::TimeDelta diff = base::Time::Now() - wifi_connect_start_time_; - // Keep waiting if we have not timed out yet. - bool timedout = (diff.InMilliseconds() > kWifiTimeoutInMS); - if (timedout) - LOG(INFO) << "Wifi connection timed out."; - return !timedout; + // Sometimes we stay in the failed state before connection starts. + // So we only know for sure that connection failed if we get a failed + // state after connection has started. + if (wifi_connection_started_) { + LOG(INFO) << "Wifi connection failed."; + return false; + } + failed = true; } + + // If state is not failed, then we know connection has started. + if (!wifi_connection_started_ && !failed) { + LOG(INFO) << "Wifi connection started."; + wifi_connection_started_ = true; + } + + base::TimeDelta diff = base::Time::Now() - wifi_connect_start_time_; + // Keep waiting if we have not timed out yet. + bool timedout = (diff.InMilliseconds() > kWifiTimeoutInMS); + if (timedout) + LOG(INFO) << "Wifi connection timed out."; + return !timedout; } return false; } @@ -234,6 +250,7 @@ void LoginUtilsImpl::Observe(NotificationType type, void LoginUtilsImpl::ConnectToPreferredNetwork() { NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); + wifi_connection_started_ = false; wifi_connecting_ = cros->ConnectToPreferredNetworkIfAvailable(); if (wifi_connecting_) wifi_connect_start_time_ = base::Time::Now(); |