Index: chrome/browser/chromeos/mobile/mobile_activator.cc |
diff --git a/chrome/browser/chromeos/mobile/mobile_activator.cc b/chrome/browser/chromeos/mobile/mobile_activator.cc |
index 3e1a82e874fb9557057d176c6d80a145ef953b05..7c05e8affd75bcc831676063f9ed048c08f06eed 100644 |
--- a/chrome/browser/chromeos/mobile/mobile_activator.cc |
+++ b/chrome/browser/chromeos/mobile/mobile_activator.cc |
@@ -13,6 +13,7 @@ |
#include "base/bind_helpers.h" |
#include "base/file_util.h" |
#include "base/json/json_reader.h" |
+#include "base/location.h" |
#include "base/logging.h" |
#include "base/memory/ref_counted_memory.h" |
#include "base/message_loop/message_loop.h" |
@@ -25,9 +26,17 @@ |
#include "base/timer/timer.h" |
#include "base/values.h" |
#include "chrome/browser/browser_process.h" |
-#include "chrome/browser/chromeos/cros/network_library.h" |
#include "chrome/common/pref_names.h" |
+#include "chromeos/network/device_state.h" |
+#include "chromeos/network/network_activation_handler.h" |
+#include "chromeos/network/network_configuration_handler.h" |
+#include "chromeos/network/network_connection_handler.h" |
+#include "chromeos/network/network_event_log.h" |
+#include "chromeos/network/network_handler_callbacks.h" |
+#include "chromeos/network/network_state.h" |
+#include "chromeos/network/network_state_handler.h" |
#include "content/public/browser/browser_thread.h" |
+#include "third_party/cros_system_api/dbus/service_constants.h" |
using content::BrowserThread; |
@@ -164,17 +173,13 @@ MobileActivator* MobileActivator::GetInstance() { |
} |
void MobileActivator::TerminateActivation() { |
- // We're exiting; don't continue with termination. |
- if (!NetworkLibrary::Get()) |
- return; |
- |
state_duration_timer_.Stop(); |
continue_reconnect_timer_.Stop(); |
reconnect_timeout_timer_.Stop(); |
- NetworkLibrary* lib = GetNetworkLibrary(); |
- lib->RemoveNetworkManagerObserver(this); |
- lib->RemoveObserverForAllNetworks(this); |
+ if (NetworkHandler::IsInitialized()) |
+ NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
+ FROM_HERE); |
ReEnableCertRevocationChecking(); |
meid_.clear(); |
iccid_.clear(); |
@@ -186,18 +191,20 @@ void MobileActivator::TerminateActivation() { |
cellular_config_ = new CellularConfigDocument(); |
} |
-void MobileActivator::OnNetworkManagerChanged(NetworkLibrary* cros) { |
+void MobileActivator::NetworkManagerChanged() { |
if (state_ == PLAN_ACTIVATION_PAGE_LOADING || |
state_ == PLAN_ACTIVATION_DONE || |
state_ == PLAN_ACTIVATION_ERROR) { |
return; |
} |
- CellularNetwork* network = FindMatchingCellularNetwork(true); |
- if (network && network->activate_over_non_cellular_network()) { |
+ NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler(); |
+ const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
+ GetNetworkState(service_path_); |
+ if (network && network->activate_over_non_cellular_networks()) { |
bool waiting = (state_ == PLAN_ACTIVATION_WAITING_FOR_CONNECTION); |
- bool is_online = |
- cros->connected_network() && cros->connected_network()->online(); |
+ bool is_online = nsh->DefaultNetwork() && |
+ nsh->DefaultNetwork()->connection_state() == flimflam::kStateOnline; |
if (waiting && is_online) { |
ChangeState(network, post_reconnect_state_, ""); |
} else if (!waiting && !is_online) { |
@@ -208,18 +215,23 @@ void MobileActivator::OnNetworkManagerChanged(NetworkLibrary* cros) { |
EvaluateCellularNetwork(network); |
} |
-void MobileActivator::OnNetworkChanged(NetworkLibrary* cros, |
- const Network* network) { |
+void MobileActivator::DefaultNetworkChanged(const NetworkState* network) { |
+ NetworkManagerChanged(); |
+} |
+ |
+void MobileActivator::NetworkPropertiesUpdated(const NetworkState* network) { |
if (state_ == PLAN_ACTIVATION_PAGE_LOADING) |
return; |
- if (!network || network->type() != TYPE_CELLULAR) { |
- NOTREACHED(); |
+ if (!network || network->type() != flimflam::kTypeCellular) |
+ return; |
+ if (network->path() != service_path_) { |
+ LOG(WARNING) << "Ignoring property update for unknown cellular service " |
+ << network->path() << " (Expected " << service_path_<< ")"; |
return; |
} |
- EvaluateCellularNetwork( |
- static_cast<CellularNetwork*>(const_cast<Network*>(network))); |
+ EvaluateCellularNetwork(network); |
} |
void MobileActivator::AddObserver(MobileActivator::Observer* observer) { |
@@ -234,15 +246,15 @@ void MobileActivator::RemoveObserver(MobileActivator::Observer* observer) { |
void MobileActivator::InitiateActivation(const std::string& service_path) { |
DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- NetworkLibrary* lib = GetNetworkLibrary(); |
- CellularNetwork* network = lib->FindCellularNetworkByPath(service_path); |
+ const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
+ GetNetworkState(service_path); |
if (!network) { |
LOG(ERROR) << "Cellular service can't be found: " << service_path; |
return; |
} |
- const chromeos::NetworkDevice* device = |
- lib->FindNetworkDeviceByPath(network->device_path()); |
+ const DeviceState* device = NetworkHandler::Get()->network_state_handler()-> |
+ GetDeviceState(network->device_path()); |
if (!device) { |
LOG(ERROR) << "Cellular device can't be found: " << network->device_path(); |
return; |
@@ -262,14 +274,22 @@ void MobileActivator::InitiateActivation(const std::string& service_path) { |
} |
void MobileActivator::ContinueActivation() { |
- CellularNetwork* network = FindMatchingCellularNetwork(false); |
- if (!network || !network->SupportsActivation()) |
+ const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
+ GetNetworkState(service_path_); |
+ if (!network || |
+ (network->payment_url().empty() && network->usage_url().empty())) |
return; |
DisableCertRevocationChecking(); |
- // We want shill to connect us after activations. |
- network->SetAutoConnect(true); |
+ // We want shill to connect us after activations, so enable autoconnect. |
+ DictionaryValue auto_connect_property; |
+ auto_connect_property.SetBoolean(flimflam::kAutoConnectProperty, true); |
+ NetworkHandler::Get()->network_configuration_handler()->SetProperties( |
+ network->path(), |
+ auto_connect_property, |
+ base::Bind(&base::DoNothing), |
+ network_handler::ErrorCallback()); |
StartActivation(); |
} |
@@ -283,13 +303,17 @@ void MobileActivator::HandleSetTransactionStatus(bool success) { |
// The payment is received, try to reconnect and check the status all over |
// again. |
if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { |
- NetworkLibrary* lib = GetNetworkLibrary(); |
- lib->SignalCellularPlanPayment(); |
+ SignalCellularPlanPayment(); |
UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1); |
- CellularNetwork* network = FindMatchingCellularNetwork(true); |
- if (network && network->activate_over_non_cellular_network()) { |
+ const NetworkState* network = |
+ NetworkHandler::Get()->network_state_handler()->GetNetworkState( |
+ service_path_); |
+ if (network && network->activate_over_non_cellular_networks()) { |
state_ = PLAN_ACTIVATION_DONE; |
- network->CompleteActivation(); |
+ NetworkHandler::Get()->network_activation_handler()-> |
+ CompleteActivation(network->path(), |
+ base::Bind(&base::DoNothing), |
+ network_handler::ErrorCallback()); |
} else { |
StartOTASP(); |
} |
@@ -305,7 +329,8 @@ void MobileActivator::OnPortalLoaded(bool success) { |
} |
void MobileActivator::HandlePortalLoaded(bool success) { |
- CellularNetwork* network = FindMatchingCellularNetwork(true); |
+ const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
+ GetNetworkState(service_path_); |
if (!network) { |
ChangeState(NULL, PLAN_ACTIVATION_ERROR, |
GetErrorMessage(kErrorNoService)); |
@@ -319,7 +344,7 @@ void MobileActivator::HandlePortalLoaded(bool success) { |
} else { |
// There is no point in forcing reconnecting the cellular network if the |
// activation should not be done over it. |
- if (network->activate_over_non_cellular_network()) |
+ if (network->activate_over_non_cellular_networks()) |
return; |
payment_reconnect_count_++; |
@@ -340,30 +365,6 @@ void MobileActivator::HandlePortalLoaded(bool success) { |
} |
} |
-CellularNetwork* MobileActivator::FindMatchingCellularNetwork( |
- bool reattach_observer) { |
- NetworkLibrary* lib = GetNetworkLibrary(); |
- for (CellularNetworkVector::const_iterator it = |
- lib->cellular_networks().begin(); |
- it != lib->cellular_networks().end(); ++it) { |
- const chromeos::NetworkDevice* device = |
- lib->FindNetworkDeviceByPath((*it)->device_path()); |
- if (device && ((!meid_.empty() && meid_ == device->meid()) || |
- (!iccid_.empty() && iccid_ == device->iccid()))) { |
- CellularNetwork* network = *it; |
- // If service path has changed, reattach the event observer for this |
- // network service. |
- if (reattach_observer && service_path_ != network->service_path()) { |
- lib->RemoveObserverForAllNetworks(this); |
- lib->AddNetworkObserver(network->service_path(), this); |
- service_path_ = network->service_path(); |
- } |
- return network; |
- } |
- } |
- return NULL; |
-} |
- |
void MobileActivator::StartOTASPTimer() { |
state_duration_timer_.Start( |
FROM_HERE, |
@@ -373,39 +374,45 @@ void MobileActivator::StartOTASPTimer() { |
void MobileActivator::StartActivation() { |
UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1); |
- NetworkLibrary* lib = GetNetworkLibrary(); |
- CellularNetwork* network = FindMatchingCellularNetwork(true); |
+ const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
+ GetNetworkState(service_path_); |
// Check if we can start activation process. |
if (!network) { |
+ NetworkStateHandler::TechnologyState technology_state = |
+ NetworkHandler::Get()->network_state_handler()->GetTechnologyState( |
+ flimflam::kTypeCellular); |
std::string error; |
- if (!lib->cellular_available()) |
+ if (technology_state == NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) { |
error = kErrorNoDevice; |
- else if (!lib->cellular_enabled()) |
+ } else if (technology_state !=NetworkStateHandler::TECHNOLOGY_ENABLED) { |
error = kErrorDisabled; |
- else |
+ } else { |
error = kErrorNoService; |
+ } |
ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error)); |
return; |
} |
// Start monitoring network property changes. |
- lib->AddNetworkManagerObserver(this); |
- if (network->activate_over_non_cellular_network()) { |
+ NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); |
+ if (network->activate_over_non_cellular_networks()) { |
// Fast forward to payment portal loading if the activation is performed |
// over a non-cellular network. |
- ChangeState(network, |
- (network->activation_state() == ACTIVATION_STATE_ACTIVATED) ? |
- PLAN_ACTIVATION_DONE : |
- PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING, |
- ""); |
+ ChangeState( |
+ network, |
+ (network->activation_state() == flimflam::kActivationStateActivated) ? |
+ PLAN_ACTIVATION_DONE : |
+ PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING, |
+ ""); |
// Verify that there is no need to wait for the connection. This will also |
// evaluate the network. |
- OnNetworkManagerChanged(lib); |
+ NetworkManagerChanged(); |
return; |
} |
- if (lib->HasRecentCellularPlanPayment() && |
- network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED) { |
+ if (HasRecentCellularPlanPayment() && |
+ (network->activation_state() == |
+ flimflam::kActivationStatePartiallyActivated)) { |
// Try to start with OTASP immediately if we have received payment recently. |
state_ = PLAN_ACTIVATION_START_OTASP; |
} else { |
@@ -421,14 +428,16 @@ void MobileActivator::RetryOTASP() { |
} |
void MobileActivator::StartOTASP() { |
- CellularNetwork* network = FindMatchingCellularNetwork(true); |
+ const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
+ GetNetworkState(service_path_); |
ChangeState(network, PLAN_ACTIVATION_START_OTASP, std::string()); |
EvaluateCellularNetwork(network); |
} |
void MobileActivator::HandleOTASPTimeout() { |
LOG(WARNING) << "OTASP seems to be taking too long."; |
- CellularNetwork* network = FindMatchingCellularNetwork(true); |
+ const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
+ GetNetworkState(service_path_); |
// We're here because one of OTASP steps is taking too long to complete. |
// Usually, this means something bad has happened below us. |
if (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION) { |
@@ -465,18 +474,21 @@ void MobileActivator::HandleOTASPTimeout() { |
GetErrorMessage(kErrorDefault)); |
} |
-void MobileActivator::ForceReconnect(CellularNetwork* network, |
+void MobileActivator::ForceReconnect(const NetworkState* network, |
PlanActivationState next_state) { |
DCHECK(network); |
// Store away our next destination for when we complete. |
post_reconnect_state_ = next_state; |
UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); |
// First, disconnect... |
- LOG(INFO) << "Disconnecting from " << network->service_path(); |
+ LOG(INFO) << "Disconnecting from " << network->path(); |
// Explicit service Disconnect()s disable autoconnect on the service until |
// Connect() is called on the service again. Hence this dance to explicitly |
// call Connect(). |
- GetNetworkLibrary()->DisconnectFromNetwork(network); |
+ NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork( |
+ network->path(), |
+ base::Bind(&base::DoNothing), |
+ network_handler::ErrorCallback()); |
// Keep trying to connect until told otherwise. |
continue_reconnect_timer_.Stop(); |
continue_reconnect_timer_.Start( |
@@ -493,20 +505,26 @@ void MobileActivator::ForceReconnect(CellularNetwork* network, |
void MobileActivator::ReconnectTimedOut() { |
LOG(ERROR) << "Ending activation attempt after failing to reconnect."; |
- ChangeState(FindMatchingCellularNetwork(true), |
+ const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
+ GetNetworkState(service_path_); |
+ ChangeState(network, |
PLAN_ACTIVATION_ERROR, |
GetErrorMessage(kFailedConnectivity)); |
} |
void MobileActivator::ContinueConnecting() { |
- CellularNetwork* network = FindMatchingCellularNetwork(true); |
- if (network && network->connected()) { |
- if (network->restricted_pool() && |
- network->error() == ERROR_DNS_LOOKUP_FAILED) { |
+ const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
+ GetNetworkState(service_path_); |
+ if (network && network->IsConnectedState()) { |
+ if (network->connection_state() == flimflam::kStatePortal && |
+ network->error() == flimflam::kErrorDNSLookupFailed) { |
// It isn't an error to be in a restricted pool, but if DNS doesn't work, |
// then we're not getting traffic through at all. Just disconnect and |
// try again. |
- GetNetworkLibrary()->DisconnectFromNetwork(network); |
+ NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork( |
+ network->path(), |
+ base::Bind(&base::DoNothing), |
+ network_handler::ErrorCallback()); |
return; |
} |
// Stop this callback |
@@ -515,14 +533,14 @@ void MobileActivator::ContinueConnecting() { |
} else { |
LOG(WARNING) << "Connect failed, will try again in a little bit."; |
if (network) { |
- LOG(INFO) << "Connecting to: " << network->service_path(); |
+ LOG(INFO) << "Connecting to: " << network->path(); |
ash::network_connect::ConnectToNetwork( |
- network->service_path(), NULL /* no parent window */); |
+ network->path(), NULL /* no parent window */); |
} |
} |
} |
-void MobileActivator::EvaluateCellularNetwork(CellularNetwork* network) { |
+void MobileActivator::EvaluateCellularNetwork(const NetworkState* network) { |
if (terminated_) { |
LOG(ERROR) << "Tried to run MobileActivator state machine while " |
<< "terminated."; |
@@ -534,16 +552,16 @@ void MobileActivator::EvaluateCellularNetwork(CellularNetwork* network) { |
return; |
} |
- LOG(WARNING) << "Cellular:\n service=" << network->GetStateString() |
- << "\n ui=" << GetStateDescription(state_) |
- << "\n activation=" << network->GetActivationStateString() |
- << "\n error=" << network->GetErrorString() |
- << "\n setvice_path=" << network->service_path() |
- << "\n connected=" << network->connected(); |
+ LOG(WARNING) << "Cellular:\n service state=" << network->connection_state() |
+ << "\n ui=" << GetStateDescription(state_) |
+ << "\n activation=" << network->activation_state() |
+ << "\n error=" << network->error() |
+ << "\n setvice_path=" << network->path() |
+ << "\n connected=" << network->IsConnectedState(); |
// If the network is activated over non cellular network, the activator state |
// does not depend on the network's own state. |
- if (network->activate_over_non_cellular_network()) |
+ if (network->activate_over_non_cellular_networks()) |
return; |
std::string error_description; |
@@ -553,9 +571,9 @@ void MobileActivator::EvaluateCellularNetwork(CellularNetwork* network) { |
} |
MobileActivator::PlanActivationState MobileActivator::PickNextState( |
- CellularNetwork* network, std::string* error_description) const { |
+ const NetworkState* network, std::string* error_description) const { |
PlanActivationState new_state = state_; |
- if (!network->connected()) |
+ if (!network->IsConnectedState()) |
new_state = PickNextOfflineState(network); |
else |
new_state = PickNextOnlineState(network); |
@@ -564,13 +582,15 @@ MobileActivator::PlanActivationState MobileActivator::PickNextState( |
// Check for this special case when we try to do activate partially |
// activated device. If that attempt failed, try to disconnect to clear the |
// state and reconnect again. |
- if ((network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED || |
- network->activation_state() == ACTIVATION_STATE_ACTIVATING) && |
- (network->error() == ERROR_NO_ERROR || |
- network->error() == ERROR_OTASP_FAILED) && |
- network->state() == STATE_ACTIVATION_FAILURE) { |
- LOG(WARNING) << "Activation failure detected " |
- << network->service_path(); |
+ const std::string& activation = network->activation_state(); |
+ bool is_partially_activated = |
+ activation == flimflam::kActivationStatePartiallyActivated || |
+ activation == flimflam::kActivationStateActivating; |
+ if (is_partially_activated && |
+ (network->error().empty() || |
+ network->error() == flimflam::kErrorOtaspFailed) && |
+ network->connection_state() == flimflam::kStateActivationFailure) { |
+ LOG(WARNING) << "Activation failure detected " << network->path(); |
switch (state_) { |
case PLAN_ACTIVATION_OTASP: |
new_state = PLAN_ACTIVATION_DELAY_OTASP; |
@@ -592,8 +612,7 @@ MobileActivator::PlanActivationState MobileActivator::PickNextState( |
break; |
} |
} else { |
- LOG(WARNING) << "Unexpected activation failure for " |
- << network->service_path(); |
+ LOG(WARNING) << "Unexpected activation failure for " << network->path(); |
new_state = PLAN_ACTIVATION_ERROR; |
} |
} |
@@ -604,70 +623,59 @@ MobileActivator::PlanActivationState MobileActivator::PickNextState( |
} |
MobileActivator::PlanActivationState MobileActivator::PickNextOfflineState( |
- CellularNetwork* network) const { |
+ const NetworkState* network) const { |
PlanActivationState new_state = state_; |
+ const std::string& activation = network->activation_state(); |
switch (state_) { |
case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
case PLAN_ACTIVATION_SHOWING_PAYMENT: |
- if (!network->activate_over_non_cellular_network()) |
+ if (!network->activate_over_non_cellular_networks()) |
new_state = PLAN_ACTIVATION_RECONNECTING; |
break; |
case PLAN_ACTIVATION_START: |
- switch (network->activation_state()) { |
- case ACTIVATION_STATE_ACTIVATED: |
- if (network->restricted_pool()) |
- new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
- else |
- new_state = PLAN_ACTIVATION_DONE; |
- break; |
- case ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
- new_state = PLAN_ACTIVATION_TRYING_OTASP; |
- break; |
- default: |
- new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
- break; |
+ if (activation == flimflam::kActivationStateActivated) { |
+ if (network->connection_state() == flimflam::kStatePortal) |
+ new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
+ else |
+ new_state = PLAN_ACTIVATION_DONE; |
+ } else if (activation == flimflam::kActivationStatePartiallyActivated) { |
+ new_state = PLAN_ACTIVATION_TRYING_OTASP; |
+ } else { |
+ new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
} |
break; |
- default: { |
+ default: |
LOG(INFO) << "Waiting for cellular service to connect."; |
- } break; |
+ break; |
} |
return new_state; |
} |
MobileActivator::PlanActivationState MobileActivator::PickNextOnlineState( |
- CellularNetwork* network) const { |
+ const NetworkState* network) const { |
PlanActivationState new_state = state_; |
+ const std::string& activation = network->activation_state(); |
switch (state_) { |
case PLAN_ACTIVATION_START: |
- switch (network->activation_state()) { |
- case ACTIVATION_STATE_ACTIVATED: |
- if (network->restricted_pool()) |
- new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
- else |
- new_state = PLAN_ACTIVATION_DONE; |
- break; |
- case ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
- new_state = PLAN_ACTIVATION_TRYING_OTASP; |
- break; |
- default: |
- new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
- break; |
+ if (activation == flimflam::kActivationStateActivated) { |
+ if (network->connection_state() == flimflam::kStatePortal) |
+ new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
+ else |
+ new_state = PLAN_ACTIVATION_DONE; |
+ } else if (activation == flimflam::kActivationStatePartiallyActivated) { |
+ new_state = PLAN_ACTIVATION_TRYING_OTASP; |
+ } else { |
+ new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
} |
break; |
case PLAN_ACTIVATION_START_OTASP: { |
- switch (network->activation_state()) { |
- case ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
+ if (activation == flimflam::kActivationStatePartiallyActivated) { |
new_state = PLAN_ACTIVATION_OTASP; |
- break; |
- case ACTIVATION_STATE_ACTIVATED: |
- new_state = PLAN_ACTIVATION_RECONNECTING; |
- break; |
- default: { |
- LOG(WARNING) << "Unexpected activation state for device " |
- << network->service_path(); |
- break; |
- } |
+ } else if (activation == flimflam::kActivationStateActivated) { |
+ new_state = PLAN_ACTIVATION_RECONNECTING; |
+ } else { |
+ LOG(WARNING) << "Unexpected activation state for device " |
+ << network->path(); |
} |
break; |
} |
@@ -675,36 +683,32 @@ MobileActivator::PlanActivationState MobileActivator::PickNextOnlineState( |
// Just ignore any changes until the OTASP retry timer kicks in. |
break; |
case PLAN_ACTIVATION_INITIATING_ACTIVATION: { |
- switch (network->activation_state()) { |
- case ACTIVATION_STATE_ACTIVATED: |
- case ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
- new_state = PLAN_ACTIVATION_START; |
- break; |
- case ACTIVATION_STATE_NOT_ACTIVATED: |
- case ACTIVATION_STATE_ACTIVATING: |
- // Wait in this state until activation state changes. |
- break; |
- default: |
- LOG(WARNING) << "Unknown transition"; |
- break; |
+ if (activation == flimflam::kActivationStateActivated || |
+ activation == flimflam::kActivationStatePartiallyActivated) { |
+ new_state = PLAN_ACTIVATION_START; |
+ } else if (activation == flimflam::kActivationStateNotActivated || |
+ activation == flimflam::kActivationStateActivating) { |
+ // Wait in this state until activation state changes. |
+ } else { |
+ LOG(WARNING) << "Unknown transition"; |
} |
break; |
} |
case PLAN_ACTIVATION_OTASP: |
case PLAN_ACTIVATION_TRYING_OTASP: |
- if (network->activation_state() == ACTIVATION_STATE_NOT_ACTIVATED || |
- network->activation_state() == ACTIVATION_STATE_ACTIVATING) { |
+ if (activation == flimflam::kActivationStateNotActivated || |
+ activation == flimflam::kActivationStateActivating) { |
LOG(INFO) << "Waiting for the OTASP to finish and the service to " |
<< "come back online"; |
- } else if (network->activation_state() == ACTIVATION_STATE_ACTIVATED) { |
+ } else if (activation == flimflam::kActivationStateActivated) { |
new_state = PLAN_ACTIVATION_DONE; |
} else { |
new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
} |
break; |
case PLAN_ACTIVATION_RECONNECTING_PAYMENT: |
- if (!network->restricted_pool() && |
- network->activation_state() == ACTIVATION_STATE_ACTIVATED) |
+ if (network->connection_state() != flimflam::kStatePortal && |
+ activation == flimflam::kActivationStateActivated) |
// We're not portalled, and we're already activated, so we're online! |
new_state = PLAN_ACTIVATION_DONE; |
else |
@@ -767,12 +771,11 @@ const char* MobileActivator::GetStateDescription(PlanActivationState state) { |
} |
-void MobileActivator::CompleteActivation( |
- CellularNetwork* network) { |
+void MobileActivator::CompleteActivation(const NetworkState* network) { |
// Remove observers, we are done with this page. |
- NetworkLibrary* lib = GetNetworkLibrary(); |
- lib->RemoveNetworkManagerObserver(this); |
- lib->RemoveObserverForAllNetworks(this); |
+ NetworkHandler::Get()->network_state_handler()->RemoveObserver( |
+ this, FROM_HERE); |
+ |
// Reactivate other types of connections if we have |
// shut them down previously. |
ReEnableCertRevocationChecking(); |
@@ -784,7 +787,28 @@ bool MobileActivator::RunningActivation() const { |
state_ == PLAN_ACTIVATION_PAGE_LOADING); |
} |
-void MobileActivator::ChangeState(CellularNetwork* network, |
+void MobileActivator::HandleActivationFailure( |
+ const std::string& service_path, |
+ PlanActivationState new_state, |
+ const std::string& error_name, |
+ scoped_ptr<base::DictionaryValue> error_data) { |
+ const NetworkState* network = |
+ NetworkHandler::Get()->network_state_handler()->GetNetworkState( |
+ service_path); |
+ if (!network) |
+ NET_LOG_ERROR("Cellular service no longer exists", service_path); |
stevenjb
2013/08/14 21:58:35
Need to return here; ChangeState does not safely h
gauravsh
2013/08/15 01:46:35
Done.
|
+ UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); |
+ NET_LOG_ERROR("Failed to call Activate() on service", service_path); |
+ if (new_state == PLAN_ACTIVATION_OTASP) { |
+ ChangeState(network, PLAN_ACTIVATION_DELAY_OTASP, std::string()); |
+ } else { |
+ ChangeState(network, |
+ PLAN_ACTIVATION_ERROR, |
+ GetErrorMessage(kFailedConnectivity)); |
+ } |
+} |
+ |
+void MobileActivator::ChangeState(const NetworkState* network, |
PlanActivationState new_state, |
const std::string& error_description) { |
static bool first_time = true; |
@@ -807,6 +831,10 @@ void MobileActivator::ChangeState(CellularNetwork* network, |
FOR_EACH_OBSERVER(Observer, observers_, |
OnActivationStateChanged(network, state_, error_description)); |
+ network_handler::ErrorCallback on_activation_error = |
+ base::Bind(&MobileActivator::HandleActivationFailure, AsWeakPtr(), |
+ network->path(), |
+ new_state); |
// Pick action that should happen on entering the new state. |
switch (new_state) { |
case PLAN_ACTIVATION_START: |
@@ -824,21 +852,13 @@ void MobileActivator::ChangeState(CellularNetwork* network, |
case PLAN_ACTIVATION_TRYING_OTASP: |
case PLAN_ACTIVATION_OTASP: |
DCHECK(network); |
- LOG(WARNING) << "Activating service " << network->service_path(); |
+ NET_LOG_EVENT("Activating cellular service", network->path()); |
UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); |
- if (!network->StartActivation()) { |
- UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); |
- LOG(ERROR) << "Failed to call Activate() on service in shill."; |
- if (new_state == PLAN_ACTIVATION_OTASP) { |
- ChangeState(network, PLAN_ACTIVATION_DELAY_OTASP, std::string()); |
- } else { |
- ChangeState(network, |
- PLAN_ACTIVATION_ERROR, |
- GetErrorMessage(kFailedConnectivity)); |
- } |
- } else { |
- StartOTASPTimer(); |
- } |
+ NetworkHandler::Get()->network_activation_handler()-> |
+ Activate(network->path(), |
+ "", // carrier |
+ base::Bind(&MobileActivator::StartOTASPTimer, AsWeakPtr()), |
+ on_activation_error); |
break; |
case PLAN_ACTIVATION_PAGE_LOADING: |
return; |
@@ -866,7 +886,7 @@ void MobileActivator::ChangeState(CellularNetwork* network, |
break; |
case PLAN_ACTIVATION_START_OTASP: |
case PLAN_ACTIVATION_OTASP: |
- if (!network || !network->connected()) { |
+ if (!network || !network->IsConnectedState()) { |
next_state = PLAN_ACTIVATION_START_OTASP; |
} else { |
// We're online, which means we've conspired with |
@@ -921,33 +941,32 @@ void MobileActivator::DisableCertRevocationChecking() { |
} |
bool MobileActivator::GotActivationError( |
- CellularNetwork* network, std::string* error) const { |
+ const NetworkState* network, std::string* error) const { |
DCHECK(network); |
bool got_error = false; |
const char* error_code = kErrorDefault; |
+ const std::string& activation = network->activation_state(); |
// This is the magic for detection of errors in during activation process. |
- if (network->state() == STATE_FAILURE && |
- network->error() == ERROR_AAA_FAILED) { |
- if (network->activation_state() == |
- ACTIVATION_STATE_PARTIALLY_ACTIVATED) { |
+ if (network->connection_state() == flimflam::kStateFailure && |
+ network->error() == flimflam::kErrorAaaFailed) { |
+ if (activation == flimflam::kActivationStatePartiallyActivated) { |
error_code = kErrorBadConnectionPartial; |
- } else if (network->activation_state() == ACTIVATION_STATE_ACTIVATED) { |
- if (network->roaming_state() == ROAMING_STATE_HOME) |
+ } else if (activation == flimflam::kActivationStateActivated) { |
+ if (network->roaming() == flimflam::kRoamingStateHome) |
error_code = kErrorBadConnectionActivated; |
- else if (network->roaming_state() == ROAMING_STATE_ROAMING) |
+ else if (network->roaming() == flimflam::kRoamingStateRoaming) |
error_code = kErrorRoamingOnConnection; |
} |
got_error = true; |
- } else if (network->state() == STATE_ACTIVATION_FAILURE) { |
- if (network->error() == ERROR_NEED_EVDO) { |
- if (network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED) |
+ } else if (network->connection_state() == flimflam::kStateActivationFailure) { |
+ if (network->error() == flimflam::kErrorNeedEvdo) { |
+ if (activation == flimflam::kActivationStatePartiallyActivated) |
error_code = kErrorNoEVDO; |
- } else if (network->error() == ERROR_NEED_HOME_NETWORK) { |
- if (network->activation_state() == ACTIVATION_STATE_NOT_ACTIVATED) { |
+ } else if (network->error() == flimflam::kErrorNeedHomeNetwork) { |
+ if (activation == flimflam::kActivationStateNotActivated) { |
error_code = kErrorRoamingActivation; |
- } else if (network->activation_state() == |
- ACTIVATION_STATE_PARTIALLY_ACTIVATED) { |
+ } else if (activation == flimflam::kActivationStatePartiallyActivated) { |
error_code = kErrorRoamingPartiallyActivated; |
} |
} |
@@ -960,19 +979,17 @@ bool MobileActivator::GotActivationError( |
return got_error; |
} |
-void MobileActivator::GetDeviceInfo(CellularNetwork* network, |
+void MobileActivator::GetDeviceInfo(const NetworkState* network, |
DictionaryValue* value) { |
DCHECK(network); |
- NetworkLibrary* cros = NetworkLibrary::Get(); |
- if (!cros) |
- return; |
value->SetString("carrier", network->name()); |
value->SetString("payment_url", network->payment_url()); |
- if (network->using_post() && network->post_data().length()) |
+ if (network->post_method() == "post" && !network->post_data().empty()) |
value->SetString("post_data", network->post_data()); |
- const NetworkDevice* device = |
- cros->FindNetworkDeviceByPath(network->device_path()); |
+ const DeviceState* device = |
+ NetworkHandler::Get()->network_state_handler()->GetDeviceState( |
+ network->device_path()); |
if (device) { |
value->SetString("MEID", device->meid()); |
value->SetString("IMEI", device->imei()); |
@@ -984,8 +1001,15 @@ std::string MobileActivator::GetErrorMessage(const std::string& code) const { |
return cellular_config_->GetErrorMessage(code); |
} |
-NetworkLibrary* MobileActivator::GetNetworkLibrary() const { |
- return NetworkLibrary::Get(); |
+void MobileActivator::SignalCellularPlanPayment() { |
+ DCHECK(!HasRecentCellularPlanPayment()); |
+ cellular_plan_payment_time_ = base::Time::Now(); |
+} |
+ |
+bool MobileActivator::HasRecentCellularPlanPayment() const { |
+ const int kRecentPlanPaymentHours = 6; |
+ return (base::Time::Now() - |
+ cellular_plan_payment_time_).InHours() < kRecentPlanPaymentHours; |
} |
} // namespace chromeos |