diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-17 21:11:13 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-17 21:11:13 +0000 |
commit | 1f9fa30cbcd681928e28c6e7085da643b50c6acb (patch) | |
tree | 49c2024f60af6406d5a1598bf4547580b78441d7 | |
parent | ffd49dfc0729301c77dcf5026d29fa9cbedaecc1 (diff) | |
download | chromium_src-1f9fa30cbcd681928e28c6e7085da643b50c6acb.zip chromium_src-1f9fa30cbcd681928e28c6e7085da643b50c6acb.tar.gz chromium_src-1f9fa30cbcd681928e28c6e7085da643b50c6acb.tar.bz2 |
Handle NetworkConnectionHandler errors in NetworkStateListDetailedView
Explicitly handle different error types in NetworkStateListDetailedView
with NetworkConnectionHandler enabled.
Modifies the SystemTrayDelegate interface for new Handler code in
preparation of removing old code.
BUG=235243
R=gspencer@chromium.org
Review URL: https://codereview.chromium.org/14762016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200881 0039d316-1c4b-4281-b951-d872f2087c98
21 files changed, 248 insertions, 78 deletions
diff --git a/ash/system/chromeos/network/network_list_detailed_view_base.cc b/ash/system/chromeos/network/network_list_detailed_view_base.cc index 787da1f..874dd84 100644 --- a/ash/system/chromeos/network/network_list_detailed_view_base.cc +++ b/ash/system/chromeos/network/network_list_detailed_view_base.cc @@ -322,7 +322,7 @@ void NetworkListDetailedViewBase::ButtonPressed(views::Button* sender, ResetInfoBubble(); SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); if (sender == settings_) - delegate->ShowNetworkSettings(); + delegate->ShowNetworkSettings(""); else if (sender == proxy_settings_) delegate->ChangeProxySettings(); else diff --git a/ash/system/chromeos/network/network_state_list_detailed_view.cc b/ash/system/chromeos/network/network_state_list_detailed_view.cc index 9ba3849..b55bed5 100644 --- a/ash/system/chromeos/network/network_state_list_detailed_view.cc +++ b/ash/system/chromeos/network/network_state_list_detailed_view.cc @@ -237,7 +237,7 @@ void NetworkStateListDetailedView::ButtonPressed(views::Button* sender, } else if (sender == button_mobile_) { ToggleMobile(); } else if (sender == settings_) { - delegate->ShowNetworkSettings(); + delegate->ShowNetworkSettings(""); } else if (sender == proxy_settings_) { delegate->ChangeProxySettings(); } else if (sender == other_mobile_) { @@ -266,8 +266,18 @@ void NetworkStateListDetailedView::OnViewClicked(views::View* sender) { std::map<views::View*, std::string>::iterator found = network_map_.find(sender); - if (found != network_map_.end()) - ConnectToNetwork(found->second); + if (found != network_map_.end()) { + const std::string& service_path = found->second; + const NetworkState* network = + NetworkStateHandler::Get()->GetNetworkState(service_path); + if (!network || + network->IsConnectedState() || network->IsConnectingState()) { + Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( + service_path); + } else { + ConnectToNetwork(service_path); + } + } } // Create UI components. @@ -730,7 +740,6 @@ views::View* NetworkStateListDetailedView::CreateNetworkInfoView() { handler->FormattedHardwareAddressForType(flimflam::kTypeVPN); } - // GetNetworkAddresses returns empty strings if no information is available. if (!ip_address.empty()) { container->AddChildView(CreateInfoBubbleLine(bundle.GetLocalizedString( IDS_ASH_STATUS_TRAY_IP), ip_address)); @@ -766,11 +775,13 @@ void NetworkStateListDetailedView::ConnectToNetwork( return; if (CommandLine::ForCurrentProcess()->HasSwitch( chromeos::switches::kUseNewNetworkConfigurationHandlers)) { + const bool ignore_error_state = false; NetworkConnectionHandler::Get()->ConnectToNetwork( service_path, base::Bind(&base::DoNothing), base::Bind(&NetworkStateListDetailedView::OnConnectFailed, - AsWeakPtr(), service_path)); + AsWeakPtr(), service_path), + ignore_error_state); } else { Shell::GetInstance()->system_tray_delegate()->ConnectToNetwork( service_path); @@ -781,12 +792,21 @@ void NetworkStateListDetailedView::OnConnectFailed( const std::string& service_path, const std::string& error_name, scoped_ptr<base::DictionaryValue> error_data) { - VLOG(1) << "ConnectFailed: " << error_name; - // This will show the settings UI for a connected/ing network or a connect - // dialog for unconfigured networks. - // TODO(stevenjb): Change the API to explicitly show network settings or - // connect dialog (i.e. explicitly handle different error types). - Shell::GetInstance()->system_tray_delegate()->ConnectToNetwork( + if (error_name == NetworkConnectionHandler::kErrorNotFound) + return; + if (error_name == NetworkConnectionHandler::kErrorPassphraseRequired) { + // TODO(stevenjb): Add inline UI to handle passphrase entry here. + Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( + service_path); + return; + } + if (error_name == NetworkConnectionHandler::kErrorCertificateRequired || + error_name == NetworkConnectionHandler::kErrorConfigurationRequired) { + Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( + service_path); + return; + } + Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( service_path); } @@ -816,9 +836,7 @@ void NetworkStateListDetailedView::ToggleMobile() { return; } if (!mobile->sim_lock_type().empty() || mobile->IsSimAbsent()) { - // TODO(stevenjb): Rename ToggleMobile() to ShowMobileSimDialog() - // when NetworkListDetailedView is deprecated. crbug.com/222540. - ash::Shell::GetInstance()->system_tray_delegate()->ToggleMobile(); + ash::Shell::GetInstance()->system_tray_delegate()->ShowMobileSimDialog(); } else { handler->SetTechnologyEnabled( NetworkStateHandler::kMatchTypeMobile, true, diff --git a/ash/system/tray/system_tray_delegate.h b/ash/system/tray/system_tray_delegate.h index 162920a..32c5830 100644 --- a/ash/system/tray/system_tray_delegate.h +++ b/ash/system/tray/system_tray_delegate.h @@ -165,8 +165,9 @@ class SystemTrayDelegate { // Shows the settings related to date, timezone etc. virtual void ShowDateSettings() = 0; - // Shows the settings related to network. - virtual void ShowNetworkSettings() = 0; + // Shows the settings related to network. If |service_path| is not empty, + // show the settings for that network. + virtual void ShowNetworkSettings(const std::string& service_path) = 0; // Shows the settings related to bluetooth. virtual void ShowBluetoothSettings() = 0; @@ -264,7 +265,10 @@ class SystemTrayDelegate { // Returns the information about all virtual networks. virtual void GetVirtualNetworks(std::vector<NetworkIconInfo>* list) = 0; - // Connects to the network specified by the unique id. + // Shows UI to configure or activate the network specified by |network_id|. + virtual void ConfigureNetwork(const std::string& network_id) = 0; + + // Sends a connect request for the network specified by |network_id|. virtual void ConnectToNetwork(const std::string& network_id) = 0; // Gets the network IP address, and the mac addresses for the ethernet and @@ -291,6 +295,9 @@ class SystemTrayDelegate { // Toggles bluetooth. virtual void ToggleBluetooth() = 0; + // Shows UI to unlock a mobile sim. + virtual void ShowMobileSimDialog() = 0; + // Shows UI to connect to an unlisted wifi network. virtual void ShowOtherWifi() = 0; diff --git a/ash/system/tray/test_system_tray_delegate.cc b/ash/system/tray/test_system_tray_delegate.cc index ddfe092..10dc85c 100644 --- a/ash/system/tray/test_system_tray_delegate.cc +++ b/ash/system/tray/test_system_tray_delegate.cc @@ -145,7 +145,8 @@ void TestSystemTrayDelegate::ShowSettings() { void TestSystemTrayDelegate::ShowDateSettings() { } -void TestSystemTrayDelegate::ShowNetworkSettings() { +void TestSystemTrayDelegate::ShowNetworkSettings( + const std::string& service_path) { } void TestSystemTrayDelegate::ShowBluetoothSettings() { @@ -247,6 +248,9 @@ void TestSystemTrayDelegate::GetVirtualNetworks( std::vector<NetworkIconInfo>* list) { } +void TestSystemTrayDelegate::ConfigureNetwork(const std::string& network_id) { +} + void TestSystemTrayDelegate::ConnectToNetwork(const std::string& network_id) { } @@ -284,6 +288,9 @@ bool TestSystemTrayDelegate::IsBluetoothDiscovering() { return false; } +void TestSystemTrayDelegate::ShowMobileSimDialog() { +} + void TestSystemTrayDelegate::ShowOtherWifi() { } diff --git a/ash/system/tray/test_system_tray_delegate.h b/ash/system/tray/test_system_tray_delegate.h index b349277..8dd1d34 100644 --- a/ash/system/tray/test_system_tray_delegate.h +++ b/ash/system/tray/test_system_tray_delegate.h @@ -42,7 +42,7 @@ class TestSystemTrayDelegate : public SystemTrayDelegate { virtual base::HourClockType GetHourClockType() const OVERRIDE; virtual void ShowSettings() OVERRIDE; virtual void ShowDateSettings() OVERRIDE; - virtual void ShowNetworkSettings() OVERRIDE; + virtual void ShowNetworkSettings(const std::string& service_path) OVERRIDE; virtual void ShowBluetoothSettings() OVERRIDE; virtual void ShowDisplaySettings() OVERRIDE; virtual void ShowDriveSettings() OVERRIDE; @@ -76,6 +76,7 @@ class TestSystemTrayDelegate : public SystemTrayDelegate { virtual void GetAvailableNetworks( std::vector<NetworkIconInfo>* list) OVERRIDE; virtual void GetVirtualNetworks(std::vector<NetworkIconInfo>* list) OVERRIDE; + virtual void ConfigureNetwork(const std::string& network_id) OVERRIDE; virtual void ConnectToNetwork(const std::string& network_id) OVERRIDE; virtual void GetNetworkAddresses(std::string* ip_address, std::string* ethernet_mac_address, @@ -87,6 +88,7 @@ class TestSystemTrayDelegate : public SystemTrayDelegate { virtual void ToggleMobile() OVERRIDE; virtual void ToggleBluetooth() OVERRIDE; virtual bool IsBluetoothDiscovering() OVERRIDE; + virtual void ShowMobileSimDialog() OVERRIDE; virtual void ShowOtherWifi() OVERRIDE; virtual void ShowOtherVPN() OVERRIDE; virtual void ShowOtherCellular() OVERRIDE; diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 35ac1e3..dcd0bbc 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -6794,6 +6794,12 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_FLAGS_ASH_DISABLE_NEW_NETWORK_STATUS_AREA_DESCRIPTION" desc="Title for the flag to enable using the new Network State Handler."> Disables the new network handlers which handle Shill communication without using NetworkLibrary for the status area. </message> + <message name="IDS_FLAGS_CHROMEOS_USE_NEW_NETWORK_CONFIGURATION_HANDLERS_NAME" desc="Title for the flag to enable using the new network configuration handlers."> + Enable new network configuration handlers + </message> + <message name="IDS_FLAGS_CHROMEOS_USE_NEW_NETWORK_CONFIGURATION_HANDLERS_DESCRIPTION" desc="Description for the flag to enable using the new network configuration handlers."> + Enable the new network configuration handlers which handle Shill connection requests without using NetworkLibrary. + </message> <message name="IDS_FLAGS_ASH_ENABLE_NEW_AUDIO_HANDLER_NAME" desc="Title for the flag to enable using the new audio handler."> Enables new audio handler </message> diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 35662c2..32a7c43 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -1161,6 +1161,12 @@ const Experiment kExperiments[] = { #endif #endif #if defined(OS_CHROMEOS) + { "use-new-network-configuration-handlers", + IDS_FLAGS_CHROMEOS_USE_NEW_NETWORK_CONFIGURATION_HANDLERS_NAME, + IDS_FLAGS_CHROMEOS_USE_NEW_NETWORK_CONFIGURATION_HANDLERS_DESCRIPTION, + kOsCrOS, + SINGLE_VALUE_TYPE(chromeos::switches::kUseNewNetworkConfigurationHandlers), + }, { "ash-disable-new-network-status-area", IDS_FLAGS_ASH_DISABLE_NEW_NETWORK_STATUS_AREA_NAME, IDS_FLAGS_ASH_DISABLE_NEW_NETWORK_STATUS_AREA_DESCRIPTION, diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index 01a8b52..02da1a7 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -379,9 +379,9 @@ class DBusServices { if (cros_initialized_ && CrosLibrary::Get()) CrosLibrary::Shutdown(); + NetworkConnectionHandler::Shutdown(); ManagedNetworkConfigurationHandler::Shutdown(); NetworkConfigurationHandler::Shutdown(); - NetworkConnectionHandler::Shutdown(); NetworkProfileHandler::Shutdown(); NetworkStateHandler::Shutdown(); diff --git a/chrome/browser/chromeos/extensions/networking_private_api.cc b/chrome/browser/chromeos/extensions/networking_private_api.cc index 9f3d519..caaa441 100644 --- a/chrome/browser/chromeos/extensions/networking_private_api.cc +++ b/chrome/browser/chromeos/extensions/networking_private_api.cc @@ -291,6 +291,7 @@ bool NetworkingPrivateStartConnectFunction::RunImpl() { api::StartConnect::Params::Create(*args_); EXTENSION_FUNCTION_VALIDATE(params); + const bool ignore_error_state = true; chromeos::NetworkConnectionHandler::Get()->ConnectToNetwork( params->network_guid, // service path base::Bind( @@ -298,7 +299,8 @@ bool NetworkingPrivateStartConnectFunction::RunImpl() { this), base::Bind( &NetworkingPrivateStartConnectFunction::ConnectionStartFailed, - this)); + this), + ignore_error_state); return true; } diff --git a/chrome/browser/chromeos/login/chrome_restart_request.cc b/chrome/browser/chromeos/login/chrome_restart_request.cc index 149ef4d..cb2f9f0 100644 --- a/chrome/browser/chromeos/login/chrome_restart_request.cc +++ b/chrome/browser/chromeos/login/chrome_restart_request.cc @@ -167,6 +167,7 @@ std::string DeriveCommandLine(const GURL& start_url, chromeos::switches::kLoginProfile, chromeos::switches::kNaturalScrollDefault, chromeos::switches::kEnableExperimentalBluetooth, + chromeos::switches::kUseNewNetworkConfigurationHandlers, gfx::switches::kEnableBrowserTextSubpixelPositioning, gfx::switches::kEnableWebkitTextSubpixelPositioning, views::corewm::switches::kNoDropShadows, diff --git a/chrome/browser/chromeos/offline/offline_load_page.cc b/chrome/browser/chromeos/offline/offline_load_page.cc index 7bf3814..1389d9e 100644 --- a/chrome/browser/chromeos/offline/offline_load_page.cc +++ b/chrome/browser/chromeos/offline/offline_load_page.cc @@ -171,7 +171,7 @@ void OfflineLoadPage::CommandReceived(const std::string& cmd) { } // TODO(oshima): record action for metrics. if (command == "open_network_settings") { - ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings(); + ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings(""); } else { LOG(WARNING) << "Unknown command:" << cmd; } diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc index b55d6b5..c0da2dc 100644 --- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc +++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc @@ -39,6 +39,7 @@ #include "base/logging.h" #include "base/memory/weak_ptr.h" #include "base/prefs/pref_service.h" +#include "base/stringprintf.h" #include "base/time.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" @@ -46,6 +47,7 @@ #include "chrome/browser/chromeos/accessibility/magnification_manager.h" #include "chrome/browser/chromeos/audio/audio_handler.h" #include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h" +#include "chrome/browser/chromeos/choose_mobile_network_dialog.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/drive/drive_system_service.h" @@ -59,7 +61,9 @@ #include "chrome/browser/chromeos/login/user.h" #include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/chromeos/mobile_config.h" +#include "chrome/browser/chromeos/options/network_config_view.h" #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" +#include "chrome/browser/chromeos/sim_dialog_delegate.h" #include "chrome/browser/chromeos/status/data_promo_notification.h" #include "chrome/browser/chromeos/status/network_menu.h" #include "chrome/browser/chromeos/status/network_menu_icon.h" @@ -91,6 +95,8 @@ #include "chromeos/ime/input_method_manager.h" #include "chromeos/ime/xkeyboard.h" #include "chromeos/login/login_state.h" +#include "chromeos/network/network_state.h" +#include "chromeos/network/network_state_handler.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_service.h" @@ -101,6 +107,8 @@ #include "grit/ash_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" +#include "net/base/escape.h" +#include "third_party/cros_system_api/dbus/service_constants.h" #include "ui/base/l10n/l10n_util.h" using drive::DriveSystemService; @@ -506,11 +514,26 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, chrome::ShowSettingsSubPage(GetAppropriateBrowser(), sub_page); } - virtual void ShowNetworkSettings() OVERRIDE { + virtual void ShowNetworkSettings(const std::string& service_path) OVERRIDE { + if (!LoginState::Get()->IsUserLoggedIn()) + return; + + std::string page = chrome::kInternetOptionsSubPage; + const chromeos::NetworkState* network = service_path.empty() ? NULL : + chromeos::NetworkStateHandler::Get()->GetNetworkState(service_path); + if (network) { + std::string name(network->name()); + if (name.empty() && network->type() == flimflam::kTypeEthernet) + name = l10n_util::GetStringUTF8(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); + page += base::StringPrintf( + "?servicePath=%s&networkType=%s&networkName=%s", + net::EscapeUrlEncodedData(service_path, true).c_str(), + net::EscapeUrlEncodedData(network->type(), true).c_str(), + net::EscapeUrlEncodedData(name, false).c_str()); + } content::RecordAction( content::UserMetricsAction("OpenInternetOptionsDialog")); - chrome::ShowSettingsSubPage(GetAppropriateBrowser(), - chrome::kInternetOptionsSubPage); + chrome::ShowSettingsSubPage(GetAppropriateBrowser(), page); } virtual void ShowBluetoothSettings() OVERRIDE { @@ -880,13 +903,41 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, NetworkLibrary::FORMAT_COLON_SEPARATED_HEX); } + virtual void ConfigureNetwork(const std::string& network_id) OVERRIDE { + const chromeos::NetworkState* network = network_id.empty() ? NULL : + chromeos::NetworkStateHandler::Get()->GetNetworkState(network_id); + if (!network) { + LOG(ERROR) << "ConfigureNetwork: Network not found: " << network_id; + return; + } + if (network->type() == flimflam::kTypeWifi || + network->type() == flimflam::kTypeWimax || + network->type() == flimflam::kTypeVPN) { + // TODO(stevenjb): Replace with non-NetworkLibrary UI. + Network* cros_network = CrosLibrary::Get()->GetNetworkLibrary()-> + FindNetworkByPath(network_id); + NetworkConfigView::Show(cros_network, GetNativeWindow()); + return; + } + if (network->type() == flimflam::kTypeCellular && + (network->activation_state() != flimflam::kActivationStateActivated || + network->cellular_out_of_credits())) { + ash::Shell::GetInstance()->delegate()->OpenMobileSetup(network_id); + return; + } + // No special configure or setup for |network_id|, show the settings UI. + ShowNetworkSettings(network_id); + } + virtual void ConnectToNetwork(const std::string& network_id) OVERRIDE { + DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( + chromeos::switches::kUseNewNetworkConfigurationHandlers)); NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); Network* network = crosnet->FindNetworkByPath(network_id); if (network) network_menu_->ConnectToNetwork(network); // Shows settings if connected else - ShowNetworkSettings(); + ShowNetworkSettings(""); } virtual void RequestNetworkScan() OVERRIDE { @@ -923,6 +974,11 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, base::Bind(&BluetoothPowerFailure)); } + virtual void ShowMobileSimDialog() OVERRIDE { + SimDialogDelegate::ShowDialog(GetNativeWindow(), + SimDialogDelegate::SIM_DIALOG_UNLOCK); + } + virtual void ShowOtherWifi() OVERRIDE { network_menu_->ShowOtherWifi(); } @@ -1494,7 +1550,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, CrosLibrary::Get()->GetNetworkLibrary()->cellular_network(); if (!cellular) return; - network_menu_->ShowTabbedNetworkSettings(cellular); + ShowNetworkSettings(cellular->service_path()); return; } } else if (link_index == 1) { diff --git a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc index c3349d4..6a867cc 100644 --- a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc @@ -589,6 +589,20 @@ int FindCurrentCarrierIndex(const base::ListValue* carriers, return -1; } +chromeos::ConnectionType ParseNetworkTypeString(const std::string& type) { + if (type == flimflam::kTypeEthernet) + return chromeos::TYPE_ETHERNET; + if (type == flimflam::kTypeWifi) + return chromeos::TYPE_WIFI; + if (type == flimflam::kTypeWimax) + return chromeos::TYPE_WIMAX; + if (type == flimflam::kTypeCellular) + return chromeos::TYPE_CELLULAR; + if (type == flimflam::kTypeVPN) + return chromeos::TYPE_VPN; + return chromeos::TYPE_UNKNOWN; +} + } // namespace namespace options { @@ -1618,8 +1632,11 @@ void InternetOptionsHandler::NetworkCommandCallback(const ListValue* args) { return; } - chromeos::ConnectionType type = - (chromeos::ConnectionType) atoi(str_type.c_str()); + // First try as a string, e.g. "wifi". + chromeos::ConnectionType type = ParseNetworkTypeString(str_type); + // Next try casting as an enum. + if (type == chromeos::TYPE_UNKNOWN) + type = (chromeos::ConnectionType) atoi(str_type.c_str()); // Process commands that do not require an existing network. if (command == kTagAddConnection) { diff --git a/chromeos/dbus/shill_service_client_stub.cc b/chromeos/dbus/shill_service_client_stub.cc index 434c4ce..af4245c 100644 --- a/chromeos/dbus/shill_service_client_stub.cc +++ b/chromeos/dbus/shill_service_client_stub.cc @@ -355,53 +355,53 @@ void ShillServiceClientStub::SetDefaultProperties() { if (!CommandLine::ForCurrentProcess()->HasSwitch( chromeos::switches::kDisableStubEthernet)) { - AddService("stub_ethernet", "eth0", + AddService("eth1", "eth1", flimflam::kTypeEthernet, flimflam::kStateOnline, add_to_watchlist); } - AddService("stub_wifi1", "wifi1", + AddService("wifi1", "wifi1", flimflam::kTypeWifi, flimflam::kStateOnline, add_to_watchlist); - SetServiceProperty("stub_wifi1", + SetServiceProperty("wifi1", flimflam::kSecurityProperty, base::StringValue(flimflam::kSecurityWep)); - AddService("stub_wifi2", "wifi2_PSK", + AddService("wifi2", "wifi2_PSK", flimflam::kTypeWifi, flimflam::kStateIdle, add_to_watchlist); - SetServiceProperty("stub_wifi2", + SetServiceProperty("wifi2", flimflam::kSecurityProperty, base::StringValue(flimflam::kSecurityPsk)); base::FundamentalValue strength_value(80); - SetServiceProperty("stub_wifi2", + SetServiceProperty("wifi2", flimflam::kSignalStrengthProperty, strength_value); - AddService("stub_cellular1", "cellular1", + AddService("cellular1", "cellular1", flimflam::kTypeCellular, flimflam::kStateIdle, add_to_watchlist); base::StringValue technology_value(flimflam::kNetworkTechnologyGsm); - SetServiceProperty("stub_cellular1", + SetServiceProperty("cellular1", flimflam::kNetworkTechnologyProperty, technology_value); - SetServiceProperty("stub_cellular1", + SetServiceProperty("cellular1", flimflam::kActivationStateProperty, base::StringValue(flimflam::kActivationStateNotActivated)); - SetServiceProperty("stub_cellular1", + SetServiceProperty("cellular1", flimflam::kRoamingStateProperty, base::StringValue(flimflam::kRoamingStateHome)); - AddService("stub_vpn1", "vpn1", + AddService("vpn1", "vpn1", flimflam::kTypeVPN, flimflam::kStateOnline, add_to_watchlist); - AddService("stub_vpn2", "vpn2", + AddService("vpn2", "vpn2", flimflam::kTypeVPN, flimflam::kStateOffline, add_to_watchlist); diff --git a/chromeos/network/network_connection_handler.cc b/chromeos/network/network_connection_handler.cc index f8035a5..4b7bdff 100644 --- a/chromeos/network/network_connection_handler.cc +++ b/chromeos/network/network_connection_handler.cc @@ -5,7 +5,9 @@ #include "chromeos/network/network_connection_handler.h" #include "base/bind.h" +#include "base/command_line.h" #include "base/json/json_reader.h" +#include "chromeos/chromeos_switches.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/shill_manager_client.h" #include "chromeos/dbus/shill_service_client.h" @@ -26,12 +28,16 @@ namespace chromeos { namespace { -void InvokeErrorCallback( - const std::string& service_path, - const network_handler::ErrorCallback& error_callback, - const std::string& error_name) { - network_handler::ShillErrorCallbackFunction( - service_path, error_callback, error_name, "Connect Error"); +void InvokeErrorCallback(const std::string& service_path, + const network_handler::ErrorCallback& error_callback, + const std::string& error_name) { + std::string error_msg = "Connect Error: " + error_name; + NET_LOG_ERROR(error_msg, service_path); + if (error_callback.is_null()) + return; + scoped_ptr<base::DictionaryValue> error_data( + network_handler::CreateErrorData(service_path, error_name, error_msg)); + error_callback.Run(error_name, error_data.Pass()); } bool NetworkMayNeedCredentials(const NetworkState* network) { @@ -142,6 +148,11 @@ NetworkConnectionHandler* NetworkConnectionHandler::Get() { } NetworkConnectionHandler::NetworkConnectionHandler() { + const char* new_handlers_enabled = + CommandLine::ForCurrentProcess()->HasSwitch( + chromeos::switches::kUseNewNetworkConfigurationHandlers) ? + "enabled" : "disabled"; + NET_LOG_EVENT("NewNetworkConfigurationHandlers", new_handlers_enabled); } NetworkConnectionHandler::~NetworkConnectionHandler() { @@ -150,7 +161,8 @@ NetworkConnectionHandler::~NetworkConnectionHandler() { void NetworkConnectionHandler::ConnectToNetwork( const std::string& service_path, const base::Closure& success_callback, - const network_handler::ErrorCallback& error_callback) { + const network_handler::ErrorCallback& error_callback, + bool ignore_error_state) { const NetworkState* network = NetworkStateHandler::Get()->GetNetworkState(service_path); if (!network) { @@ -166,14 +178,32 @@ void NetworkConnectionHandler::ConnectToNetwork( InvokeErrorCallback(service_path, error_callback, kErrorConnecting); return; } - if (network->passphrase_required()) { - InvokeErrorCallback(service_path, error_callback, kErrorPassphraseRequired); - return; - } if (NetworkRequiresActivation(network)) { InvokeErrorCallback(service_path, error_callback, kErrorActivationRequired); return; } + if (!ignore_error_state) { + if (network->passphrase_required()) { + InvokeErrorCallback(service_path, error_callback, + kErrorPassphraseRequired); + return; + } + if (network->error() == flimflam::kErrorConnectFailed) { + InvokeErrorCallback(service_path, error_callback, + kErrorPassphraseRequired); + return; + } + if (network->error() == flimflam::kErrorBadPassphrase) { + InvokeErrorCallback(service_path, error_callback, + kErrorPassphraseRequired); + return; + } + if (network->HasAuthenticationError()) { + InvokeErrorCallback(service_path, error_callback, + kErrorConfigurationRequired); + return; + } + } // All synchronous checks passed, add |service_path| to connecting list. pending_requests_.insert(service_path); @@ -289,7 +319,7 @@ void NetworkConnectionHandler::HandleShillSuccess( // point (or maybe call it twice, once indicating in-progress, then success // or failure). pending_requests_.erase(service_path); - NET_LOG_EVENT("Connected", service_path); + NET_LOG_EVENT("Connect Request Sent", service_path); success_callback.Run(); } diff --git a/chromeos/network/network_connection_handler.h b/chromeos/network/network_connection_handler.h index afe09e4..cc147be 100644 --- a/chromeos/network/network_connection_handler.h +++ b/chromeos/network/network_connection_handler.h @@ -47,6 +47,7 @@ class CHROMEOS_EXPORT NetworkConnectionHandler static const char kErrorCertificateRequired[]; static const char kErrorConfigurationRequired[]; static const char kErrorShillError[]; + static const char kErrorPreviousConnectFailed[]; // Sets the global instance. Must be called before any calls to Get(). static void Initialize(); @@ -69,9 +70,12 @@ class CHROMEOS_EXPORT NetworkConnectionHandler // kErrorConfigurationRequired if additional configuration is required. // kErrorShillError if a DBus or Shill error occurred. // |error_message| will contain an additional error string for debugging. + // If |ignore_error_state| is true, error state for the network is ignored + // (e.g. for repeat attempts). void ConnectToNetwork(const std::string& service_path, const base::Closure& success_callback, - const network_handler::ErrorCallback& error_callback); + const network_handler::ErrorCallback& error_callback, + bool ignore_error_state); // DisconnectToNetwork() will send a Disconnect request to Shill. // On success, |success_callback| will be called. diff --git a/chromeos/network/network_connection_handler_unittest.cc b/chromeos/network/network_connection_handler_unittest.cc index 7b4ab2b..bd3f5a2 100644 --- a/chromeos/network/network_connection_handler_unittest.cc +++ b/chromeos/network/network_connection_handler_unittest.cc @@ -66,12 +66,14 @@ class NetworkConnectionHandlerTest : public testing::Test { } void Connect(const std::string& service_path) { + const bool ignore_error_state = false; NetworkConnectionHandler::Get()->ConnectToNetwork( service_path, base::Bind(&NetworkConnectionHandlerTest::SuccessCallback, base::Unretained(this)), base::Bind(&NetworkConnectionHandlerTest::ErrorCallback, - base::Unretained(this))); + base::Unretained(this)), + ignore_error_state); message_loop_.RunUntilIdle(); } diff --git a/chromeos/network/network_handler_callbacks.cc b/chromeos/network/network_handler_callbacks.cc index 597b8bd..c23dc50 100644 --- a/chromeos/network/network_handler_callbacks.cc +++ b/chromeos/network/network_handler_callbacks.cc @@ -44,5 +44,5 @@ void ShillErrorCallbackFunction(const std::string& path, error_callback.Run(error_name, error_data.Pass()); } -} // namespace network_handler +} // namespace network_handler } // namespace chromeos diff --git a/chromeos/network/network_state.cc b/chromeos/network/network_state.cc index 3c24999..84ff8f3 100644 --- a/chromeos/network/network_state.cc +++ b/chromeos/network/network_state.cc @@ -188,6 +188,15 @@ bool NetworkState::IsConnectingState() const { return StateIsConnecting(connection_state_); } +bool NetworkState::HasAuthenticationError() const { + return (error_ == flimflam::kErrorBadPassphrase || + error_ == flimflam::kErrorBadWEPKey || + error_ == flimflam::kErrorPppAuthFailed || + error_ == shill::kErrorEapLocalTlsFailed || + error_ == shill::kErrorEapRemoteTlsFailed || + error_ == shill::kErrorEapAuthenticationFailed); +} + void NetworkState::UpdateName() { if (hex_ssid_.empty()) { // Validate name for UTF8. diff --git a/chromeos/network/network_state.h b/chromeos/network/network_state.h index d49c5d8..b8b867e 100644 --- a/chromeos/network/network_state.h +++ b/chromeos/network/network_state.h @@ -66,6 +66,9 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState { bool IsConnectedState() const; bool IsConnectingState() const; + // Returns true if |error_| contains an authentication error. + bool HasAuthenticationError() const; + // Helpers (used e.g. when a state is cached) static bool StateIsConnected(const std::string& connection_state); static bool StateIsConnecting(const std::string& connection_state); diff --git a/chromeos/network/network_state_handler_unittest.cc b/chromeos/network/network_state_handler_unittest.cc index af39bc7..f21d802 100644 --- a/chromeos/network/network_state_handler_unittest.cc +++ b/chromeos/network/network_state_handler_unittest.cc @@ -29,10 +29,10 @@ void ErrorCallbackFunction(const std::string& error_name, LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; } -const std::string kShillManagerClientStubDefaultService = "stub_ethernet"; -const std::string kShillManagerClientStubDefaultWireless = "stub_wifi1"; -const std::string kShillManagerClientStubWireless2 = "stub_wifi2"; -const std::string kShillManagerClientStubCellular = "stub_cellular"; +const std::string kShillManagerClientStubDefaultService = "eth1"; +const std::string kShillManagerClientStubDefaultWireless = "wifi1"; +const std::string kShillManagerClientStubWireless2 = "wifi2"; +const std::string kShillManagerClientStubCellular = "cellular1"; using chromeos::NetworkState; using chromeos::NetworkStateHandler; @@ -262,46 +262,46 @@ TEST_F(NetworkStateHandlerTest, TechnologyState) { TEST_F(NetworkStateHandlerTest, ServicePropertyChanged) { // Set a service property. - const std::string eth0 = kShillManagerClientStubDefaultService; - EXPECT_EQ("", network_state_handler_->GetNetworkState(eth0)->security()); - EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(eth0)); + const std::string eth1 = kShillManagerClientStubDefaultService; + EXPECT_EQ("", network_state_handler_->GetNetworkState(eth1)->security()); + EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(eth1)); base::StringValue security_value("TestSecurity"); DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( - dbus::ObjectPath(eth0), + dbus::ObjectPath(eth1), flimflam::kSecurityProperty, security_value, base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); message_loop_.RunUntilIdle(); EXPECT_EQ("TestSecurity", - network_state_handler_->GetNetworkState(eth0)->security()); - EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth0)); + network_state_handler_->GetNetworkState(eth1)->security()); + EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth1)); // Changing a service to the existing value should not trigger an update. DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( - dbus::ObjectPath(eth0), + dbus::ObjectPath(eth1), flimflam::kSecurityProperty, security_value, base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); message_loop_.RunUntilIdle(); - EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth0)); + EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(eth1)); } TEST_F(NetworkStateHandlerTest, NetworkConnectionStateChanged) { // Change a network state. ShillServiceClient::TestInterface* service_test = DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); - const std::string eth0 = kShillManagerClientStubDefaultService; + const std::string eth1 = kShillManagerClientStubDefaultService; base::StringValue connection_state_idle_value(flimflam::kStateIdle); - service_test->SetServiceProperty(eth0, flimflam::kStateProperty, + service_test->SetServiceProperty(eth1, flimflam::kStateProperty, connection_state_idle_value); message_loop_.RunUntilIdle(); EXPECT_EQ(flimflam::kStateIdle, - test_observer_->NetworkConnectionStateForService(eth0)); - EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth0)); + test_observer_->NetworkConnectionStateForService(eth1)); + EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); // Confirm that changing the connection state to the same value does *not* // signal the observer. - service_test->SetServiceProperty(eth0, flimflam::kStateProperty, + service_test->SetServiceProperty(eth1, flimflam::kStateProperty, connection_state_idle_value); message_loop_.RunUntilIdle(); - EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth0)); + EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); } TEST_F(NetworkStateHandlerTest, DefaultServiceChanged) { @@ -313,12 +313,12 @@ TEST_F(NetworkStateHandlerTest, DefaultServiceChanged) { ASSERT_TRUE(service_test); // Change the default network by moving wifi1 to the front of the list - // and changing the state of stub_ethernet to Idle. + // and changing the state of eth1 to Idle. const std::string wifi1 = kShillManagerClientStubDefaultWireless; manager_test->MoveServiceToIndex(wifi1, 0, true); - const std::string eth0 = kShillManagerClientStubDefaultService; + const std::string eth1 = kShillManagerClientStubDefaultService; base::StringValue connection_state_idle_value(flimflam::kStateIdle); - service_test->SetServiceProperty(eth0, flimflam::kStateProperty, + service_test->SetServiceProperty(eth1, flimflam::kStateProperty, connection_state_idle_value); message_loop_.RunUntilIdle(); EXPECT_EQ(wifi1, test_observer_->default_network()); |