OLD | NEW |
---|---|
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/network_icon.h" | 5 #include "ash/system/chromeos/network/network_icon.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/chromeos/network/network_icon_animation.h" | 8 #include "ash/system/chromeos/network/network_icon_animation.h" |
9 #include "ash/system/chromeos/network/network_icon_animation_observer.h" | 9 #include "ash/system/chromeos/network/network_icon_animation_observer.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chromeos/network/device_state.h" | 11 #include "chromeos/network/device_state.h" |
12 #include "chromeos/network/network_connection_handler.h" | 12 #include "chromeos/network/network_connection_handler.h" |
13 #include "chromeos/network/network_state.h" | 13 #include "chromeos/network/network_state.h" |
14 #include "chromeos/network/network_state_handler.h" | 14 #include "chromeos/network/network_state_handler.h" |
15 #include "chromeos/network/shill_property_util.h" | |
15 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
16 #include "grit/ash_strings.h" | 17 #include "grit/ash_strings.h" |
17 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
21 #include "ui/gfx/image/image_skia_operations.h" | 22 #include "ui/gfx/image/image_skia_operations.h" |
22 #include "ui/gfx/image/image_skia_source.h" | 23 #include "ui/gfx/image/image_skia_source.h" |
23 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
24 #include "ui/gfx/size_conversions.h" | 25 #include "ui/gfx/size_conversions.h" |
25 | 26 |
26 using chromeos::DeviceState; | 27 using chromeos::DeviceState; |
27 using chromeos::NetworkConnectionHandler; | 28 using chromeos::NetworkConnectionHandler; |
28 using chromeos::NetworkHandler; | 29 using chromeos::NetworkHandler; |
29 using chromeos::NetworkState; | 30 using chromeos::NetworkState; |
30 using chromeos::NetworkStateHandler; | 31 using chromeos::NetworkStateHandler; |
32 using chromeos::NetworkTypePattern; | |
31 | 33 |
32 namespace ash { | 34 namespace ash { |
33 namespace network_icon { | 35 namespace network_icon { |
34 | 36 |
35 namespace { | 37 namespace { |
36 | 38 |
37 //------------------------------------------------------------------------------ | 39 //------------------------------------------------------------------------------ |
38 // Struct to pass icon badges to NetworkIconImageSource. | 40 // Struct to pass icon badges to NetworkIconImageSource. |
39 struct Badges { | 41 struct Badges { |
40 Badges() | 42 Badges() |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 const gfx::ImageSkia* BadgeForVPN(IconType icon_type) { | 459 const gfx::ImageSkia* BadgeForVPN(IconType icon_type) { |
458 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 460 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
459 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); | 461 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); |
460 } | 462 } |
461 | 463 |
462 gfx::ImageSkia GetIcon(const NetworkState* network, | 464 gfx::ImageSkia GetIcon(const NetworkState* network, |
463 IconType icon_type, | 465 IconType icon_type, |
464 int strength_index) { | 466 int strength_index) { |
465 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 467 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
466 const std::string& type = network->type(); | 468 const std::string& type = network->type(); |
467 if (type == flimflam::kTypeEthernet) { | 469 if (NetworkTypePattern::Ethernet().Matches(type)) { |
468 return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); | 470 return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); |
469 } else if (type == flimflam::kTypeWifi || | 471 } else if (type == flimflam::kTypeWifi || |
470 type == flimflam::kTypeWimax || | 472 type == flimflam::kTypeWimax || |
471 type == flimflam::kTypeCellular) { | 473 type == flimflam::kTypeCellular) { |
stevenjb
2013/09/03 16:22:43
We should use NetworkTypePattern consistently in e
pneubeck (no reviews)
2013/09/04 12:57:29
Adapted the other conditions here too.
| |
472 DCHECK(strength_index > 0); | 474 DCHECK(strength_index > 0); |
473 return GetImageForIndex( | 475 return GetImageForIndex( |
474 ImageTypeForNetworkType(type), icon_type, strength_index); | 476 ImageTypeForNetworkType(type), icon_type, strength_index); |
475 } else if (type == flimflam::kTypeVPN) { | 477 } else if (type == flimflam::kTypeVPN) { |
476 return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN); | 478 return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN); |
477 } else { | 479 } else { |
478 LOG(WARNING) << "Request for icon for unsupported type: " << type; | 480 LOG(WARNING) << "Request for icon for unsupported type: " << type; |
479 return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); | 481 return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); |
480 } | 482 } |
481 } | 483 } |
482 | 484 |
483 //------------------------------------------------------------------------------ | 485 //------------------------------------------------------------------------------ |
484 // Get connecting images | 486 // Get connecting images |
485 | 487 |
486 gfx::ImageSkia GetConnectingVpnImage(IconType icon_type) { | 488 gfx::ImageSkia GetConnectingVpnImage(IconType icon_type) { |
487 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 489 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
488 const NetworkState* connected_network = NULL; | 490 const NetworkState* connected_network = NULL; |
489 if (icon_type == ICON_TYPE_TRAY) { | 491 if (icon_type == ICON_TYPE_TRAY) { |
490 connected_network = handler->ConnectedNetworkByType( | 492 connected_network = |
491 NetworkStateHandler::kMatchTypeNonVirtual); | 493 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); |
492 } | 494 } |
493 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); | 495 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); |
494 | 496 |
495 if (connected_network) { | 497 if (connected_network) { |
496 gfx::ImageSkia icon = GetImageForNetwork(connected_network, icon_type); | 498 gfx::ImageSkia icon = GetImageForNetwork(connected_network, icon_type); |
497 Badges badges; | 499 Badges badges; |
498 badges.bottom_left = ConnectingVpnBadge(animation); | 500 badges.bottom_left = ConnectingVpnBadge(animation); |
499 return gfx::ImageSkia( | 501 return gfx::ImageSkia( |
500 new NetworkIconImageSource(icon, badges), icon.size()); | 502 new NetworkIconImageSource(icon, badges), icon.size()); |
501 } else { | 503 } else { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 // Determine whether or not we need to update the icon. | 540 // Determine whether or not we need to update the icon. |
539 bool dirty = image_.isNull(); | 541 bool dirty = image_.isNull(); |
540 | 542 |
541 // If the network state has changed, the icon needs updating. | 543 // If the network state has changed, the icon needs updating. |
542 if (state_ != network->connection_state()) { | 544 if (state_ != network->connection_state()) { |
543 state_ = network->connection_state(); | 545 state_ = network->connection_state(); |
544 dirty = true; | 546 dirty = true; |
545 } | 547 } |
546 | 548 |
547 const std::string& type = network->type(); | 549 const std::string& type = network->type(); |
548 if (type != flimflam::kTypeEthernet) | 550 if (!NetworkTypePattern::Ethernet().Matches(type)) |
549 dirty |= UpdateWirelessStrengthIndex(network); | 551 dirty |= UpdateWirelessStrengthIndex(network); |
550 | 552 |
551 if (type == flimflam::kTypeCellular) | 553 if (type == flimflam::kTypeCellular) |
552 dirty |= UpdateCellularState(network); | 554 dirty |= UpdateCellularState(network); |
553 | 555 |
554 if (IconTypeHasVPNBadge(icon_type_) && type != flimflam::kTypeVPN) | 556 if (IconTypeHasVPNBadge(icon_type_) && type != flimflam::kTypeVPN) |
555 dirty |= UpdateVPNBadge(); | 557 dirty |= UpdateVPNBadge(); |
556 | 558 |
557 if (dirty) { | 559 if (dirty) { |
558 // Set the icon and badges based on the network and generate the image. | 560 // Set the icon and badges based on the network and generate the image. |
(...skipping 21 matching lines...) Expand all Loading... | |
580 std::string roaming_state = network->roaming(); | 582 std::string roaming_state = network->roaming(); |
581 if (roaming_state != roaming_state_) { | 583 if (roaming_state != roaming_state_) { |
582 roaming_state_ = roaming_state; | 584 roaming_state_ = roaming_state; |
583 dirty = true; | 585 dirty = true; |
584 } | 586 } |
585 return dirty; | 587 return dirty; |
586 } | 588 } |
587 | 589 |
588 bool NetworkIconImpl::UpdateVPNBadge() { | 590 bool NetworkIconImpl::UpdateVPNBadge() { |
589 const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> | 591 const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> |
590 ConnectedNetworkByType(flimflam::kTypeVPN); | 592 ConnectedNetworkByType(NetworkTypePattern::VPN()); |
591 if (vpn && vpn_badge_ == NULL) { | 593 if (vpn && vpn_badge_ == NULL) { |
592 vpn_badge_ = BadgeForVPN(icon_type_); | 594 vpn_badge_ = BadgeForVPN(icon_type_); |
593 return true; | 595 return true; |
594 } else if (!vpn && vpn_badge_ != NULL) { | 596 } else if (!vpn && vpn_badge_ != NULL) { |
595 vpn_badge_ = NULL; | 597 vpn_badge_ = NULL; |
596 return true; | 598 return true; |
597 } | 599 } |
598 return false; | 600 return false; |
599 } | 601 } |
600 | 602 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 return l10n_util::GetStringFUTF16( | 720 return l10n_util::GetStringFUTF16( |
719 IDS_ASH_STATUS_TRAY_NETWORK_CONNECTING, UTF8ToUTF16(network->name())); | 721 IDS_ASH_STATUS_TRAY_NETWORK_CONNECTING, UTF8ToUTF16(network->name())); |
720 } | 722 } |
721 if (activation_state == flimflam::kActivationStateActivating) { | 723 if (activation_state == flimflam::kActivationStateActivating) { |
722 return l10n_util::GetStringFUTF16( | 724 return l10n_util::GetStringFUTF16( |
723 IDS_ASH_STATUS_TRAY_NETWORK_ACTIVATING, UTF8ToUTF16(network->name())); | 725 IDS_ASH_STATUS_TRAY_NETWORK_ACTIVATING, UTF8ToUTF16(network->name())); |
724 } | 726 } |
725 } | 727 } |
726 | 728 |
727 // Otherwise just show the network name or 'Ethernet'. | 729 // Otherwise just show the network name or 'Ethernet'. |
728 if (network->type() == flimflam::kTypeEthernet) { | 730 if (network->Matches(NetworkTypePattern::Ethernet())) { |
729 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ETHERNET); | 731 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ETHERNET); |
730 } else { | 732 } else { |
731 return UTF8ToUTF16(network->name()); | 733 return UTF8ToUTF16(network->name()); |
732 } | 734 } |
733 } | 735 } |
734 | 736 |
735 int GetCellularUninitializedMsg() { | 737 int GetCellularUninitializedMsg() { |
736 static base::Time s_uninitialized_state_time; | 738 static base::Time s_uninitialized_state_time; |
737 static int s_uninitialized_msg(0); | 739 static int s_uninitialized_msg(0); |
738 | 740 |
739 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 741 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
740 if (handler->GetTechnologyState(NetworkStateHandler::kMatchTypeMobile) | 742 if (handler->GetTechnologyState(NetworkTypePattern::Mobile()) |
741 == NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) { | 743 == NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) { |
742 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR; | 744 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR; |
743 s_uninitialized_state_time = base::Time::Now(); | 745 s_uninitialized_state_time = base::Time::Now(); |
744 return s_uninitialized_msg; | 746 return s_uninitialized_msg; |
745 } else if (handler->GetScanningByType( | 747 } else if (handler->GetScanningByType(NetworkTypePattern::Mobile())) { |
746 NetworkStateHandler::kMatchTypeMobile)) { | |
747 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_CELLULAR_SCANNING; | 748 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_CELLULAR_SCANNING; |
748 s_uninitialized_state_time = base::Time::Now(); | 749 s_uninitialized_state_time = base::Time::Now(); |
749 return s_uninitialized_msg; | 750 return s_uninitialized_msg; |
750 } | 751 } |
751 // There can be a delay between leaving the Initializing state and when | 752 // There can be a delay between leaving the Initializing state and when |
752 // a Cellular device shows up, so keep showing the initializing | 753 // a Cellular device shows up, so keep showing the initializing |
753 // animation for a bit to avoid flashing the disconnect icon. | 754 // animation for a bit to avoid flashing the disconnect icon. |
754 const int kInitializingDelaySeconds = 1; | 755 const int kInitializingDelaySeconds = 1; |
755 base::TimeDelta dtime = base::Time::Now() - s_uninitialized_state_time; | 756 base::TimeDelta dtime = base::Time::Now() - s_uninitialized_state_time; |
756 if (dtime.InSeconds() < kInitializingDelaySeconds) | 757 if (dtime.InSeconds() < kInitializingDelaySeconds) |
757 return s_uninitialized_msg; | 758 return s_uninitialized_msg; |
758 return 0; | 759 return 0; |
759 } | 760 } |
760 | 761 |
761 void GetDefaultNetworkImageAndLabel(IconType icon_type, | 762 void GetDefaultNetworkImageAndLabel(IconType icon_type, |
762 gfx::ImageSkia* image, | 763 gfx::ImageSkia* image, |
763 base::string16* label, | 764 base::string16* label, |
764 bool* animating) { | 765 bool* animating) { |
765 NetworkStateHandler* state_handler = | 766 NetworkStateHandler* state_handler = |
766 NetworkHandler::Get()->network_state_handler(); | 767 NetworkHandler::Get()->network_state_handler(); |
767 NetworkConnectionHandler* connect_handler = | 768 NetworkConnectionHandler* connect_handler = |
768 NetworkHandler::Get()->network_connection_handler(); | 769 NetworkHandler::Get()->network_connection_handler(); |
769 const NetworkState* connected_network = | 770 const NetworkState* connected_network = |
770 state_handler->ConnectedNetworkByType( | 771 state_handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); |
771 NetworkStateHandler::kMatchTypeNonVirtual); | |
772 const NetworkState* connecting_network = | 772 const NetworkState* connecting_network = |
773 state_handler->ConnectingNetworkByType( | 773 state_handler->ConnectingNetworkByType(NetworkTypePattern::Wireless()); |
774 NetworkStateHandler::kMatchTypeWireless); | |
775 if (!connecting_network && icon_type == ICON_TYPE_TRAY) { | 774 if (!connecting_network && icon_type == ICON_TYPE_TRAY) { |
776 connecting_network = | 775 connecting_network = |
777 state_handler->ConnectingNetworkByType(flimflam::kTypeVPN); | 776 state_handler->ConnectingNetworkByType(NetworkTypePattern::VPN()); |
778 } | 777 } |
779 | 778 |
780 const NetworkState* network; | 779 const NetworkState* network; |
781 // If we are connecting to a network, and there is either no connected | 780 // If we are connecting to a network, and there is either no connected |
782 // network, or the connection was user requested, use the connecting | 781 // network, or the connection was user requested, use the connecting |
783 // network. | 782 // network. |
784 if (connecting_network && | 783 if (connecting_network && |
785 (!connected_network || | 784 (!connected_network || |
786 connect_handler->HasConnectingNetwork(connecting_network->path()))) { | 785 connect_handler->HasConnectingNetwork(connecting_network->path()))) { |
787 network = connecting_network; | 786 network = connecting_network; |
788 } else { | 787 } else { |
789 network = connected_network; | 788 network = connected_network; |
790 } | 789 } |
791 | 790 |
792 // Don't show ethernet in the tray | 791 // Don't show ethernet in the tray |
793 if (icon_type == ICON_TYPE_TRAY && | 792 if (icon_type == ICON_TYPE_TRAY && network && |
794 network && network->type() == flimflam::kTypeEthernet) { | 793 network->Matches(NetworkTypePattern::Ethernet())) { |
795 *image = gfx::ImageSkia(); | 794 *image = gfx::ImageSkia(); |
796 *animating = false; | 795 *animating = false; |
797 return; | 796 return; |
798 } | 797 } |
799 | 798 |
800 if (!network) { | 799 if (!network) { |
801 // If no connecting network, check if we are activating a network. | 800 // If no connecting network, check if we are activating a network. |
802 const NetworkState* mobile_network = state_handler->FirstNetworkByType( | 801 const NetworkState* mobile_network = |
803 NetworkStateHandler::kMatchTypeMobile); | 802 state_handler->FirstNetworkByType(NetworkTypePattern::Mobile()); |
804 if (mobile_network && (mobile_network->activation_state() == | 803 if (mobile_network && (mobile_network->activation_state() == |
805 flimflam::kActivationStateActivating)) { | 804 flimflam::kActivationStateActivating)) { |
806 network = mobile_network; | 805 network = mobile_network; |
807 } | 806 } |
808 } | 807 } |
809 if (!network) { | 808 if (!network) { |
810 // If no connecting network, check for cellular initializing. | 809 // If no connecting network, check for cellular initializing. |
811 int uninitialized_msg = GetCellularUninitializedMsg(); | 810 int uninitialized_msg = GetCellularUninitializedMsg(); |
812 if (uninitialized_msg != 0) { | 811 if (uninitialized_msg != 0) { |
813 *image = GetImageForConnectingNetwork(icon_type, flimflam::kTypeCellular); | 812 *image = GetImageForConnectingNetwork(icon_type, flimflam::kTypeCellular); |
(...skipping 26 matching lines...) Expand all Loading... | |
840 iter != networks.end(); ++iter) { | 839 iter != networks.end(); ++iter) { |
841 network_paths.insert((*iter)->path()); | 840 network_paths.insert((*iter)->path()); |
842 } | 841 } |
843 PurgeIconMap(ICON_TYPE_TRAY, network_paths); | 842 PurgeIconMap(ICON_TYPE_TRAY, network_paths); |
844 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); | 843 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); |
845 PurgeIconMap(ICON_TYPE_LIST, network_paths); | 844 PurgeIconMap(ICON_TYPE_LIST, network_paths); |
846 } | 845 } |
847 | 846 |
848 } // namespace network_icon | 847 } // namespace network_icon |
849 } // namespace ash | 848 } // namespace ash |
OLD | NEW |