Commit 2bed21e8 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Remove NetworkHandler dependencies from network_icon

This CL removes all remaining chromeos/network deps from
network_icon.cc besides NetworkState and NetworkTypePattern in
preparation for switching to using mojo types.

Bug: 923444
Change-Id: Ia4657cfb28223fd82bddcc2635ffb13187565357
Reviewed-on: https://chromium-review.googlesource.com/c/1448781Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630411}
parent 8dc30d09
...@@ -11,11 +11,13 @@ ...@@ -11,11 +11,13 @@
#include "chromeos/network/network_handler.h" #include "chromeos/network/network_handler.h"
#include "chromeos/network/network_state.h" #include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_type_pattern.h"
#include "third_party/cros_system_api/dbus/service_constants.h" #include "third_party/cros_system_api/dbus/service_constants.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
using chromeos::NetworkState; using chromeos::NetworkState;
using chromeos::NetworkStateHandler;
using chromeos::NetworkTypePattern; using chromeos::NetworkTypePattern;
namespace ash { namespace ash {
...@@ -190,10 +192,40 @@ void ActiveNetworkIcon::UpdateActiveNetworks() { ...@@ -190,10 +192,40 @@ void ActiveNetworkIcon::UpdateActiveNetworks() {
ActiveNetworksChanged(active_networks); ActiveNetworksChanged(active_networks);
} }
void ActiveNetworkIcon::SetCellularUninitializedMsg() {
if (network_state_handler_->GetTechnologyState(
NetworkTypePattern::Cellular()) ==
NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) {
cellular_uninitialized_msg_ = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR;
uninitialized_state_time_ = base::Time::Now();
return;
}
if (network_state_handler_->GetScanningByType(
NetworkTypePattern::Cellular())) {
cellular_uninitialized_msg_ = IDS_ASH_STATUS_TRAY_MOBILE_SCANNING;
uninitialized_state_time_ = base::Time::Now();
return;
}
// There can be a delay between leaving the Initializing state and when
// a Cellular device shows up, so keep showing the initializing
// animation for a bit to avoid flashing the disconnect icon.
const int kInitializingDelaySeconds = 1;
base::TimeDelta dtime = base::Time::Now() - uninitialized_state_time_;
if (dtime.InSeconds() >= kInitializingDelaySeconds)
cellular_uninitialized_msg_ = 0;
}
void ActiveNetworkIcon::DeviceListChanged() { void ActiveNetworkIcon::DeviceListChanged() {
UpdateActiveNetworks(); UpdateActiveNetworks();
} }
void ActiveNetworkIcon::DevicePropertiesUpdated(
const chromeos::DeviceState* device) {
SetCellularUninitializedMsg();
}
void ActiveNetworkIcon::ActiveNetworksChanged( void ActiveNetworkIcon::ActiveNetworksChanged(
const std::vector<const NetworkState*>& active_networks) { const std::vector<const NetworkState*>& active_networks) {
active_cellular_ = nullptr; active_cellular_ = nullptr;
...@@ -238,7 +270,7 @@ void ActiveNetworkIcon::ActiveNetworksChanged( ...@@ -238,7 +270,7 @@ void ActiveNetworkIcon::ActiveNetworksChanged(
active_non_cellular_ = active_non_cellular_ =
GetConnectingOrConnected(connecting_non_cellular, connected_non_cellular); GetConnectingOrConnected(connecting_non_cellular, connected_non_cellular);
cellular_uninitialized_msg_ = network_icon::GetCellularUninitializedMsg(); SetCellularUninitializedMsg();
} }
void ActiveNetworkIcon::OnShuttingDown() { void ActiveNetworkIcon::OnShuttingDown() {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ash/system/network/network_icon.h" #include "ash/system/network/network_icon.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/time/time.h"
#include "chromeos/network/network_state_handler_observer.h" #include "chromeos/network/network_state_handler_observer.h"
namespace chromeos { namespace chromeos {
...@@ -59,6 +60,10 @@ class ASH_EXPORT ActiveNetworkIcon ...@@ -59,6 +60,10 @@ class ASH_EXPORT ActiveNetworkIcon
gfx::ImageSkia GetDualImageCellular(network_icon::IconType icon_type, gfx::ImageSkia GetDualImageCellular(network_icon::IconType icon_type,
bool* animating); bool* animating);
int cellular_uninitialized_msg_for_test() const {
return cellular_uninitialized_msg_;
}
private: private:
gfx::ImageSkia GetDefaultImageImpl( gfx::ImageSkia GetDefaultImageImpl(
const chromeos::NetworkState* default_network, const chromeos::NetworkState* default_network,
...@@ -71,9 +76,11 @@ class ASH_EXPORT ActiveNetworkIcon ...@@ -71,9 +76,11 @@ class ASH_EXPORT ActiveNetworkIcon
bool* animating); bool* animating);
void UpdateActiveNetworks(); void UpdateActiveNetworks();
void SetCellularUninitializedMsg();
// chromeos::NetworkStateHandlerObserver // chromeos::NetworkStateHandlerObserver
void DeviceListChanged() override; void DeviceListChanged() override;
void DevicePropertiesUpdated(const chromeos::DeviceState* device) override;
void ActiveNetworksChanged(const std::vector<const chromeos::NetworkState*>& void ActiveNetworksChanged(const std::vector<const chromeos::NetworkState*>&
active_networks) override; active_networks) override;
void OnShuttingDown() override; void OnShuttingDown() override;
...@@ -84,6 +91,7 @@ class ASH_EXPORT ActiveNetworkIcon ...@@ -84,6 +91,7 @@ class ASH_EXPORT ActiveNetworkIcon
const chromeos::NetworkState* active_cellular_ = nullptr; const chromeos::NetworkState* active_cellular_ = nullptr;
const chromeos::NetworkState* active_vpn_ = nullptr; const chromeos::NetworkState* active_vpn_ = nullptr;
int cellular_uninitialized_msg_ = 0; int cellular_uninitialized_msg_ = 0;
base::Time uninitialized_state_time_;
DISALLOW_COPY_AND_ASSIGN(ActiveNetworkIcon); DISALLOW_COPY_AND_ASSIGN(ActiveNetworkIcon);
}; };
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chromeos/network/network_state.h" #include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_type_pattern.h"
#include "chromeos/network/tether_constants.h" #include "chromeos/network/tether_constants.h"
#include "components/vector_icons/vector_icons.h" #include "components/vector_icons/vector_icons.h"
#include "third_party/cros_system_api/dbus/service_constants.h" #include "third_party/cros_system_api/dbus/service_constants.h"
...@@ -26,10 +26,7 @@ ...@@ -26,10 +26,7 @@
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
#include "ui/gfx/vector_icon_types.h" #include "ui/gfx/vector_icon_types.h"
using chromeos::NetworkConnectionHandler;
using chromeos::NetworkHandler;
using chromeos::NetworkState; using chromeos::NetworkState;
using chromeos::NetworkStateHandler;
using chromeos::NetworkTypePattern; using chromeos::NetworkTypePattern;
namespace ash { namespace ash {
...@@ -631,44 +628,7 @@ base::string16 GetLabelForNetwork(const chromeos::NetworkState* network, ...@@ -631,44 +628,7 @@ base::string16 GetLabelForNetwork(const chromeos::NetworkState* network,
} }
} }
int GetCellularUninitializedMsg() { void PurgeNetworkIconCache(const std::set<std::string>& network_paths) {
static base::Time s_uninitialized_state_time;
static int s_uninitialized_msg(0);
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
if (handler->GetTechnologyState(NetworkTypePattern::Cellular()) ==
NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) {
s_uninitialized_msg = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR;
s_uninitialized_state_time = base::Time::Now();
return s_uninitialized_msg;
}
if (handler->GetScanningByType(NetworkTypePattern::Cellular())) {
s_uninitialized_msg = IDS_ASH_STATUS_TRAY_MOBILE_SCANNING;
s_uninitialized_state_time = base::Time::Now();
return s_uninitialized_msg;
}
// There can be a delay between leaving the Initializing state and when
// a Cellular device shows up, so keep showing the initializing
// animation for a bit to avoid flashing the disconnect icon.
const int kInitializingDelaySeconds = 1;
base::TimeDelta dtime = base::Time::Now() - s_uninitialized_state_time;
if (dtime.InSeconds() < kInitializingDelaySeconds)
return s_uninitialized_msg;
return 0;
}
void PurgeNetworkIconCache() {
NetworkStateHandler::NetworkStateList networks;
NetworkHandler::Get()->network_state_handler()->GetVisibleNetworkList(
&networks);
std::set<std::string> network_paths;
for (NetworkStateHandler::NetworkStateList::iterator iter = networks.begin();
iter != networks.end(); ++iter) {
network_paths.insert((*iter)->path());
}
PurgeIconMap(ICON_TYPE_TRAY_OOBE, network_paths); PurgeIconMap(ICON_TYPE_TRAY_OOBE, network_paths);
PurgeIconMap(ICON_TYPE_TRAY_REGULAR, network_paths); PurgeIconMap(ICON_TYPE_TRAY_REGULAR, network_paths);
PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef ASH_SYSTEM_NETWORK_NETWORK_ICON_H_ #ifndef ASH_SYSTEM_NETWORK_NETWORK_ICON_H_
#define ASH_SYSTEM_NETWORK_NETWORK_ICON_H_ #define ASH_SYSTEM_NETWORK_NETWORK_ICON_H_
#include <set>
#include <string> #include <string>
#include "ash/ash_export.h" #include "ash/ash_export.h"
...@@ -87,14 +88,10 @@ ASH_EXPORT base::string16 GetLabelForNetwork( ...@@ -87,14 +88,10 @@ ASH_EXPORT base::string16 GetLabelForNetwork(
const chromeos::NetworkState* network, const chromeos::NetworkState* network,
IconType icon_type); IconType icon_type);
// Updates and returns the appropriate message id if the cellular network // Called periodically with the current list of network paths. Removes cached
// is uninitialized. // entries that are no longer in the list.
ASH_EXPORT int GetCellularUninitializedMsg(); ASH_EXPORT void PurgeNetworkIconCache(
const std::set<std::string>& network_paths);
// Called when the list of networks changes. Retrieves the list of networks
// from the global NetworkStateHandler instance and removes cached entries
// that are no longer in the list.
ASH_EXPORT void PurgeNetworkIconCache();
// Called by ChromeVox to give a verbal indication of the network icon. Returns // Called by ChromeVox to give a verbal indication of the network icon. Returns
// the signal strength of |network|, if it is a network type with a signal // the signal strength of |network|, if it is a network type with a signal
......
...@@ -9,26 +9,41 @@ ...@@ -9,26 +9,41 @@
#include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_state_handler.h"
using chromeos::NetworkHandler; using chromeos::NetworkHandler;
using chromeos::NetworkStateHandler;
namespace ash {
namespace { namespace {
const int kPurgeDelayMs = 300; const int kPurgeDelayMs = 300;
} // namespace
namespace ash { void PurgeNetworkIconCache() {
NetworkStateHandler::NetworkStateList networks;
NetworkHandler::Get()->network_state_handler()->GetVisibleNetworkList(
&networks);
std::set<std::string> network_paths;
for (NetworkStateHandler::NetworkStateList::iterator iter = networks.begin();
iter != networks.end(); ++iter) {
network_paths.insert((*iter)->path());
}
network_icon::PurgeNetworkIconCache(network_paths);
}
} // namespace
NetworkIconPurger::NetworkIconPurger() { NetworkIconPurger::NetworkIconPurger() {
// NetworkHandler may not be initialized in tests. // NetworkHandler may not be initialized in tests.
if (NetworkHandler::IsInitialized()) { if (NetworkHandler::IsInitialized()) {
auto* network_handler = NetworkHandler::Get(); NetworkHandler::Get()->network_state_handler()->AddObserver(this,
network_handler->network_state_handler()->AddObserver(this, FROM_HERE); FROM_HERE);
} }
} }
NetworkIconPurger::~NetworkIconPurger() { NetworkIconPurger::~NetworkIconPurger() {
// NetworkHandler may not be initialized in tests. // NetworkHandler may not be initialized in tests.
if (NetworkHandler::IsInitialized()) { if (NetworkHandler::IsInitialized()) {
auto* network_handler = NetworkHandler::Get(); NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
network_handler->network_state_handler()->RemoveObserver(this, FROM_HERE); FROM_HERE);
} }
} }
...@@ -36,7 +51,7 @@ void NetworkIconPurger::NetworkListChanged() { ...@@ -36,7 +51,7 @@ void NetworkIconPurger::NetworkListChanged() {
if (timer_.IsRunning()) if (timer_.IsRunning())
return; return;
timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kPurgeDelayMs), timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kPurgeDelayMs),
base::BindOnce(&network_icon::PurgeNetworkIconCache)); base::BindOnce(&PurgeNetworkIconCache));
} }
} // namespace ash } // namespace ash
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ash/system/network/network_icon.h" #include "ash/system/network/network_icon.h"
#include <memory> #include <memory>
#include <set>
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/network/active_network_icon.h" #include "ash/system/network/active_network_icon.h"
...@@ -47,7 +48,7 @@ class NetworkIconTest : public testing::Test { ...@@ -47,7 +48,7 @@ class NetworkIconTest : public testing::Test {
void TearDown() override { void TearDown() override {
active_network_icon_.reset(); active_network_icon_.reset();
PurgeNetworkIconCache(); PurgeNetworkIconCache(std::set<std::string>());
} }
std::string ConfigureService(const std::string& shill_json_string) { std::string ConfigureService(const std::string& shill_json_string) {
...@@ -119,6 +120,10 @@ class NetworkIconTest : public testing::Test { ...@@ -119,6 +120,10 @@ class NetworkIconTest : public testing::Test {
*label = active_network_icon_->GetDefaultLabel(icon_type); *label = active_network_icon_->GetDefaultLabel(icon_type);
} }
int GetCellularUninitializedMsg() {
return active_network_icon_->cellular_uninitialized_msg_for_test();
}
// The icon for a Tether network should be the same as one for a cellular // The icon for a Tether network should be the same as one for a cellular
// network. The icon for a Tether network should be different from one for a // network. The icon for a Tether network should be different from one for a
// Wi-Fi network. The icon for a cellular network should be different from one // Wi-Fi network. The icon for a cellular network should be different from one
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment