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

Side by Side Diff: ash/system/chromeos/network/tray_network.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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/system/chromeos/network/tray_network.h" 5 #include "ash/system/chromeos/network/tray_network.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/metrics/user_metrics_recorder.h" 8 #include "ash/metrics/user_metrics_recorder.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" 10 #include "ash/system/chromeos/network/network_state_list_detailed_view.h"
(...skipping 29 matching lines...) Expand all
40 using chromeos::NetworkStateHandler; 40 using chromeos::NetworkStateHandler;
41 using chromeos::NetworkTypePattern; 41 using chromeos::NetworkTypePattern;
42 42
43 namespace ash { 43 namespace ash {
44 namespace tray { 44 namespace tray {
45 45
46 class NetworkTrayView : public TrayItemView, 46 class NetworkTrayView : public TrayItemView,
47 public ui::network_icon::AnimationObserver { 47 public ui::network_icon::AnimationObserver {
48 public: 48 public:
49 explicit NetworkTrayView(TrayNetwork* network_tray) 49 explicit NetworkTrayView(TrayNetwork* network_tray)
50 : TrayItemView(network_tray), 50 : TrayItemView(network_tray), network_tray_(network_tray) {
51 network_tray_(network_tray) {
52 SetLayoutManager( 51 SetLayoutManager(
53 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); 52 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
54 53
55 image_view_ = new views::ImageView; 54 image_view_ = new views::ImageView;
56 AddChildView(image_view_); 55 AddChildView(image_view_);
57 56
58 UpdateNetworkStateHandlerIcon(); 57 UpdateNetworkStateHandlerIcon();
59 } 58 }
60 59
61 virtual ~NetworkTrayView() { 60 ~NetworkTrayView() override {
62 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 61 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
63 } 62 }
64 63
65 virtual const char* GetClassName() const override { 64 const char* GetClassName() const override { return "NetworkTrayView"; }
66 return "NetworkTrayView";
67 }
68 65
69 void UpdateNetworkStateHandlerIcon() { 66 void UpdateNetworkStateHandlerIcon() {
70 NetworkStateHandler* handler = 67 NetworkStateHandler* handler =
71 NetworkHandler::Get()->network_state_handler(); 68 NetworkHandler::Get()->network_state_handler();
72 gfx::ImageSkia image; 69 gfx::ImageSkia image;
73 base::string16 name; 70 base::string16 name;
74 bool animating = false; 71 bool animating = false;
75 ui::network_icon::GetDefaultNetworkImageAndLabel( 72 ui::network_icon::GetDefaultNetworkImageAndLabel(
76 ui::network_icon::ICON_TYPE_TRAY, &image, &name, &animating); 73 ui::network_icon::ICON_TYPE_TRAY, &image, &name, &animating);
77 bool show_in_tray = !image.isNull(); 74 bool show_in_tray = !image.isNull();
78 UpdateIcon(show_in_tray, image); 75 UpdateIcon(show_in_tray, image);
79 if (animating) 76 if (animating)
80 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 77 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
81 else 78 else
82 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( 79 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(
83 this); 80 this);
84 // Update accessibility. 81 // Update accessibility.
85 const NetworkState* connected_network = 82 const NetworkState* connected_network =
86 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); 83 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual());
87 if (connected_network) { 84 if (connected_network) {
88 UpdateConnectionStatus( 85 UpdateConnectionStatus(base::UTF8ToUTF16(connected_network->name()),
89 base::UTF8ToUTF16(connected_network->name()), true); 86 true);
90 } else { 87 } else {
91 UpdateConnectionStatus(base::string16(), false); 88 UpdateConnectionStatus(base::string16(), false);
92 } 89 }
93 } 90 }
94 91
95 void UpdateAlignment(ShelfAlignment alignment) { 92 void UpdateAlignment(ShelfAlignment alignment) {
96 SetLayoutManager(new views::BoxLayout( 93 SetLayoutManager(new views::BoxLayout(alignment == SHELF_ALIGNMENT_BOTTOM
97 alignment == SHELF_ALIGNMENT_BOTTOM ? 94 ? views::BoxLayout::kHorizontal
98 views::BoxLayout::kHorizontal : views::BoxLayout::kVertical, 95 : views::BoxLayout::kVertical,
99 0, 0, 0)); 96 0, 0, 0));
100 Layout(); 97 Layout();
101 } 98 }
102 99
103 // views::View override. 100 // views::View override.
104 virtual void GetAccessibleState(ui::AXViewState* state) override { 101 void GetAccessibleState(ui::AXViewState* state) override {
105 state->name = connection_status_string_; 102 state->name = connection_status_string_;
106 state->role = ui::AX_ROLE_BUTTON; 103 state->role = ui::AX_ROLE_BUTTON;
107 } 104 }
108 105
109 // ui::network_icon::AnimationObserver 106 // ui::network_icon::AnimationObserver
110 virtual void NetworkIconChanged() override { 107 void NetworkIconChanged() override { UpdateNetworkStateHandlerIcon(); }
111 UpdateNetworkStateHandlerIcon();
112 }
113 108
114 private: 109 private:
115 // Updates connection status and notifies accessibility event when necessary. 110 // Updates connection status and notifies accessibility event when necessary.
116 void UpdateConnectionStatus(const base::string16& network_name, 111 void UpdateConnectionStatus(const base::string16& network_name,
117 bool connected) { 112 bool connected) {
118 base::string16 new_connection_status_string; 113 base::string16 new_connection_status_string;
119 if (connected) { 114 if (connected) {
120 new_connection_status_string = l10n_util::GetStringFUTF16( 115 new_connection_status_string = l10n_util::GetStringFUTF16(
121 IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, network_name); 116 IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, network_name);
122 } 117 }
123 if (new_connection_status_string != connection_status_string_) { 118 if (new_connection_status_string != connection_status_string_) {
124 connection_status_string_ = new_connection_status_string; 119 connection_status_string_ = new_connection_status_string;
125 if(!connection_status_string_.empty()) 120 if (!connection_status_string_.empty())
126 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 121 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
127 } 122 }
128 } 123 }
129 124
130 void UpdateIcon(bool tray_icon_visible, const gfx::ImageSkia& image) { 125 void UpdateIcon(bool tray_icon_visible, const gfx::ImageSkia& image) {
131 image_view_->SetImage(image); 126 image_view_->SetImage(image);
132 SetVisible(tray_icon_visible); 127 SetVisible(tray_icon_visible);
133 SchedulePaint(); 128 SchedulePaint();
134 } 129 }
135 130
136 TrayNetwork* network_tray_; 131 TrayNetwork* network_tray_;
137 views::ImageView* image_view_; 132 views::ImageView* image_view_;
138 base::string16 connection_status_string_; 133 base::string16 connection_status_string_;
139 134
140 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); 135 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView);
141 }; 136 };
142 137
143 class NetworkDefaultView : public TrayItemMore, 138 class NetworkDefaultView : public TrayItemMore,
144 public ui::network_icon::AnimationObserver { 139 public ui::network_icon::AnimationObserver {
145 public: 140 public:
146 NetworkDefaultView(TrayNetwork* network_tray, bool show_more) 141 NetworkDefaultView(TrayNetwork* network_tray, bool show_more)
147 : TrayItemMore(network_tray, show_more), 142 : TrayItemMore(network_tray, show_more), network_tray_(network_tray) {
148 network_tray_(network_tray) {
149 Update(); 143 Update();
150 } 144 }
151 145
152 virtual ~NetworkDefaultView() { 146 ~NetworkDefaultView() override {
153 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 147 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
154 } 148 }
155 149
156 void Update() { 150 void Update() {
157 gfx::ImageSkia image; 151 gfx::ImageSkia image;
158 base::string16 label; 152 base::string16 label;
159 bool animating = false; 153 bool animating = false;
160 ui::network_icon::GetDefaultNetworkImageAndLabel( 154 ui::network_icon::GetDefaultNetworkImageAndLabel(
161 ui::network_icon::ICON_TYPE_DEFAULT_VIEW, &image, &label, &animating); 155 ui::network_icon::ICON_TYPE_DEFAULT_VIEW, &image, &label, &animating);
162 if (animating) 156 if (animating)
163 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 157 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
164 else 158 else
165 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( 159 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(
166 this); 160 this);
167 SetImage(&image); 161 SetImage(&image);
168 SetLabel(label); 162 SetLabel(label);
169 SetAccessibleName(label); 163 SetAccessibleName(label);
170 } 164 }
171 165
172 // ui::network_icon::AnimationObserver 166 // ui::network_icon::AnimationObserver
173 virtual void NetworkIconChanged() override { 167 void NetworkIconChanged() override { Update(); }
174 Update();
175 }
176 168
177 private: 169 private:
178 TrayNetwork* network_tray_; 170 TrayNetwork* network_tray_;
179 171
180 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); 172 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView);
181 }; 173 };
182 174
183 class NetworkWifiDetailedView : public NetworkDetailedView { 175 class NetworkWifiDetailedView : public NetworkDetailedView {
184 public: 176 public:
185 explicit NetworkWifiDetailedView(SystemTrayItem* owner) 177 explicit NetworkWifiDetailedView(SystemTrayItem* owner)
186 : NetworkDetailedView(owner) { 178 : NetworkDetailedView(owner) {
187 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 179 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
188 kTrayPopupPaddingHorizontal, 180 kTrayPopupPaddingHorizontal, 10,
189 10,
190 kTrayPopupPaddingBetweenItems)); 181 kTrayPopupPaddingBetweenItems));
191 image_view_ = new views::ImageView; 182 image_view_ = new views::ImageView;
192 AddChildView(image_view_); 183 AddChildView(image_view_);
193 184
194 label_view_ = new views::Label(); 185 label_view_ = new views::Label();
195 label_view_->SetMultiLine(true); 186 label_view_->SetMultiLine(true);
196 label_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 187 label_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
197 AddChildView(label_view_); 188 AddChildView(label_view_);
198 189
199 Update(); 190 Update();
200 } 191 }
201 192
202 virtual ~NetworkWifiDetailedView() { 193 ~NetworkWifiDetailedView() override {}
203 }
204 194
205 // Overridden from NetworkDetailedView: 195 // Overridden from NetworkDetailedView:
206 196
207 virtual void Init() override { 197 void Init() override {}
208 }
209 198
210 virtual NetworkDetailedView::DetailedViewType GetViewType() const override { 199 NetworkDetailedView::DetailedViewType GetViewType() const override {
211 return NetworkDetailedView::WIFI_VIEW; 200 return NetworkDetailedView::WIFI_VIEW;
212 } 201 }
213 202
214 virtual void ManagerChanged() override { 203 void Layout() override {
215 Update(); 204 // Center both views vertically.
205 views::View::Layout();
206 image_view_->SetY((height() - image_view_->GetPreferredSize().height()) /
207 2);
208 label_view_->SetY((height() - label_view_->GetPreferredSize().height()) /
209 2);
216 } 210 }
217 211
218 virtual void NetworkListChanged() override { 212 void Update() override {
219 Update(); 213 bool wifi_enabled =
220 } 214 NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled(
215 NetworkTypePattern::WiFi());
216 const int image_id = wifi_enabled ? IDR_AURA_UBER_TRAY_WIFI_ENABLED
217 : IDR_AURA_UBER_TRAY_WIFI_DISABLED;
218 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
219 image_view_->SetImage(bundle.GetImageNamed(image_id).ToImageSkia());
221 220
222 virtual void NetworkServiceChanged( 221 const int string_id = wifi_enabled
223 const chromeos::NetworkState* network) override { 222 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED
223 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
224 label_view_->SetText(bundle.GetLocalizedString(string_id));
225 label_view_->SizeToFit(
226 kTrayPopupMinWidth - kTrayPopupPaddingHorizontal * 2 -
227 kTrayPopupPaddingBetweenItems - kTrayPopupDetailsIconWidth);
224 } 228 }
225 229
226 private: 230 private:
227 virtual void Layout() override {
228 // Center both views vertically.
229 views::View::Layout();
230 image_view_->SetY(
231 (height() - image_view_->GetPreferredSize().height()) / 2);
232 label_view_->SetY(
233 (height() - label_view_->GetPreferredSize().height()) / 2);
234 }
235
236 void Update() {
237 bool wifi_enabled =
238 NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled(
239 NetworkTypePattern::WiFi());
240 const int image_id = wifi_enabled ?
241 IDR_AURA_UBER_TRAY_WIFI_ENABLED : IDR_AURA_UBER_TRAY_WIFI_DISABLED;
242 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
243 image_view_->SetImage(bundle.GetImageNamed(image_id).ToImageSkia());
244
245 const int string_id = wifi_enabled ?
246 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED :
247 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
248 label_view_->SetText(bundle.GetLocalizedString(string_id));
249 label_view_->SizeToFit(kTrayPopupMinWidth -
250 kTrayPopupPaddingHorizontal * 2 - kTrayPopupPaddingBetweenItems -
251 kTrayPopupDetailsIconWidth);
252 }
253
254 views::ImageView* image_view_; 231 views::ImageView* image_view_;
255 views::Label* label_view_; 232 views::Label* label_view_;
256 233
257 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); 234 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView);
258 }; 235 };
259 236
260 } // namespace tray 237 } // namespace tray
261 238
262 TrayNetwork::TrayNetwork(SystemTray* system_tray) 239 TrayNetwork::TrayNetwork(SystemTray* system_tray)
263 : SystemTrayItem(system_tray), 240 : SystemTrayItem(system_tray),
(...skipping 19 matching lines...) Expand all
283 return NULL; 260 return NULL;
284 tray_ = new tray::NetworkTrayView(this); 261 tray_ = new tray::NetworkTrayView(this);
285 return tray_; 262 return tray_;
286 } 263 }
287 264
288 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { 265 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) {
289 CHECK(default_ == NULL); 266 CHECK(default_ == NULL);
290 if (!chromeos::NetworkHandler::IsInitialized()) 267 if (!chromeos::NetworkHandler::IsInitialized())
291 return NULL; 268 return NULL;
292 CHECK(tray_ != NULL); 269 CHECK(tray_ != NULL);
293 default_ = new tray::NetworkDefaultView( 270 default_ =
294 this, status != user::LOGGED_IN_LOCKED); 271 new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED);
295 return default_; 272 return default_;
296 } 273 }
297 274
298 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { 275 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) {
299 CHECK(detailed_ == NULL); 276 CHECK(detailed_ == NULL);
300 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 277 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
301 ash::UMA_STATUS_AREA_DETAILED_NETWORK_VIEW); 278 ash::UMA_STATUS_AREA_DETAILED_NETWORK_VIEW);
302 if (!chromeos::NetworkHandler::IsInitialized()) 279 if (!chromeos::NetworkHandler::IsInitialized())
303 return NULL; 280 return NULL;
304 if (request_wifi_view_) { 281 if (request_wifi_view_) {
305 detailed_ = new tray::NetworkWifiDetailedView(this); 282 detailed_ = new tray::NetworkWifiDetailedView(this);
306 request_wifi_view_ = false; 283 request_wifi_view_ = false;
307 } else { 284 } else {
308 detailed_ = new tray::NetworkStateListDetailedView( 285 detailed_ = new tray::NetworkStateListDetailedView(
309 this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status); 286 this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status);
310 detailed_->Init(); 287 detailed_->Init();
311 } 288 }
(...skipping 25 matching lines...) Expand all
337 void TrayNetwork::RequestToggleWifi() { 314 void TrayNetwork::RequestToggleWifi() {
338 // This will always be triggered by a user action (e.g. keyboard shortcut) 315 // This will always be triggered by a user action (e.g. keyboard shortcut)
339 if (!detailed_ || 316 if (!detailed_ ||
340 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { 317 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) {
341 request_wifi_view_ = true; 318 request_wifi_view_ = true;
342 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 319 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
343 } 320 }
344 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 321 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
345 bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()); 322 bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi());
346 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 323 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
347 enabled ? 324 enabled ? ash::UMA_STATUS_AREA_DISABLE_WIFI
348 ash::UMA_STATUS_AREA_DISABLE_WIFI : 325 : ash::UMA_STATUS_AREA_ENABLE_WIFI);
349 ash::UMA_STATUS_AREA_ENABLE_WIFI); 326 handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), !enabled,
350 handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(),
351 !enabled,
352 chromeos::network_handler::ErrorCallback()); 327 chromeos::network_handler::ErrorCallback());
353 } 328 }
354 329
355 void TrayNetwork::OnCaptivePortalDetected( 330 void TrayNetwork::OnCaptivePortalDetected(
356 const std::string& /* service_path */) { 331 const std::string& /* service_path */) {
357 NetworkStateChanged(false); 332 NetworkStateChanged();
358 } 333 }
359 334
360 void TrayNetwork::NetworkStateChanged(bool list_changed) { 335 void TrayNetwork::NetworkStateChanged() {
361 if (tray_) 336 if (tray_)
362 tray_->UpdateNetworkStateHandlerIcon(); 337 tray_->UpdateNetworkStateHandlerIcon();
363 if (default_) 338 if (default_)
364 default_->Update(); 339 default_->Update();
365 if (detailed_) {
366 if (list_changed)
367 detailed_->NetworkListChanged();
368 else
369 detailed_->ManagerChanged();
370 }
371 }
372
373 void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) {
374 if (detailed_) 340 if (detailed_)
375 detailed_->NetworkServiceChanged(network); 341 detailed_->Update();
376 } 342 }
377 343
378 } // namespace ash 344 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/tray_network.h ('k') | ash/system/chromeos/network/tray_network_state_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698