Chromium Code Reviews| Index: chrome/browser/ui/webui/chromeos/login/network_state_informer.cc |
| diff --git a/chrome/browser/ui/webui/chromeos/login/network_state_informer.cc b/chrome/browser/ui/webui/chromeos/login/network_state_informer.cc |
| index 7e3358f69ba4291d354e53cd48b746d935194f55..4787bf757fc55ad76401ff9253137588b657c88e 100644 |
| --- a/chrome/browser/ui/webui/chromeos/login/network_state_informer.cc |
| +++ b/chrome/browser/ui/webui/chromeos/login/network_state_informer.cc |
| @@ -7,11 +7,13 @@ |
| #include "base/bind.h" |
| #include "base/logging.h" |
| #include "base/message_loop.h" |
| -#include "chrome/browser/chromeos/cros/cros_library.h" |
| #include "chrome/browser/chromeos/login/screens/error_screen_actor.h" |
| #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| #include "chrome/common/chrome_notification_types.h" |
| +#include "chromeos/network/network_state.h" |
| +#include "chromeos/network/network_state_handler.h" |
| #include "net/proxy/proxy_config.h" |
| +#include "third_party/cros_system_api/dbus/service_constants.h" |
| namespace { |
| @@ -24,13 +26,11 @@ namespace chromeos { |
| NetworkStateInformer::NetworkStateInformer() |
| : state_(OFFLINE), |
| - delegate_(NULL), |
| - last_network_type_(TYPE_WIFI) { |
| + delegate_(NULL) { |
| } |
| NetworkStateInformer::~NetworkStateInformer() { |
| - CrosLibrary::Get()->GetNetworkLibrary()-> |
| - RemoveNetworkManagerObserver(this); |
| + NetworkStateHandler::Get()->RemoveObserver(this); |
| if (NetworkPortalDetector::IsEnabledInCommandLine() && |
| NetworkPortalDetector::GetInstance()) { |
| NetworkPortalDetector::GetInstance()->RemoveObserver(this); |
| @@ -38,9 +38,8 @@ NetworkStateInformer::~NetworkStateInformer() { |
| } |
| void NetworkStateInformer::Init() { |
| - NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| - UpdateState(cros); |
| - cros->AddNetworkManagerObserver(this); |
| + UpdateState(); |
| + NetworkStateHandler::Get()->AddObserver(this); |
| if (NetworkPortalDetector::IsEnabledInCommandLine() && |
| NetworkPortalDetector::GetInstance()) { |
| @@ -69,13 +68,14 @@ void NetworkStateInformer::RemoveObserver( |
| observers_.RemoveObserver(observer); |
| } |
| -void NetworkStateInformer::OnNetworkManagerChanged(NetworkLibrary* cros) { |
| - const Network* active_network = cros->active_network(); |
| +void NetworkStateInformer::NetworkManagerChanged() { |
| + const NetworkState* default_network = |
| + NetworkStateHandler::Get()->DefaultNetwork(); |
| State new_state = OFFLINE; |
| std::string new_network_service_path; |
| - if (active_network) { |
| - new_state = GetNetworkState(active_network); |
| - new_network_service_path = active_network->service_path(); |
| + if (default_network) { |
| + new_state = GetNetworkState(default_network); |
| + new_network_service_path = default_network->path(); |
| } |
| if ((state_ != ONLINE && (new_state == ONLINE || new_state == CONNECTING)) || |
| (state_ == ONLINE && (new_state == ONLINE || new_state == CONNECTING) && |
| @@ -102,14 +102,16 @@ void NetworkStateInformer::OnNetworkManagerChanged(NetworkLibrary* cros) { |
| } |
| } |
| +void NetworkStateInformer::DefaultNetworkChanged(const NetworkState* network) { |
| + NetworkManagerChanged(); |
| +} |
| + |
| void NetworkStateInformer::OnPortalDetectionCompleted( |
| - const Network* network, |
| + const NetworkState* network, |
| const NetworkPortalDetector::CaptivePortalState& state) { |
| - if (CrosLibrary::Get() && network) { |
| - NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); |
| - if (network_library && network_library->active_network() == network) |
| - OnNetworkManagerChanged(network_library); |
| - } |
| + if (NetworkStateHandler::Get() && |
|
stevenjb
2013/05/14 15:46:16
IsInitialized()
gauravsh
2013/05/14 21:51:15
Done.
|
| + NetworkStateHandler::Get()->DefaultNetwork() == network) |
| + NetworkManagerChanged(); |
| } |
| void NetworkStateInformer::Observe( |
| @@ -128,14 +130,15 @@ void NetworkStateInformer::OnPortalDetected() { |
| SendStateToObservers(ErrorScreenActor::kErrorReasonPortalDetected); |
| } |
| -bool NetworkStateInformer::UpdateState(NetworkLibrary* cros) { |
| +bool NetworkStateInformer::UpdateState() { |
| State new_state = OFFLINE; |
| - const Network* active_network = cros->active_network(); |
| - if (active_network) { |
| - new_state = GetNetworkState(active_network); |
| - last_network_service_path_ = active_network->service_path(); |
| - last_network_type_ = active_network->type(); |
| + const NetworkState* default_network = |
| + NetworkStateHandler::Get()->DefaultNetwork(); |
| + if (default_network) { |
| + new_state = GetNetworkState(default_network); |
| + last_network_service_path_ = default_network->path(); |
| + last_network_type_ = default_network->type(); |
| } |
| bool updated = (new_state != state_) || |
| @@ -155,7 +158,7 @@ void NetworkStateInformer::UpdateStateAndNotify() { |
| // Cancel pending update request if any. |
| check_state_.Cancel(); |
| - if (UpdateState(CrosLibrary::Get()->GetNetworkLibrary())) |
| + if (UpdateState()) |
| SendStateToObservers(ErrorScreenActor::kErrorReasonNetworkChanged); |
| else |
| SendStateToObservers(ErrorScreenActor::kErrorReasonUpdate); |
| @@ -170,7 +173,7 @@ void NetworkStateInformer::SendStateToObservers(const std::string& reason) { |
| } |
| NetworkStateInformer::State NetworkStateInformer::GetNetworkState( |
| - const Network* network) { |
| + const NetworkState* network) { |
| DCHECK(network); |
| if (NetworkPortalDetector::IsEnabledInCommandLine() && |
| NetworkPortalDetector::GetInstance()) { |
| @@ -178,14 +181,15 @@ NetworkStateInformer::State NetworkStateInformer::GetNetworkState( |
| NetworkPortalDetector::GetInstance()->GetCaptivePortalState(network); |
| NetworkPortalDetector::CaptivePortalStatus status = state.status; |
| if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && |
| - network->connecting()) { |
| + NetworkState::StateIsConnecting(network->connection_state())) { |
| return CONNECTING; |
| } |
| // For proxy-less networks rely on shill's online state if |
| // NetworkPortalDetector's state of current network is unknown. |
| if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE || |
| (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && |
| - !IsProxyConfigured(network) && network->online())) { |
| + !IsProxyConfigured(network) && |
| + network->connection_state() == flimflam::kStateOnline)) { |
| return ONLINE; |
| } |
| if (status == |
| @@ -195,31 +199,33 @@ NetworkStateInformer::State NetworkStateInformer::GetNetworkState( |
| } |
| if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL || |
| (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && |
| - network->restricted_pool())) |
| + network->connection_state() == flimflam::kStatePortal)) |
| return CAPTIVE_PORTAL; |
| } else { |
| - if (network->connecting()) |
| + if (NetworkState::StateIsConnecting(network->connection_state())) |
| return CONNECTING; |
| - if (network->online()) |
| + if (network->connection_state() == flimflam::kStateOnline) |
| return ONLINE; |
| - if (network->restricted_pool()) |
| + if (network->connection_state() == flimflam::kStatePortal) |
| return CAPTIVE_PORTAL; |
| } |
| return OFFLINE; |
| } |
| -bool NetworkStateInformer::IsProxyConfigured(const Network* network) { |
| +bool NetworkStateInformer::IsProxyConfigured(const NetworkState* network) { |
| DCHECK(network); |
| - ProxyStateMap::iterator it = proxy_state_map_.find(network->unique_id()); |
| + |
| + ProxyStateMap::iterator it = proxy_state_map_.find(network->guid()); |
| if (it != proxy_state_map_.end() && |
| it->second.proxy_config == network->proxy_config()) { |
| return it->second.configured; |
| } |
| net::ProxyConfig proxy_config; |
| - if (!ProxyConfigServiceImpl::ParseProxyConfig(network, &proxy_config)) |
| + if (!ProxyConfigServiceImpl::ParseProxyConfig(network->proxy_config(), |
| + &proxy_config)) |
| return false; |
| bool configured = !proxy_config.proxy_rules().empty(); |
| - proxy_state_map_[network->unique_id()] = |
| + proxy_state_map_[network->guid()] = |
| ProxyState(network->proxy_config(), configured); |
| return configured; |
| } |