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

Side by Side Diff: ash/system/chromeos/network/tray_network.cc

Issue 23712002: Cleanup network type matching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unit test in Debug. Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
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/shell.h" 8 #include "ash/shell.h"
9 #include "ash/system/chromeos/network/network_icon_animation.h" 9 #include "ash/system/chromeos/network/network_icon_animation.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"
11 #include "ash/system/chromeos/network/tray_network_state_observer.h" 11 #include "ash/system/chromeos/network/tray_network_state_observer.h"
12 #include "ash/system/tray/system_tray.h" 12 #include "ash/system/tray/system_tray.h"
13 #include "ash/system/tray/system_tray_delegate.h" 13 #include "ash/system/tray/system_tray_delegate.h"
14 #include "ash/system/tray/system_tray_notifier.h" 14 #include "ash/system/tray/system_tray_notifier.h"
15 #include "ash/system/tray/tray_constants.h" 15 #include "ash/system/tray/tray_constants.h"
16 #include "ash/system/tray/tray_item_more.h" 16 #include "ash/system/tray/tray_item_more.h"
17 #include "ash/system/tray/tray_item_view.h" 17 #include "ash/system/tray/tray_item_view.h"
18 #include "ash/system/tray/tray_utils.h" 18 #include "ash/system/tray/tray_utils.h"
19 #include "base/command_line.h" 19 #include "base/command_line.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "chromeos/network/network_state.h" 21 #include "chromeos/network/network_state.h"
22 #include "chromeos/network/network_state_handler.h" 22 #include "chromeos/network/network_state_handler.h"
23 #include "chromeos/network/shill_property_util.h"
23 #include "grit/ash_resources.h" 24 #include "grit/ash_resources.h"
24 #include "grit/ash_strings.h" 25 #include "grit/ash_strings.h"
25 #include "third_party/cros_system_api/dbus/service_constants.h" 26 #include "third_party/cros_system_api/dbus/service_constants.h"
26 #include "ui/base/accessibility/accessible_view_state.h" 27 #include "ui/base/accessibility/accessible_view_state.h"
27 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/views/controls/image_view.h" 30 #include "ui/views/controls/image_view.h"
30 #include "ui/views/controls/link.h" 31 #include "ui/views/controls/link.h"
31 #include "ui/views/controls/link_listener.h" 32 #include "ui/views/controls/link_listener.h"
32 #include "ui/views/layout/box_layout.h" 33 #include "ui/views/layout/box_layout.h"
33 #include "ui/views/widget/widget.h" 34 #include "ui/views/widget/widget.h"
34 35
35 using chromeos::NetworkHandler; 36 using chromeos::NetworkHandler;
36 using chromeos::NetworkState; 37 using chromeos::NetworkState;
37 using chromeos::NetworkStateHandler; 38 using chromeos::NetworkStateHandler;
39 using chromeos::NetworkTypePattern;
38 40
39 namespace ash { 41 namespace ash {
40 namespace internal { 42 namespace internal {
41 43
42 namespace tray { 44 namespace tray {
43 45
44 class NetworkTrayView : public TrayItemView, 46 class NetworkTrayView : public TrayItemView,
45 public network_icon::AnimationObserver { 47 public network_icon::AnimationObserver {
46 public: 48 public:
47 explicit NetworkTrayView(TrayNetwork* network_tray) 49 explicit NetworkTrayView(TrayNetwork* network_tray)
(...skipping 24 matching lines...) Expand all
72 bool animating = false; 74 bool animating = false;
73 network_icon::GetDefaultNetworkImageAndLabel( 75 network_icon::GetDefaultNetworkImageAndLabel(
74 network_icon::ICON_TYPE_TRAY, &image, &name, &animating); 76 network_icon::ICON_TYPE_TRAY, &image, &name, &animating);
75 bool show_in_tray = !image.isNull(); 77 bool show_in_tray = !image.isNull();
76 UpdateIcon(show_in_tray, image); 78 UpdateIcon(show_in_tray, image);
77 if (animating) 79 if (animating)
78 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 80 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
79 else 81 else
80 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 82 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
81 // Update accessibility. 83 // Update accessibility.
82 const NetworkState* connected_network = handler->ConnectedNetworkByType( 84 const NetworkState* connected_network =
83 NetworkStateHandler::kMatchTypeNonVirtual); 85 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual());
84 if (connected_network) 86 if (connected_network)
85 UpdateConnectionStatus(UTF8ToUTF16(connected_network->name()), true); 87 UpdateConnectionStatus(UTF8ToUTF16(connected_network->name()), true);
86 else 88 else
87 UpdateConnectionStatus(base::string16(), false); 89 UpdateConnectionStatus(base::string16(), false);
88 } 90 }
89 91
90 // views::View override. 92 // views::View override.
91 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE { 93 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE {
92 state->name = connection_status_string_; 94 state->name = connection_status_string_;
93 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; 95 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 virtual void Layout() OVERRIDE { 215 virtual void Layout() OVERRIDE {
214 // Center both views vertically. 216 // Center both views vertically.
215 views::View::Layout(); 217 views::View::Layout();
216 image_view_->SetY( 218 image_view_->SetY(
217 (height() - image_view_->GetPreferredSize().height()) / 2); 219 (height() - image_view_->GetPreferredSize().height()) / 2);
218 label_view_->SetY( 220 label_view_->SetY(
219 (height() - label_view_->GetPreferredSize().height()) / 2); 221 (height() - label_view_->GetPreferredSize().height()) / 2);
220 } 222 }
221 223
222 void Update() { 224 void Update() {
223 bool wifi_enabled = NetworkHandler::Get()->network_state_handler()-> 225 bool wifi_enabled =
224 IsTechnologyEnabled(flimflam::kTypeWifi); 226 NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled(
227 NetworkTypePattern::WiFi());
225 const int image_id = wifi_enabled ? 228 const int image_id = wifi_enabled ?
226 IDR_AURA_UBER_TRAY_WIFI_ENABLED : IDR_AURA_UBER_TRAY_WIFI_DISABLED; 229 IDR_AURA_UBER_TRAY_WIFI_ENABLED : IDR_AURA_UBER_TRAY_WIFI_DISABLED;
227 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 230 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
228 image_view_->SetImage(bundle.GetImageNamed(image_id).ToImageSkia()); 231 image_view_->SetImage(bundle.GetImageNamed(image_id).ToImageSkia());
229 232
230 const int string_id = wifi_enabled ? 233 const int string_id = wifi_enabled ?
231 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED : 234 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED :
232 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; 235 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
233 label_view_->SetText(bundle.GetLocalizedString(string_id)); 236 label_view_->SetText(bundle.GetLocalizedString(string_id));
234 label_view_->SizeToFit(kTrayPopupMinWidth - 237 label_view_->SizeToFit(kTrayPopupMinWidth -
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 315 }
313 316
314 void TrayNetwork::RequestToggleWifi() { 317 void TrayNetwork::RequestToggleWifi() {
315 // This will always be triggered by a user action (e.g. keyboard shortcut) 318 // This will always be triggered by a user action (e.g. keyboard shortcut)
316 if (!detailed_ || 319 if (!detailed_ ||
317 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { 320 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) {
318 request_wifi_view_ = true; 321 request_wifi_view_ = true;
319 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 322 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
320 } 323 }
321 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 324 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
322 bool enabled = handler->IsTechnologyEnabled(flimflam::kTypeWifi); 325 bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi());
323 handler->SetTechnologyEnabled( 326 handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(),
324 flimflam::kTypeWifi, !enabled, 327 !enabled,
325 chromeos::network_handler::ErrorCallback()); 328 chromeos::network_handler::ErrorCallback());
326 } 329 }
327 330
328 void TrayNetwork::NetworkStateChanged(bool list_changed) { 331 void TrayNetwork::NetworkStateChanged(bool list_changed) {
329 if (tray_) 332 if (tray_)
330 tray_->UpdateNetworkStateHandlerIcon(); 333 tray_->UpdateNetworkStateHandlerIcon();
331 if (default_) 334 if (default_)
332 default_->Update(); 335 default_->Update();
333 if (detailed_) { 336 if (detailed_) {
334 if (list_changed) 337 if (list_changed)
335 detailed_->NetworkListChanged(); 338 detailed_->NetworkListChanged();
336 else 339 else
337 detailed_->ManagerChanged(); 340 detailed_->ManagerChanged();
338 } 341 }
339 } 342 }
340 343
341 void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) { 344 void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) {
342 if (detailed_) 345 if (detailed_)
343 detailed_->NetworkServiceChanged(network); 346 detailed_->NetworkServiceChanged(network);
344 } 347 }
345 348
346 } // namespace internal 349 } // namespace internal
347 } // namespace ash 350 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/network_state_notifier.cc ('k') | ash/system/chromeos/network/tray_vpn.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698