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

Side by Side Diff: ui/chromeos/network/network_list.cc

Issue 811623002: Add logging for slow device events, limit network UI update rate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch_441650
Patch Set: Feedback Created 6 years 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 unified diff | Download patch
« no previous file with comments | « ui/chromeos/network/network_list.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/chromeos/network/network_list.h" 5 #include "ui/chromeos/network/network_list.h"
6 6
7 #include "chromeos/dbus/dbus_thread_manager.h" 7 #include "chromeos/dbus/dbus_thread_manager.h"
8 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" 8 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
9 #include "chromeos/dbus/power_manager_client.h" 9 #include "chromeos/dbus/power_manager_client.h"
10 #include "chromeos/device_event_log.h"
10 #include "chromeos/network/network_state.h" 11 #include "chromeos/network/network_state.h"
11 #include "chromeos/network/network_state_handler.h" 12 #include "chromeos/network/network_state_handler.h"
12 #include "chromeos/network/network_state_handler_observer.h" 13 #include "chromeos/network/network_state_handler_observer.h"
13 #include "grit/ui_chromeos_strings.h" 14 #include "grit/ui_chromeos_strings.h"
14 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/chromeos/network/network_icon.h" 16 #include "ui/chromeos/network/network_icon.h"
16 #include "ui/chromeos/network/network_icon_animation.h" 17 #include "ui/chromeos/network/network_icon_animation.h"
17 #include "ui/chromeos/network/network_info.h" 18 #include "ui/chromeos/network/network_info.h"
18 #include "ui/chromeos/network/network_list_delegate.h" 19 #include "ui/chromeos/network/network_list_delegate.h"
19 #include "ui/gfx/font.h" 20 #include "ui/gfx/font.h"
(...skipping 20 matching lines...) Expand all
40 NetworkListView::~NetworkListView() { 41 NetworkListView::~NetworkListView() {
41 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 42 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
42 } 43 }
43 44
44 void NetworkListView::UpdateNetworkList() { 45 void NetworkListView::UpdateNetworkList() {
45 CHECK(content_); 46 CHECK(content_);
46 NetworkStateHandler::NetworkStateList network_list; 47 NetworkStateHandler::NetworkStateList network_list;
47 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 48 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
48 handler->GetVisibleNetworkList(&network_list); 49 handler->GetVisibleNetworkList(&network_list);
49 UpdateNetworks(network_list); 50 UpdateNetworks(network_list);
51 UpdateNetworkIcons();
50 UpdateNetworkListInternal(); 52 UpdateNetworkListInternal();
51 } 53 }
52 54
53 bool NetworkListView::IsViewInList(views::View* view, 55 bool NetworkListView::IsViewInList(views::View* view,
54 std::string* service_path) const { 56 std::string* service_path) const {
55 std::map<views::View*, std::string>::const_iterator found = 57 std::map<views::View*, std::string>::const_iterator found =
56 network_map_.find(view); 58 network_map_.find(view);
57 if (found == network_map_.end()) 59 if (found == network_map_.end())
58 return false; 60 return false;
59 *service_path = found->second; 61 *service_path = found->second;
60 return true; 62 return true;
61 } 63 }
62 64
63 void NetworkListView::UpdateNetworks( 65 void NetworkListView::UpdateNetworks(
64 const NetworkStateHandler::NetworkStateList& networks) { 66 const NetworkStateHandler::NetworkStateList& networks) {
67 SCOPED_NET_LOG_IF_SLOW();
65 network_list_.clear(); 68 network_list_.clear();
66 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); 69 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern();
67 for (NetworkStateHandler::NetworkStateList::const_iterator iter = 70 for (NetworkStateHandler::NetworkStateList::const_iterator iter =
68 networks.begin(); 71 networks.begin();
69 iter != networks.end(); 72 iter != networks.end();
70 ++iter) { 73 ++iter) {
71 const chromeos::NetworkState* network = *iter; 74 const chromeos::NetworkState* network = *iter;
72 if (!pattern.MatchesType(network->type())) 75 if (!pattern.MatchesType(network->type()))
73 continue; 76 continue;
74 NetworkInfo* info = new NetworkInfo(network->path()); 77 NetworkInfo* info = new NetworkInfo(network->path());
75 network_list_.push_back(info); 78 network_list_.push_back(info);
76 } 79 }
77 } 80 }
78 81
79 void NetworkListView::UpdateNetworkListInternal() { 82 void NetworkListView::UpdateNetworkIcons() {
83 SCOPED_NET_LOG_IF_SLOW();
80 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 84 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
81 85
82 // First, update state for all networks 86 // First, update state for all networks
83 bool animating = false; 87 bool animating = false;
84 for (size_t i = 0; i < network_list_.size(); ++i) { 88 for (size_t i = 0; i < network_list_.size(); ++i) {
85 NetworkInfo* info = network_list_[i]; 89 NetworkInfo* info = network_list_[i];
86 const chromeos::NetworkState* network = 90 const chromeos::NetworkState* network =
87 handler->GetNetworkState(info->service_path); 91 handler->GetNetworkState(info->service_path);
88 if (!network) 92 if (!network)
89 continue; 93 continue;
90 info->image = 94 info->image =
91 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); 95 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST);
92 info->label = 96 info->label =
93 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST); 97 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST);
94 info->highlight = 98 info->highlight =
95 network->IsConnectedState() || network->IsConnectingState(); 99 network->IsConnectedState() || network->IsConnectingState();
96 info->disable = 100 info->disable =
97 network->activation_state() == shill::kActivationStateActivating; 101 network->activation_state() == shill::kActivationStateActivating;
98 if (!animating && network->IsConnectingState()) 102 if (!animating && network->IsConnectingState())
99 animating = true; 103 animating = true;
100 } 104 }
101
102 if (animating) 105 if (animating)
103 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 106 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
104 else 107 else
105 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 108 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
109 }
106 110
111 void NetworkListView::UpdateNetworkListInternal() {
112 SCOPED_NET_LOG_IF_SLOW();
107 // Get the updated list entries 113 // Get the updated list entries
108 network_map_.clear(); 114 network_map_.clear();
109 std::set<std::string> new_service_paths; 115 std::set<std::string> new_service_paths;
110 bool needs_relayout = UpdateNetworkListEntries(&new_service_paths); 116 bool needs_relayout = UpdateNetworkListEntries(&new_service_paths);
111 117
112 // Remove old children 118 // Remove old children
113 std::set<std::string> remove_service_paths; 119 std::set<std::string> remove_service_paths;
114 for (ServicePathMap::const_iterator it = service_path_map_.begin(); 120 for (ServicePathMap::const_iterator it = service_path_map_.begin();
115 it != service_path_map_.end(); 121 it != service_path_map_.end();
116 ++it) { 122 ++it) {
117 if (new_service_paths.find(it->first) == new_service_paths.end()) { 123 if (new_service_paths.find(it->first) == new_service_paths.end()) {
118 remove_service_paths.insert(it->first); 124 remove_service_paths.insert(it->first);
119 network_map_.erase(it->second); 125 network_map_.erase(it->second);
120 content_->RemoveChildView(it->second); 126 content_->RemoveChildView(it->second);
121 needs_relayout = true; 127 needs_relayout = true;
122 } 128 }
123 } 129 }
124 130
125 for (std::set<std::string>::const_iterator remove_it = 131 for (std::set<std::string>::const_iterator remove_it =
126 remove_service_paths.begin(); 132 remove_service_paths.begin();
127 remove_it != remove_service_paths.end(); 133 remove_it != remove_service_paths.end();
128 ++remove_it) { 134 ++remove_it) {
129 service_path_map_.erase(*remove_it); 135 service_path_map_.erase(*remove_it);
130 } 136 }
131 137
132 if (needs_relayout) { 138 if (needs_relayout)
133 views::View* selected_view = NULL; 139 HandleRelayout();
134 for (ServicePathMap::const_iterator iter = service_path_map_.begin(); 140 }
135 iter != service_path_map_.end(); 141
136 ++iter) { 142 void NetworkListView::HandleRelayout() {
137 if (delegate_->IsViewHovered(iter->second)) { 143 views::View* selected_view = NULL;
138 selected_view = iter->second; 144 for (auto& iter : service_path_map_) {
139 break; 145 if (delegate_->IsViewHovered(iter.second)) {
140 } 146 selected_view = iter.second;
147 break;
141 } 148 }
142 content_->SizeToPreferredSize();
143 delegate_->RelayoutScrollList();
144 if (selected_view)
145 content_->ScrollRectToVisible(selected_view->bounds());
146 } 149 }
150 content_->SizeToPreferredSize();
151 delegate_->RelayoutScrollList();
152 if (selected_view)
153 content_->ScrollRectToVisible(selected_view->bounds());
147 } 154 }
148 155
149 bool NetworkListView::UpdateNetworkListEntries( 156 bool NetworkListView::UpdateNetworkListEntries(
150 std::set<std::string>* new_service_paths) { 157 std::set<std::string>* new_service_paths) {
151 bool needs_relayout = false; 158 bool needs_relayout = false;
152 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 159 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
153 160
154 // Insert child views 161 // Insert child views
155 int index = 0; 162 int index = 0;
156 163
157 // Highlighted networks 164 // Highlighted networks
158 for (size_t i = 0; i < network_list_.size(); ++i) { 165 needs_relayout |=
159 const NetworkInfo* info = network_list_[i]; 166 UpdateNetworkChildren(new_service_paths, &index, true /* highlighted */);
160 if (info->highlight) {
161 if (UpdateNetworkChild(index++, info))
162 needs_relayout = true;
163 new_service_paths->insert(info->service_path);
164 }
165 }
166 167
167 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); 168 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern();
168 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) { 169 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) {
169 // Cellular initializing 170 // Cellular initializing
170 int message_id = network_icon::GetCellularUninitializedMsg(); 171 int message_id = network_icon::GetCellularUninitializedMsg();
171 if (!message_id && 172 if (!message_id &&
172 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && 173 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) &&
173 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { 174 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) {
174 message_id = IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS; 175 message_id = IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS;
175 } 176 }
176 if (UpdateInfoLabel(message_id, index, &no_cellular_networks_view_)) 177 needs_relayout |=
177 needs_relayout = true; 178 UpdateInfoLabel(message_id, index, &no_cellular_networks_view_);
179
178 if (message_id) 180 if (message_id)
179 ++index; 181 ++index;
180 } 182 }
181 183
182 if (pattern.MatchesPattern(NetworkTypePattern::WiFi())) { 184 if (pattern.MatchesPattern(NetworkTypePattern::WiFi())) {
183 // "Wifi Enabled / Disabled" 185 // "Wifi Enabled / Disabled"
184 int message_id = 0; 186 int message_id = 0;
185 if (network_list_.empty()) { 187 if (network_list_.empty()) {
186 message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) 188 message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi())
187 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED 189 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED
188 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; 190 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
189 } 191 }
190 if (UpdateInfoLabel(message_id, index, &no_wifi_networks_view_)) 192 needs_relayout |=
191 needs_relayout = true; 193 UpdateInfoLabel(message_id, index, &no_wifi_networks_view_);
192 if (message_id) 194 if (message_id)
193 ++index; 195 ++index;
194 196
195 // "Wifi Scanning" 197 // "Wifi Scanning"
196 message_id = 0; 198 message_id = 0;
197 if (handler->GetScanningByType(NetworkTypePattern::WiFi())) 199 if (handler->GetScanningByType(NetworkTypePattern::WiFi()))
198 message_id = IDS_ASH_STATUS_TRAY_WIFI_SCANNING_MESSAGE; 200 message_id = IDS_ASH_STATUS_TRAY_WIFI_SCANNING_MESSAGE;
199 if (UpdateInfoLabel(message_id, index, &scanning_view_)) 201 needs_relayout |= UpdateInfoLabel(message_id, index, &scanning_view_);
200 needs_relayout = true;
201 if (message_id) 202 if (message_id)
202 ++index; 203 ++index;
203 } 204 }
204 205
205 // Un-highlighted networks 206 // Un-highlighted networks
206 for (size_t i = 0; i < network_list_.size(); ++i) { 207 needs_relayout |= UpdateNetworkChildren(new_service_paths, &index,
207 const NetworkInfo* info = network_list_[i]; 208 false /* not highlighted */);
208 if (!info->highlight) {
209 if (UpdateNetworkChild(index++, info))
210 needs_relayout = true;
211 new_service_paths->insert(info->service_path);
212 }
213 }
214 209
215 // No networks or other messages (fallback) 210 // No networks or other messages (fallback)
216 if (index == 0) { 211 if (index == 0) {
217 int message_id = 0; 212 int message_id = 0;
218 if (pattern.Equals(NetworkTypePattern::VPN())) 213 if (pattern.Equals(NetworkTypePattern::VPN()))
219 message_id = IDS_ASH_STATUS_TRAY_NETWORK_NO_VPN; 214 message_id = IDS_ASH_STATUS_TRAY_NETWORK_NO_VPN;
220 else 215 else
221 message_id = IDS_ASH_STATUS_TRAY_NO_NETWORKS; 216 message_id = IDS_ASH_STATUS_TRAY_NO_NETWORKS;
222 if (UpdateInfoLabel(message_id, index, &scanning_view_)) 217 needs_relayout |= UpdateInfoLabel(message_id, index, &scanning_view_);
223 needs_relayout = true;
224 } 218 }
225 219
226 return needs_relayout; 220 return needs_relayout;
227 } 221 }
228 222
223 bool NetworkListView::UpdateNetworkChildren(
224 std::set<std::string>* new_service_paths,
225 int* child_index,
226 bool highlighted) {
227 bool needs_relayout = false;
228 int index = *child_index;
229 for (auto& info : network_list_) {
230 if (info->highlight != highlighted)
231 continue;
232 needs_relayout |= UpdateNetworkChild(index++, info);
233 new_service_paths->insert(info->service_path);
234 }
235 *child_index = index;
236 return needs_relayout;
237 }
238
229 bool NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) { 239 bool NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) {
230 bool needs_relayout = false; 240 bool needs_relayout = false;
231 views::View* container = NULL; 241 views::View* container = NULL;
232 ServicePathMap::const_iterator found = 242 ServicePathMap::const_iterator found =
233 service_path_map_.find(info->service_path); 243 service_path_map_.find(info->service_path);
234 if (found == service_path_map_.end()) { 244 if (found == service_path_map_.end()) {
235 container = delegate_->CreateViewForNetwork(*info); 245 container = delegate_->CreateViewForNetwork(*info);
236 content_->AddChildViewAt(container, index); 246 content_->AddChildViewAt(container, index);
237 needs_relayout = true; 247 needs_relayout = true;
238 } else { 248 } else {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 needs_relayout = true; 291 needs_relayout = true;
282 } 292 }
283 return needs_relayout; 293 return needs_relayout;
284 } 294 }
285 295
286 void NetworkListView::NetworkIconChanged() { 296 void NetworkListView::NetworkIconChanged() {
287 UpdateNetworkList(); 297 UpdateNetworkList();
288 } 298 }
289 299
290 } // namespace ui 300 } // namespace ui
OLDNEW
« no previous file with comments | « ui/chromeos/network/network_list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698