summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorstevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-16 18:17:54 +0000
committerstevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-16 18:17:54 +0000
commita4a89cfcd896832434ccf2d2502e3d06a91541d2 (patch)
treeab489cdf456acc94d61984995606aed92c6e90e6 /chrome
parent524283de25962f9182fe37975c4245012f722b60 (diff)
downloadchromium_src-a4a89cfcd896832434ccf2d2502e3d06a91541d2.zip
chromium_src-a4a89cfcd896832434ccf2d2502e3d06a91541d2.tar.gz
chromium_src-a4a89cfcd896832434ccf2d2502e3d06a91541d2.tar.bz2
Request data plans when activation state changes.
Also request data plans when requesting a network scan (i.e. when the network menu is opened). BUG=chromium-os:13042 TEST=Make sure network menu continues to update correctly and indicates 'scanning' when first opened. Review URL: http://codereview.chromium.org/6680014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78396 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/cros/mock_network_library.h3
-rw-r--r--chrome/browser/chromeos/cros/network_library.cc69
-rw-r--r--chrome/browser/chromeos/cros/network_library.h17
-rw-r--r--chrome/browser/chromeos/status/network_menu.cc2
-rw-r--r--chrome/browser/chromeos/webui/internet_options_handler.cc8
-rw-r--r--chrome/browser/chromeos/webui/internet_options_handler.h1
6 files changed, 68 insertions, 32 deletions
diff --git a/chrome/browser/chromeos/cros/mock_network_library.h b/chrome/browser/chromeos/cros/mock_network_library.h
index 7c8f15d..66cb71a 100644
--- a/chrome/browser/chromeos/cros/mock_network_library.h
+++ b/chrome/browser/chromeos/cros/mock_network_library.h
@@ -66,7 +66,7 @@ class MockNetworkLibrary : public NetworkLibrary {
MOCK_CONST_METHOD1(GetSignificantDataPlan,
CellularDataPlan*(const std::string&));
- MOCK_METHOD0(RequestWifiScan, void(void));
+ MOCK_METHOD0(RequestNetworkScan, void(void));
MOCK_METHOD1(GetWifiAccessPoints, bool(WifiAccessPointVector*));
MOCK_METHOD1(ConnectToWifiNetwork, void(WifiNetwork*));
MOCK_METHOD1(ConnectToWifiNetwork, void(const std::string&));
@@ -77,7 +77,6 @@ class MockNetworkLibrary : public NetworkLibrary {
const std::string&,
bool));
MOCK_METHOD1(ConnectToCellularNetwork, void(const CellularNetwork*));
- MOCK_METHOD1(RefreshCellularDataPlans, void(const CellularNetwork* network));
MOCK_METHOD0(SignalCellularPlanPayment, void(void));
MOCK_METHOD0(HasRecentCellularPlanPayment, bool(void));
diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc
index 3f6c816..551a21b 100644
--- a/chrome/browser/chromeos/cros/network_library.cc
+++ b/chrome/browser/chromeos/cros/network_library.cc
@@ -702,9 +702,6 @@ bool Network::ParseValue(int index, const Value* value) {
// State changed, so refresh IP address.
// Note: blocking DBus call. TODO(stevenjb): refactor this.
InitIPAddress();
- // If cellular state has just changed to connected request data plans.
- if (type_ == TYPE_CELLULAR && connected())
- RequestCellularDataPlanUpdate(service_path_.c_str());
}
return true;
}
@@ -1026,7 +1023,10 @@ bool CellularNetwork::ParseValue(int index, const Value* value) {
case PROPERTY_INDEX_ACTIVATION_STATE: {
std::string activation_state_string;
if (value->GetAsString(&activation_state_string)) {
+ ActivationState prev_state = activation_state_;
activation_state_ = ParseActivationState(activation_state_string);
+ if (activation_state_ != prev_state)
+ RefreshDataPlansIfNeeded();
return true;
}
break;
@@ -1055,6 +1055,26 @@ bool CellularNetwork::ParseValue(int index, const Value* value) {
return value->GetAsString(&payment_url_);
case PROPERTY_INDEX_USAGE_URL:
return value->GetAsString(&usage_url_);
+ case PROPERTY_INDEX_STATE: {
+ // Save previous state before calling WirelessNetwork::ParseValue.
+ ConnectionState prev_state = state_;
+ if (WirelessNetwork::ParseValue(index, value)) {
+ if (state_ != prev_state)
+ RefreshDataPlansIfNeeded();
+ return true;
+ }
+ break;
+ }
+ case PROPERTY_INDEX_CONNECTIVITY_STATE: {
+ // Save previous state before calling WirelessNetwork::ParseValue.
+ ConnectivityState prev_state = connectivity_state_;
+ if (WirelessNetwork::ParseValue(index, value)) {
+ if (connectivity_state_ != prev_state)
+ RefreshDataPlansIfNeeded();
+ return true;
+ }
+ break;
+ }
default:
return WirelessNetwork::ParseValue(index, value);
}
@@ -1067,6 +1087,13 @@ bool CellularNetwork::StartActivation() const {
return ActivateCellularModem(service_path().c_str(), NULL);
}
+void CellularNetwork::RefreshDataPlansIfNeeded() const {
+ if (!EnsureCrosLoaded())
+ return;
+ if (connected() && activated())
+ RequestCellularDataPlanUpdate(service_path().c_str());
+}
+
std::string CellularNetwork::GetNetworkTechnologyString() const {
// No need to localize these cellular technology abbreviations.
switch (network_technology_) {
@@ -1424,7 +1451,6 @@ class NetworkLibraryImpl : public NetworkLibrary {
virtual bool cellular_connected() const {
return active_cellular_ ? active_cellular_->connected() : false;
}
-
virtual const VirtualNetwork* virtual_network() const {
return active_virtual_;
}
@@ -1510,11 +1536,15 @@ class NetworkLibraryImpl : public NetworkLibrary {
return NULL;
}
- virtual void RequestWifiScan() {
- if (EnsureCrosLoaded() && wifi_enabled()) {
- wifi_scanning_ = true; // Cleared when updates are received.
- RequestNetworkScan(kTypeWifi);
- RequestRememberedNetworksUpdate();
+ virtual void RequestNetworkScan() {
+ if (EnsureCrosLoaded()) {
+ if (wifi_enabled()) {
+ wifi_scanning_ = true; // Cleared when updates are received.
+ chromeos::RequestNetworkScan(kTypeWifi);
+ RequestRememberedNetworksUpdate();
+ }
+ if (cellular_network())
+ cellular_network()->RefreshDataPlansIfNeeded();
}
}
@@ -1672,14 +1702,6 @@ class NetworkLibraryImpl : public NetworkLibrary {
WirelessConnectCallback, this);
}
- virtual void RefreshCellularDataPlans(const CellularNetwork* network) {
- DCHECK(network);
- if (!EnsureCrosLoaded() || !network)
- return;
- VLOG(1) << " Requesting data plan for: " << network->service_path();
- RequestCellularDataPlanUpdate(network->service_path().c_str());
- }
-
// Records information that cellular play payment had happened.
virtual void SignalCellularPlanPayment() {
DCHECK(!HasRecentCellularPlanPayment());
@@ -2394,7 +2416,7 @@ class NetworkLibraryImpl : public NetworkLibrary {
Network* CreateNewNetwork(ConnectionType type,
const std::string& service_path) {
- switch(type) {
+ switch (type) {
case TYPE_ETHERNET: {
EthernetNetwork* ethernet = new EthernetNetwork(service_path);
return ethernet;
@@ -2717,6 +2739,7 @@ class NetworkLibraryImpl : public NetworkLibrary {
void UpdateCellularDataPlan(const std::string& service_path,
const CellularDataPlanList* data_plan_list) {
+ VLOG(1) << "Updating cellular data plans for: " << service_path;
CellularDataPlanVector* data_plans = NULL;
// Find and delete any existing data plans associated with |service_path|.
CellularDataPlanMap::iterator found = data_plan_map_.find(service_path);
@@ -2729,7 +2752,10 @@ class NetworkLibraryImpl : public NetworkLibrary {
}
for (size_t i = 0; i < data_plan_list->plans_size; i++) {
const CellularDataPlanInfo* info(data_plan_list->GetCellularDataPlan(i));
- data_plans->push_back(new CellularDataPlan(*info));
+ CellularDataPlan* plan = new CellularDataPlan(*info);
+ data_plans->push_back(plan);
+ VLOG(2) << " Plan: " << plan->GetPlanDesciption()
+ << " : " << plan->GetDataRemainingDesciption();
}
// Now, update any matching cellular network's cached data
CellularNetwork* cellular = GetCellularNetworkByPath(service_path);
@@ -2740,6 +2766,8 @@ class NetworkLibraryImpl : public NetworkLibrary {
data_left = CellularNetwork::DATA_NONE;
else
data_left = GetDataLeft(data_plans);
+ VLOG(2) << " Data left: " << data_left
+ << " Need plan: " << cellular->needs_new_plan();
cellular->set_data_left(data_left);
}
NotifyCellularDataPlanChanged();
@@ -3042,7 +3070,7 @@ class NetworkLibraryStubImpl : public NetworkLibrary {
virtual const CellularDataPlan* GetSignificantDataPlan(
const std::string& path) const { return NULL; }
- virtual void RequestWifiScan() {}
+ virtual void RequestNetworkScan() {}
virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) {
return false;
}
@@ -3056,7 +3084,6 @@ class NetworkLibraryStubImpl : public NetworkLibrary {
const std::string& certpath,
bool auto_connect) {}
virtual void ConnectToCellularNetwork(const CellularNetwork* network) {}
- virtual void RefreshCellularDataPlans(const CellularNetwork* network) {}
virtual void SignalCellularPlanPayment() {}
virtual bool HasRecentCellularPlanPayment() { return false; }
virtual void DisconnectFromWirelessNetwork(const WirelessNetwork* network) {}
diff --git a/chrome/browser/chromeos/cros/network_library.h b/chrome/browser/chromeos/cros/network_library.h
index cad2f84..df5c6f1 100644
--- a/chrome/browser/chromeos/cros/network_library.h
+++ b/chrome/browser/chromeos/cros/network_library.h
@@ -348,7 +348,15 @@ class CellularNetwork : public WirelessNetwork {
// Starts device activation process. Returns false if the device state does
// not permit activation.
bool StartActivation() const;
+ // Requests data plans if the network is conencted and activated.
+ // Plan data will be passed through Network::Observer::CellularDataPlanChanged
+ // callback.
+ void RefreshDataPlansIfNeeded() const;
+
const ActivationState activation_state() const { return activation_state_; }
+ bool activated() const {
+ return activation_state() == ACTIVATION_STATE_ACTIVATED;
+ }
const NetworkTechnology network_technology() const {
return network_technology_;
}
@@ -357,8 +365,7 @@ class CellularNetwork : public WirelessNetwork {
return connectivity_state() == CONN_STATE_RESTRICTED;
}
bool needs_new_plan() const {
- return restricted_pool() && connected() &&
- activation_state() == ACTIVATION_STATE_ACTIVATED;
+ return restricted_pool() && connected() && activated();
}
const std::string& operator_name() const { return operator_name_; }
const std::string& operator_code() const { return operator_code_; }
@@ -709,7 +716,7 @@ class NetworkLibrary {
const std::string& path) const = 0;
// Request a scan for new wifi networks.
- virtual void RequestWifiScan() = 0;
+ virtual void RequestNetworkScan() = 0;
// Reads out the results of the last wifi scan. These results are not
// pre-cached in the library, so the call may block whilst the results are
@@ -740,10 +747,6 @@ class NetworkLibrary {
// Connect to the specified cellular network.
virtual void ConnectToCellularNetwork(const CellularNetwork* network) = 0;
- // Initiates cellular data plan refresh. Plan data will be passed through
- // Network::Observer::CellularDataPlanChanged callback.
- virtual void RefreshCellularDataPlans(const CellularNetwork* network) = 0;
-
// Records information that cellular play payment had happened.
virtual void SignalCellularPlanPayment() = 0;
diff --git a/chrome/browser/chromeos/status/network_menu.cc b/chrome/browser/chromeos/status/network_menu.cc
index 028d36c..93e0906b 100644
--- a/chrome/browser/chromeos/status/network_menu.cc
+++ b/chrome/browser/chromeos/status/network_menu.cc
@@ -528,7 +528,7 @@ SkBitmap NetworkMenu::IconForDisplay(const SkBitmap* icon,
void NetworkMenu::RunMenu(views::View* source, const gfx::Point& pt) {
refreshing_menu_ = true;
NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
- cros->RequestWifiScan();
+ cros->RequestNetworkScan();
// Build initial menu items. They will be updated when UpdateMenu is
// called from NetworkChanged.
diff --git a/chrome/browser/chromeos/webui/internet_options_handler.cc b/chrome/browser/chromeos/webui/internet_options_handler.cc
index c1ce745..2491f7b 100644
--- a/chrome/browser/chromeos/webui/internet_options_handler.cc
+++ b/chrome/browser/chromeos/webui/internet_options_handler.cc
@@ -306,6 +306,12 @@ void InternetOptionsHandler::GetLocalizedValues(
localized_strings->SetBoolean("networkUseSettingsUI", use_settings_ui_);
}
+void InternetOptionsHandler::Initialize() {
+ chromeos::NetworkLibrary* cros =
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary();
+ cros->RequestNetworkScan();
+}
+
void InternetOptionsHandler::RegisterMessages() {
// Setup handlers specific to this panel.
DCHECK(web_ui_);
@@ -843,7 +849,7 @@ void InternetOptionsHandler::RefreshCellularPlanCallback(
const chromeos::CellularNetwork* cellular =
cros->FindCellularNetworkByPath(service_path);
if (cellular)
- cros->RefreshCellularDataPlans(cellular);
+ cellular->RefreshDataPlansIfNeeded();
}
ListValue* InternetOptionsHandler::GetNetwork(
diff --git a/chrome/browser/chromeos/webui/internet_options_handler.h b/chrome/browser/chromeos/webui/internet_options_handler.h
index 83da94a..4b6d07f 100644
--- a/chrome/browser/chromeos/webui/internet_options_handler.h
+++ b/chrome/browser/chromeos/webui/internet_options_handler.h
@@ -27,6 +27,7 @@ class InternetOptionsHandler
// OptionsPageUIHandler implementation.
virtual void GetLocalizedValues(DictionaryValue* localized_strings);
+ virtual void Initialize();
// WebUIMessageHandler implementation.
virtual void RegisterMessages();