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

Unified Diff: chromeos/network/network_state_handler.cc

Issue 2819383002: [CrOS Tether] Update NetworkState to include tether properties and integrate into NetworkStateHandl… (Closed)
Patch Set: Comments. Created 3 years, 8 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
« no previous file with comments | « chromeos/network/network_state_handler.h ('k') | chromeos/network/network_state_handler_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/network/network_state_handler.cc
diff --git a/chromeos/network/network_state_handler.cc b/chromeos/network/network_state_handler.cc
index 620ae84f4872738cf701f42994016c6f30db9d66..4a78b88a0cf18f9b8e5fe34e0a7dde311b2efb51 100644
--- a/chromeos/network/network_state_handler.cc
+++ b/chromeos/network/network_state_handler.cc
@@ -13,7 +13,6 @@
#include "base/json/json_string_value_serializer.h"
#include "base/json/json_writer.h"
#include "base/location.h"
-#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
@@ -223,6 +222,18 @@ const NetworkState* NetworkStateHandler::DefaultNetwork() const {
const NetworkState* NetworkStateHandler::ConnectedNetworkByType(
const NetworkTypePattern& type) const {
+ // If a tether network is connected, return that network before checking other
+ // network types.
+ if (type.MatchesPattern(NetworkTypePattern::Tether())) {
+ for (auto iter = tether_network_list_.begin();
+ iter != tether_network_list_.end(); ++iter) {
+ const NetworkState* network = (*iter)->AsNetworkState();
+ DCHECK(network);
+ if (network->IsConnectedState())
+ return network;
+ }
+ }
+
// Active networks are always listed first by Shill so no need to sort.
for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) {
const NetworkState* network = (*iter)->AsNetworkState();
@@ -239,6 +250,18 @@ const NetworkState* NetworkStateHandler::ConnectedNetworkByType(
const NetworkState* NetworkStateHandler::ConnectingNetworkByType(
const NetworkTypePattern& type) const {
+ // If a tether network is connecting, return that network before checking
+ // other network types.
+ if (type.MatchesPattern(NetworkTypePattern::Tether())) {
+ for (auto iter = tether_network_list_.begin();
+ iter != tether_network_list_.end(); ++iter) {
+ const NetworkState* network = (*iter)->AsNetworkState();
+ DCHECK(network);
+ if (network->IsConnectingState())
+ return network;
+ }
+ }
+
// Active networks are always listed first by Shill so no need to sort.
for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) {
const NetworkState* network = (*iter)->AsNetworkState();
@@ -257,6 +280,14 @@ const NetworkState* NetworkStateHandler::FirstNetworkByType(
const NetworkTypePattern& type) {
if (!network_list_sorted_)
SortNetworkList(); // Sort to ensure visible networks are listed first.
+
+ // If |type| matches tether networks and at least one tether network is
+ // present, return the first network (since it has been sorted already).
+ if (type.MatchesPattern(NetworkTypePattern::Tether()) &&
+ !tether_network_list_.empty()) {
+ return tether_network_list_[0]->AsNetworkState();
+ }
+
for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) {
const NetworkState* network = (*iter)->AsNetworkState();
DCHECK(network);
@@ -298,10 +329,25 @@ void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type,
NetworkStateList* list) {
DCHECK(list);
list->clear();
- int count = 0;
+
// Sort the network list if necessary.
if (!network_list_sorted_)
SortNetworkList();
+
+ if (type.MatchesPattern(NetworkTypePattern::Tether())) {
+ GetTetherNetworkList(limit, list);
+ }
+
+ int count = list->size();
+
+ if (type.Equals(NetworkTypePattern::Tether()) ||
+ (limit != 0 && count >= limit)) {
+ // If only searching for tether networks, there is no need to continue
+ // searching through other network types; likewise, if the limit has already
+ // been reached, there is no need to continue searching.
+ return;
+ }
+
for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) {
const NetworkState* network = (*iter)->AsNetworkState();
DCHECK(network);
@@ -354,8 +400,13 @@ const NetworkState* NetworkStateHandler::GetNetworkStateFromGuid(
}
void NetworkStateHandler::AddTetherNetworkState(const std::string& guid,
- const std::string& name) {
+ const std::string& name,
+ const std::string& carrier,
+ int battery_percentage,
+ int signal_strength) {
DCHECK(!guid.empty());
+ DCHECK(battery_percentage >= 0 && battery_percentage <= 100);
+ DCHECK(signal_strength >= 0 && signal_strength <= 100);
// If the network already exists, do nothing.
if (GetNetworkStateFromGuid(guid)) {
@@ -364,19 +415,42 @@ void NetworkStateHandler::AddTetherNetworkState(const std::string& guid,
return;
}
+ // Use the GUID as the network's service path.
std::unique_ptr<NetworkState> tether_network_state =
- base::MakeUnique<NetworkState>(guid);
+ base::MakeUnique<NetworkState>(guid /* path */);
+ // Tether networks are always connectable
+ tether_network_state->connectable_ = true;
tether_network_state->set_name(name);
tether_network_state->set_type(kTypeTether);
tether_network_state->SetGuid(guid);
tether_network_state->set_visible(true);
tether_network_state->set_update_received();
+ tether_network_state->SetCarrier(carrier);
+ tether_network_state->SetBatteryPercentage(battery_percentage);
+ tether_network_state->SetTetherSignalStrength(signal_strength);
tether_network_list_.push_back(std::move(tether_network_state));
NotifyNetworkListChanged();
}
+bool NetworkStateHandler::UpdateTetherNetworkProperties(
+ const std::string& guid,
+ const std::string& carrier,
+ int battery_percentage,
+ int signal_strength) {
+ NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid);
+ if (!tether_network_state)
+ return false;
+
+ tether_network_state->SetCarrier(carrier);
+ tether_network_state->SetBatteryPercentage(battery_percentage);
+ tether_network_state->SetTetherSignalStrength(signal_strength);
+
+ NotifyNetworkListChanged();
+ return true;
+}
+
void NetworkStateHandler::RemoveTetherNetworkState(const std::string& guid) {
for (auto iter = tether_network_list_.begin();
iter != tether_network_list_.end(); ++iter) {
@@ -427,16 +501,24 @@ bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork(
void NetworkStateHandler::SetTetherNetworkStateDisconnected(
const std::string& guid) {
+ // TODO(khorimoto): Change default network? Notify of connection change?
Kyle Horimoto 2017/04/18 01:16:06 stevenjb@: Can you comment on what the correct thi
SetTetherNetworkStateConnectionState(guid, shill::kStateDisconnect);
}
void NetworkStateHandler::SetTetherNetworkStateConnecting(
const std::string& guid) {
+ // TODO(khorimoto): Change default network? Notify of connection change?
SetTetherNetworkStateConnectionState(guid, shill::kStateConfiguration);
}
void NetworkStateHandler::SetTetherNetworkStateConnected(
const std::string& guid) {
+ // Being connected implies that AssociateTetherNetworkStateWithWifiNetwork()
+ // was already called, so ensure that the association is still intact.
+ DCHECK(GetNetworkStateFromGuid(GetNetworkStateFromGuid(guid)->tether_guid())
+ ->tether_guid() == guid);
+
+ // TODO(khorimoto): Change default network? Notify of connection change?
SetTetherNetworkStateConnectionState(guid, shill::kStateOnline);
}
@@ -575,7 +657,7 @@ void NetworkStateHandler::SetLastErrorForTest(const std::string& service_path,
const std::string& error) {
NetworkState* network_state = GetModifiableNetworkState(service_path);
if (!network_state) {
- LOG(ERROR) << "No matching NetworkState for: " << service_path;
+ NET_LOG(ERROR) << "No matching NetworkState for: " << service_path;
return;
}
network_state->last_error_ = error;
@@ -867,6 +949,7 @@ void NetworkStateHandler::ManagedStateListChanged(
}
}
+// TODO(khorimoto): Add sorting for the tether network list as well.
void NetworkStateHandler::SortNetworkList() {
// Note: usually active networks will precede inactive networks, however
// this may briefly be untrue during state transitions (e.g. a network may
« no previous file with comments | « chromeos/network/network_state_handler.h ('k') | chromeos/network/network_state_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698