diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 19:16:37 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 19:16:37 +0000 |
commit | 07788f76260eb3bb8b0be60d4a67ba544296da65 (patch) | |
tree | 155313fcf45df1d91455fc25e33e38d863eca95c /ash | |
parent | 465ee396265a13b07f75d38ef73d94f03449dcb8 (diff) | |
download | chromium_src-07788f76260eb3bb8b0be60d4a67ba544296da65.zip chromium_src-07788f76260eb3bb8b0be60d4a67ba544296da65.tar.gz chromium_src-07788f76260eb3bb8b0be60d4a67ba544296da65.tar.bz2 |
Purge icon cache when services are removed from the list
Because Shill routinely removes and adds network services, this was
potentially causing a not insignificant amount of memory bloat, in
addition to incorrect behavior when Shill reuses service path names
after restarting.
Also removes extra NetworkStateList typedefs.
BUG=249129
Review URL: https://chromiumcodereview.appspot.com/16854006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207051 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
7 files changed, 58 insertions, 18 deletions
diff --git a/ash/system/chromeos/network/network_detailed_view.h b/ash/system/chromeos/network/network_detailed_view.h index fd48348..fe7ac21d 100644 --- a/ash/system/chromeos/network/network_detailed_view.h +++ b/ash/system/chromeos/network/network_detailed_view.h @@ -17,8 +17,6 @@ namespace tray { // which includes NetworkWifiDetailedView and NetworkStateListDetailedView. class NetworkDetailedView : public TrayDetailsView { public: - typedef chromeos::NetworkStateHandler::NetworkStateList NetworkStateList; - enum DetailedViewType { LIST_VIEW, STATE_LIST_VIEW, diff --git a/ash/system/chromeos/network/network_icon.cc b/ash/system/chromeos/network/network_icon.cc index 5bed702..141c24b 100644 --- a/ash/system/chromeos/network/network_icon.cc +++ b/ash/system/chromeos/network/network_icon.cc @@ -108,16 +108,41 @@ class NetworkIconImpl { typedef std::map<std::string, NetworkIconImpl*> NetworkIconMap; -NetworkIconMap* GetIconMap(IconType icon_type) { +NetworkIconMap* GetIconMapInstance(IconType icon_type, bool create) { typedef std::map<IconType, NetworkIconMap*> IconTypeMap; static IconTypeMap* s_icon_map = NULL; - if (s_icon_map == NULL) + if (s_icon_map == NULL) { + if (!create) + return NULL; s_icon_map = new IconTypeMap; - if (s_icon_map->count(icon_type) == 0) + } + if (s_icon_map->count(icon_type) == 0) { + if (!create) + return NULL; (*s_icon_map)[icon_type] = new NetworkIconMap; + } return (*s_icon_map)[icon_type]; } +NetworkIconMap* GetIconMap(IconType icon_type) { + return GetIconMapInstance(icon_type, true); +} + +void PurgeIconMap(IconType icon_type, + const std::set<std::string>& network_paths) { + NetworkIconMap* icon_map = GetIconMapInstance(icon_type, false); + if (!icon_map) + return; + for (NetworkIconMap::iterator loop_iter = icon_map->begin(); + loop_iter != icon_map->end(); ) { + NetworkIconMap::iterator cur_iter = loop_iter++; + if (network_paths.count(cur_iter->first) == 0) { + delete cur_iter->second; + icon_map->erase(cur_iter); + } + } +} + //------------------------------------------------------------------------------ // Utilities for generating icon images. @@ -807,5 +832,18 @@ void GetDefaultNetworkImageAndLabel(IconType icon_type, *label = GetLabelForNetwork(network, icon_type); } +void PurgeNetworkIconCache() { + NetworkStateHandler::NetworkStateList networks; + NetworkHandler::Get()->network_state_handler()->GetNetworkList(&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, network_paths); + PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); + PurgeIconMap(ICON_TYPE_LIST, network_paths); +} + } // namespace network_icon } // namespace ash diff --git a/ash/system/chromeos/network/network_icon.h b/ash/system/chromeos/network/network_icon.h index 6d72e1b..1f9b2c7 100644 --- a/ash/system/chromeos/network/network_icon.h +++ b/ash/system/chromeos/network/network_icon.h @@ -65,6 +65,11 @@ ASH_EXPORT void GetDefaultNetworkImageAndLabel(IconType icon_type, base::string16* label, bool* animating); +// Called when the list of networks changes. Retreives the list of networks +// from the global NetworkStateHandler instance and removes cached entries +// that are no longer in the list. +ASH_EXPORT void PurgeNetworkIconCache(); + } // namespace network_icon } // namespace ash diff --git a/ash/system/chromeos/network/network_state_list_detailed_view.cc b/ash/system/chromeos/network/network_state_list_detailed_view.cc index 009b4b5..5d2e553 100644 --- a/ash/system/chromeos/network/network_state_list_detailed_view.cc +++ b/ash/system/chromeos/network/network_state_list_detailed_view.cc @@ -168,7 +168,7 @@ void NetworkStateListDetailedView::ManagerChanged() { } void NetworkStateListDetailedView::NetworkListChanged() { - NetworkStateList network_list; + NetworkStateHandler::NetworkStateList network_list; NetworkHandler::Get()->network_state_handler()->GetNetworkList(&network_list); UpdateNetworks(network_list); UpdateNetworkList(); @@ -196,7 +196,7 @@ void NetworkStateListDetailedView::Init() { CreateHeaderEntry(); CreateHeaderButtons(); - NetworkStateList network_list; + NetworkStateHandler::NetworkStateList network_list; NetworkHandler::Get()->network_state_handler()->GetNetworkList(&network_list); UpdateNetworks(network_list); UpdateNetworkList(); @@ -418,10 +418,10 @@ void NetworkStateListDetailedView::UpdateTechnologyButton( } void NetworkStateListDetailedView::UpdateNetworks( - const NetworkStateList& networks) { + const NetworkStateHandler::NetworkStateList& networks) { network_list_.clear(); - for (NetworkStateList::const_iterator iter = networks.begin(); - iter != networks.end(); ++iter) { + for (NetworkStateHandler::NetworkStateList::const_iterator iter = + networks.begin(); iter != networks.end(); ++iter) { const NetworkState* network = *iter; if ((list_type_ == LIST_TYPE_NETWORK && network->type() != flimflam::kTypeVPN) || diff --git a/ash/system/chromeos/network/network_state_list_detailed_view.h b/ash/system/chromeos/network/network_state_list_detailed_view.h index 6abeb72..8a58bb7 100644 --- a/ash/system/chromeos/network/network_state_list_detailed_view.h +++ b/ash/system/chromeos/network/network_state_list_detailed_view.h @@ -18,10 +18,6 @@ #include "base/memory/weak_ptr.h" #include "ui/views/controls/button/button.h" -namespace chromeos { -class NetworkStateList; -} - namespace views { class BubbleDelegateView; } @@ -89,7 +85,8 @@ class NetworkStateListDetailedView void UpdateTechnologyButton(TrayPopupHeaderButton* button, const std::string& technology); - void UpdateNetworks(const NetworkStateList& networks); + void UpdateNetworks( + const chromeos::NetworkStateHandler::NetworkStateList& networks); void UpdateNetworkList(); bool CreateOrUpdateInfoLabel( int index, const base::string16& text, views::Label** label); diff --git a/ash/system/chromeos/network/network_state_notifier.cc b/ash/system/chromeos/network/network_state_notifier.cc index c8b2144..934e939 100644 --- a/ash/system/chromeos/network/network_state_notifier.cc +++ b/ash/system/chromeos/network/network_state_notifier.cc @@ -249,12 +249,12 @@ void NetworkStateNotifier::ShowConnectError(const std::string& error_name, } void NetworkStateNotifier::InitializeNetworks() { - NetworkStateList network_list; + NetworkStateHandler::NetworkStateList network_list; NetworkHandler::Get()->network_state_handler()->GetNetworkList(&network_list); VLOG(1) << "NetworkStateNotifier:InitializeNetworks: " << network_list.size(); - for (NetworkStateList::iterator iter = network_list.begin(); - iter != network_list.end(); ++iter) { + for (NetworkStateHandler::NetworkStateList::iterator iter = + network_list.begin(); iter != network_list.end(); ++iter) { const NetworkState* network = *iter; VLOG(2) << " Network: " << network->path(); cached_state_[network->path()] = network->connection_state(); diff --git a/ash/system/chromeos/network/tray_network_state_observer.cc b/ash/system/chromeos/network/tray_network_state_observer.cc index 1aef119..49ba738 100644 --- a/ash/system/chromeos/network/tray_network_state_observer.cc +++ b/ash/system/chromeos/network/tray_network_state_observer.cc @@ -7,6 +7,7 @@ #include <set> #include <string> +#include "ash/system/chromeos/network/network_icon.h" #include "base/location.h" #include "chromeos/network/network_state.h" #include "chromeos/network/network_state_handler.h" @@ -38,6 +39,7 @@ void TrayNetworkStateObserver::NetworkManagerChanged() { void TrayNetworkStateObserver::NetworkListChanged() { delegate_->NetworkStateChanged(true); + network_icon::PurgeNetworkIconCache(); } void TrayNetworkStateObserver::DeviceListChanged() { |