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

Unified Diff: chrome/browser/ui/webui/chromeos/mobile_setup_ui.cc

Issue 22611005: Switch over MobileActivator to use Network*Handler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add activation handler files 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/ui/webui/chromeos/mobile_setup_ui.cc
diff --git a/chrome/browser/ui/webui/chromeos/mobile_setup_ui.cc b/chrome/browser/ui/webui/chromeos/mobile_setup_ui.cc
index b85a4b95cdfbe06a3f98083fab03a138bde9c3cc..f8068008a4d67ac48be354b207fb986974448748 100644
--- a/chrome/browser/ui/webui/chromeos/mobile_setup_ui.cc
+++ b/chrome/browser/ui/webui/chromeos/mobile_setup_ui.cc
@@ -26,6 +26,10 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
+#include "chromeos/network/device_state.h"
+#include "chromeos/network/network_state.h"
+#include "chromeos/network/network_state_handler.h"
+#include "chromeos/network/network_state_handler_observer.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_view_host_observer.h"
#include "content/public/browser/url_data_source.h"
@@ -36,15 +40,16 @@
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
+#include "third_party/cros_system_api/dbus/service_constants.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/webui/jstemplate_builder.h"
#include "ui/webui/web_ui_util.h"
#include "url/gurl.h"
-using chromeos::CellularNetwork;
using chromeos::MobileActivator;
-using chromeos::NetworkLibrary;
+using chromeos::NetworkHandler;
+using chromeos::NetworkState;
using content::BrowserThread;
using content::RenderViewHost;
using content::WebContents;
@@ -145,7 +150,7 @@ class MobileSetupUIHTMLSource : public content::URLDataSource {
class MobileSetupHandler
: public WebUIMessageHandler,
public MobileActivator::Observer,
- public NetworkLibrary::NetworkManagerObserver,
+ public chromeos::NetworkStateHandlerObserver,
public base::SupportsWeakPtr<MobileSetupHandler> {
public:
MobileSetupHandler();
@@ -167,9 +172,9 @@ class MobileSetupHandler
TYPE_PORTAL_LTE
};
- // Changes internal state.
+ // MobileActivator::Observer.
virtual void OnActivationStateChanged(
- CellularNetwork* network,
+ const NetworkState* network,
MobileActivator::PlanActivationState new_state,
const std::string& error_description) OVERRIDE;
@@ -179,21 +184,22 @@ class MobileSetupHandler
void HandlePaymentPortalLoad(const ListValue* args);
void HandleGetDeviceInfo(const ListValue* args);
- // NetworkLibrary::NetworkManagerObserver implementation.
- virtual void OnNetworkManagerChanged(NetworkLibrary* network_lib) OVERRIDE;
+ // NetworkStateHandlerObserver implementation.
+ virtual void NetworkManagerChanged() OVERRIDE;
+ virtual void DefaultNetworkChanged(
+ const NetworkState* default_network) OVERRIDE;
// Updates |lte_portal_reachable_| for lte network |network| and notifies
// webui of the new state if the reachability changed or |force_notification|
// is set.
- void UpdatePortalReachability(NetworkLibrary* network_lib,
- CellularNetwork* network,
+ void UpdatePortalReachability(const NetworkState* network,
bool force_notification);
// Sends message to host registration page with system/user info data.
void SendDeviceInfo();
// Converts the currently active CellularNetwork device into a JS object.
- static void GetDeviceInfo(CellularNetwork* network,
+ static void GetDeviceInfo(const NetworkState* network,
DictionaryValue* value);
// Type of the mobilesetup webui deduced from received messages.
@@ -224,12 +230,15 @@ void MobileSetupUIHTMLSource::StartDataRequest(
int render_process_id,
int render_view_id,
const content::URLDataSource::GotDataCallback& callback) {
- CellularNetwork* network = NULL;
+ const NetworkState* network = NULL;
if (!path.empty()) {
- network = NetworkLibrary::Get()-> FindCellularNetworkByPath(path);
+ network = NetworkHandler::Get()->network_state_handler()->GetNetworkState(
+ path);
}
- if (!network || (!network->SupportsActivation() && !network->activated())) {
+ if (!network ||
+ (network->payment_url().empty() && network->usage_url().empty() &&
+ network->activation_state() != flimflam::kActivationStateActivated)) {
LOG(WARNING) << "Can't find device to activate for service path " << path;
scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes);
callback.Run(html_bytes.get());
@@ -269,7 +278,7 @@ void MobileSetupUIHTMLSource::StartDataRequest(
// network is activated, the webui goes straight to portal. Otherwise the
// webui is used for activation flow.
std::string full_html;
- if (network->activated()) {
+ if (network->activation_state() == flimflam::kActivationStateActivated) {
static const base::StringPiece html_for_activated(
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_MOBILE_SETUP_PORTAL_PAGE_HTML));
@@ -299,12 +308,13 @@ MobileSetupHandler::~MobileSetupHandler() {
MobileActivator::GetInstance()->RemoveObserver(this);
MobileActivator::GetInstance()->TerminateActivation();
} else if (type_ == TYPE_PORTAL_LTE) {
- NetworkLibrary::Get()->RemoveNetworkManagerObserver(this);
+ NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
+ FROM_HERE);
}
}
void MobileSetupHandler::OnActivationStateChanged(
- CellularNetwork* network,
+ const NetworkState* network,
MobileActivator::PlanActivationState state,
const std::string& error_description) {
DCHECK_EQ(TYPE_ACTIVATION, type_);
@@ -396,9 +406,9 @@ void MobileSetupHandler::HandleGetDeviceInfo(const ListValue* args) {
if (path.empty())
return;
- NetworkLibrary* network_lib = NetworkLibrary::Get();
- CellularNetwork* network =
- network_lib->FindCellularNetworkByPath(path.substr(1));
+ chromeos::NetworkStateHandler* nsh =
+ NetworkHandler::Get()->network_state_handler();
+ const NetworkState* network = nsh->GetNetworkState(path.substr(1));
stevenjb 2013/08/14 02:28:31 the path.substr(1) should probably be assigned to
gauravsh 2013/08/14 21:42:29 The path is of the form //service/5, so the path.s
stevenjb 2013/08/14 21:58:35 I do not. We should at least add some sort of comm
armansito 2013/08/14 22:46:34 The URL should be obtained from the service in que
gauravsh 2013/08/15 01:46:35 Done.
if (!network) {
web_ui()->GetWebContents()->Close();
return;
@@ -408,16 +418,14 @@ void MobileSetupHandler::HandleGetDeviceInfo(const ListValue* args) {
// network changes, but only for LTE networks. The other networks should
// ignore network status.
if (type_ == TYPE_UNDETERMINED) {
- if (network->network_technology() == chromeos::NETWORK_TECHNOLOGY_LTE ||
+ if (network->network_technology() == flimflam::kNetworkTechnologyLte ||
network->network_technology() ==
- chromeos::NETWORK_TECHNOLOGY_LTE_ADVANCED) {
+ flimflam::kNetworkTechnologyLteAdvanced) {
type_ = TYPE_PORTAL_LTE;
- network_lib->AddNetworkManagerObserver(this);
+ nsh->AddObserver(this, FROM_HERE);
// Update the network status and notify the webui. This is the initial
// network state so the webui should be notified no matter what.
- UpdatePortalReachability(network_lib,
- network,
- true /*force notification*/);
+ UpdatePortalReachability(network, true /*force notification*/);
} else {
type_ = TYPE_PORTAL;
// For non-LTE networks network state is ignored, so report the portal is
@@ -432,7 +440,7 @@ void MobileSetupHandler::HandleGetDeviceInfo(const ListValue* args) {
web_ui()->CallJavascriptFunction(kJsGetDeviceInfoCallback, device_info);
}
-void MobileSetupHandler::OnNetworkManagerChanged(NetworkLibrary* network_lib) {
+void MobileSetupHandler::NetworkManagerChanged() {
if (!web_ui())
return;
@@ -440,27 +448,36 @@ void MobileSetupHandler::OnNetworkManagerChanged(NetworkLibrary* network_lib) {
if (path.empty())
return;
- CellularNetwork* network =
- network_lib->FindCellularNetworkByPath(path.substr(1));
+ const NetworkState* network =
+ NetworkHandler::Get()->network_state_handler()->GetNetworkState(
+ path.substr(1));
if (!network) {
LOG(ERROR) << "Service path lost";
web_ui()->GetWebContents()->Close();
return;
}
- UpdatePortalReachability(network_lib, network, false /*force notification*/);
+ UpdatePortalReachability(network, false /*force notification*/);
armansito 2013/08/14 00:49:51 The inline comment here makes me think that "false
gauravsh 2013/08/14 21:42:29 Done.
}
-void MobileSetupHandler::UpdatePortalReachability(NetworkLibrary* network_lib,
- CellularNetwork* network,
- bool force_notification) {
+void MobileSetupHandler::DefaultNetworkChanged(
+ const NetworkState* default_network) {
+ NetworkManagerChanged();
+}
+
+void MobileSetupHandler::UpdatePortalReachability(
+ const NetworkState* network,
+ bool force_notification) {
DCHECK(web_ui());
DCHECK_EQ(type_, TYPE_PORTAL_LTE);
- bool portal_reachable = network->connected() ||
- (network_lib->connected_network() &&
- network_lib->connected_network()->online());
+ chromeos::NetworkStateHandler* nsh =
+ NetworkHandler::Get()->network_state_handler();
+ bool portal_reachable =
+ (network->IsConnectedState() ||
+ (nsh->DefaultNetwork() &&
+ nsh->DefaultNetwork()->connection_state() == flimflam::kStateOnline));
if (force_notification || portal_reachable != lte_portal_reachable_) {
web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback,
@@ -470,7 +487,7 @@ void MobileSetupHandler::UpdatePortalReachability(NetworkLibrary* network_lib,
lte_portal_reachable_ = portal_reachable;
}
-void MobileSetupHandler::GetDeviceInfo(CellularNetwork* network,
+void MobileSetupHandler::GetDeviceInfo(const NetworkState* network,
DictionaryValue* value) {
DCHECK(network);
chromeos::NetworkLibrary* cros =
@@ -478,14 +495,15 @@ void MobileSetupHandler::GetDeviceInfo(CellularNetwork* network,
if (!cros)
return;
stevenjb 2013/08/14 02:28:31 Remove
gauravsh 2013/08/14 21:42:29 Done.
value->SetBoolean("activate_over_non_cellular_network",
- network->activate_over_non_cellular_network());
+ network->activate_over_non_cellular_networks());
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 chromeos::NetworkDevice* device =
- cros->FindNetworkDeviceByPath(network->device_path());
+ const chromeos::DeviceState* device =
+ NetworkHandler::Get()->network_state_handler()->GetDeviceState(
+ network->device_path());
if (device) {
value->SetString("MEID", device->meid());
value->SetString("IMEI", device->imei());

Powered by Google App Engine
This is Rietveld 408576698