Commit 1b57b4c4 authored by zelidrag@chromium.org's avatar zelidrag@chromium.org

Added flags to prevent messing with network connections while 3G device is being activated.

BUG=chromium-os:9870
TEST=make sure cellular/wireless network can't be enabled/disabled during 3g plan activation process

Review URL: http://codereview.chromium.org/6292008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72199 0039d316-1c4b-4281-b951-d872f2087c98
parent dc470488
......@@ -10187,6 +10187,9 @@ Keep your key file in a safe place. You will need it to create new versions of y
desc="The label for the Chrome OS configuration dialog">
fast
</message>
<message name="IDS_STATUSBAR_NETWORK_LOCKED" desc="Message displayed while access to network devices is temporarily locked due to mobile network activation">
Please wait while we setup your mobile network.
</message>
<message name="IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET" desc="The ethernet network device.">
Ethernet
</message>
......
......@@ -25,6 +25,9 @@ class MockNetworkLibrary : public NetworkLibrary {
MOCK_METHOD1(RemoveObserverForAllNetworks, void(NetworkObserver*));
MOCK_METHOD1(AddCellularDataPlanObserver, void(CellularDataPlanObserver*));
MOCK_METHOD1(RemoveCellularDataPlanObserver, void(CellularDataPlanObserver*));
MOCK_METHOD0(Lock, void(void));
MOCK_METHOD0(Unlock, void(void));
MOCK_METHOD0(IsLocked, bool(void));
MOCK_CONST_METHOD0(ethernet_network, const EthernetNetwork*(void));
MOCK_CONST_METHOD0(ethernet_connecting, bool(void));
MOCK_CONST_METHOD0(ethernet_connected, bool(void));
......
......@@ -842,6 +842,7 @@ class NetworkLibraryImpl : public NetworkLibrary {
connected_devices_(0),
wifi_scanning_(false),
offline_mode_(false),
is_locked_(false),
update_task_(NULL) {
if (EnsureCrosLoaded()) {
Init();
......@@ -940,6 +941,25 @@ class NetworkLibraryImpl : public NetworkLibrary {
}
}
virtual void Lock() {
if (is_locked_)
return;
is_locked_ = true;
NotifyNetworkManagerChanged();
}
virtual void Unlock() {
DCHECK(is_locked_);
if (!is_locked_)
return;
is_locked_ = false;
NotifyNetworkManagerChanged();
}
virtual bool IsLocked() {
return is_locked_;
}
virtual void AddCellularDataPlanObserver(CellularDataPlanObserver* observer) {
if (!data_plan_observers_.HasObserver(observer))
data_plan_observers_.AddObserver(observer);
......@@ -1300,14 +1320,20 @@ class NetworkLibraryImpl : public NetworkLibrary {
}
virtual void EnableEthernetNetworkDevice(bool enable) {
if (is_locked_)
return;
EnableNetworkDeviceType(TYPE_ETHERNET, enable);
}
virtual void EnableWifiNetworkDevice(bool enable) {
if (is_locked_)
return;
EnableNetworkDeviceType(TYPE_WIFI, enable);
}
virtual void EnableCellularNetworkDevice(bool enable) {
if (is_locked_)
return;
EnableNetworkDeviceType(TYPE_CELLULAR, enable);
}
......@@ -1597,6 +1623,7 @@ class NetworkLibraryImpl : public NetworkLibrary {
}
void InitTestData() {
is_locked_ = true;
ethernet_ = new EthernetNetwork();
ethernet_->set_connected(true);
ethernet_->set_service_path("eth1");
......@@ -1914,6 +1941,9 @@ class NetworkLibraryImpl : public NetworkLibrary {
// Currently not implemented. TODO: implement or eliminate.
bool offline_mode_;
// True if access network library is locked.
bool is_locked_;
// Delayed task to retrieve the network information.
CancelableTask* update_task_;
......@@ -1939,6 +1969,9 @@ class NetworkLibraryStubImpl : public NetworkLibrary {
virtual void RemoveNetworkObserver(const std::string& service_path,
NetworkObserver* observer) {}
virtual void RemoveObserverForAllNetworks(NetworkObserver* observer) {}
virtual void Lock() {}
virtual void Unlock() {}
virtual bool IsLocked() { return true; }
virtual void AddCellularDataPlanObserver(
CellularDataPlanObserver* observer) {}
virtual void RemoveCellularDataPlanObserver(
......
......@@ -495,6 +495,15 @@ class NetworkLibrary {
// Stop |observer| from observing any networks
virtual void RemoveObserverForAllNetworks(NetworkObserver* observer) = 0;
// Temporarily locks down certain functionality in network library to prevent
// unplanned side effects. During the lock down, Enable*Device() calls cannot
// be made.
virtual void Lock() = 0;
// Removes temporarily lock of network library.
virtual void Unlock() = 0;
// Checks if access to network library is locked.
virtual bool IsLocked() = 0;
virtual void AddCellularDataPlanObserver(
CellularDataPlanObserver* observer) = 0;
virtual void RemoveCellularDataPlanObserver(
......
......@@ -143,6 +143,9 @@ void InternetOptionsHandler::GetLocalizedValues(
l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_HARDWARE_ADDRESS));
localized_strings->SetString("accessLockedMsg",
l10n_util::GetStringUTF16(
IDS_STATUSBAR_NETWORK_LOCKED));
localized_strings->SetString("inetSsid",
l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID));
......@@ -1028,6 +1031,7 @@ ListValue* InternetOptionsHandler::GetRememberedList() {
void InternetOptionsHandler::FillNetworkInfo(
DictionaryValue* dictionary, chromeos::NetworkLibrary* cros) {
dictionary->SetBoolean("accessLocked", cros->IsLocked());
dictionary->Set("wiredList", GetWiredList());
dictionary->Set("wirelessList", GetWirelessList());
dictionary->Set("rememberedList", GetRememberedList());
......
......@@ -62,6 +62,7 @@ const char kErrorDisabled[] = "disabled";
const char kErrorNoDevice[] = "no_device";
const char kFailedPaymentError[] = "failed_payment";
const char kFailedConnectivity[] = "connectivity";
const char kErrorAlreadyRunning[] = "already_running";
// Cellular configuration file path.
const char kCellularConfigPath[] =
......@@ -309,6 +310,8 @@ class MobileSetupHandler
bool reenable_ethernet_;
bool reenable_cert_check_;
bool evaluating_;
// True if we think that another tab is already running activation.
bool already_running_;
// Connection retry counter.
int connection_retry_count_;
// Post payment reconnect wait counters.
......@@ -438,6 +441,7 @@ MobileSetupHandler::MobileSetupHandler(const std::string& service_path)
reenable_ethernet_(false),
reenable_cert_check_(false),
evaluating_(false),
already_running_(false),
connection_retry_count_(0),
reconnect_wait_count_(0),
activation_attempt_(0) {
......@@ -449,6 +453,8 @@ MobileSetupHandler::~MobileSetupHandler() {
chromeos::CrosLibrary::Get()->GetNetworkLibrary();
lib->RemoveNetworkManagerObserver(this);
lib->RemoveObserverForAllNetworks(this);
if (lib->IsLocked())
lib->Unlock();
ReEnableOtherConnections();
}
......@@ -459,7 +465,10 @@ DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) {
void MobileSetupHandler::Init(TabContents* contents) {
tab_contents_ = contents;
LoadCellularConfig();
SetupActivationProcess(GetCellularNetwork(service_path_));
if (!chromeos::CrosLibrary::Get()->GetNetworkLibrary()->IsLocked())
SetupActivationProcess(GetCellularNetwork(service_path_));
else
already_running_ = true;
}
void MobileSetupHandler::RegisterMessages() {
......@@ -518,15 +527,18 @@ void MobileSetupHandler::StartActivation() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
chromeos::NetworkLibrary* lib =
chromeos::CrosLibrary::Get()->GetNetworkLibrary();
chromeos::CellularNetwork* network = GetCellularNetwork(service_path_);
// Check if we can start activation process.
if (!network) {
std::string error(kErrorNoService);
if (!lib->cellular_available())
if (!network || already_running_) {
std::string error;
if (already_running_)
error = kErrorAlreadyRunning;
else if (!lib->cellular_available())
error = kErrorNoDevice;
else if (!lib->cellular_enabled())
error = kErrorDisabled;
else
error = kErrorNoService;
ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error));
return;
}
......@@ -1008,13 +1020,14 @@ void MobileSetupHandler::CompleteActivation(
// Remove observers, we are done with this page.
chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()->
GetNetworkLibrary();
lib->RemoveNetworkManagerObserver(this);
lib->RemoveObserverForAllNetworks(this);
lib->Unlock();
// If we have successfully activated the connection, set autoconnect flag.
if (network) {
network->set_auto_connect(true);
lib->SaveCellularNetwork(network);
}
lib->RemoveNetworkManagerObserver(this);
lib->RemoveObserverForAllNetworks(this);
// Reactivate other types of connections if we have
// shut them down previously.
ReEnableOtherConnections();
......@@ -1163,7 +1176,9 @@ void MobileSetupHandler::SetupActivationProcess(
network->set_auto_connect(false);
lib->SaveCellularNetwork(network);
// Prevent any other network interference.
DisableOtherNetworks();
lib->Lock();
}
void MobileSetupHandler::DisableOtherNetworks() {
......
......@@ -483,6 +483,15 @@ void NetworkMenu::InitMenuItems() {
string16 label;
if (cros->IsLocked()) {
label = l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_LOCKED);
menu_items_.push_back(
MenuItem(ui::MenuModel::TYPE_COMMAND,
label, SkBitmap(),
std::string(), FLAG_DISABLED));
return;
}
// Ethernet
bool ethernet_available = cros->ethernet_available();
bool ethernet_enabled = cros->ethernet_enabled();
......
<div class="page hidden" id="internetPage">
<h1 i18n-content="internetPage"></h1>
<div id="lockedNetworkBanner">
<span id="lockedNetworkIcon"></span>
<span id="accessLockedText" i18n-content="accessLockedMsg"></span>
</div>
<section id="wirelessButtons">
<h3 i18n-content="generalNetworkingTitle"></h3>
<div id="networkingControls">
......
......@@ -31,6 +31,11 @@ cr.define('options', function() {
initializePage: function() {
OptionsPage.prototype.initializePage.call(this);
if (templateData.accessLocked) {
var page = $('internetPage');
page.setAttribute('accesslocked', true);
}
options.internet.NetworkElement.decorate($('wiredList'));
$('wiredList').load(templateData.wiredList);
options.internet.NetworkElement.decorate($('wirelessList'));
......@@ -175,6 +180,12 @@ cr.define('options', function() {
//Chrome callbacks
//
InternetOptions.refreshNetworkData = function (data) {
var page = $('internetPage');
if (data.accessLocked) {
page.setAttribute('accesslocked', true);
return;
}
page.removeAttribute('accesslocked');
if (InternetOptions.updateLocked) {
InternetOptions.updateData = data;
InternetOptions.updatePending = true;
......
......@@ -150,6 +150,38 @@ html[dir='rtl'] .details-button {
float: left;
}
#lockedNetworkBanner {
height: 31px;
width: 100%;
margin: 0;
padding-top: 10px;
vertical-align: middle;
}
#lockedNetworkIcon {
background-image: url("chrome://theme/IDR_WARNING");
background-repeat: no-repeat;
background-position:center;
display: inline-block;
padding: 5px;
height: 21px;
vertical-align: middle;
width: 24px;
}
#accessLockedText {
vertical-align: middle;
}
#internetPage:not([accesslocked]) #lockedNetworkBanner,
#internetPage[accesslocked] #wirelessButtons,
#internetPage[accesslocked] #wiredSection,
#internetPage[accesslocked] #wirelessSection,
#internetPage[accesslocked] #rememberedSection,
#internetPage[accesslocked] #detailsInternetPage {
display: none;
}
#detailsInternetPage:not([connected]) > #advancedSection,
#detailsInternetPage[connecting] > * > #detailsInternetLogin,
#detailsInternetPage[connected] > * > #detailsInternetLogin,
......
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