| Index: chrome/browser/chromeos/mobile/mobile_activator.cc
|
| diff --git a/chrome/browser/ui/webui/chromeos/mobile_setup_ui.cc b/chrome/browser/chromeos/mobile/mobile_activator.cc
|
| similarity index 55%
|
| copy from chrome/browser/ui/webui/chromeos/mobile_setup_ui.cc
|
| copy to chrome/browser/chromeos/mobile/mobile_activator.cc
|
| index 3158f6494d30cee6ce4e3acd204d90060be58e9e..ade7d3ae9a0ab4956db61cec844f29eaa483d0c6 100644
|
| --- a/chrome/browser/ui/webui/chromeos/mobile_setup_ui.cc
|
| +++ b/chrome/browser/chromeos/mobile/mobile_activator.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/ui/webui/chromeos/mobile_setup_ui.h"
|
| +#include "chrome/browser/chromeos/mobile/mobile_activator.h"
|
|
|
| #include <algorithm>
|
| #include <map>
|
| @@ -12,11 +12,11 @@
|
| #include "base/bind_helpers.h"
|
| #include "base/file_util.h"
|
| #include "base/json/json_reader.h"
|
| -#include "base/json/json_writer.h"
|
| #include "base/logging.h"
|
| #include "base/memory/ref_counted_memory.h"
|
| #include "base/message_loop.h"
|
| #include "base/metrics/histogram.h"
|
| +#include "base/observer_list_threadsafe.h"
|
| #include "base/string_piece.h"
|
| #include "base/string_util.h"
|
| #include "base/timer.h"
|
| @@ -26,62 +26,13 @@
|
| #include "chrome/browser/chromeos/cros/cros_library.h"
|
| #include "chrome/browser/chromeos/cros/network_library.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| -#include "chrome/browser/profiles/profile.h"
|
| -#include "chrome/browser/ui/browser_list.h"
|
| -#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
|
| -#include "chrome/common/jstemplate_builder.h"
|
| #include "chrome/common/pref_names.h"
|
| -#include "chrome/common/render_messages.h"
|
| -#include "chrome/common/url_constants.h"
|
| #include "content/public/browser/browser_thread.h"
|
| -#include "content/public/browser/render_view_host_observer.h"
|
| -#include "content/public/browser/web_contents.h"
|
| -#include "content/public/browser/web_ui.h"
|
| -#include "content/public/browser/web_ui_message_handler.h"
|
| -#include "googleurl/src/gurl.h"
|
| -#include "grit/browser_resources.h"
|
| -#include "grit/chromium_strings.h"
|
| -#include "grit/generated_resources.h"
|
| -#include "grit/locale_settings.h"
|
| -#include "ui/base/l10n/l10n_util.h"
|
| -#include "ui/base/layout.h"
|
| -#include "ui/base/resource/resource_bundle.h"
|
|
|
| using content::BrowserThread;
|
| -using content::RenderViewHost;
|
| -using content::WebContents;
|
| -using content::WebUIMessageHandler;
|
|
|
| namespace {
|
|
|
| -// Host page JS API function names.
|
| -const char kJsApiStartActivation[] = "startActivation";
|
| -const char kJsApiSetTransactionStatus[] = "setTransactionStatus";
|
| -const char kJsApiPaymentPortalLoad[] = "paymentPortalLoad";
|
| -const char kJsApiResultOK[] = "ok";
|
| -
|
| -const char kJsDeviceStatusChangedCallback[] =
|
| - "mobile.MobileSetup.deviceStateChanged";
|
| -const char kJsPortalFrameLoadFailedCallback[] =
|
| - "mobile.MobileSetup.portalFrameLoadError";
|
| -const char kJsPortalFrameLoadCompletedCallback[] =
|
| - "mobile.MobileSetup.portalFrameLoadCompleted";
|
| -
|
| -// Error codes matching codes defined in the cellular config file.
|
| -const char kErrorDefault[] = "default";
|
| -const char kErrorBadConnectionPartial[] = "bad_connection_partial";
|
| -const char kErrorBadConnectionActivated[] = "bad_connection_activated";
|
| -const char kErrorRoamingOnConnection[] = "roaming_connection";
|
| -const char kErrorNoEVDO[] = "no_evdo";
|
| -const char kErrorRoamingActivation[] = "roaming_activation";
|
| -const char kErrorRoamingPartiallyActivated[] = "roaming_partially_activated";
|
| -const char kErrorNoService[] = "no_service";
|
| -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[] =
|
| "/usr/share/chromeos-assets/mobile/mobile_config.json";
|
| @@ -114,258 +65,34 @@ const int kFailedReconnectDelayMS = 10000;
|
| // Retry delay after failed OTASP attempt.
|
| const int kOTASPRetryDelay = 20000;
|
|
|
| -chromeos::CellularNetwork* GetCellularNetwork() {
|
| - chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()->
|
| - GetNetworkLibrary();
|
| - if (lib->cellular_networks().begin() != lib->cellular_networks().end()) {
|
| - return *(lib->cellular_networks().begin());
|
| - }
|
| - return NULL;
|
| -}
|
| +// Error codes matching codes defined in the cellular config file.
|
| +const char kErrorDefault[] = "default";
|
| +const char kErrorBadConnectionPartial[] = "bad_connection_partial";
|
| +const char kErrorBadConnectionActivated[] = "bad_connection_activated";
|
| +const char kErrorRoamingOnConnection[] = "roaming_connection";
|
| +const char kErrorNoEVDO[] = "no_evdo";
|
| +const char kErrorRoamingActivation[] = "roaming_activation";
|
| +const char kErrorRoamingPartiallyActivated[] = "roaming_partially_activated";
|
| +const char kErrorNoService[] = "no_service";
|
| +const char kErrorDisabled[] = "disabled";
|
| +const char kErrorNoDevice[] = "no_device";
|
| +const char kFailedPaymentError[] = "failed_payment";
|
| +const char kFailedConnectivity[] = "connectivity";
|
|
|
| } // namespace
|
|
|
| -// Observes IPC messages from the rederer and notifies JS if frame loading error
|
| -// appears.
|
| -class PortalFrameLoadObserver : public content::RenderViewHostObserver {
|
| - public:
|
| - PortalFrameLoadObserver(const base::WeakPtr<MobileSetupUI>& parent,
|
| - RenderViewHost* host)
|
| - : content::RenderViewHostObserver(host), parent_(parent) {
|
| - Send(new ChromeViewMsg_StartFrameSniffer(routing_id(),
|
| - UTF8ToUTF16("paymentForm")));
|
| - }
|
| -
|
| - // IPC::Channel::Listener implementation.
|
| - virtual bool OnMessageReceived(const IPC::Message& message) {
|
| - bool handled = true;
|
| - IPC_BEGIN_MESSAGE_MAP(PortalFrameLoadObserver, message)
|
| - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FrameLoadingError, OnFrameLoadError)
|
| - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FrameLoadingCompleted,
|
| - OnFrameLoadCompleted)
|
| - IPC_MESSAGE_UNHANDLED(handled = false)
|
| - IPC_END_MESSAGE_MAP()
|
| - return handled;
|
| - }
|
| -
|
| - private:
|
| - void OnFrameLoadError(int error) {
|
| - if (!parent_.get())
|
| - return;
|
| -
|
| - base::FundamentalValue result_value(error);
|
| - parent_->web_ui()->CallJavascriptFunction(kJsPortalFrameLoadFailedCallback,
|
| - result_value);
|
| - }
|
| -
|
| - void OnFrameLoadCompleted() {
|
| - if (!parent_.get())
|
| - return;
|
| -
|
| - parent_->web_ui()->CallJavascriptFunction(
|
| - kJsPortalFrameLoadCompletedCallback);
|
| - }
|
| -
|
| - base::WeakPtr<MobileSetupUI> parent_;
|
| - DISALLOW_COPY_AND_ASSIGN(PortalFrameLoadObserver);
|
| -};
|
| -
|
| -class CellularConfigDocument
|
| - : public base::RefCountedThreadSafe<CellularConfigDocument> {
|
| - public:
|
| - CellularConfigDocument() {}
|
| -
|
| - // Return error message for a given code.
|
| - std::string GetErrorMessage(const std::string& code);
|
| - void LoadCellularConfigFile();
|
| - const std::string& version() { return version_; }
|
| -
|
| - private:
|
| - typedef std::map<std::string, std::string> ErrorMap;
|
| -
|
| - void SetErrorMap(const ErrorMap& map);
|
| - bool LoadFromFile(const FilePath& config_path);
|
| -
|
| - std::string version_;
|
| - ErrorMap error_map_;
|
| - base::Lock config_lock_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(CellularConfigDocument);
|
| -};
|
| -
|
| -class MobileSetupUIHTMLSource : public ChromeURLDataManager::DataSource {
|
| - public:
|
| - explicit MobileSetupUIHTMLSource(const std::string& service_path);
|
| -
|
| - // Called when the network layer has requested a resource underneath
|
| - // the path we registered.
|
| - virtual void StartDataRequest(const std::string& path,
|
| - bool is_incognito,
|
| - int request_id);
|
| - virtual std::string GetMimeType(const std::string&) const {
|
| - return "text/html";
|
| - }
|
| -
|
| - private:
|
| - virtual ~MobileSetupUIHTMLSource() {}
|
| -
|
| - std::string service_path_;
|
| - DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource);
|
| -};
|
| -
|
| -// The handler for Javascript messages related to the "register" view.
|
| -class MobileSetupHandler
|
| - : public WebUIMessageHandler,
|
| - public chromeos::NetworkLibrary::NetworkManagerObserver,
|
| - public chromeos::NetworkLibrary::NetworkObserver,
|
| - public base::SupportsWeakPtr<MobileSetupHandler> {
|
| - public:
|
| - explicit MobileSetupHandler(const std::string& service_path);
|
| - virtual ~MobileSetupHandler();
|
| -
|
| - // Init work after Attach.
|
| - void StartActivationOnUIThread();
|
| -
|
| - // WebUIMessageHandler implementation.
|
| - virtual void RegisterMessages() OVERRIDE;
|
| -
|
| - // NetworkLibrary::NetworkManagerObserver implementation.
|
| - virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* obj) OVERRIDE;
|
| - // NetworkLibrary::NetworkObserver implementation.
|
| - virtual void OnNetworkChanged(chromeos::NetworkLibrary* obj,
|
| - const chromeos::Network* network) OVERRIDE;
|
| -
|
| - private:
|
| - typedef enum PlanActivationState {
|
| - PLAN_ACTIVATION_PAGE_LOADING = -1,
|
| - PLAN_ACTIVATION_START = 0,
|
| - PLAN_ACTIVATION_TRYING_OTASP = 1,
|
| - PLAN_ACTIVATION_RECONNECTING_OTASP_TRY = 2,
|
| - PLAN_ACTIVATION_INITIATING_ACTIVATION = 3,
|
| - PLAN_ACTIVATION_RECONNECTING = 4,
|
| - PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING = 5,
|
| - PLAN_ACTIVATION_SHOWING_PAYMENT = 6,
|
| - PLAN_ACTIVATION_RECONNECTING_PAYMENT = 7,
|
| - PLAN_ACTIVATION_DELAY_OTASP = 8,
|
| - PLAN_ACTIVATION_START_OTASP = 9,
|
| - PLAN_ACTIVATION_OTASP = 10,
|
| - PLAN_ACTIVATION_RECONNECTING_OTASP = 11,
|
| - PLAN_ACTIVATION_DONE = 12,
|
| - PLAN_ACTIVATION_ERROR = 0xFF,
|
| - } PlanActivationState;
|
| -
|
| - // Handlers for JS WebUI messages.
|
| - void HandleSetTransactionStatus(const ListValue* args);
|
| - void HandleStartActivation(const ListValue* args);
|
| - void HandlePaymentPortalLoad(const ListValue* args);
|
| - void SetTransactionStatus(const std::string& status);
|
| - // Starts activation.
|
| - void StartActivation();
|
| - // Retried OTASP.
|
| - void RetryOTASP();
|
| - // Continues activation process. This method is called after we disconnect
|
| - // due to detected connectivity issue to kick off reconnection.
|
| - void ContinueConnecting(int delay);
|
| -
|
| - // Sends message to host registration page with system/user info data.
|
| - void SendDeviceInfo();
|
| -
|
| - // Callback for when |reconnect_timer_| fires.
|
| - void ReconnectTimerFired();
|
| - // Starts OTASP process.
|
| - void StartOTASP();
|
| - // Checks if we need to reconnect due to failed connection attempt.
|
| - bool NeedsReconnecting(chromeos::CellularNetwork* network,
|
| - PlanActivationState* new_state,
|
| - std::string* error_description);
|
| - // Disconnect from network.
|
| - void DisconnectFromNetwork(chromeos::CellularNetwork* network);
|
| - // Connects to cellular network, resets connection timer.
|
| - bool ConnectToNetwork(chromeos::CellularNetwork* network, int delay);
|
| - // Forces disconnect / reconnect when we detect portal connectivity issues.
|
| - void ForceReconnect(chromeos::CellularNetwork* network, int delay);
|
| - // Reports connection timeout.
|
| - bool ConnectionTimeout();
|
| - // Verify the state of cellular network and modify internal state.
|
| - void EvaluateCellularNetwork(chromeos::CellularNetwork* network);
|
| - // Finds cellular network given device |meid|, reattach network change
|
| - // observer if |reattach_observer| flag is set.
|
| - chromeos::CellularNetwork* FindCellularNetworkByMeid(const std::string& meid,
|
| - bool reattach_observer);
|
| - // Check the current cellular network for error conditions.
|
| - bool GotActivationError(chromeos::CellularNetwork* network,
|
| - std::string* error);
|
| - // Sends status updates to WebUI page.
|
| - void UpdatePage(chromeos::CellularNetwork* network,
|
| - const std::string& error_description);
|
| - // Changes internal state.
|
| - void ChangeState(chromeos::CellularNetwork* network,
|
| - PlanActivationState new_state,
|
| - const std::string& error_description);
|
| - // Prepares network devices for cellular activation process.
|
| - void SetupActivationProcess(chromeos::CellularNetwork* network);
|
| - // Disables ethernet and wifi newtorks since they interefere with
|
| - // detection of restricted pool on cellular side.
|
| - void DisableOtherNetworks();
|
| - // Resets network devices after cellular activation process.
|
| - // |network| should be NULL if the activation process failed.
|
| - void CompleteActivation(chromeos::CellularNetwork* network);
|
| - // Control routines for handling other types of connections during
|
| - // cellular activation.
|
| - void ReEnableOtherConnections();
|
| - // Return error message for a given code.
|
| - std::string GetErrorMessage(const std::string& code);
|
| -
|
| - // Converts the currently active CellularNetwork device into a JS object.
|
| - static void GetDeviceInfo(chromeos::CellularNetwork* network,
|
| - DictionaryValue* value);
|
| - static bool ShouldReportDeviceState(std::string* state, std::string* error);
|
| -
|
| - // Performs activation state cellular device evaluation.
|
| - // Returns false if device activation failed. In this case |error|
|
| - // will contain error message to be reported to Web UI.
|
| - static bool EvaluateCellularDeviceState(bool* report_status,
|
| - std::string* state,
|
| - std::string* error);
|
| -
|
| - // Returns next reconnection state based on the current activation phase.
|
| - static PlanActivationState GetNextReconnectState(PlanActivationState state);
|
| - static const char* GetStateDescription(PlanActivationState state);
|
| -
|
| - scoped_refptr<CellularConfigDocument> cellular_config_;
|
| - // Internal handler state.
|
| - PlanActivationState state_;
|
| - std::string meid_;
|
| - std::string service_path_;
|
| - // Flags that control if wifi and ethernet connection needs to be restored
|
| - // after the activation of cellular network.
|
| - bool reenable_wifi_;
|
| - 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.
|
| - int reconnect_wait_count_;
|
| - // Payment portal reload/reconnect attempt count.
|
| - int payment_reconnect_count_;
|
| - // Activation retry attempt count;
|
| - int activation_attempt_;
|
| - // Connection start time.
|
| - base::Time connection_start_time_;
|
| - // Timer that monitors reconnection timeouts.
|
| - base::RepeatingTimer<MobileSetupHandler> reconnect_timer_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler);
|
| -};
|
| +namespace chromeos {
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| //
|
| // CellularConfigDocument
|
| //
|
| ////////////////////////////////////////////////////////////////////////////////
|
| +CellularConfigDocument::CellularConfigDocument() {
|
| +}
|
| +
|
| +CellularConfigDocument::~CellularConfigDocument() {
|
| +}
|
|
|
| std::string CellularConfigDocument::GetErrorMessage(const std::string& code) {
|
| base::AutoLock create(config_lock_);
|
| @@ -435,156 +162,124 @@ void CellularConfigDocument::SetErrorMap(
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| //
|
| -// MobileSetupUIHTMLSource
|
| +// MobileActivator
|
| //
|
| ////////////////////////////////////////////////////////////////////////////////
|
| -
|
| -MobileSetupUIHTMLSource::MobileSetupUIHTMLSource(
|
| - const std::string& service_path)
|
| - : DataSource(chrome::kChromeUIMobileSetupHost, MessageLoop::current()),
|
| - service_path_(service_path) {
|
| -}
|
| -
|
| -void MobileSetupUIHTMLSource::StartDataRequest(const std::string& path,
|
| - bool is_incognito,
|
| - int request_id) {
|
| - chromeos::CellularNetwork* network =
|
| - chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
|
| - FindCellularNetworkByPath(service_path_);
|
| -
|
| - // If we are activating, shutting down, or logging in, |network| may not
|
| - // be available.
|
| - if (!network || !network->SupportsActivation()) {
|
| - scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes);
|
| - SendResponse(request_id, html_bytes);
|
| - return;
|
| - }
|
| - DictionaryValue strings;
|
| - strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE));
|
| - strings.SetString("connecting_header",
|
| - l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER,
|
| - network ? UTF8ToUTF16(network->name()) : string16()));
|
| - strings.SetString("error_header",
|
| - l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER));
|
| - strings.SetString("activating_header",
|
| - l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER));
|
| - strings.SetString("completed_header",
|
| - l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER));
|
| - strings.SetString("please_wait",
|
| - l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT));
|
| - strings.SetString("completed_text",
|
| - l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT));
|
| - strings.SetString("close_button",
|
| - l10n_util::GetStringUTF16(IDS_CLOSE));
|
| - strings.SetString("cancel_button",
|
| - l10n_util::GetStringUTF16(IDS_CANCEL));
|
| - strings.SetString("ok_button",
|
| - l10n_util::GetStringUTF16(IDS_OK));
|
| - SetFontAndTextDirection(&strings);
|
| -
|
| - static const base::StringPiece html(
|
| - ResourceBundle::GetSharedInstance().GetRawDataResource(
|
| - IDR_MOBILE_SETUP_PAGE_HTML, ui::SCALE_FACTOR_NONE));
|
| -
|
| - std::string full_html = jstemplate_builder::GetI18nTemplateHtml(html,
|
| - &strings);
|
| -
|
| - SendResponse(request_id, base::RefCountedString::TakeString(&full_html));
|
| -}
|
| -
|
| -////////////////////////////////////////////////////////////////////////////////
|
| -//
|
| -// MobileSetupHandler
|
| -//
|
| -////////////////////////////////////////////////////////////////////////////////
|
| -MobileSetupHandler::MobileSetupHandler(const std::string& service_path)
|
| +MobileActivator::MobileActivator()
|
| : cellular_config_(new CellularConfigDocument()),
|
| state_(PLAN_ACTIVATION_PAGE_LOADING),
|
| - service_path_(service_path),
|
| reenable_wifi_(false),
|
| reenable_ethernet_(false),
|
| reenable_cert_check_(false),
|
| evaluating_(false),
|
| - already_running_(false),
|
| + terminated_(true),
|
| connection_retry_count_(0),
|
| reconnect_wait_count_(0),
|
| payment_reconnect_count_(0),
|
| activation_attempt_(0) {
|
| }
|
|
|
| -MobileSetupHandler::~MobileSetupHandler() {
|
| +MobileActivator::~MobileActivator() {
|
| + TerminateActivation();
|
| +}
|
| +
|
| +MobileActivator* MobileActivator::GetInstance() {
|
| + return Singleton<MobileActivator>::get();
|
| +}
|
| +
|
| +void MobileActivator::TerminateActivation() {
|
| reconnect_timer_.Stop();
|
| - chromeos::NetworkLibrary* lib =
|
| - chromeos::CrosLibrary::Get()->GetNetworkLibrary();
|
| + NetworkLibrary* lib =
|
| + CrosLibrary::Get()->GetNetworkLibrary();
|
| lib->RemoveNetworkManagerObserver(this);
|
| lib->RemoveObserverForAllNetworks(this);
|
| if (lib->IsLocked())
|
| lib->Unlock();
|
| ReEnableOtherConnections();
|
| + meid_.clear();
|
| + service_path_.clear();
|
| + state_ = PLAN_ACTIVATION_PAGE_LOADING;
|
| + reconnect_wait_count_ = 0;
|
| + evaluating_ = false;
|
| + reenable_wifi_ = false;
|
| + reenable_ethernet_ = false;
|
| + reenable_cert_check_ = false;
|
| + terminated_ = true;
|
| + cellular_config_ = NULL;
|
| }
|
|
|
| -void MobileSetupHandler::RegisterMessages() {
|
| - web_ui()->RegisterMessageCallback(kJsApiStartActivation,
|
| - base::Bind(&MobileSetupHandler::HandleStartActivation,
|
| - base::Unretained(this)));
|
| - web_ui()->RegisterMessageCallback(kJsApiSetTransactionStatus,
|
| - base::Bind(&MobileSetupHandler::HandleSetTransactionStatus,
|
| - base::Unretained(this)));
|
| - web_ui()->RegisterMessageCallback(kJsApiPaymentPortalLoad,
|
| - base::Bind(&MobileSetupHandler::HandlePaymentPortalLoad,
|
| - base::Unretained(this)));
|
| -}
|
| -
|
| -void MobileSetupHandler::OnNetworkManagerChanged(
|
| - chromeos::NetworkLibrary* cros) {
|
| +void MobileActivator::OnNetworkManagerChanged(NetworkLibrary* cros) {
|
| if (state_ == PLAN_ACTIVATION_PAGE_LOADING)
|
| return;
|
| - // Note that even though we get here when the service has
|
| - // reappeared after disappearing earlier in the activation
|
| - // process, there's no need to re-establish the NetworkObserver,
|
| - // because the service path remains the same.
|
| EvaluateCellularNetwork(FindCellularNetworkByMeid(meid_, true));
|
| }
|
|
|
| -void MobileSetupHandler::OnNetworkChanged(chromeos::NetworkLibrary* cros,
|
| - const chromeos::Network* network) {
|
| +void MobileActivator::OnNetworkChanged(NetworkLibrary* cros,
|
| + const Network* network) {
|
| if (state_ == PLAN_ACTIVATION_PAGE_LOADING)
|
| return;
|
| - DCHECK(network && network->type() == chromeos::TYPE_CELLULAR);
|
| +
|
| + if (!network || network->type() != TYPE_CELLULAR) {
|
| + NOTREACHED();
|
| + return;
|
| + }
|
| +
|
| EvaluateCellularNetwork(
|
| - static_cast<chromeos::CellularNetwork*>(
|
| - const_cast<chromeos::Network*>(network)));
|
| + static_cast<CellularNetwork*>(const_cast<Network*>(network)));
|
| +}
|
| +
|
| +void MobileActivator::AddObserver(MobileActivator::Observer* observer) {
|
| + observers_.AddObserver(observer);
|
| +}
|
| +
|
| +void MobileActivator::RemoveObserver(MobileActivator::Observer* observer) {
|
| + observers_.RemoveObserver(observer);
|
| }
|
|
|
| -void MobileSetupHandler::HandleStartActivation(const ListValue* args) {
|
| +void MobileActivator::InitiateActivation(const std::string& service_path) {
|
| + NetworkLibrary* lib = CrosLibrary::Get()->GetNetworkLibrary();
|
| + CellularNetwork* network = lib->FindCellularNetworkByPath(service_path);
|
| + if (!network) {
|
| + LOG(ERROR) << "Cellular service can't be found: " << service_path;
|
| + return;
|
| + }
|
| +
|
| + const chromeos::NetworkDevice* device =
|
| + lib->FindNetworkDeviceByPath(network->device_path());
|
| + if (!device) {
|
| + LOG(ERROR) << "Cellular device can't be found: " << network->device_path();
|
| + return;
|
| + }
|
| +
|
| + terminated_ = false;
|
| + meid_ = device->meid();
|
| + service_path_ = service_path;
|
| BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE,
|
| base::Bind(&CellularConfigDocument::LoadCellularConfigFile,
|
| cellular_config_.get()),
|
| - base::Bind(&MobileSetupHandler::StartActivationOnUIThread, AsWeakPtr()));
|
| + base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr()));
|
| }
|
|
|
| -void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) {
|
| - const size_t kSetTransactionStatusParamCount = 1;
|
| - if (args->GetSize() != kSetTransactionStatusParamCount)
|
| - return;
|
| - // Get change callback function name.
|
| - std::string status;
|
| - if (!args->GetString(0, &status))
|
| +void MobileActivator::ContinueActivation() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + CellularNetwork* network = FindCellularNetworkByMeid(meid_, false);
|
| + if (!network || !network->SupportsActivation())
|
| return;
|
| +
|
| + DCHECK(!CrosLibrary::Get()->GetNetworkLibrary()->IsLocked());
|
| + SetupActivationProcess(network);
|
| +
|
| + StartActivation();
|
| +}
|
| +
|
| +void MobileActivator::OnSetTransactionStatus(bool success) {
|
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&MobileSetupHandler::SetTransactionStatus, AsWeakPtr(),
|
| - status));
|
| + base::Bind(&MobileActivator::SetTransactionStatus,
|
| + AsWeakPtr(), success));
|
| }
|
|
|
| -void MobileSetupHandler::HandlePaymentPortalLoad(const ListValue* args) {
|
| - const size_t kPaymentPortalLoadParamCount = 1;
|
| - if (args->GetSize() != kPaymentPortalLoadParamCount)
|
| - return;
|
| - // Get change callback function name.
|
| - std::string result;
|
| - if (!args->GetString(0, &result))
|
| - return;
|
| - chromeos::CellularNetwork* network = FindCellularNetworkByMeid(meid_, true);
|
| +void MobileActivator::OnPortalLoaded(bool success) {
|
| + CellularNetwork* network = FindCellularNetworkByMeid(meid_, true);
|
| if (!network) {
|
| ChangeState(NULL, PLAN_ACTIVATION_ERROR,
|
| GetErrorMessage(kErrorNoService));
|
| @@ -592,7 +287,7 @@ void MobileSetupHandler::HandlePaymentPortalLoad(const ListValue* args) {
|
| }
|
| if (state_ == PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING ||
|
| state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) {
|
| - if (LowerCaseEqualsASCII(result, kJsApiResultOK)) {
|
| + if (success) {
|
| payment_reconnect_count_ = 0;
|
| ChangeState(network, PLAN_ACTIVATION_SHOWING_PAYMENT, std::string());
|
| } else {
|
| @@ -612,17 +307,16 @@ void MobileSetupHandler::HandlePaymentPortalLoad(const ListValue* args) {
|
| }
|
| }
|
|
|
| -chromeos::CellularNetwork* MobileSetupHandler::FindCellularNetworkByMeid(
|
| +CellularNetwork* MobileActivator::FindCellularNetworkByMeid(
|
| const std::string& meid, bool reattach_observer) {
|
| - chromeos::NetworkLibrary* lib =
|
| - chromeos::CrosLibrary::Get()->GetNetworkLibrary();
|
| - for (chromeos::CellularNetworkVector::const_iterator it =
|
| + NetworkLibrary* lib = CrosLibrary::Get()->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 == device->meid()) {
|
| - chromeos::CellularNetwork* network = *it;
|
| + CellularNetwork* network = *it;
|
| // If service path has changed, reattach the event observer for this
|
| // network service.
|
| if (reattach_observer && service_path_ != network->service_path()) {
|
| @@ -636,18 +330,16 @@ chromeos::CellularNetwork* MobileSetupHandler::FindCellularNetworkByMeid(
|
| return NULL;
|
| }
|
|
|
| -void MobileSetupHandler::StartActivation() {
|
| +void MobileActivator::StartActivation() {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1);
|
| - chromeos::NetworkLibrary* lib =
|
| - chromeos::CrosLibrary::Get()->GetNetworkLibrary();
|
| - chromeos::CellularNetwork* network = FindCellularNetworkByMeid(meid_, true);
|
| + NetworkLibrary* lib =
|
| + CrosLibrary::Get()->GetNetworkLibrary();
|
| + CellularNetwork* network = FindCellularNetworkByMeid(meid_, true);
|
| // Check if we can start activation process.
|
| - if (!network || already_running_) {
|
| + if (!network) {
|
| std::string error;
|
| - if (already_running_)
|
| - error = kErrorAlreadyRunning;
|
| - else if (!lib->cellular_available())
|
| + if (!lib->cellular_available())
|
| error = kErrorNoDevice;
|
| else if (!lib->cellular_enabled())
|
| error = kErrorDisabled;
|
| @@ -668,15 +360,15 @@ void MobileSetupHandler::StartActivation() {
|
| EvaluateCellularNetwork(network);
|
| }
|
|
|
| -void MobileSetupHandler::RetryOTASP() {
|
| +void MobileActivator::RetryOTASP() {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| DCHECK(state_ == PLAN_ACTIVATION_DELAY_OTASP);
|
| StartOTASP();
|
| }
|
|
|
| -void MobileSetupHandler::ContinueConnecting(int delay) {
|
| +void MobileActivator::ContinueConnecting(int delay) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - chromeos::CellularNetwork* network = FindCellularNetworkByMeid(meid_, true);
|
| + CellularNetwork* network = FindCellularNetworkByMeid(meid_, true);
|
| if (network && network->connecting_or_connected()) {
|
| EvaluateCellularNetwork(network);
|
| } else {
|
| @@ -684,14 +376,13 @@ void MobileSetupHandler::ContinueConnecting(int delay) {
|
| }
|
| }
|
|
|
| -void MobileSetupHandler::SetTransactionStatus(const std::string& status) {
|
| +void MobileActivator::SetTransactionStatus(bool success) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| // The payment is received, try to reconnect and check the status all over
|
| // again.
|
| - if (LowerCaseEqualsASCII(status, kJsApiResultOK) &&
|
| - state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) {
|
| - chromeos::NetworkLibrary* lib =
|
| - chromeos::CrosLibrary::Get()->GetNetworkLibrary();
|
| + if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) {
|
| + NetworkLibrary* lib =
|
| + CrosLibrary::Get()->GetNetworkLibrary();
|
| lib->SignalCellularPlanPayment();
|
| UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1);
|
| StartOTASP();
|
| @@ -700,20 +391,20 @@ void MobileSetupHandler::SetTransactionStatus(const std::string& status) {
|
| }
|
| }
|
|
|
| -void MobileSetupHandler::StartOTASP() {
|
| +void MobileActivator::StartOTASP() {
|
| state_ = PLAN_ACTIVATION_START_OTASP;
|
| - chromeos::CellularNetwork* network = FindCellularNetworkByMeid(meid_, true);
|
| + CellularNetwork* network = FindCellularNetworkByMeid(meid_, true);
|
| if (network &&
|
| network->connected() &&
|
| - network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATED) {
|
| - chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
|
| + network->activation_state() == ACTIVATION_STATE_ACTIVATED) {
|
| + CrosLibrary::Get()->GetNetworkLibrary()->
|
| DisconnectFromNetwork(network);
|
| } else {
|
| EvaluateCellularNetwork(network);
|
| }
|
| }
|
|
|
| -void MobileSetupHandler::ReconnectTimerFired() {
|
| +void MobileActivator::ReconnectTimerFired() {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| // Permit network connection changes only in reconnecting states.
|
| if (state_ != PLAN_ACTIVATION_RECONNECTING_OTASP_TRY &&
|
| @@ -721,7 +412,7 @@ void MobileSetupHandler::ReconnectTimerFired() {
|
| state_ != PLAN_ACTIVATION_RECONNECTING_PAYMENT &&
|
| state_ != PLAN_ACTIVATION_RECONNECTING_OTASP)
|
| return;
|
| - chromeos::CellularNetwork* network = FindCellularNetworkByMeid(meid_, true);
|
| + CellularNetwork* network = FindCellularNetworkByMeid(meid_, true);
|
| if (!network) {
|
| // No service, try again since this is probably just transient condition.
|
| LOG(WARNING) << "Service not present at reconnect attempt.";
|
| @@ -729,21 +420,19 @@ void MobileSetupHandler::ReconnectTimerFired() {
|
| EvaluateCellularNetwork(network);
|
| }
|
|
|
| -void MobileSetupHandler::DisconnectFromNetwork(
|
| - chromeos::CellularNetwork* network) {
|
| +void MobileActivator::DisconnectFromNetwork(CellularNetwork* network) {
|
| DCHECK(network);
|
| LOG(INFO) << "Disconnecting from: " << network->service_path();
|
| - chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
|
| + CrosLibrary::Get()->GetNetworkLibrary()->
|
| DisconnectFromNetwork(network);
|
| // Disconnect will force networks to be reevaluated, so
|
| // we don't want to continue processing on this path anymore.
|
| evaluating_ = false;
|
| }
|
|
|
| -bool MobileSetupHandler::NeedsReconnecting(
|
| - chromeos::CellularNetwork* network,
|
| - PlanActivationState* new_state,
|
| - std::string* error_description) {
|
| +bool MobileActivator::NeedsReconnecting(CellularNetwork* network,
|
| + PlanActivationState* new_state,
|
| + std::string* error_description) {
|
| DCHECK(network);
|
| if (!network->failed() && !ConnectionTimeout())
|
| return false;
|
| @@ -764,9 +453,7 @@ bool MobileSetupHandler::NeedsReconnecting(
|
| return false;
|
| }
|
|
|
| -bool MobileSetupHandler::ConnectToNetwork(
|
| - chromeos::CellularNetwork* network,
|
| - int delay) {
|
| +bool MobileActivator::ConnectToNetwork(CellularNetwork* network, int delay) {
|
| if (network && network->connecting_or_connected())
|
| return true;
|
| // Permit network connection changes only in reconnecting states.
|
| @@ -778,24 +465,22 @@ bool MobileSetupHandler::ConnectToNetwork(
|
| LOG(INFO) << "Connecting to: " << network->service_path();
|
| connection_retry_count_++;
|
| connection_start_time_ = base::Time::Now();
|
| - if (!network) {
|
| - LOG(WARNING) << "Connect failed."
|
| + if (!network || state_ == PLAN_ACTIVATION_RECONNECTING_OTASP) {
|
| + LOG(WARNING) << "Delaying reconnect to "
|
| << (network ? network->service_path().c_str() : "no service");
|
| // If we coudn't connect during reconnection phase, try to reconnect
|
| // with a delay (and try to reconnect if needed).
|
| BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&MobileSetupHandler::ContinueConnecting, AsWeakPtr(), delay),
|
| + base::Bind(&MobileActivator::ContinueConnecting, AsWeakPtr(), delay),
|
| base::TimeDelta::FromMilliseconds(delay));
|
| return false;
|
| }
|
| - chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
|
| + CrosLibrary::Get()->GetNetworkLibrary()->
|
| ConnectToCellularNetwork(network);
|
| return true;
|
| }
|
|
|
| -void MobileSetupHandler::ForceReconnect(
|
| - chromeos::CellularNetwork* network,
|
| - int delay) {
|
| +void MobileActivator::ForceReconnect(CellularNetwork* network, int delay) {
|
| DCHECK(network);
|
| UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1);
|
| // Reset reconnect metrics.
|
| @@ -803,22 +488,21 @@ void MobileSetupHandler::ForceReconnect(
|
| connection_start_time_ = base::Time();
|
| // First, disconnect...
|
| LOG(INFO) << "Disconnecting from " << network->service_path();
|
| - chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
|
| + CrosLibrary::Get()->GetNetworkLibrary()->
|
| DisconnectFromNetwork(network);
|
| // Check the network state 3s after we disconnect to make sure.
|
| BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&MobileSetupHandler::ContinueConnecting, AsWeakPtr(), delay),
|
| + base::Bind(&MobileActivator::ContinueConnecting, AsWeakPtr(), delay),
|
| base::TimeDelta::FromMilliseconds(delay));
|
| }
|
|
|
| -bool MobileSetupHandler::ConnectionTimeout() {
|
| +bool MobileActivator::ConnectionTimeout() {
|
| return (base::Time::Now() -
|
| connection_start_time_).InSeconds() > kConnectionTimeoutSeconds;
|
| }
|
|
|
| -void MobileSetupHandler::EvaluateCellularNetwork(
|
| - chromeos::CellularNetwork* network) {
|
| - if (!web_ui())
|
| +void MobileActivator::EvaluateCellularNetwork(CellularNetwork* network) {
|
| + if (terminated_)
|
| return;
|
|
|
| PlanActivationState new_state = state_;
|
| @@ -851,7 +535,7 @@ void MobileSetupHandler::EvaluateCellularNetwork(
|
| switch (state_) {
|
| case PLAN_ACTIVATION_START: {
|
| switch (network->activation_state()) {
|
| - case chromeos::ACTIVATION_STATE_ACTIVATED: {
|
| + case ACTIVATION_STATE_ACTIVATED: {
|
| if (network->disconnected()) {
|
| new_state = PLAN_ACTIVATION_RECONNECTING;
|
| } else if (network->connected()) {
|
| @@ -865,9 +549,9 @@ void MobileSetupHandler::EvaluateCellularNetwork(
|
| }
|
| default: {
|
| if (network->disconnected() ||
|
| - network->state() == chromeos::STATE_ACTIVATION_FAILURE) {
|
| + network->state() == STATE_ACTIVATION_FAILURE) {
|
| new_state = (network->activation_state() ==
|
| - chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED) ?
|
| + ACTIVATION_STATE_PARTIALLY_ACTIVATED) ?
|
| PLAN_ACTIVATION_TRYING_OTASP :
|
| PLAN_ACTIVATION_INITIATING_ACTIVATION;
|
| } else if (network->connected()) {
|
| @@ -881,7 +565,7 @@ void MobileSetupHandler::EvaluateCellularNetwork(
|
| }
|
| case PLAN_ACTIVATION_START_OTASP: {
|
| switch (network->activation_state()) {
|
| - case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: {
|
| + case ACTIVATION_STATE_PARTIALLY_ACTIVATED: {
|
| if (network->disconnected()) {
|
| new_state = PLAN_ACTIVATION_OTASP;
|
| } else if (network->connected()) {
|
| @@ -890,7 +574,7 @@ void MobileSetupHandler::EvaluateCellularNetwork(
|
| }
|
| break;
|
| }
|
| - case chromeos::ACTIVATION_STATE_ACTIVATED:
|
| + case ACTIVATION_STATE_ACTIVATED:
|
| new_state = PLAN_ACTIVATION_RECONNECTING_OTASP;
|
| break;
|
| default: {
|
| @@ -907,12 +591,12 @@ void MobileSetupHandler::EvaluateCellularNetwork(
|
| return;
|
| case PLAN_ACTIVATION_INITIATING_ACTIVATION: {
|
| switch (network->activation_state()) {
|
| - case chromeos::ACTIVATION_STATE_ACTIVATED:
|
| - case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED:
|
| + case ACTIVATION_STATE_ACTIVATED:
|
| + case ACTIVATION_STATE_PARTIALLY_ACTIVATED:
|
| new_state = PLAN_ACTIVATION_START;
|
| break;
|
| - case chromeos::ACTIVATION_STATE_NOT_ACTIVATED:
|
| - case chromeos::ACTIVATION_STATE_ACTIVATING:
|
| + case ACTIVATION_STATE_NOT_ACTIVATED:
|
| + case ACTIVATION_STATE_ACTIVATING:
|
| // Wait in this state until activation state changes.
|
| break;
|
| default:
|
| @@ -923,7 +607,7 @@ void MobileSetupHandler::EvaluateCellularNetwork(
|
| case PLAN_ACTIVATION_OTASP:
|
| case PLAN_ACTIVATION_TRYING_OTASP: {
|
| switch (network->activation_state()) {
|
| - case chromeos::ACTIVATION_STATE_ACTIVATED:
|
| + case ACTIVATION_STATE_ACTIVATED:
|
| if (network->disconnected()) {
|
| new_state = GetNextReconnectState(state_);
|
| } else if (network->connected()) {
|
| @@ -934,7 +618,7 @@ void MobileSetupHandler::EvaluateCellularNetwork(
|
| }
|
| }
|
| break;
|
| - case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED:
|
| + case ACTIVATION_STATE_PARTIALLY_ACTIVATED:
|
| if (network->connected()) {
|
| if (network->restricted_pool())
|
| new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING;
|
| @@ -942,8 +626,8 @@ void MobileSetupHandler::EvaluateCellularNetwork(
|
| new_state = GetNextReconnectState(state_);
|
| }
|
| break;
|
| - case chromeos::ACTIVATION_STATE_NOT_ACTIVATED:
|
| - case chromeos::ACTIVATION_STATE_ACTIVATING:
|
| + case ACTIVATION_STATE_NOT_ACTIVATED:
|
| + case ACTIVATION_STATE_ACTIVATING:
|
| // Wait in this state until activation state changes.
|
| break;
|
| default:
|
| @@ -960,10 +644,10 @@ void MobileSetupHandler::EvaluateCellularNetwork(
|
| DisableOtherNetworks();
|
| // Wait until the service shows up and gets activated.
|
| switch (network->activation_state()) {
|
| - case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED:
|
| - case chromeos::ACTIVATION_STATE_ACTIVATED:
|
| + case ACTIVATION_STATE_PARTIALLY_ACTIVATED:
|
| + case ACTIVATION_STATE_ACTIVATED:
|
| if (network->restricted_pool()) {
|
| - if (network->error() == chromeos::ERROR_DNS_LOOKUP_FAILED) {
|
| + if (network->error() == ERROR_DNS_LOOKUP_FAILED) {
|
| LOG(WARNING) << "No connectivity for device "
|
| << network->service_path().c_str();
|
| // If we are connected but there is no connectivity at all,
|
| @@ -987,7 +671,7 @@ void MobileSetupHandler::EvaluateCellularNetwork(
|
| new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING;
|
| }
|
| } else if (network->activation_state() ==
|
| - chromeos::ACTIVATION_STATE_ACTIVATED) {
|
| + ACTIVATION_STATE_ACTIVATED) {
|
| new_state = PLAN_ACTIVATION_DONE;
|
| }
|
| break;
|
| @@ -1007,8 +691,8 @@ void MobileSetupHandler::EvaluateCellularNetwork(
|
| DisableOtherNetworks();
|
| // Wait until the service shows up and gets activated.
|
| switch (network->activation_state()) {
|
| - case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED:
|
| - case chromeos::ACTIVATION_STATE_ACTIVATED:
|
| + case ACTIVATION_STATE_PARTIALLY_ACTIVATED:
|
| + case ACTIVATION_STATE_ACTIVATED:
|
| if (network->restricted_pool()) {
|
| LOG(WARNING) << "Still no connectivity after OTASP for device "
|
| << network->service_path().c_str();
|
| @@ -1060,11 +744,11 @@ void MobileSetupHandler::EvaluateCellularNetwork(
|
| // activated device. If that attempt failed, try to disconnect to clear the
|
| // state and reconnect again.
|
| if ((network->activation_state() ==
|
| - chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED ||
|
| - network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATING) &&
|
| - (network->error() == chromeos::ERROR_NO_ERROR ||
|
| - network->error() == chromeos::ERROR_OTASP_FAILED) &&
|
| - network->state() == chromeos::STATE_ACTIVATION_FAILURE) {
|
| + 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().c_str();
|
| switch (state_) {
|
| @@ -1106,9 +790,8 @@ void MobileSetupHandler::EvaluateCellularNetwork(
|
| evaluating_ = false;
|
| }
|
|
|
| -MobileSetupHandler::PlanActivationState
|
| - MobileSetupHandler::GetNextReconnectState(
|
| - MobileSetupHandler::PlanActivationState state) {
|
| +MobileActivator::PlanActivationState MobileActivator::GetNextReconnectState(
|
| + MobileActivator::PlanActivationState state) {
|
| switch (state) {
|
| case PLAN_ACTIVATION_INITIATING_ACTIVATION:
|
| return PLAN_ACTIVATION_RECONNECTING;
|
| @@ -1122,8 +805,7 @@ MobileSetupHandler::PlanActivationState
|
| }
|
|
|
| // Debugging helper function, will take it out at the end.
|
| -const char* MobileSetupHandler::GetStateDescription(
|
| - PlanActivationState state) {
|
| +const char* MobileActivator::GetStateDescription(PlanActivationState state) {
|
| switch (state) {
|
| case PLAN_ACTIVATION_PAGE_LOADING:
|
| return "PAGE_LOADING";
|
| @@ -1160,10 +842,10 @@ const char* MobileSetupHandler::GetStateDescription(
|
| }
|
|
|
|
|
| -void MobileSetupHandler::CompleteActivation(
|
| - chromeos::CellularNetwork* network) {
|
| +void MobileActivator::CompleteActivation(
|
| + CellularNetwork* network) {
|
| // Remove observers, we are done with this page.
|
| - chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()->
|
| + NetworkLibrary* lib = CrosLibrary::Get()->
|
| GetNetworkLibrary();
|
| lib->RemoveNetworkManagerObserver(this);
|
| lib->RemoveObserverForAllNetworks(this);
|
| @@ -1177,23 +859,15 @@ void MobileSetupHandler::CompleteActivation(
|
| ReEnableOtherConnections();
|
| }
|
|
|
| -void MobileSetupHandler::UpdatePage(
|
| - chromeos::CellularNetwork* network,
|
| - const std::string& error_description) {
|
| - DictionaryValue device_dict;
|
| - if (network)
|
| - GetDeviceInfo(network, &device_dict);
|
| - device_dict.SetInteger("state", state_);
|
| - if (error_description.length())
|
| - device_dict.SetString("error", error_description);
|
| - web_ui()->CallJavascriptFunction(
|
| - kJsDeviceStatusChangedCallback, device_dict);
|
| +bool MobileActivator::RunningActivation() const {
|
| + return !(state_ == PLAN_ACTIVATION_DONE ||
|
| + state_ == PLAN_ACTIVATION_ERROR ||
|
| + state_ == PLAN_ACTIVATION_PAGE_LOADING);
|
| }
|
|
|
| -
|
| -void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network,
|
| - PlanActivationState new_state,
|
| - const std::string& error_description) {
|
| +void MobileActivator::ChangeState(CellularNetwork* network,
|
| + PlanActivationState new_state,
|
| + const std::string& error_description) {
|
| static bool first_time = true;
|
| if (state_ == new_state && !first_time)
|
| return;
|
| @@ -1216,8 +890,9 @@ void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network,
|
| }
|
| state_ = new_state;
|
|
|
| - // Signal to JS layer that the state is changing.
|
| - UpdatePage(network, error_description);
|
| + // Signal to observers layer that the state is changing.
|
| + FOR_EACH_OBSERVER(Observer, observers_,
|
| + OnActivationStateChanged(network, state_, error_description));
|
|
|
| // Pick action that should happen on entering the new state.
|
| switch (new_state) {
|
| @@ -1226,7 +901,7 @@ void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network,
|
| case PLAN_ACTIVATION_DELAY_OTASP: {
|
| UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1);
|
| BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&MobileSetupHandler::RetryOTASP, AsWeakPtr()),
|
| + base::Bind(&MobileActivator::RetryOTASP, AsWeakPtr()),
|
| base::TimeDelta::FromMilliseconds(kOTASPRetryDelay));
|
| break;
|
| }
|
| @@ -1256,7 +931,7 @@ void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network,
|
| reconnect_timer_.Start(
|
| FROM_HERE,
|
| base::TimeDelta::FromMilliseconds(kReconnectTimerDelayMS),
|
| - this, &MobileSetupHandler::ReconnectTimerFired);
|
| + this, &MobileActivator::ReconnectTimerFired);
|
| }
|
| // Reset connection metrics and try to connect.
|
| reconnect_wait_count_ = 0;
|
| @@ -1286,9 +961,8 @@ void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network,
|
| }
|
| }
|
|
|
| -void MobileSetupHandler::ReEnableOtherConnections() {
|
| - chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()->
|
| - GetNetworkLibrary();
|
| +void MobileActivator::ReEnableOtherConnections() {
|
| + NetworkLibrary* lib = CrosLibrary::Get()->GetNetworkLibrary();
|
| if (reenable_ethernet_) {
|
| reenable_ethernet_ = false;
|
| lib->EnableEthernetNetworkDevice(true);
|
| @@ -1306,8 +980,7 @@ void MobileSetupHandler::ReEnableOtherConnections() {
|
| }
|
| }
|
|
|
| -void MobileSetupHandler::SetupActivationProcess(
|
| - chromeos::CellularNetwork* network) {
|
| +void MobileActivator::SetupActivationProcess(CellularNetwork* network) {
|
| if (!network)
|
| return;
|
|
|
| @@ -1321,7 +994,7 @@ void MobileSetupHandler::SetupActivationProcess(
|
| prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false);
|
| }
|
|
|
| - chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()->
|
| + NetworkLibrary* lib = CrosLibrary::Get()->
|
| GetNetworkLibrary();
|
| // Disable autoconnect to cellular network.
|
| network->SetAutoConnect(false);
|
| @@ -1331,9 +1004,8 @@ void MobileSetupHandler::SetupActivationProcess(
|
| lib->Lock();
|
| }
|
|
|
| -void MobileSetupHandler::DisableOtherNetworks() {
|
| - chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()->
|
| - GetNetworkLibrary();
|
| +void MobileActivator::DisableOtherNetworks() {
|
| + NetworkLibrary* lib = CrosLibrary::Get()->GetNetworkLibrary();
|
| // Disable ethernet and wifi.
|
| if (lib->ethernet_enabled()) {
|
| reenable_ethernet_ = true;
|
| @@ -1345,38 +1017,38 @@ void MobileSetupHandler::DisableOtherNetworks() {
|
| }
|
| }
|
|
|
| -bool MobileSetupHandler::GotActivationError(
|
| - chromeos::CellularNetwork* network, std::string* error) {
|
| +bool MobileActivator::GotActivationError(
|
| + CellularNetwork* network, std::string* error) {
|
| DCHECK(network);
|
| bool got_error = false;
|
| const char* error_code = kErrorDefault;
|
|
|
| // This is the magic for detection of errors in during activation process.
|
| - if (network->state() == chromeos::STATE_FAILURE &&
|
| - network->error() == chromeos::ERROR_AAA_FAILED) {
|
| + if (network->state() == STATE_FAILURE &&
|
| + network->error() == ERROR_AAA_FAILED) {
|
| if (network->activation_state() ==
|
| - chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED) {
|
| + ACTIVATION_STATE_PARTIALLY_ACTIVATED) {
|
| error_code = kErrorBadConnectionPartial;
|
| } else if (network->activation_state() ==
|
| - chromeos::ACTIVATION_STATE_ACTIVATED) {
|
| - if (network->roaming_state() == chromeos::ROAMING_STATE_HOME) {
|
| + ACTIVATION_STATE_ACTIVATED) {
|
| + if (network->roaming_state() == ROAMING_STATE_HOME) {
|
| error_code = kErrorBadConnectionActivated;
|
| - } else if (network->roaming_state() == chromeos::ROAMING_STATE_ROAMING) {
|
| + } else if (network->roaming_state() == ROAMING_STATE_ROAMING) {
|
| error_code = kErrorRoamingOnConnection;
|
| }
|
| }
|
| got_error = true;
|
| - } else if (network->state() == chromeos::STATE_ACTIVATION_FAILURE) {
|
| - if (network->error() == chromeos::ERROR_NEED_EVDO) {
|
| + } else if (network->state() == STATE_ACTIVATION_FAILURE) {
|
| + if (network->error() == ERROR_NEED_EVDO) {
|
| if (network->activation_state() ==
|
| - chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED)
|
| + ACTIVATION_STATE_PARTIALLY_ACTIVATED)
|
| error_code = kErrorNoEVDO;
|
| - } else if (network->error() == chromeos::ERROR_NEED_HOME_NETWORK) {
|
| + } else if (network->error() == ERROR_NEED_HOME_NETWORK) {
|
| if (network->activation_state() ==
|
| - chromeos::ACTIVATION_STATE_NOT_ACTIVATED) {
|
| + ACTIVATION_STATE_NOT_ACTIVATED) {
|
| error_code = kErrorRoamingActivation;
|
| } else if (network->activation_state() ==
|
| - chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED) {
|
| + ACTIVATION_STATE_PARTIALLY_ACTIVATED) {
|
| error_code = kErrorRoamingPartiallyActivated;
|
| }
|
| }
|
| @@ -1389,11 +1061,11 @@ bool MobileSetupHandler::GotActivationError(
|
| return got_error;
|
| }
|
|
|
| -void MobileSetupHandler::GetDeviceInfo(chromeos::CellularNetwork* network,
|
| - DictionaryValue* value) {
|
| +void MobileActivator::GetDeviceInfo(CellularNetwork* network,
|
| + DictionaryValue* value) {
|
| DCHECK(network);
|
| - chromeos::NetworkLibrary* cros =
|
| - chromeos::CrosLibrary::Get()->GetNetworkLibrary();
|
| + NetworkLibrary* cros =
|
| + CrosLibrary::Get()->GetNetworkLibrary();
|
| if (!cros)
|
| return;
|
| value->SetString("carrier", network->name());
|
| @@ -1401,7 +1073,7 @@ void MobileSetupHandler::GetDeviceInfo(chromeos::CellularNetwork* network,
|
| if (network->using_post() && network->post_data().length())
|
| value->SetString("post_data", network->post_data());
|
|
|
| - const chromeos::NetworkDevice* device =
|
| + const NetworkDevice* device =
|
| cros->FindNetworkDeviceByPath(network->device_path());
|
| if (device) {
|
| value->SetString("MEID", device->meid());
|
| @@ -1410,59 +1082,8 @@ void MobileSetupHandler::GetDeviceInfo(chromeos::CellularNetwork* network,
|
| }
|
| }
|
|
|
| -std::string MobileSetupHandler::GetErrorMessage(const std::string& code) {
|
| +std::string MobileActivator::GetErrorMessage(const std::string& code) {
|
| return cellular_config_->GetErrorMessage(code);
|
| }
|
|
|
| -void MobileSetupHandler::StartActivationOnUIThread() {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - chromeos::NetworkLibrary* lib =
|
| - chromeos::CrosLibrary::Get()->GetNetworkLibrary();
|
| -
|
| - chromeos::CellularNetwork* network =
|
| - lib->FindCellularNetworkByPath(service_path_);
|
| -
|
| - if (!network || !network->SupportsActivation()) {
|
| - LOG(ERROR) << "Cellular service can't be found: " << service_path_;
|
| - return;
|
| - }
|
| -
|
| - const chromeos::NetworkDevice* device =
|
| - lib->FindNetworkDeviceByPath(network->device_path());
|
| - if (!device) {
|
| - LOG(ERROR) << "Cellular device can't be found: " << network->device_path();
|
| - return;
|
| - }
|
| -
|
| - meid_ = device->meid();
|
| - if (!chromeos::CrosLibrary::Get()->GetNetworkLibrary()->IsLocked())
|
| - SetupActivationProcess(network);
|
| - else
|
| - already_running_ = true;
|
| -
|
| - StartActivation();
|
| -}
|
| -
|
| -////////////////////////////////////////////////////////////////////////////////
|
| -//
|
| -// MobileSetupUI
|
| -//
|
| -////////////////////////////////////////////////////////////////////////////////
|
| -
|
| -MobileSetupUI::MobileSetupUI(content::WebUI* web_ui)
|
| - : WebUIController(web_ui) {
|
| - chromeos::CellularNetwork* network = GetCellularNetwork();
|
| - std::string service_path = network ? network->service_path() : std::string();
|
| - web_ui->AddMessageHandler(new MobileSetupHandler(service_path));
|
| - MobileSetupUIHTMLSource* html_source =
|
| - new MobileSetupUIHTMLSource(service_path);
|
| -
|
| - // Set up the chrome://mobilesetup/ source.
|
| - Profile* profile = Profile::FromWebUI(web_ui);
|
| - ChromeURLDataManager::AddDataSource(profile, html_source);
|
| -}
|
| -
|
| -void MobileSetupUI::RenderViewCreated(RenderViewHost* host) {
|
| - // Destroyed by the corresponding RenderViewHost
|
| - new PortalFrameLoadObserver(AsWeakPtr(), host);
|
| -}
|
| +} // namespace chromeos
|
|
|