Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2095)

Unified Diff: chrome/browser/chromeos/login/network_screen.cc

Issue 3166028: Replace network combobox with network dropdown button (Closed)
Patch Set: Removed trailing spaces Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/network_screen.cc
diff --git a/chrome/browser/chromeos/login/network_screen.cc b/chrome/browser/chromeos/login/network_screen.cc
index 93c4d3fafcb56a78e7aeb780dcb87ea644f9677d..ab003f01e0a7b4e8691be3067eb8eaf91f01b16c 100644
--- a/chrome/browser/chromeos/login/network_screen.cc
+++ b/chrome/browser/chromeos/login/network_screen.cc
@@ -28,15 +28,10 @@ namespace chromeos {
///////////////////////////////////////////////////////////////////////////////
// NetworkScreen, public:
-NetworkScreen::NetworkScreen(WizardScreenDelegate* delegate, bool is_out_of_box)
+NetworkScreen::NetworkScreen(WizardScreenDelegate* delegate)
: ViewScreen<NetworkSelectionView>(delegate),
is_network_subscribed_(false),
- wifi_disabled_(false),
- is_out_of_box_(is_out_of_box),
- is_waiting_for_connect_(false),
- continue_pressed_(false),
- ethernet_preselected_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) {
+ continue_pressed_(false) {
}
NetworkScreen::~NetworkScreen() {
@@ -44,86 +39,17 @@ NetworkScreen::~NetworkScreen() {
UnsubscribeNetworkNotification();
}
-////////////////////////////////////////////////////////////////////////////////
-// ComboboxModel implementation:
-
-int NetworkScreen::GetItemCount() {
- // Item with index = 0 is either "no networks are available" or
- // "no selection".
- // If WiFi is disabled adding extra item to enable it.
- return static_cast<int>(networks_.GetNetworkCount()) + 1 +
- (wifi_disabled_ ? 1 : 0);
-}
-
-string16 NetworkScreen::GetItemAt(int index) {
- if (index == 0) {
- return networks_.IsEmpty() ?
- l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_NETWORKS_MESSAGE) :
- l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_NONE);
- }
- if (wifi_disabled_ &&
- index == static_cast<int>(networks_.GetNetworkCount()) + 1) {
- return l10n_util::GetStringFUTF16(
- IDS_STATUSBAR_NETWORK_DEVICE_ENABLE,
- l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_WIFI));
- }
- NetworkList::NetworkItem* network =
- networks_.GetNetworkAt(index - 1);
- return network ? network->label : string16();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// views::Combobox::Listener implementation:
-
-void NetworkScreen::ItemChanged(views::Combobox* sender,
- int prev_index,
- int new_index) {
- view()->EnableContinue(new_index > 0);
- // Corner case: item with index 0 is "No selection". Just select it.
- if (new_index == prev_index || new_index <= 0 || prev_index < 0)
- return;
-
- if (wifi_disabled_ &&
- new_index == static_cast<int>(networks_.GetNetworkCount()) + 1) {
- view()->EnableContinue(false);
- MessageLoop::current()->PostTask(FROM_HERE,
- task_factory_.NewRunnableMethod(&NetworkScreen::EnableWiFi));
- return;
- }
-
- if (networks_.IsEmpty())
- return;
-
- // Connect to network as early as possible.
- const NetworkList::NetworkItem* network =
- networks_.GetNetworkAt(new_index - 1);
- MessageLoop::current()->PostTask(FROM_HERE, task_factory_.NewRunnableMethod(
- &NetworkScreen::ConnectToNetwork, network->network_type, network->label));
-}
-
///////////////////////////////////////////////////////////////////////////////
// views::ButtonListener implementation:
void NetworkScreen::ButtonPressed(views::Button* sender,
const views::Event& event) {
- // Proceed only when selected network is connected.
- const NetworkList::NetworkItem* network = GetSelectedNetwork();
- if (!network)
- return;
- if (networks_.IsNetworkConnected(network->network_type, network->label)) {
- MessageLoop::current()->PostTask(FROM_HERE,
- task_factory_.NewRunnableMethod(&NetworkScreen::NotifyOnConnection));
+ NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary();
+ if (network && network->Connected()) {
+ NotifyOnConnection();
} else {
continue_pressed_ = true;
- if (is_waiting_for_connect_) {
- ShowConnectingStatus();
- } else {
- MessageLoop::current()->PostTask(
- FROM_HERE,
- task_factory_.NewRunnableMethod(&NetworkScreen::ConnectToNetwork,
- network->network_type,
- network->label));
- }
+ WaitForConnection(network_id_);
}
}
@@ -131,58 +57,7 @@ void NetworkScreen::ButtonPressed(views::Button* sender,
// NetworkLibrary::Observer implementation:
void NetworkScreen::NetworkChanged(NetworkLibrary* network_lib) {
- if (!view())
- return;
-
- // TODO(nkostylev): Reuse network menu button - http://crosbug.com/4133
- wifi_disabled_ = !chromeos::CrosLibrary::Get()->
- GetNetworkLibrary()->wifi_enabled();
-
- // Save network selection in case it would be available after refresh.
- NetworkList::NetworkType network_type = NetworkList::NETWORK_EMPTY;
- string16 network_id;
- const NetworkList::NetworkItem* selected_network = GetSelectedNetwork();
- if (selected_network) {
- network_type = selected_network->network_type;
- network_id = selected_network->label;
- }
- networks_.NetworkChanged(network_lib);
- if (is_waiting_for_connect_ &&
- networks_.IsNetworkConnected(connecting_network_.network_type,
- connecting_network_.label)) {
- // Stop waiting & don't update spinner status.
- StopWaitingForConnection(false);
- if (continue_pressed_) {
- MessageLoop::current()->PostTask(FROM_HERE,
- task_factory_.NewRunnableMethod(&NetworkScreen::NotifyOnConnection));
- return;
- }
- }
- view()->NetworkModelChanged();
- // Prefer Ethernet when it's connected (only once).
- if (!ethernet_preselected_ &&
- networks_.IsNetworkConnected(NetworkList::NETWORK_ETHERNET, string16())) {
- ethernet_preselected_ = true;
- SelectNetwork(NetworkList::NETWORK_ETHERNET, string16());
- } else {
- SelectNetwork(network_type, network_id);
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// NetworkLibrary::Observer implementation:
-
-void NetworkScreen::OnDialogAccepted() {
- const NetworkList::NetworkItem* network = GetSelectedNetwork();
- if (network)
- WaitForConnection(network);
-}
-
-void NetworkScreen::OnDialogCancelled() {
- if (view()) {
- view()->EnableContinue(false);
- view()->SetSelectedNetworkItem(0);
- }
+ UpdateStatus(network_lib);
}
///////////////////////////////////////////////////////////////////////////////
@@ -210,37 +85,6 @@ void NetworkScreen::Refresh() {
////////////////////////////////////////////////////////////////////////////////
// NetworkScreen, private:
-void NetworkScreen::ConnectToNetwork(NetworkList::NetworkType type,
- const string16& id) {
- const NetworkList::NetworkItem* network =
- networks_.GetNetworkById(type, id);
- if (network &&
- !networks_.IsNetworkConnected(type, id)) {
- if (NetworkList::NETWORK_WIFI == network->network_type) {
- if (network->wifi_network.encrypted()) {
- OpenPasswordDialog(network->wifi_network);
- return;
- } else {
- WaitForConnection(network);
- chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
- ConnectToWifiNetwork(network->wifi_network,
- std::string(), std::string(), std::string());
- }
- } else if (NetworkList::NETWORK_CELLULAR == network->network_type) {
- WaitForConnection(network);
- chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
- ConnectToCellularNetwork(network->cellular_network);
- }
- }
-}
-
-void NetworkScreen::EnableWiFi() {
- if (CrosLibrary::Get()->EnsureLoaded()) {
- chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
- EnableWifiNetworkDevice(true);
- }
-}
-
void NetworkScreen::SubscribeNetworkNotification() {
if (!is_network_subscribed_) {
is_network_subscribed_ = true;
@@ -255,13 +99,6 @@ void NetworkScreen::UnsubscribeNetworkNotification() {
}
}
-NetworkList::NetworkItem* NetworkScreen::GetSelectedNetwork() {
- if (!view())
- return NULL;
-
- return networks_.GetNetworkAt(view()->GetSelectedNetworkItem() - 1);
-}
-
void NetworkScreen::NotifyOnConnection() {
// TODO(nkostylev): Check network connectivity.
UnsubscribeNetworkNotification();
@@ -270,62 +107,59 @@ void NetworkScreen::NotifyOnConnection() {
}
void NetworkScreen::OnConnectionTimeout() {
- continue_pressed_ = false;
// TODO(nkostylev): Notify on connection error.
- if (is_waiting_for_connect_) {
- // Stop waiting & show selection combobox.
- StopWaitingForConnection(true);
- }
+ StopWaitingForConnection(network_id_);
}
-void NetworkScreen::OpenPasswordDialog(WifiNetwork network) {
- NetworkConfigView* dialog = new NetworkConfigView(network, true);
- dialog->set_delegate(this);
- dialog->set_browser_mode(false);
- views::Window* window = views::Window::CreateChromeWindow(
- view()->GetNativeWindow(), gfx::Rect(), dialog);
- window->SetIsAlwaysOnTop(true);
- window->Show();
- dialog->SetLoginTextfieldFocus();
-}
+void NetworkScreen::UpdateStatus(NetworkLibrary* network) {
+ if (!view() || !network)
+ return;
-void NetworkScreen::SelectNetwork(NetworkList::NetworkType type,
- const string16& id) {
- int index = networks_.GetNetworkIndexById(type, id);
- if (index >= 0) {
- view()->SetSelectedNetworkItem(index + 1);
+ if (network->ethernet_connected()) {
+ StopWaitingForConnection(
+ l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET));
+ } else if (network->wifi_connected()) {
+ StopWaitingForConnection(ASCIIToUTF16(network->wifi_name()));
+ } else if (network->cellular_connected()) {
+ StopWaitingForConnection(ASCIIToUTF16(network->cellular_name()));
+ } else if (network->ethernet_connecting()) {
+ WaitForConnection(
+ l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET));
+ } else if (network->wifi_connecting()) {
+ WaitForConnection(ASCIIToUTF16(network->wifi_name()));
+ } else if (network->cellular_connecting()) {
+ WaitForConnection(ASCIIToUTF16(network->cellular_name()));
} else {
- view()->SetSelectedNetworkItem(0);
+ view()->EnableContinue(network->Connected());
}
}
-void NetworkScreen::ShowConnectingStatus() {
- view()->ShowConnectingStatus(is_waiting_for_connect_,
- connecting_network_.label);
-}
+void NetworkScreen::StopWaitingForConnection(const string16& network_id) {
+ NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary();
+ bool is_connected = network && network->Connected();
+ if (is_connected && continue_pressed_) {
+ NotifyOnConnection();
+ return;
+ }
-void NetworkScreen::StopWaitingForConnection(bool show_combobox) {
- if (connection_timer_.IsRunning())
- connection_timer_.Stop();
- is_waiting_for_connect_ = false;
- connecting_network_.network_type = NetworkList::NETWORK_EMPTY;
- connecting_network_.label.clear();
- if (show_combobox)
- ShowConnectingStatus();
+ continue_pressed_ = false;
+ connection_timer_.Stop();
+
+ network_id_ = network_id;
+ view()->ShowConnectingStatus(false, network_id_);
+ view()->EnableContinue(is_connected);
}
-void NetworkScreen::WaitForConnection(const NetworkList::NetworkItem* network) {
- is_waiting_for_connect_ = true;
- DCHECK(network);
- connecting_network_.network_type = network->network_type;
- connecting_network_.label = network->label;
- if (connection_timer_.IsRunning())
- connection_timer_.Stop();
+void NetworkScreen::WaitForConnection(const string16& network_id) {
+ connection_timer_.Stop();
connection_timer_.Start(base::TimeDelta::FromSeconds(kConnectionTimeoutSec),
this,
&NetworkScreen::OnConnectionTimeout);
- if (continue_pressed_)
- ShowConnectingStatus();
+
+ network_id_ = network_id;
+ view()->ShowConnectingStatus(true, network_id_);
+
+ view()->EnableContinue(false);
}
} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/login/network_screen.h ('k') | chrome/browser/chromeos/login/network_screen_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698