network_list_view.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_SYSTEM_NETWORK_NETWORK_LIST_VIEW_H_
  5. #define ASH_SYSTEM_NETWORK_NETWORK_LIST_VIEW_H_
  6. #include <map>
  7. #include <memory>
  8. #include <set>
  9. #include <string>
  10. #include <vector>
  11. #include "ash/system/network/network_icon_animation_observer.h"
  12. #include "ash/system/network/network_info.h"
  13. #include "ash/system/network/network_state_list_detailed_view.h"
  14. #include "base/memory/weak_ptr.h"
  15. #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h"
  16. #include "chromeos/services/network_config/public/mojom/network_types.mojom-forward.h"
  17. namespace views {
  18. class Separator;
  19. class View;
  20. } // namespace views
  21. namespace ash {
  22. class HoverHighlightView;
  23. class NetworkSectionHeaderView;
  24. class MobileSectionHeaderView;
  25. class TrayInfoLabel;
  26. class TriView;
  27. class WifiSectionHeaderView;
  28. // A list of available networks of a given type. This class is used for all
  29. // network types except VPNs. For VPNs, see the |VPNList| class.
  30. class NetworkListView : public NetworkStateListDetailedView,
  31. public network_icon::AnimationObserver {
  32. public:
  33. NetworkListView(DetailedViewDelegate* delegate, LoginStatus login);
  34. NetworkListView(const NetworkListView&) = delete;
  35. NetworkListView& operator=(const NetworkListView&) = delete;
  36. ~NetworkListView() override;
  37. // NetworkStateListDetailedView:
  38. void UpdateNetworkList() override;
  39. bool IsNetworkEntry(views::View* view, std::string* guid) const override;
  40. // views::View:
  41. const char* GetClassName() const override;
  42. private:
  43. void OnGetNetworkStateList(
  44. std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr>
  45. networks);
  46. // Refreshes a list of child views, updates |network_map_| and
  47. // |network_guid_map_| and performs layout making sure selected view if any is
  48. // scrolled into view.
  49. void UpdateNetworkListInternal();
  50. // Adds new or updates existing child views including header row and messages.
  51. // Returns a set of guids for the added network connections.
  52. std::unique_ptr<std::set<std::string>> UpdateNetworkListEntries();
  53. bool ShouldMobileDataSectionBeShown();
  54. // Creates the view which displays a warning message, if a VPN or proxy is
  55. // being used.
  56. TriView* CreateConnectionWarning();
  57. // Updates |view| with the information in |info|.
  58. void UpdateViewForNetwork(HoverHighlightView* view, const NetworkInfo& info);
  59. // Creates a battery icon next to the name of Tether networks indicating
  60. // the battery percentage of the mobile device that is being used as a
  61. // hotspot.
  62. views::View* CreatePowerStatusView(const NetworkInfo& info);
  63. // Creates a policy icon next to the name of managed networks indicating
  64. // that the network is managed by policy. Returns |nullptr| if the network is
  65. // not managed by policy.
  66. views::View* CreatePolicyView(const NetworkInfo& info);
  67. // Adds or updates child views representing the network connections when
  68. // |is_wifi| is matching the attribute of a network connection starting at
  69. // |child_index|. Returns a set of guids for the added network
  70. // connections.
  71. std::unique_ptr<std::set<std::string>> UpdateNetworkChildren(
  72. chromeos::network_config::mojom::NetworkType type,
  73. size_t child_index);
  74. void UpdateNetworkChild(size_t index, const NetworkInfo* info);
  75. // Reorders children of |scroll_content()| as necessary placing |view| at
  76. // |index|.
  77. void PlaceViewAtIndex(views::View* view, size_t index);
  78. // Creates an info label with text specified by |message_id| and adds it to
  79. // |scroll_content()| if necessary or updates the text and reorders the
  80. // |scroll_content()| placing the info label at |insertion_index|. When
  81. // |message_id| is zero removes the |*info_label_ptr| from the
  82. // |scroll_content()| and destroys it. |info_label_ptr| is an in/out parameter
  83. // and is only modified if the info label is created or destroyed.
  84. void UpdateInfoLabel(int message_id,
  85. size_t insertion_index,
  86. TrayInfoLabel** info_label_ptr);
  87. // Updates a cellular/Wi-Fi header row |view| and reorders the
  88. // |scroll_content()| placing the |view| at |child_index|. Returns the index
  89. // where the next child should be inserted, i.e., the index directly after the
  90. // last inserted child.
  91. size_t UpdateNetworkSectionHeader(
  92. chromeos::network_config::mojom::NetworkType type,
  93. bool enabled,
  94. size_t child_index,
  95. NetworkSectionHeaderView* view,
  96. views::Separator** separator_view);
  97. // network_icon::AnimationObserver:
  98. void NetworkIconChanged() override;
  99. // Returns true if the info should be updated to the view for network,
  100. // otherwise false.
  101. bool NeedUpdateViewForNetwork(const NetworkInfo& info) const;
  102. // Creates an accessibility label for given network.
  103. std::u16string GenerateAccessibilityLabel(const NetworkInfo& info);
  104. // Creates an accessibility description for the given network that includes
  105. // all details that are shown in the ui.
  106. std::u16string GenerateAccessibilityDescription(const NetworkInfo& info);
  107. bool needs_relayout_ = false;
  108. // Owned by the views heirarchy.
  109. TrayInfoLabel* mobile_status_message_ = nullptr;
  110. TrayInfoLabel* wifi_status_message_ = nullptr;
  111. MobileSectionHeaderView* mobile_header_view_ = nullptr;
  112. WifiSectionHeaderView* wifi_header_view_ = nullptr;
  113. views::Separator* mobile_separator_view_ = nullptr;
  114. views::Separator* wifi_separator_view_ = nullptr;
  115. TriView* connection_warning_ = nullptr;
  116. bool vpn_connected_ = false;
  117. bool wifi_has_networks_ = false;
  118. bool tether_has_networks_ = false;
  119. bool mobile_has_networks_ = false;
  120. // An owned list of network info.
  121. std::vector<std::unique_ptr<NetworkInfo>> network_list_;
  122. using NetworkMap = std::map<views::View*, std::string>;
  123. NetworkMap network_map_;
  124. // A map of network guids to their view.
  125. using NetworkGuidMap = std::map<std::string, HoverHighlightView*>;
  126. NetworkGuidMap network_guid_map_;
  127. // Save a map of network guids to their infos against current |network_list_|.
  128. using NetworkInfoMap = std::map<std::string, std::unique_ptr<NetworkInfo>>;
  129. NetworkInfoMap last_network_info_map_;
  130. base::WeakPtrFactory<NetworkListView> weak_ptr_factory_{this};
  131. };
  132. } // namespace ash
  133. #endif // ASH_SYSTEM_NETWORK_NETWORK_LIST_VIEW_H_