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

Unified Diff: ash/system/chromeos/network/network_state_list_detailed_view.cc

Issue 14137017: Add TechnologyState to NetworkStateHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 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: ash/system/chromeos/network/network_state_list_detailed_view.cc
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 b127de17288794a9157b430814cbb67327f5c00b..661cb47b4646374246d07eba1983587f2282f63f 100644
--- a/ash/system/chromeos/network/network_state_list_detailed_view.cc
+++ b/ash/system/chromeos/network/network_state_list_detailed_view.cc
@@ -39,6 +39,7 @@
#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h"
+using chromeos::DeviceState;
using chromeos::NetworkState;
using chromeos::NetworkStateHandler;
@@ -230,7 +231,7 @@ void NetworkStateListDetailedView::ButtonPressed(views::Button* sender,
ash::SystemTrayDelegate* delegate =
ash::Shell::GetInstance()->system_tray_delegate();
if (sender == button_wifi_) {
- bool enabled = handler->TechnologyEnabled(flimflam::kTypeWifi);
+ bool enabled = handler->IsTechnologyEnabled(flimflam::kTypeWifi);
handler->SetTechnologyEnabled(
flimflam::kTypeWifi, !enabled,
chromeos::network_handler::ErrorCallback());
@@ -239,12 +240,7 @@ void NetworkStateListDetailedView::ButtonPressed(views::Button* sender,
flimflam::kTypeWifi, true,
chromeos::network_handler::ErrorCallback());
} else if (sender == button_mobile_) {
- // TODO: This needs to be fixed to use
- // NetworkStateHandler::SetTechnologyEnabled instead. Currently
- // ToggleMobile has code to handle the locked SIM case, which cannot
- // be moved here yet due to dependencies on src/chrome/* - see,
- // crbug.com/222540.
- delegate->ToggleMobile();
+ ToggleMobile();
} else if (sender == settings_) {
delegate->ShowNetworkSettings();
} else if (sender == proxy_settings_) {
@@ -400,15 +396,11 @@ void NetworkStateListDetailedView::CreateNetworkExtra() {
void NetworkStateListDetailedView::UpdateHeaderButtons() {
NetworkStateHandler* handler = NetworkStateHandler::Get();
- if (button_wifi_) {
- button_wifi_->SetToggled(
- !handler->TechnologyEnabled(flimflam::kTypeWifi));
- }
+ if (button_wifi_)
+ UpdateTechnologyButton(button_wifi_, flimflam::kTypeWifi);
if (button_mobile_) {
- button_mobile_->SetToggled(!handler->TechnologyEnabled(
- NetworkStateHandler::kMatchTypeMobile));
- button_mobile_->SetVisible(handler->TechnologyAvailable(
- NetworkStateHandler::kMatchTypeMobile));
+ UpdateTechnologyButton(
+ button_mobile_, NetworkStateHandler::kMatchTypeMobile);
}
if (proxy_settings_)
proxy_settings_->SetEnabled(handler->DefaultNetwork() != NULL);
@@ -416,6 +408,31 @@ void NetworkStateListDetailedView::UpdateHeaderButtons() {
static_cast<views::View*>(footer())->Layout();
}
+void NetworkStateListDetailedView::UpdateTechnologyButton(
+ TrayPopupHeaderButton* button,
+ const std::string& technology) {
+ NetworkStateHandler::TechnologyState state =
+ NetworkStateHandler::Get()->GetTechnologyState(technology);
+ if (state == NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) {
+ button->SetVisible(false);
+ return;
+ }
+ button->SetVisible(true);
+ if (state == NetworkStateHandler::TECHNOLOGY_AVAILABLE) {
+ button->SetEnabled(true);
+ button->SetToggled(true);
+ } else if (state == NetworkStateHandler::TECHNOLOGY_ENABLED) {
+ button->SetEnabled(true);
+ button->SetToggled(false);
+ } else if (state == NetworkStateHandler::TECHNOLOGY_ENABLING) {
+ button->SetEnabled(false);
+ button->SetToggled(false);
+ } else { // Initializing
+ button->SetEnabled(false);
+ button->SetToggled(true);
+ }
+}
+
void NetworkStateListDetailedView::UpdateNetworks(
const NetworkStateList& networks) {
network_list_.clear();
@@ -564,7 +581,7 @@ bool NetworkStateListDetailedView::UpdateNetworkListEntries(
// Cellular initializing
int status_message_id = network_icon::GetCellularUninitializedMsg();
if (!status_message_id &&
- handler->TechnologyEnabled(NetworkStateHandler::kMatchTypeMobile) &&
+ handler->IsTechnologyEnabled(NetworkStateHandler::kMatchTypeMobile) &&
!handler->FirstNetworkByType(NetworkStateHandler::kMatchTypeMobile)) {
status_message_id = IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS;
}
@@ -580,7 +597,7 @@ bool NetworkStateListDetailedView::UpdateNetworkListEntries(
// "Wifi Enabled / Disabled"
if (network_list_.empty()) {
- int message_id = handler->TechnologyEnabled(flimflam::kTypeWifi) ?
+ int message_id = handler->IsTechnologyEnabled(flimflam::kTypeWifi) ?
IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED :
IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
base::string16 text = rb.GetLocalizedString(message_id);
@@ -667,22 +684,34 @@ void NetworkStateListDetailedView::UpdateNetworkExtra() {
NetworkStateHandler* handler = NetworkStateHandler::Get();
if (other_wifi_) {
DCHECK(turn_on_wifi_);
- if (!handler->TechnologyAvailable(flimflam::kTypeWifi)) {
+ NetworkStateHandler::TechnologyState state =
+ handler->GetTechnologyState(flimflam::kTypeWifi);
+ if (state == NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) {
turn_on_wifi_->SetVisible(false);
other_wifi_->SetVisible(false);
- } else if (!handler->TechnologyEnabled(flimflam::kTypeWifi)) {
- turn_on_wifi_->SetVisible(true);
- other_wifi_->SetVisible(false);
} else {
- turn_on_wifi_->SetVisible(false);
- other_wifi_->SetVisible(true);
+ if (state == NetworkStateHandler::TECHNOLOGY_AVAILABLE) {
+ turn_on_wifi_->SetVisible(true);
+ turn_on_wifi_->SetEnabled(true);
+ other_wifi_->SetVisible(false);
+ } else if (state == NetworkStateHandler::TECHNOLOGY_ENABLED) {
+ turn_on_wifi_->SetVisible(false);
+ other_wifi_->SetVisible(true);
+ } else {
+ // Initializing or Enabling
+ turn_on_wifi_->SetVisible(true);
+ turn_on_wifi_->SetEnabled(false);
+ other_wifi_->SetVisible(false);
+ }
}
layout_parent = other_wifi_->parent();
}
if (other_mobile_) {
bool show_other_mobile = false;
- if (handler->TechnologyAvailable(NetworkStateHandler::kMatchTypeMobile)) {
+ NetworkStateHandler::TechnologyState state =
+ handler->GetTechnologyState(NetworkStateHandler::kMatchTypeMobile);
+ if (state != NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) {
const chromeos::DeviceState* device =
handler->GetDeviceStateByType(NetworkStateHandler::kMatchTypeMobile);
show_other_mobile = (device && device->support_network_scan());
@@ -690,7 +719,7 @@ void NetworkStateListDetailedView::UpdateNetworkExtra() {
if (show_other_mobile) {
other_mobile_->SetVisible(true);
other_mobile_->SetEnabled(
- handler->TechnologyEnabled(NetworkStateHandler::kMatchTypeMobile));
+ state == NetworkStateHandler::TECHNOLOGY_ENABLED);
} else {
other_mobile_->SetVisible(false);
}
@@ -817,6 +846,33 @@ void NetworkStateListDetailedView::CallRequestScan() {
base::TimeDelta::FromSeconds(kRequestScanDelaySeconds));
}
+void NetworkStateListDetailedView::ToggleMobile() {
+ NetworkStateHandler* handler = NetworkStateHandler::Get();
+ bool enabled =
+ handler->IsTechnologyEnabled(NetworkStateHandler::kMatchTypeMobile);
+ if (enabled) {
+ handler->SetTechnologyEnabled(
+ NetworkStateHandler::kMatchTypeMobile, false,
+ chromeos::network_handler::ErrorCallback());
+ } else {
+ const DeviceState* mobile =
+ handler->GetDeviceStateByType(NetworkStateHandler::kMatchTypeMobile);
+ if (!mobile) {
+ LOG(ERROR) << "Mobile device not found.";
+ 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();
+ } else {
+ handler->SetTechnologyEnabled(
+ NetworkStateHandler::kMatchTypeMobile, true,
+ chromeos::network_handler::ErrorCallback());
+ }
+ }
+}
+
} // namespace tray
} // namespace internal
} // namespace ash
« no previous file with comments | « ash/system/chromeos/network/network_state_list_detailed_view.h ('k') | chromeos/dbus/shill_manager_client_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698