| 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/ui/webui/chromeos/login/network_state_informer.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/chromeos/login/screens/network_error.h" | 12 #include "chrome/browser/chromeos/login/screens/network_error.h" |
| 13 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 13 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 14 #include "chromeos/network/network_state.h" | 14 #include "chromeos/network/network_state.h" |
| 15 #include "chromeos/network/network_state_handler.h" | 15 #include "chromeos/network/network_state_handler.h" |
| 16 #include "chromeos/network/proxy/proxy_config_handler.h" | 16 #include "chromeos/network/proxy/proxy_config_handler.h" |
| 17 #include "chromeos/network/proxy/ui_proxy_config_service.h" |
| 17 #include "components/proxy_config/proxy_config_dictionary.h" | 18 #include "components/proxy_config/proxy_config_dictionary.h" |
| 18 #include "components/proxy_config/proxy_prefs.h" | 19 #include "components/proxy_config/proxy_prefs.h" |
| 19 #include "net/proxy/proxy_config.h" | 20 #include "net/proxy/proxy_config.h" |
| 20 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 21 | 22 |
| 22 namespace chromeos { | 23 namespace chromeos { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 const char kNetworkStateOffline[] = "offline"; | 27 const char kNetworkStateOffline[] = "offline"; |
| 27 const char kNetworkStateOnline[] = "online"; | 28 const char kNetworkStateOnline[] = "online"; |
| 28 const char kNetworkStateCaptivePortal[] = "behind captive portal"; | 29 const char kNetworkStateCaptivePortal[] = "behind captive portal"; |
| 29 const char kNetworkStateConnecting[] = "connecting"; | 30 const char kNetworkStateConnecting[] = "connecting"; |
| 30 const char kNetworkStateProxyAuthRequired[] = "proxy auth required"; | 31 const char kNetworkStateProxyAuthRequired[] = "proxy auth required"; |
| 31 | 32 |
| 32 bool HasDefaultNetworkProxyConfigured() { | |
| 33 const NetworkState* network = | |
| 34 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); | |
| 35 if (!network) | |
| 36 return false; | |
| 37 onc::ONCSource onc_source = onc::ONC_SOURCE_NONE; | |
| 38 std::unique_ptr<ProxyConfigDictionary> proxy_dict = | |
| 39 proxy_config::GetProxyConfigForNetwork( | |
| 40 NULL, g_browser_process->local_state(), *network, &onc_source); | |
| 41 ProxyPrefs::ProxyMode mode; | |
| 42 return (proxy_dict && proxy_dict->GetMode(&mode) && | |
| 43 mode == ProxyPrefs::MODE_FIXED_SERVERS); | |
| 44 } | |
| 45 | |
| 46 NetworkStateInformer::State GetStateForDefaultNetwork() { | 33 NetworkStateInformer::State GetStateForDefaultNetwork() { |
| 47 const NetworkState* network = | 34 const NetworkState* network = |
| 48 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); | 35 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
| 49 if (!network) | 36 if (!network) |
| 50 return NetworkStateInformer::OFFLINE; | 37 return NetworkStateInformer::OFFLINE; |
| 51 | 38 |
| 52 if (network_portal_detector::GetInstance()->IsEnabled()) { | 39 if (network_portal_detector::GetInstance()->IsEnabled()) { |
| 53 NetworkPortalDetector::CaptivePortalState state = | 40 NetworkPortalDetector::CaptivePortalState state = |
| 54 network_portal_detector::GetInstance()->GetCaptivePortalState( | 41 network_portal_detector::GetInstance()->GetCaptivePortalState( |
| 55 network->guid()); | 42 network->guid()); |
| 56 NetworkPortalDetector::CaptivePortalStatus status = state.status; | 43 NetworkPortalDetector::CaptivePortalStatus status = state.status; |
| 57 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && | 44 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && |
| 58 NetworkState::StateIsConnecting(network->connection_state())) { | 45 NetworkState::StateIsConnecting(network->connection_state())) { |
| 59 return NetworkStateInformer::CONNECTING; | 46 return NetworkStateInformer::CONNECTING; |
| 60 } | 47 } |
| 61 // For proxy-less networks rely on shill's online state if | 48 // For proxy-less networks rely on shill's online state if |
| 62 // NetworkPortalDetector's state of current network is unknown. | 49 // NetworkPortalDetector's state of current network is unknown. |
| 63 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE || | 50 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE || |
| 64 (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && | 51 (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && |
| 65 !HasDefaultNetworkProxyConfigured() && | 52 !NetworkHandler::Get() |
| 53 ->ui_proxy_config_service() |
| 54 ->HasDefaultNetworkProxyConfigured() && |
| 66 network->connection_state() == shill::kStateOnline)) { | 55 network->connection_state() == shill::kStateOnline)) { |
| 67 return NetworkStateInformer::ONLINE; | 56 return NetworkStateInformer::ONLINE; |
| 68 } | 57 } |
| 69 if (status == | 58 if (status == |
| 70 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED && | 59 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED && |
| 71 HasDefaultNetworkProxyConfigured()) { | 60 NetworkHandler::Get() |
| 61 ->ui_proxy_config_service() |
| 62 ->HasDefaultNetworkProxyConfigured()) { |
| 72 return NetworkStateInformer::PROXY_AUTH_REQUIRED; | 63 return NetworkStateInformer::PROXY_AUTH_REQUIRED; |
| 73 } | 64 } |
| 74 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL || | 65 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL || |
| 75 (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && | 66 (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && |
| 76 network->is_captive_portal())) | 67 network->is_captive_portal())) |
| 77 return NetworkStateInformer::CAPTIVE_PORTAL; | 68 return NetworkStateInformer::CAPTIVE_PORTAL; |
| 78 } else { | 69 } else { |
| 79 if (NetworkState::StateIsConnecting(network->connection_state())) | 70 if (NetworkState::StateIsConnecting(network->connection_state())) |
| 80 return NetworkStateInformer::CONNECTING; | 71 return NetworkStateInformer::CONNECTING; |
| 81 if (network->connection_state() == shill::kStateOnline) | 72 if (network->connection_state() == shill::kStateOnline) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 SendStateToObservers(NetworkError::ERROR_REASON_UPDATE); | 206 SendStateToObservers(NetworkError::ERROR_REASON_UPDATE); |
| 216 } | 207 } |
| 217 | 208 |
| 218 void NetworkStateInformer::SendStateToObservers( | 209 void NetworkStateInformer::SendStateToObservers( |
| 219 NetworkError::ErrorReason reason) { | 210 NetworkError::ErrorReason reason) { |
| 220 for (NetworkStateInformerObserver& observer : observers_) | 211 for (NetworkStateInformerObserver& observer : observers_) |
| 221 observer.UpdateState(reason); | 212 observer.UpdateState(reason); |
| 222 } | 213 } |
| 223 | 214 |
| 224 } // namespace chromeos | 215 } // namespace chromeos |
| OLD | NEW |