Commit 7b1bb207 authored by stevenjb@chromium.org's avatar stevenjb@chromium.org

Unify ActivateCellular into network_connect.cc

BUG=242285
For ash delegate
TBR=jamescook@chromium.org

Review URL: https://chromiumcodereview.appspot.com/15937008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202807 0039d316-1c4b-4281-b951-d872f2087c98
parent 00969d41
...@@ -119,9 +119,6 @@ void ShellDelegateImpl::OpenFileManager(bool as_dialog) { ...@@ -119,9 +119,6 @@ void ShellDelegateImpl::OpenFileManager(bool as_dialog) {
void ShellDelegateImpl::OpenCrosh() { void ShellDelegateImpl::OpenCrosh() {
} }
void ShellDelegateImpl::OpenMobileSetup(const std::string& service_path) {
}
void ShellDelegateImpl::RestoreTab() { void ShellDelegateImpl::RestoreTab() {
} }
......
...@@ -39,7 +39,6 @@ class ShellDelegateImpl : public ash::ShellDelegate { ...@@ -39,7 +39,6 @@ class ShellDelegateImpl : public ash::ShellDelegate {
virtual void ToggleMaximized() OVERRIDE; virtual void ToggleMaximized() OVERRIDE;
virtual void OpenFileManager(bool as_dialog) OVERRIDE; virtual void OpenFileManager(bool as_dialog) OVERRIDE;
virtual void OpenCrosh() OVERRIDE; virtual void OpenCrosh() OVERRIDE;
virtual void OpenMobileSetup(const std::string& service_path) OVERRIDE;
virtual void RestoreTab() OVERRIDE; virtual void RestoreTab() OVERRIDE;
virtual void ShowKeyboardOverlay() OVERRIDE; virtual void ShowKeyboardOverlay() OVERRIDE;
virtual keyboard::KeyboardControllerProxy* virtual keyboard::KeyboardControllerProxy*
......
...@@ -141,9 +141,6 @@ class ASH_EXPORT ShellDelegate { ...@@ -141,9 +141,6 @@ class ASH_EXPORT ShellDelegate {
// Invoked when the user opens Crosh. // Invoked when the user opens Crosh.
virtual void OpenCrosh() = 0; virtual void OpenCrosh() = 0;
// Invoked when the user needs to set up mobile networking.
virtual void OpenMobileSetup(const std::string& service_path) = 0;
// Invoked when the user uses Shift+Ctrl+T to restore the closed tab. // Invoked when the user uses Shift+Ctrl+T to restore the closed tab.
virtual void RestoreTab() = 0; virtual void RestoreTab() = 0;
......
...@@ -77,9 +77,6 @@ void TestShellDelegate::OpenFileManager(bool as_dialog) { ...@@ -77,9 +77,6 @@ void TestShellDelegate::OpenFileManager(bool as_dialog) {
void TestShellDelegate::OpenCrosh() { void TestShellDelegate::OpenCrosh() {
} }
void TestShellDelegate::OpenMobileSetup(const std::string& service_path) {
}
void TestShellDelegate::RestoreTab() { void TestShellDelegate::RestoreTab() {
} }
......
...@@ -42,7 +42,6 @@ class TestShellDelegate : public ShellDelegate { ...@@ -42,7 +42,6 @@ class TestShellDelegate : public ShellDelegate {
virtual void ToggleMaximized() OVERRIDE; virtual void ToggleMaximized() OVERRIDE;
virtual void OpenFileManager(bool as_dialog) OVERRIDE; virtual void OpenFileManager(bool as_dialog) OVERRIDE;
virtual void OpenCrosh() OVERRIDE; virtual void OpenCrosh() OVERRIDE;
virtual void OpenMobileSetup(const std::string& service_path) OVERRIDE;
virtual void RestoreTab() OVERRIDE; virtual void RestoreTab() OVERRIDE;
virtual void ShowKeyboardOverlay() OVERRIDE; virtual void ShowKeyboardOverlay() OVERRIDE;
virtual keyboard::KeyboardControllerProxy* virtual keyboard::KeyboardControllerProxy*
......
...@@ -6,29 +6,24 @@ ...@@ -6,29 +6,24 @@
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/shell_delegate.h" #include "ash/shell_delegate.h"
#include "ash/system/chromeos/network/network_observer.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/enrollment_dialog_view.h" #include "chrome/browser/chromeos/enrollment_dialog_view.h"
#include "chrome/browser/chromeos/options/network_config_view.h" #include "chrome/browser/chromeos/options/network_config_view.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
#include "grit/generated_resources.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
#include "ui/base/l10n/l10n_util.h"
namespace chromeos { namespace chromeos {
namespace network_connect { namespace network_connect {
namespace { namespace {
void ActivateCellular(chromeos::CellularNetwork* cellular) {
DCHECK(cellular);
chromeos::NetworkLibrary* cros =
chromeos::CrosLibrary::Get()->GetNetworkLibrary();
if (cros->CellularDeviceUsesDirectActivation()) {
cellular->StartActivation();
} else {
ash::Shell::GetInstance()->delegate()->OpenMobileSetup(
cellular->service_path());
}
}
void DoConnect(Network* network, gfx::NativeWindow parent_window) { void DoConnect(Network* network, gfx::NativeWindow parent_window) {
NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
if (network->type() == TYPE_VPN) { if (network->type() == TYPE_VPN) {
...@@ -65,7 +60,7 @@ void DoConnect(Network* network, gfx::NativeWindow parent_window) { ...@@ -65,7 +60,7 @@ void DoConnect(Network* network, gfx::NativeWindow parent_window) {
CellularNetwork* cellular = static_cast<CellularNetwork*>(network); CellularNetwork* cellular = static_cast<CellularNetwork*>(network);
if (cellular->activation_state() != ACTIVATION_STATE_ACTIVATED || if (cellular->activation_state() != ACTIVATION_STATE_ACTIVATED ||
cellular->out_of_credits()) { cellular->out_of_credits()) {
ActivateCellular(cellular); ActivateCellular(cellular->service_path());
} else { } else {
cros->ConnectToCellularNetwork(cellular); cros->ConnectToCellularNetwork(cellular);
} }
...@@ -74,6 +69,50 @@ void DoConnect(Network* network, gfx::NativeWindow parent_window) { ...@@ -74,6 +69,50 @@ void DoConnect(Network* network, gfx::NativeWindow parent_window) {
} // namespace } // namespace
void ActivateCellular(const std::string& service_path) {
chromeos::NetworkLibrary* cros =
chromeos::CrosLibrary::Get()->GetNetworkLibrary();
if (!cros->CellularDeviceUsesDirectActivation()) {
// For non direct activation, show the mobile setup dialog which can be
// used to activate the network.
ShowMobileSetup(service_path);
return;
}
chromeos::CellularNetwork* cellular =
cros->FindCellularNetworkByPath(service_path);
if (!cellular)
return;
if (cellular->activation_state() != chromeos::ACTIVATION_STATE_ACTIVATED)
cellular->StartActivation();
return;
}
void ShowMobileSetup(const std::string& service_path) {
NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
const CellularNetwork* cellular =
cros->FindCellularNetworkByPath(service_path);
if (cellular && !cellular->activated() &&
cellular->activate_over_non_cellular_network() &&
(!cros->connected_network() || !cros->connected_network()->online())) {
NetworkTechnology technology = cellular->network_technology();
ash::NetworkObserver::NetworkType network_type =
(technology == chromeos::NETWORK_TECHNOLOGY_LTE ||
technology == chromeos::NETWORK_TECHNOLOGY_LTE_ADVANCED)
? ash::NetworkObserver::NETWORK_CELLULAR_LTE
: ash::NetworkObserver::NETWORK_CELLULAR;
ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage(
NULL,
ash::NetworkObserver::ERROR_CONNECT_FAILED,
network_type,
l10n_util::GetStringUTF16(IDS_NETWORK_ACTIVATION_ERROR_TITLE),
l10n_util::GetStringFUTF16(IDS_NETWORK_ACTIVATION_NEEDS_CONNECTION,
UTF8ToUTF16((cellular->name()))),
std::vector<string16>());
return;
}
MobileSetupDialog::Show(service_path);
}
ConnectResult ConnectToNetwork(const std::string& service_path, ConnectResult ConnectToNetwork(const std::string& service_path,
gfx::NativeWindow parent_window) { gfx::NativeWindow parent_window) {
NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
...@@ -107,7 +146,7 @@ ConnectResult ConnectToNetwork(const std::string& service_path, ...@@ -107,7 +146,7 @@ ConnectResult ConnectToNetwork(const std::string& service_path,
if (network->type() == TYPE_CELLULAR) { if (network->type() == TYPE_CELLULAR) {
CellularNetwork* cellular = static_cast<CellularNetwork*>(network); CellularNetwork* cellular = static_cast<CellularNetwork*>(network);
if (cellular->NeedsActivation() || cellular->out_of_credits()) { if (cellular->NeedsActivation() || cellular->out_of_credits()) {
ActivateCellular(cellular); ActivateCellular(service_path);
return CONNECT_STARTED; return CONNECT_STARTED;
} }
if (cellular->activation_state() == ACTIVATION_STATE_ACTIVATING) if (cellular->activation_state() == ACTIVATION_STATE_ACTIVATING)
......
...@@ -18,6 +18,15 @@ enum ConnectResult { ...@@ -18,6 +18,15 @@ enum ConnectResult {
CONNECT_STARTED CONNECT_STARTED
}; };
// Activate the cellular network associated with |service_path| if direct
// activation is supported, otherwise call ShowMobileSetup.
void ActivateCellular(const std::string& service_path);
// Shows the mobile setup dialog which handles:
// * Activation for non direct-activation networks
// * Showing network plan info
void ShowMobileSetup(const std::string& service_path);
// Attempts to connect to the network specified by |service_path|. // Attempts to connect to the network specified by |service_path|.
// Returns one of the following results: // Returns one of the following results:
// NETWORK_NOT_FOUND if the network does not exist. // NETWORK_NOT_FOUND if the network does not exist.
......
...@@ -763,10 +763,11 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, ...@@ -763,10 +763,11 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
NetworkConfigView::Show(cros_network, GetNativeWindow()); NetworkConfigView::Show(cros_network, GetNativeWindow());
return; return;
} }
if (network->type() == flimflam::kTypeCellular && if (network->type() == flimflam::kTypeCellular) {
(network->activation_state() != flimflam::kActivationStateActivated || if (network->activation_state() != flimflam::kActivationStateActivated)
network->cellular_out_of_credits())) { network_connect::ActivateCellular(network_id);
ash::Shell::GetInstance()->delegate()->OpenMobileSetup(network_id); else if (network->cellular_out_of_credits())
network_connect::ShowMobileSetup(network_id);
return; return;
} }
// No special configure or setup for |network_id|, show the settings UI. // No special configure or setup for |network_id|, show the settings UI.
......
...@@ -56,7 +56,6 @@ class ChromeShellDelegate : public ash::ShellDelegate, ...@@ -56,7 +56,6 @@ class ChromeShellDelegate : public ash::ShellDelegate,
virtual void ToggleMaximized() OVERRIDE; virtual void ToggleMaximized() OVERRIDE;
virtual void OpenFileManager(bool as_dialog) OVERRIDE; virtual void OpenFileManager(bool as_dialog) OVERRIDE;
virtual void OpenCrosh() OVERRIDE; virtual void OpenCrosh() OVERRIDE;
virtual void OpenMobileSetup(const std::string& service_path) OVERRIDE;
virtual void RestoreTab() OVERRIDE; virtual void RestoreTab() OVERRIDE;
virtual void ShowKeyboardOverlay() OVERRIDE; virtual void ShowKeyboardOverlay() OVERRIDE;
virtual keyboard::KeyboardControllerProxy* virtual keyboard::KeyboardControllerProxy*
......
...@@ -5,17 +5,12 @@ ...@@ -5,17 +5,12 @@
#include "chrome/browser/ui/ash/chrome_shell_delegate.h" #include "chrome/browser/ui/ash/chrome_shell_delegate.h"
#include "ash/keyboard_overlay/keyboard_overlay_view.h" #include "ash/keyboard_overlay/keyboard_overlay_view.h"
#include "ash/system/chromeos/network/network_observer.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/chromeos/accessibility/accessibility_util.h" #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
#include "chrome/browser/chromeos/accessibility/magnification_manager.h" #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
#include "chrome/browser/chromeos/background/ash_user_wallpaper_delegate.h" #include "chrome/browser/chromeos/background/ash_user_wallpaper_delegate.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/display/display_preferences.h" #include "chrome/browser/chromeos/display/display_preferences.h"
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
#include "chrome/browser/chromeos/extensions/media_player_api.h" #include "chrome/browser/chromeos/extensions/media_player_api.h"
...@@ -38,7 +33,6 @@ ...@@ -38,7 +33,6 @@
#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/browser/ui/webui/chrome_web_contents_handler.h" #include "chrome/browser/ui/webui/chrome_web_contents_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
...@@ -49,8 +43,6 @@ ...@@ -49,8 +43,6 @@
#include "content/public/browser/user_metrics.h" #include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h" #include "content/public/browser/web_contents_view.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
bool ChromeShellDelegate::IsFirstRunAfterBoot() const { bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
return CommandLine::ForCurrentProcess()->HasSwitch( return CommandLine::ForCurrentProcess()->HasSwitch(
...@@ -119,34 +111,6 @@ void ChromeShellDelegate::OpenCrosh() { ...@@ -119,34 +111,6 @@ void ChromeShellDelegate::OpenCrosh() {
page->GetView()->Focus(); page->GetView()->Focus();
} }
void ChromeShellDelegate::OpenMobileSetup(const std::string& service_path) {
// TODO(stevenjb): Replace with non-NetworkLibrary UI.
chromeos::NetworkLibrary* cros =
chromeos::CrosLibrary::Get()->GetNetworkLibrary();
const chromeos::CellularNetwork* cellular =
cros->FindCellularNetworkByPath(service_path);
if (cellular && !cellular->activated() &&
cellular->activate_over_non_cellular_network() &&
(!cros->connected_network() || !cros->connected_network()->online())) {
chromeos::NetworkTechnology technology = cellular->network_technology();
ash::NetworkObserver::NetworkType network_type =
(technology == chromeos::NETWORK_TECHNOLOGY_LTE ||
technology == chromeos::NETWORK_TECHNOLOGY_LTE_ADVANCED)
? ash::NetworkObserver::NETWORK_CELLULAR_LTE
: ash::NetworkObserver::NETWORK_CELLULAR;
ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage(
NULL,
ash::NetworkObserver::ERROR_CONNECT_FAILED,
network_type,
l10n_util::GetStringUTF16(IDS_NETWORK_ACTIVATION_ERROR_TITLE),
l10n_util::GetStringFUTF16(IDS_NETWORK_ACTIVATION_NEEDS_CONNECTION,
UTF8ToUTF16((cellular->name()))),
std::vector<string16>());
return;
}
MobileSetupDialog::Show(service_path);
}
void ChromeShellDelegate::ToggleHighContrast() { void ChromeShellDelegate::ToggleHighContrast() {
bool enabled = chromeos::accessibility::IsHighContrastEnabled(); bool enabled = chromeos::accessibility::IsHighContrastEnabled();
chromeos::accessibility::EnableHighContrast(!enabled); chromeos::accessibility::EnableHighContrast(!enabled);
......
...@@ -39,9 +39,6 @@ void ChromeShellDelegate::OpenFileManager(bool as_dialog) { ...@@ -39,9 +39,6 @@ void ChromeShellDelegate::OpenFileManager(bool as_dialog) {
void ChromeShellDelegate::OpenCrosh() { void ChromeShellDelegate::OpenCrosh() {
} }
void ChromeShellDelegate::OpenMobileSetup(const std::string& service_path) {
}
void ChromeShellDelegate::ShowKeyboardOverlay() { void ChromeShellDelegate::ShowKeyboardOverlay() {
} }
......
...@@ -533,26 +533,6 @@ void PopulateVPNDetails( ...@@ -533,26 +533,6 @@ void PopulateVPNDetails(
hostname_ui_data); hostname_ui_data);
} }
// Activate the cellular device pointed to by the service path.
void Activate(std::string service_path) {
chromeos::Network* network = NULL;
if (!service_path.empty()) {
network = chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
FindNetworkByPath(service_path);
} else {
NOTREACHED();
return;
}
if (network->type() != chromeos::TYPE_CELLULAR)
return;
chromeos::CellularNetwork* cellular =
static_cast<chromeos::CellularNetwork*>(network);
if (cellular->activation_state() != chromeos::ACTIVATION_STATE_ACTIVATED)
cellular->StartActivation();
}
// Given a list of supported carrier's by the device, return the index of // Given a list of supported carrier's by the device, return the index of
// the carrier the device is currently using. // the carrier the device is currently using.
int FindCurrentCarrierIndex(const base::ListValue* carriers, int FindCurrentCarrierIndex(const base::ListValue* carriers,
...@@ -923,12 +903,7 @@ void InternetOptionsHandler::ShowMorePlanInfoCallback(const ListValue* args) { ...@@ -923,12 +903,7 @@ void InternetOptionsHandler::ShowMorePlanInfoCallback(const ListValue* args) {
NOTREACHED(); NOTREACHED();
return; return;
} }
chromeos::network_connect::ShowMobileSetup(service_path);
const chromeos::CellularNetwork* cellular =
cros_->FindCellularNetworkByPath(service_path);
if (!cellular)
return;
ash::Shell::GetInstance()->delegate()->OpenMobileSetup(service_path);
} }
void InternetOptionsHandler::BuyDataPlanCallback(const ListValue* args) { void InternetOptionsHandler::BuyDataPlanCallback(const ListValue* args) {
...@@ -940,7 +915,7 @@ void InternetOptionsHandler::BuyDataPlanCallback(const ListValue* args) { ...@@ -940,7 +915,7 @@ void InternetOptionsHandler::BuyDataPlanCallback(const ListValue* args) {
NOTREACHED(); NOTREACHED();
return; return;
} }
ash::Shell::GetInstance()->delegate()->OpenMobileSetup(service_path); chromeos::network_connect::ShowMobileSetup(service_path);
} }
void InternetOptionsHandler::SetApnCallback(const ListValue* args) { void InternetOptionsHandler::SetApnCallback(const ListValue* args) {
...@@ -971,7 +946,7 @@ void InternetOptionsHandler::CarrierStatusCallback( ...@@ -971,7 +946,7 @@ void InternetOptionsHandler::CarrierStatusCallback(
const std::string& error_message) { const std::string& error_message) {
if ((error == chromeos::NETWORK_METHOD_ERROR_NONE) && if ((error == chromeos::NETWORK_METHOD_ERROR_NONE) &&
cros_->CellularDeviceUsesDirectActivation()) { cros_->CellularDeviceUsesDirectActivation()) {
Activate(service_path); chromeos::network_connect::ActivateCellular(service_path);
UpdateConnectionData(cros_->FindNetworkByPath(service_path)); UpdateConnectionData(cros_->FindNetworkByPath(service_path));
} }
...@@ -1667,17 +1642,10 @@ void InternetOptionsHandler::NetworkCommandCallback(const ListValue* args) { ...@@ -1667,17 +1642,10 @@ void InternetOptionsHandler::NetworkCommandCallback(const ListValue* args) {
} else if (command == kTagDisconnect && type != chromeos::TYPE_ETHERNET) { } else if (command == kTagDisconnect && type != chromeos::TYPE_ETHERNET) {
cros_->DisconnectFromNetwork(network); cros_->DisconnectFromNetwork(network);
} else if (command == kTagActivate && type == chromeos::TYPE_CELLULAR) { } else if (command == kTagActivate && type == chromeos::TYPE_CELLULAR) {
if (!cros_->CellularDeviceUsesDirectActivation()) { chromeos::network_connect::ActivateCellular(service_path);
ash::Shell::GetInstance()->delegate()->OpenMobileSetup( // Activation may update network properties (e.g. ActivationState), so
network->service_path()); // request them here in case they change.
} else { UpdateConnectionData(network);
Activate(service_path);
// Update network properties after we start activation. The Activate
// call is a blocking call, which blocks on finishing the "start" of
// the activation, hence when we query for network properties after
// this call is done, we will have the "activating" activation state.
UpdateConnectionData(network);
}
} else { } else {
VLOG(1) << "Unknown command: " << command; VLOG(1) << "Unknown command: " << command;
NOTREACHED(); NOTREACHED();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment