| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/network_login_observer.h" | 5 #include "chrome/browser/chromeos/network_login_observer.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/cros/cros_library.h" | 7 #include "chrome/browser/chromeos/cros/cert_library.h" |
| 8 #include "chrome/browser/chromeos/cros/network_library.h" | 8 #include "chrome/browser/chromeos/cros/network_library.h" |
| 9 #include "chrome/browser/chromeos/options/network_config_view.h" | 9 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 10 #include "chromeos/network/network_state_handler.h" | 10 #include "chromeos/network/network_state_handler.h" |
| 11 #include "ui/views/widget/widget.h" | 11 #include "ui/views/widget/widget.h" |
| 12 #include "ui/views/widget/widget_delegate.h" | 12 #include "ui/views/widget/widget_delegate.h" |
| 13 | 13 |
| 14 namespace chromeos { | 14 namespace chromeos { |
| 15 | 15 |
| 16 NetworkLoginObserver::NetworkLoginObserver() { | 16 NetworkLoginObserver::NetworkLoginObserver() { |
| 17 CrosLibrary::Get()->GetCertLibrary()->AddObserver(this); | 17 // CertLibrary does not get initialized in many unit tests even though |
| 18 // NetworkLibrary which owns this class does. TODO(stevenjb): Eliminate |
| 19 // this class along with NetworkLibrary, crbug.com/154852. |
| 20 if (CertLibrary::IsInitialized()) |
| 21 CertLibrary::Get()->AddObserver(this); |
| 18 } | 22 } |
| 19 | 23 |
| 20 NetworkLoginObserver::~NetworkLoginObserver() { | 24 NetworkLoginObserver::~NetworkLoginObserver() { |
| 21 CrosLibrary::Get()->GetCertLibrary()->RemoveObserver(this); | 25 if (CertLibrary::IsInitialized()) |
| 26 CertLibrary::Get()->RemoveObserver(this); |
| 22 } | 27 } |
| 23 | 28 |
| 24 void NetworkLoginObserver::OnNetworkManagerChanged(NetworkLibrary* cros) { | 29 void NetworkLoginObserver::OnNetworkManagerChanged(NetworkLibrary* cros) { |
| 25 // Check to see if we have any newly failed wifi network. | 30 // Check to see if we have any newly failed wifi network. |
| 26 const WifiNetworkVector& wifi_networks = cros->wifi_networks(); | 31 const WifiNetworkVector& wifi_networks = cros->wifi_networks(); |
| 27 for (WifiNetworkVector::const_iterator it = wifi_networks.begin(); | 32 for (WifiNetworkVector::const_iterator it = wifi_networks.begin(); |
| 28 it != wifi_networks.end(); it++) { | 33 it != wifi_networks.end(); it++) { |
| 29 WifiNetwork* wifi = *it; | 34 WifiNetwork* wifi = *it; |
| 30 if (wifi->notify_failure()) { | 35 if (wifi->notify_failure()) { |
| 31 // Display login dialog again for bad_passphrase and bad_wepkey errors. | 36 // Display login dialog again for bad_passphrase and bad_wepkey errors. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 90 } |
| 86 | 91 |
| 87 void NetworkLoginObserver::OnCertificatesLoaded(bool initial_load) { | 92 void NetworkLoginObserver::OnCertificatesLoaded(bool initial_load) { |
| 88 if (initial_load) { | 93 if (initial_load) { |
| 89 // Once certificates have loaded, connect to the "best" available network. | 94 // Once certificates have loaded, connect to the "best" available network. |
| 90 NetworkStateHandler::Get()->ConnectToBestWifiNetwork(); | 95 NetworkStateHandler::Get()->ConnectToBestWifiNetwork(); |
| 91 } | 96 } |
| 92 } | 97 } |
| 93 | 98 |
| 94 } // namespace chromeos | 99 } // namespace chromeos |
| OLD | NEW |