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 <iostream> | |
Kyle Horimoto
2017/04/27 01:28:07
Remove.
lesliewatkins
2017/04/28 21:30:42
Done.
| |
6 | |
5 #include "ash/system/network/network_icon.h" | 7 #include "ash/system/network/network_icon.h" |
6 | 8 |
7 #include "ash/resources/vector_icons/vector_icons.h" | 9 #include "ash/resources/vector_icons/vector_icons.h" |
8 #include "ash/strings/grit/ash_strings.h" | 10 #include "ash/strings/grit/ash_strings.h" |
9 #include "ash/system/network/network_icon_animation.h" | 11 #include "ash/system/network/network_icon_animation.h" |
10 #include "ash/system/network/network_icon_animation_observer.h" | 12 #include "ash/system/network/network_icon_animation_observer.h" |
11 #include "ash/system/tray/tray_constants.h" | 13 #include "ash/system/tray/tray_constants.h" |
12 #include "base/macros.h" | 14 #include "base/macros.h" |
13 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
14 #include "chromeos/network/device_state.h" | 16 #include "chromeos/network/device_state.h" |
15 #include "chromeos/network/network_connection_handler.h" | 17 #include "chromeos/network/network_connection_handler.h" |
16 #include "chromeos/network/network_state.h" | 18 #include "chromeos/network/network_state.h" |
17 #include "chromeos/network/network_state_handler.h" | 19 #include "chromeos/network/network_state_handler.h" |
18 #include "chromeos/network/portal_detector/network_portal_detector.h" | 20 #include "chromeos/network/portal_detector/network_portal_detector.h" |
21 #include "chromeos/network/tether_constants.h" | |
19 #include "third_party/cros_system_api/dbus/service_constants.h" | 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
20 #include "third_party/skia/include/core/SkPaint.h" | 23 #include "third_party/skia/include/core/SkPaint.h" |
21 #include "third_party/skia/include/core/SkPath.h" | 24 #include "third_party/skia/include/core/SkPath.h" |
22 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
24 #include "ui/gfx/color_palette.h" | 27 #include "ui/gfx/color_palette.h" |
25 #include "ui/gfx/geometry/insets.h" | 28 #include "ui/gfx/geometry/insets.h" |
26 #include "ui/gfx/geometry/rect.h" | 29 #include "ui/gfx/geometry/rect.h" |
27 #include "ui/gfx/geometry/size_conversions.h" | 30 #include "ui/gfx/geometry/size_conversions.h" |
28 #include "ui/gfx/image/canvas_image_source.h" | 31 #include "ui/gfx/image/canvas_image_source.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 Badge top_left = {}; | 75 Badge top_left = {}; |
73 Badge center = {}; | 76 Badge center = {}; |
74 Badge bottom_left = {}; | 77 Badge bottom_left = {}; |
75 Badge bottom_right = {}; | 78 Badge bottom_right = {}; |
76 }; | 79 }; |
77 | 80 |
78 //------------------------------------------------------------------------------ | 81 //------------------------------------------------------------------------------ |
79 // class used for maintaining a map of network state and images. | 82 // class used for maintaining a map of network state and images. |
80 class NetworkIconImpl { | 83 class NetworkIconImpl { |
81 public: | 84 public: |
82 NetworkIconImpl(const std::string& path, IconType icon_type); | 85 NetworkIconImpl(const std::string& path, |
86 IconType icon_type, | |
87 const std::string& network_type); | |
83 | 88 |
84 // Determines whether or not the associated network might be dirty and if so | 89 // Determines whether or not the associated network might be dirty and if so |
85 // updates and generates the icon. Does nothing if network no longer exists. | 90 // updates and generates the icon. Does nothing if network no longer exists. |
86 void Update(const chromeos::NetworkState* network); | 91 void Update(const chromeos::NetworkState* network); |
87 | 92 |
88 const gfx::ImageSkia& image() const { return image_; } | 93 const gfx::ImageSkia& image() const { return image_; } |
89 | 94 |
90 private: | 95 private: |
91 // Updates |strength_index_| for wireless networks. Returns true if changed. | 96 // Updates |strength_index_| for wireless networks. Returns true if changed. |
92 bool UpdateWirelessStrengthIndex(const chromeos::NetworkState* network); | 97 bool UpdateWirelessStrengthIndex(const chromeos::NetworkState* network); |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 | 421 |
417 DISALLOW_COPY_AND_ASSIGN(SignalStrengthImageSource); | 422 DISALLOW_COPY_AND_ASSIGN(SignalStrengthImageSource); |
418 }; | 423 }; |
419 | 424 |
420 //------------------------------------------------------------------------------ | 425 //------------------------------------------------------------------------------ |
421 // Utilities for extracting icon images. | 426 // Utilities for extracting icon images. |
422 | 427 |
423 ImageType ImageTypeForNetworkType(const std::string& type) { | 428 ImageType ImageTypeForNetworkType(const std::string& type) { |
424 if (type == shill::kTypeWifi) | 429 if (type == shill::kTypeWifi) |
425 return ARCS; | 430 return ARCS; |
426 else if (type == shill::kTypeCellular || type == shill::kTypeWimax) | 431 else if (type == shill::kTypeCellular || type == shill::kTypeWimax || |
432 type == chromeos::kTypeTether) | |
427 return BARS; | 433 return BARS; |
428 return NONE; | 434 return NONE; |
429 } | 435 } |
430 | 436 |
437 // Returns the network type, performing a check to see if Wi-Fi networks | |
438 // have an associated Tether network. Used to display the correct icon. | |
439 std::string NetworkTypeForIcon(const NetworkState* network) { | |
Kyle Horimoto
2017/04/27 01:28:07
nit: How about GetEffectiveNetworkType()? This doe
lesliewatkins
2017/04/28 21:30:42
Done.
Kyle Horimoto
2017/04/28 22:07:28
Update the comment as well. "Returns the effective
| |
440 if (network->type() == shill::kTypeWifi && !network->tether_guid().empty()) | |
441 return chromeos::kTypeTether; | |
442 | |
443 return network->type(); | |
444 } | |
445 | |
446 ImageType ImageTypeForNetwork(const NetworkState* network) { | |
447 return ImageTypeForNetworkType(NetworkTypeForIcon(network)); | |
448 } | |
449 | |
431 gfx::ImageSkia GetImageForIndex(ImageType image_type, | 450 gfx::ImageSkia GetImageForIndex(ImageType image_type, |
432 IconType icon_type, | 451 IconType icon_type, |
433 int index) { | 452 int index) { |
434 gfx::CanvasImageSource* source = | 453 gfx::CanvasImageSource* source = |
435 new SignalStrengthImageSource(image_type, icon_type, index); | 454 new SignalStrengthImageSource(image_type, icon_type, index); |
436 return gfx::ImageSkia(source, source->size()); | 455 return gfx::ImageSkia(source, source->size()); |
437 } | 456 } |
438 | 457 |
439 // Returns an image to represent either a fully connected network or a | 458 // Returns an image to represent either a fully connected network or a |
440 // disconnected network. | 459 // disconnected network. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 return badge; | 545 return badge; |
527 } | 546 } |
528 | 547 |
529 gfx::ImageSkia GetIcon(const NetworkState* network, | 548 gfx::ImageSkia GetIcon(const NetworkState* network, |
530 IconType icon_type, | 549 IconType icon_type, |
531 int strength_index) { | 550 int strength_index) { |
532 if (network->Matches(NetworkTypePattern::Ethernet())) { | 551 if (network->Matches(NetworkTypePattern::Ethernet())) { |
533 DCHECK_NE(ICON_TYPE_TRAY, icon_type); | 552 DCHECK_NE(ICON_TYPE_TRAY, icon_type); |
534 return gfx::CreateVectorIcon(kNetworkEthernetIcon, | 553 return gfx::CreateVectorIcon(kNetworkEthernetIcon, |
535 GetDefaultColorForIconType(ICON_TYPE_LIST)); | 554 GetDefaultColorForIconType(ICON_TYPE_LIST)); |
536 } else if (network->Matches(NetworkTypePattern::Wireless())) { | 555 } else if (network->Matches(NetworkTypePattern::Wireless()) || |
556 network->Matches(NetworkTypePattern::Tether())) { | |
537 DCHECK(strength_index > 0); | 557 DCHECK(strength_index > 0); |
538 return GetImageForIndex(ImageTypeForNetworkType(network->type()), icon_type, | 558 return GetImageForIndex(ImageTypeForNetwork(network), icon_type, |
539 strength_index); | 559 strength_index); |
540 } else if (network->Matches(NetworkTypePattern::VPN())) { | 560 } else if (network->Matches(NetworkTypePattern::VPN())) { |
541 DCHECK_NE(ICON_TYPE_TRAY, icon_type); | 561 DCHECK_NE(ICON_TYPE_TRAY, icon_type); |
542 return gfx::CreateVectorIcon(kNetworkVpnIcon, | 562 return gfx::CreateVectorIcon(kNetworkVpnIcon, |
543 GetDefaultColorForIconType(ICON_TYPE_LIST)); | 563 GetDefaultColorForIconType(ICON_TYPE_LIST)); |
544 } | 564 } |
545 | 565 |
546 NOTREACHED() << "Request for icon for unsupported type: " << network->type(); | 566 NOTREACHED() << "Request for icon for unsupported type: " << network->type(); |
547 return gfx::ImageSkia(); | 567 return gfx::ImageSkia(); |
548 } | 568 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 | 600 |
581 return NetworkIconImageSource::CreateImage( | 601 return NetworkIconImageSource::CreateImage( |
582 *ConnectingWirelessImage(image_type, icon_type, animation), Badges()); | 602 *ConnectingWirelessImage(image_type, icon_type, animation), Badges()); |
583 } | 603 } |
584 | 604 |
585 } // namespace | 605 } // namespace |
586 | 606 |
587 //------------------------------------------------------------------------------ | 607 //------------------------------------------------------------------------------ |
588 // NetworkIconImpl | 608 // NetworkIconImpl |
589 | 609 |
590 NetworkIconImpl::NetworkIconImpl(const std::string& path, IconType icon_type) | 610 NetworkIconImpl::NetworkIconImpl(const std::string& path, |
611 IconType icon_type, | |
612 const std::string& network_type) | |
591 : network_path_(path), | 613 : network_path_(path), |
592 icon_type_(icon_type), | 614 icon_type_(icon_type), |
593 strength_index_(-1), | 615 strength_index_(-1), |
594 behind_captive_portal_(false) { | 616 behind_captive_portal_(false) { |
595 // Default image | 617 // Default image |
596 image_ = GetBasicImage(false, icon_type, shill::kTypeWifi); | 618 std::cout << network_type << std::endl; |
Kyle Horimoto
2017/04/27 01:28:07
Remove test logs.
Also, FYI, the preferred loggin
lesliewatkins
2017/04/28 21:30:42
Done.
| |
619 image_ = GetBasicImage(false, icon_type, network_type); | |
597 } | 620 } |
598 | 621 |
599 void NetworkIconImpl::Update(const NetworkState* network) { | 622 void NetworkIconImpl::Update(const NetworkState* network) { |
600 DCHECK(network); | 623 DCHECK(network); |
601 // Determine whether or not we need to update the icon. | 624 // Determine whether or not we need to update the icon. |
602 bool dirty = image_.isNull(); | 625 bool dirty = image_.isNull(); |
603 | 626 |
604 // If the network state has changed, the icon needs updating. | 627 // If the network state has changed, the icon needs updating. |
605 if (state_ != network->connection_state()) { | 628 if (state_ != network->connection_state()) { |
606 state_ = network->connection_state(); | 629 state_ = network->connection_state(); |
607 dirty = true; | 630 dirty = true; |
608 } | 631 } |
609 | 632 |
610 dirty |= UpdatePortalState(network); | 633 dirty |= UpdatePortalState(network); |
611 | 634 |
612 if (network->Matches(NetworkTypePattern::Wireless())) { | 635 if (network->Matches(NetworkTypePattern::Wireless()) || |
636 network->Matches(NetworkTypePattern::Tether())) { | |
613 dirty |= UpdateWirelessStrengthIndex(network); | 637 dirty |= UpdateWirelessStrengthIndex(network); |
614 } | 638 } |
615 | 639 |
616 if (network->Matches(NetworkTypePattern::Cellular())) | 640 if (network->Matches(NetworkTypePattern::Cellular())) |
617 dirty |= UpdateCellularState(network); | 641 dirty |= UpdateCellularState(network); |
618 | 642 |
619 if (IconTypeHasVPNBadge(icon_type_) && | 643 if (IconTypeHasVPNBadge(icon_type_) && |
620 network->Matches(NetworkTypePattern::NonVirtual())) { | 644 network->Matches(NetworkTypePattern::NonVirtual())) { |
621 dirty |= UpdateVPNBadge(); | 645 dirty |= UpdateVPNBadge(); |
622 } | 646 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
726 | 750 |
727 namespace { | 751 namespace { |
728 | 752 |
729 NetworkIconImpl* FindAndUpdateImageImpl(const NetworkState* network, | 753 NetworkIconImpl* FindAndUpdateImageImpl(const NetworkState* network, |
730 IconType icon_type) { | 754 IconType icon_type) { |
731 // Find or add the icon. | 755 // Find or add the icon. |
732 NetworkIconMap* icon_map = GetIconMap(icon_type); | 756 NetworkIconMap* icon_map = GetIconMap(icon_type); |
733 NetworkIconImpl* icon; | 757 NetworkIconImpl* icon; |
734 NetworkIconMap::iterator iter = icon_map->find(network->path()); | 758 NetworkIconMap::iterator iter = icon_map->find(network->path()); |
735 if (iter == icon_map->end()) { | 759 if (iter == icon_map->end()) { |
736 icon = new NetworkIconImpl(network->path(), icon_type); | 760 icon = new NetworkIconImpl(network->path(), icon_type, network->type()); |
737 icon_map->insert(std::make_pair(network->path(), icon)); | 761 icon_map->insert(std::make_pair(network->path(), icon)); |
738 } else { | 762 } else { |
739 icon = iter->second; | 763 icon = iter->second; |
740 } | 764 } |
741 | 765 |
742 // Update and return the icon's image. | 766 // Update and return the icon's image. |
743 icon->Update(network); | 767 icon->Update(network); |
744 return icon; | 768 return icon; |
745 } | 769 } |
746 | 770 |
747 } // namespace | 771 } // namespace |
748 | 772 |
749 //------------------------------------------------------------------------------ | 773 //------------------------------------------------------------------------------ |
750 // Public interface | 774 // Public interface |
751 | 775 |
752 gfx::ImageSkia GetImageForNetwork(const NetworkState* network, | 776 gfx::ImageSkia GetImageForNetwork(const NetworkState* network, |
753 IconType icon_type) { | 777 IconType icon_type) { |
754 DCHECK(network); | 778 DCHECK(network); |
779 std::string network_type = NetworkTypeForIcon(network); | |
780 | |
755 if (!network->visible()) | 781 if (!network->visible()) |
756 return GetBasicImage(false, icon_type, network->type()); | 782 return GetBasicImage(false /* not connected */, icon_type, network_type); |
Ryan Hansberry
2017/04/27 16:32:26
just 'connected'
lesliewatkins
2017/04/28 21:30:42
Changed to is_connected.
Kyle Horimoto
2017/04/28 22:07:28
You're supposed to match the name of the parameter
| |
757 | 783 |
758 if (network->IsConnectingState()) | 784 if (network->IsConnectingState()) |
759 return GetConnectingImage(icon_type, network->type()); | 785 return GetConnectingImage(icon_type, network_type); |
760 | 786 |
761 NetworkIconImpl* icon = FindAndUpdateImageImpl(network, icon_type); | 787 NetworkIconImpl* icon = FindAndUpdateImageImpl(network, icon_type); |
762 return icon->image(); | 788 return icon->image(); |
763 } | 789 } |
764 | 790 |
765 gfx::ImageSkia GetImageForWiFiEnabledState(bool enabled, IconType icon_type) { | 791 gfx::ImageSkia GetImageForWiFiEnabledState(bool enabled, IconType icon_type) { |
766 gfx::ImageSkia image = | 792 gfx::ImageSkia image = |
767 GetBasicImage(true /* connected */, icon_type, shill::kTypeWifi); | 793 GetBasicImage(true /* connected */, icon_type, shill::kTypeWifi); |
768 Badges badges; | 794 Badges badges; |
769 if (!enabled) { | 795 if (!enabled) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
966 network_paths.insert((*iter)->path()); | 992 network_paths.insert((*iter)->path()); |
967 } | 993 } |
968 PurgeIconMap(ICON_TYPE_TRAY, network_paths); | 994 PurgeIconMap(ICON_TYPE_TRAY, network_paths); |
969 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); | 995 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); |
970 PurgeIconMap(ICON_TYPE_LIST, network_paths); | 996 PurgeIconMap(ICON_TYPE_LIST, network_paths); |
971 PurgeIconMap(ICON_TYPE_MENU_LIST, network_paths); | 997 PurgeIconMap(ICON_TYPE_MENU_LIST, network_paths); |
972 } | 998 } |
973 | 999 |
974 } // namespace network_icon | 1000 } // namespace network_icon |
975 } // namespace ash | 1001 } // namespace ash |
OLD | NEW |