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

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

Issue 2819303002: Changed wifi arcs to mobile bars for Tether network. (Closed)
Patch Set: Fixed small typo preventing unit tests from building. 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
« no previous file with comments | « ash/BUILD.gn ('k') | ash/system/network/network_icon_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 // See crbug.com/623987 and crbug.com/632827 417 // See crbug.com/623987 and crbug.com/632827
415 static constexpr int kBgAlpha = 0x4D; 418 static constexpr int kBgAlpha = 0x4D;
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;
432 }
428 return NONE; 433 return NONE;
429 } 434 }
430 435
436 // Returns the network type, performing a check to see if Wi-Fi networks
437 // have an associated Tether network. Used to display the correct icon.
438 std::string GetEffectiveNetworkType(const NetworkState* network,
439 IconType icon_type) {
440 if (icon_type == ICON_TYPE_TRAY && network->type() == shill::kTypeWifi &&
441 !network->tether_guid().empty()) {
442 return chromeos::kTypeTether;
443 }
444
445 return network->type();
446 }
447
448 ImageType ImageTypeForNetwork(const NetworkState* network, IconType icon_type) {
449 return ImageTypeForNetworkType(GetEffectiveNetworkType(network, icon_type));
450 }
451
431 gfx::ImageSkia GetImageForIndex(ImageType image_type, 452 gfx::ImageSkia GetImageForIndex(ImageType image_type,
432 IconType icon_type, 453 IconType icon_type,
433 int index) { 454 int index) {
434 gfx::CanvasImageSource* source = 455 gfx::CanvasImageSource* source =
435 new SignalStrengthImageSource(image_type, icon_type, index); 456 new SignalStrengthImageSource(image_type, icon_type, index);
436 return gfx::ImageSkia(source, source->size()); 457 return gfx::ImageSkia(source, source->size());
437 } 458 }
438 459
439 // Returns an image to represent either a fully connected network or a 460 // Returns an image to represent either a fully connected network or a
440 // disconnected network. 461 // disconnected network.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 return badge; 547 return badge;
527 } 548 }
528 549
529 gfx::ImageSkia GetIcon(const NetworkState* network, 550 gfx::ImageSkia GetIcon(const NetworkState* network,
530 IconType icon_type, 551 IconType icon_type,
531 int strength_index) { 552 int strength_index) {
532 if (network->Matches(NetworkTypePattern::Ethernet())) { 553 if (network->Matches(NetworkTypePattern::Ethernet())) {
533 DCHECK_NE(ICON_TYPE_TRAY, icon_type); 554 DCHECK_NE(ICON_TYPE_TRAY, icon_type);
534 return gfx::CreateVectorIcon(kNetworkEthernetIcon, 555 return gfx::CreateVectorIcon(kNetworkEthernetIcon,
535 GetDefaultColorForIconType(ICON_TYPE_LIST)); 556 GetDefaultColorForIconType(ICON_TYPE_LIST));
536 } else if (network->Matches(NetworkTypePattern::Wireless())) { 557 } else if (network->Matches(NetworkTypePattern::Wireless()) ||
558 network->Matches(NetworkTypePattern::Tether())) {
537 DCHECK(strength_index > 0); 559 DCHECK(strength_index > 0);
538 return GetImageForIndex(ImageTypeForNetworkType(network->type()), icon_type, 560 return GetImageForIndex(ImageTypeForNetwork(network, icon_type), icon_type,
539 strength_index); 561 strength_index);
540 } else if (network->Matches(NetworkTypePattern::VPN())) { 562 } else if (network->Matches(NetworkTypePattern::VPN())) {
541 DCHECK_NE(ICON_TYPE_TRAY, icon_type); 563 DCHECK_NE(ICON_TYPE_TRAY, icon_type);
542 return gfx::CreateVectorIcon(kNetworkVpnIcon, 564 return gfx::CreateVectorIcon(kNetworkVpnIcon,
543 GetDefaultColorForIconType(ICON_TYPE_LIST)); 565 GetDefaultColorForIconType(ICON_TYPE_LIST));
544 } 566 }
545 567
546 NOTREACHED() << "Request for icon for unsupported type: " << network->type(); 568 NOTREACHED() << "Request for icon for unsupported type: " << network->type();
547 return gfx::ImageSkia(); 569 return gfx::ImageSkia();
548 } 570 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 602
581 return NetworkIconImageSource::CreateImage( 603 return NetworkIconImageSource::CreateImage(
582 *ConnectingWirelessImage(image_type, icon_type, animation), Badges()); 604 *ConnectingWirelessImage(image_type, icon_type, animation), Badges());
583 } 605 }
584 606
585 } // namespace 607 } // namespace
586 608
587 //------------------------------------------------------------------------------ 609 //------------------------------------------------------------------------------
588 // NetworkIconImpl 610 // NetworkIconImpl
589 611
590 NetworkIconImpl::NetworkIconImpl(const std::string& path, IconType icon_type) 612 NetworkIconImpl::NetworkIconImpl(const std::string& path,
613 IconType icon_type,
614 const std::string& network_type)
591 : network_path_(path), 615 : network_path_(path),
592 icon_type_(icon_type), 616 icon_type_(icon_type),
593 strength_index_(-1), 617 strength_index_(-1),
594 behind_captive_portal_(false) { 618 behind_captive_portal_(false) {
595 // Default image 619 // Default image
596 image_ = GetBasicImage(false, icon_type, shill::kTypeWifi); 620 image_ = GetBasicImage(false, icon_type, network_type);
stevenjb 2017/05/08 23:56:19 This will crash in GetBasicImage if network_type i
597 } 621 }
598 622
599 void NetworkIconImpl::Update(const NetworkState* network) { 623 void NetworkIconImpl::Update(const NetworkState* network) {
600 DCHECK(network); 624 DCHECK(network);
601 // Determine whether or not we need to update the icon. 625 // Determine whether or not we need to update the icon.
602 bool dirty = image_.isNull(); 626 bool dirty = image_.isNull();
603 627
604 // If the network state has changed, the icon needs updating. 628 // If the network state has changed, the icon needs updating.
605 if (state_ != network->connection_state()) { 629 if (state_ != network->connection_state()) {
606 state_ = network->connection_state(); 630 state_ = network->connection_state();
607 dirty = true; 631 dirty = true;
608 } 632 }
609 633
610 dirty |= UpdatePortalState(network); 634 dirty |= UpdatePortalState(network);
611 635
612 if (network->Matches(NetworkTypePattern::Wireless())) { 636 if (network->Matches(NetworkTypePattern::Wireless()) ||
637 network->Matches(NetworkTypePattern::Tether())) {
613 dirty |= UpdateWirelessStrengthIndex(network); 638 dirty |= UpdateWirelessStrengthIndex(network);
614 } 639 }
615 640
616 if (network->Matches(NetworkTypePattern::Cellular())) 641 if (network->Matches(NetworkTypePattern::Cellular()))
617 dirty |= UpdateCellularState(network); 642 dirty |= UpdateCellularState(network);
618 643
619 if (IconTypeHasVPNBadge(icon_type_) && 644 if (IconTypeHasVPNBadge(icon_type_) &&
620 network->Matches(NetworkTypePattern::NonVirtual())) { 645 network->Matches(NetworkTypePattern::NonVirtual())) {
621 dirty |= UpdateVPNBadge(); 646 dirty |= UpdateVPNBadge();
622 } 647 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 751
727 namespace { 752 namespace {
728 753
729 NetworkIconImpl* FindAndUpdateImageImpl(const NetworkState* network, 754 NetworkIconImpl* FindAndUpdateImageImpl(const NetworkState* network,
730 IconType icon_type) { 755 IconType icon_type) {
731 // Find or add the icon. 756 // Find or add the icon.
732 NetworkIconMap* icon_map = GetIconMap(icon_type); 757 NetworkIconMap* icon_map = GetIconMap(icon_type);
733 NetworkIconImpl* icon; 758 NetworkIconImpl* icon;
734 NetworkIconMap::iterator iter = icon_map->find(network->path()); 759 NetworkIconMap::iterator iter = icon_map->find(network->path());
735 if (iter == icon_map->end()) { 760 if (iter == icon_map->end()) {
736 icon = new NetworkIconImpl(network->path(), icon_type); 761 icon = new NetworkIconImpl(network->path(), icon_type,
762 GetEffectiveNetworkType(network, icon_type));
737 icon_map->insert(std::make_pair(network->path(), icon)); 763 icon_map->insert(std::make_pair(network->path(), icon));
738 } else { 764 } else {
739 icon = iter->second; 765 icon = iter->second;
740 } 766 }
741 767
742 // Update and return the icon's image. 768 // Update and return the icon's image.
743 icon->Update(network); 769 icon->Update(network);
744 return icon; 770 return icon;
745 } 771 }
746 772
747 } // namespace 773 } // namespace
748 774
749 //------------------------------------------------------------------------------ 775 //------------------------------------------------------------------------------
750 // Public interface 776 // Public interface
751 777
752 gfx::ImageSkia GetImageForNetwork(const NetworkState* network, 778 gfx::ImageSkia GetImageForNetwork(const NetworkState* network,
753 IconType icon_type) { 779 IconType icon_type) {
754 DCHECK(network); 780 DCHECK(network);
781 const std::string network_type = GetEffectiveNetworkType(network, icon_type);
782
755 if (!network->visible()) 783 if (!network->visible())
756 return GetBasicImage(false, icon_type, network->type()); 784 return GetBasicImage(false /* is_connected */, icon_type, network_type);
757 785
758 if (network->IsConnectingState()) 786 if (network->IsConnectingState())
759 return GetConnectingImage(icon_type, network->type()); 787 return GetConnectingImage(icon_type, network_type);
760 788
761 NetworkIconImpl* icon = FindAndUpdateImageImpl(network, icon_type); 789 NetworkIconImpl* icon = FindAndUpdateImageImpl(network, icon_type);
762 return icon->image(); 790 return icon->image();
763 } 791 }
764 792
765 gfx::ImageSkia GetImageForWiFiEnabledState(bool enabled, IconType icon_type) { 793 gfx::ImageSkia GetImageForWiFiEnabledState(bool enabled, IconType icon_type) {
766 gfx::ImageSkia image = 794 gfx::ImageSkia image =
767 GetBasicImage(true /* connected */, icon_type, shill::kTypeWifi); 795 GetBasicImage(true /* connected */, icon_type, shill::kTypeWifi);
768 Badges badges; 796 Badges badges;
769 if (!enabled) { 797 if (!enabled) {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 network_paths.insert((*iter)->path()); 994 network_paths.insert((*iter)->path());
967 } 995 }
968 PurgeIconMap(ICON_TYPE_TRAY, network_paths); 996 PurgeIconMap(ICON_TYPE_TRAY, network_paths);
969 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); 997 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths);
970 PurgeIconMap(ICON_TYPE_LIST, network_paths); 998 PurgeIconMap(ICON_TYPE_LIST, network_paths);
971 PurgeIconMap(ICON_TYPE_MENU_LIST, network_paths); 999 PurgeIconMap(ICON_TYPE_MENU_LIST, network_paths);
972 } 1000 }
973 1001
974 } // namespace network_icon 1002 } // namespace network_icon
975 } // namespace ash 1003 } // namespace ash
OLDNEW
« no previous file with comments | « ash/BUILD.gn ('k') | ash/system/network/network_icon_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698