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

Unified Diff: chrome/browser/chromeos/mobile/mobile_activator.cc

Issue 22611005: Switch over MobileActivator to use Network*Handler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: keep track of device path + fix null network in callback Created 7 years, 4 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/mobile/mobile_activator.cc
diff --git a/chrome/browser/chromeos/mobile/mobile_activator.cc b/chrome/browser/chromeos/mobile/mobile_activator.cc
index 3e1a82e874fb9557057d176c6d80a145ef953b05..edeafee1c16cd5f0617f16ffe100af6d6631a85e 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;
@@ -151,7 +160,11 @@ MobileActivator::MobileActivator()
state_(PLAN_ACTIVATION_PAGE_LOADING),
reenable_cert_check_(false),
terminated_(true),
+ pending_activation_request_(false),
connection_retry_count_(0),
+ initial_OTASP_attempts_(0),
+ trying_OTASP_attempts_(0),
+ final_OTASP_attempts_(0),
payment_reconnect_count_(0) {
}
@@ -164,21 +177,18 @@ 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();
service_path_.clear();
+ device_path_.clear();
state_ = PLAN_ACTIVATION_PAGE_LOADING;
reenable_cert_check_ = false;
terminated_ = true;
@@ -186,40 +196,36 @@ void MobileActivator::TerminateActivation() {
cellular_config_ = new CellularConfigDocument();
}
-void MobileActivator::OnNetworkManagerChanged(NetworkLibrary* cros) {
- 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()) {
- bool waiting = (state_ == PLAN_ACTIVATION_WAITING_FOR_CONNECTION);
- bool is_online =
- cros->connected_network() && cros->connected_network()->online();
- if (waiting && is_online) {
- ChangeState(network, post_reconnect_state_, "");
- } else if (!waiting && !is_online) {
- ChangeState(network, PLAN_ACTIVATION_WAITING_FOR_CONNECTION, "");
- }
- }
-
- EvaluateCellularNetwork(network);
+void MobileActivator::DefaultNetworkChanged(const NetworkState* network) {
+ RefreshCellularNetworks();
}
-void MobileActivator::OnNetworkChanged(NetworkLibrary* cros,
- const Network* network) {
+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;
+
+ 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;
}
+ if (network->device_path() != device_path_) {
+ LOG(WARNING) << "Ignoring property update for cellular service "
+ << network->path()
+ << " on unknown device " << network->device_path()
+ << " (Stored device path = " << device_path_ << ")";
+ return;
+ }
+
+ // A modem reset leads to a new service path. Since we have verified that we
+ // are a cellular service on a still valid stored device path, update it.
+ service_path_ = network->path();
- EvaluateCellularNetwork(
- static_cast<CellularNetwork*>(const_cast<Network*>(network)));
+ EvaluateCellularNetwork(network);
}
void MobileActivator::AddObserver(MobileActivator::Observer* observer) {
@@ -234,15 +240,14 @@ 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 = 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;
@@ -252,6 +257,7 @@ void MobileActivator::InitiateActivation(const std::string& service_path) {
meid_ = device->meid();
iccid_ = device->iccid();
service_path_ = service_path;
+ device_path_ = network->device_path();
ChangeState(network, PLAN_ACTIVATION_PAGE_LOADING, "");
@@ -262,14 +268,21 @@ void MobileActivator::InitiateActivation(const std::string& service_path) {
}
void MobileActivator::ContinueActivation() {
- CellularNetwork* network = FindMatchingCellularNetwork(false);
- if (!network || !network->SupportsActivation())
+ const NetworkState* network = 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 +296,15 @@ 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 = 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 +320,7 @@ void MobileActivator::OnPortalLoaded(bool success) {
}
void MobileActivator::HandlePortalLoaded(bool success) {
- CellularNetwork* network = FindMatchingCellularNetwork(true);
+ const NetworkState* network = GetNetworkState(service_path_);
if (!network) {
ChangeState(NULL, PLAN_ACTIVATION_ERROR,
GetErrorMessage(kErrorNoService));
@@ -319,7 +334,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,31 +355,8 @@ 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() {
+ pending_activation_request_ = false;
state_duration_timer_.Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(kOTASPRetryDelay),
@@ -373,39 +365,44 @@ void MobileActivator::StartOTASPTimer() {
void MobileActivator::StartActivation() {
UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1);
- NetworkLibrary* lib = GetNetworkLibrary();
- CellularNetwork* network = FindMatchingCellularNetwork(true);
+ const NetworkState* network = 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) {
stevenjb 2013/08/28 21:22:47 ' ' after !=
gauravsh 2013/08/28 23:45:07 Done.
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);
+ RefreshCellularNetworks();
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 +418,14 @@ void MobileActivator::RetryOTASP() {
}
void MobileActivator::StartOTASP() {
- CellularNetwork* network = FindMatchingCellularNetwork(true);
+ const NetworkState* network = 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 = 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 +462,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 +493,24 @@ void MobileActivator::ForceReconnect(CellularNetwork* network,
void MobileActivator::ReconnectTimedOut() {
LOG(ERROR) << "Ending activation attempt after failing to reconnect.";
- ChangeState(FindMatchingCellularNetwork(true),
+ const NetworkState* network = 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 = 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 +519,43 @@ 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::RefreshCellularNetworks() {
+ if (state_ == PLAN_ACTIVATION_PAGE_LOADING ||
+ state_ == PLAN_ACTIVATION_DONE ||
+ state_ == PLAN_ACTIVATION_ERROR) {
+ return;
+ }
+
+ NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler();
+ const NetworkState* network = GetNetworkState(service_path_);
+ if (network && network->activate_over_non_cellular_networks()) {
+ bool waiting = (state_ == PLAN_ACTIVATION_WAITING_FOR_CONNECTION);
+ 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) {
+ ChangeState(network, PLAN_ACTIVATION_WAITING_FOR_CONNECTION, "");
+ }
+ }
+
+ EvaluateCellularNetwork(network);
+}
+
+const NetworkState*MobileActivator::GetNetworkState(
stevenjb 2013/08/28 21:22:47 ' ' after *
gauravsh 2013/08/28 23:45:07 Done.
+ const std::string& service_path) {
+ return NetworkHandler::Get()->network_state_handler()->GetNetworkState(
+ service_path);
+}
+
+void MobileActivator::EvaluateCellularNetwork(const NetworkState* network) {
if (terminated_) {
LOG(ERROR) << "Tried to run MobileActivator state machine while "
<< "terminated.";
@@ -534,16 +567,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 +586,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 +597,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;
stevenjb 2013/08/28 21:22:47 nit: not sure that local is_partially_activated ma
gauravsh 2013/08/28 23:45:07 Done.
+ if (is_partially_activated &&
+ (network->error().empty() ||
+ network->error() == flimflam::kErrorOtaspFailed) &&
+ network->connection_state() == flimflam::kStateActivationFailure) {
+ LOG(WARNING) << "Activation failure detected " << network->path();
stevenjb 2013/08/28 21:22:47 NET_LOG_EVENT()
gauravsh 2013/08/28 23:45:07 Done.
switch (state_) {
case PLAN_ACTIVATION_OTASP:
new_state = PLAN_ACTIVATION_DELAY_OTASP;
@@ -592,8 +627,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 +638,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 +698,36 @@ 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 (pending_activation_request_) {
+ LOG(INFO) << "Waiting for pending activation attempt to finish";
+ } else 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 (pending_activation_request_) {
+ LOG(INFO) << "Waiting for pending activation attempt to finish";
+ } else 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 +790,11 @@ const char* MobileActivator::GetStateDescription(PlanActivationState state) {
}
-void MobileActivator::CompleteActivation(
- CellularNetwork* network) {
+void MobileActivator::CompleteActivation() {
// 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 +806,44 @@ 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) {
+ pending_activation_request_ = false;
+ const NetworkState* network = GetNetworkState(service_path);
+ if (!network) {
+ NET_LOG_ERROR("Cellular service no longer exists", service_path);
+ return;
+ }
+ 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::RequestCellularActivation(
+ const NetworkState* network,
+ const base::Closure& success_callback,
+ const network_handler::ErrorCallback& error_callback) {
+ DCHECK(network);
+ NET_LOG_EVENT("Activating cellular service", network->path());
+ UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1);
+ pending_activation_request_ = true;
+ NetworkHandler::Get()->network_activation_handler()->
+ Activate(network->path(),
+ "", // carrier
+ success_callback,
+ error_callback);
+}
+
+void MobileActivator::ChangeState(const NetworkState* network,
PlanActivationState new_state,
const std::string& error_description) {
static bool first_time = true;
@@ -822,22 +881,16 @@ void MobileActivator::ChangeState(CellularNetwork* network,
break;
case PLAN_ACTIVATION_INITIATING_ACTIVATION:
case PLAN_ACTIVATION_TRYING_OTASP:
- case PLAN_ACTIVATION_OTASP:
+ case PLAN_ACTIVATION_OTASP: {
DCHECK(network);
- LOG(WARNING) << "Activating service " << network->service_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();
+ network_handler::ErrorCallback on_activation_error =
+ base::Bind(&MobileActivator::HandleActivationFailure, AsWeakPtr(),
+ network->path(),
+ new_state);
+ RequestCellularActivation(
+ network,
+ base::Bind(&MobileActivator::StartOTASPTimer, AsWeakPtr()),
+ on_activation_error);
}
break;
case PLAN_ACTIVATION_PAGE_LOADING:
@@ -866,7 +919,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
@@ -886,11 +939,11 @@ void MobileActivator::ChangeState(CellularNetwork* network,
}
case PLAN_ACTIVATION_DONE:
DCHECK(network);
- CompleteActivation(network);
+ CompleteActivation();
UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupSucceeded", 1);
break;
case PLAN_ACTIVATION_ERROR:
- CompleteActivation(NULL);
+ CompleteActivation();
UMA_HISTOGRAM_COUNTS("Cellular.PlanFailed", 1);
break;
default:
@@ -921,33 +974,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 +1012,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 +1034,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
« no previous file with comments | « chrome/browser/chromeos/mobile/mobile_activator.h ('k') | chrome/browser/chromeos/mobile/mobile_activator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698