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

Side by Side Diff: ash/system/network/network_icon.cc

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

Powered by Google App Engine
This is Rietveld 408576698