OLD | NEW |
| (Empty) |
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 | |
5 #ifndef ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_NETWORK_LIST_H_ | |
6 #define ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_NETWORK_LIST_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 #include <set> | |
11 #include <string> | |
12 #include <vector> | |
13 | |
14 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" | |
15 #include "ash/common/system/chromeos/network/network_info.h" | |
16 #include "ash/common/system/chromeos/network/network_list_view_base.h" | |
17 #include "base/macros.h" | |
18 #include "chromeos/network/network_state_handler.h" | |
19 #include "chromeos/network/network_type_pattern.h" | |
20 #include "ui/gfx/image/image_skia.h" | |
21 | |
22 namespace views { | |
23 class Label; | |
24 class Separator; | |
25 class View; | |
26 } | |
27 | |
28 namespace ash { | |
29 | |
30 struct NetworkInfo; | |
31 class NetworkListDelegate; | |
32 | |
33 // A list of available networks of a given type. This class is used for all | |
34 // network types except VPNs. For VPNs, see the |VPNList| class. | |
35 class NetworkListView : public NetworkListViewBase, | |
36 public network_icon::AnimationObserver { | |
37 public: | |
38 class SectionHeaderRowView; | |
39 | |
40 explicit NetworkListView(NetworkListDelegate* delegate); | |
41 ~NetworkListView() override; | |
42 | |
43 // NetworkListViewBase: | |
44 void Update() override; | |
45 bool IsNetworkEntry(views::View* view, std::string* guid) const override; | |
46 | |
47 private: | |
48 // Clears |network_list_| and adds to it |networks| that match |delegate_|'s | |
49 // network type pattern. | |
50 void UpdateNetworks( | |
51 const chromeos::NetworkStateHandler::NetworkStateList& networks); | |
52 | |
53 // Updates |network_list_| entries and sets |this| to observe network icon | |
54 // animations when any of the networks are in connecting state. | |
55 void UpdateNetworkIcons(); | |
56 | |
57 // Orders entries in |network_list_| such that higher priority network types | |
58 // are at the top of the list. | |
59 void OrderNetworks(); | |
60 | |
61 // Refreshes a list of child views, updates |network_map_| and | |
62 // |network_guid_map_| and performs layout making sure selected view if any is | |
63 // scrolled into view. | |
64 void UpdateNetworkListInternal(); | |
65 | |
66 // Adds new or updates existing child views including header row and messages. | |
67 // Returns a set of guids for the added network connections. | |
68 std::unique_ptr<std::set<std::string>> UpdateNetworkListEntries(); | |
69 | |
70 // Adds or updates child views representing the network connections when | |
71 // |is_wifi| is matching the attribute of a network connection starting at | |
72 // |child_index|. Returns a set of guids for the added network | |
73 // connections. | |
74 std::unique_ptr<std::set<std::string>> UpdateNetworkChildren( | |
75 NetworkInfo::Type type, | |
76 int child_index); | |
77 void UpdateNetworkChild(int index, const NetworkInfo* info); | |
78 | |
79 // Reorders children of |container()| as necessary placing |view| at |index|. | |
80 void PlaceViewAtIndex(views::View* view, int index); | |
81 | |
82 // Creates a Label with text specified by |message_id| and adds it to | |
83 // |container()| if necessary or updates the text and reorders the | |
84 // |container()| placing the label at |insertion_index|. When |message_id| is | |
85 // zero removes the |*label_ptr| from the |container()| and destroys it. | |
86 // |label_ptr| is an in / out parameter and is only modified if the Label is | |
87 // created or destroyed. | |
88 void UpdateInfoLabel(int message_id, | |
89 int insertion_index, | |
90 views::Label** label_ptr); | |
91 | |
92 // Creates a cellular/Wi-Fi header row |view| and adds it to |container()| if | |
93 // necessary and reorders the |container()| placing the |view| at | |
94 // |child_index|. Returns the index where the next child should be inserted, | |
95 // i.e., the index directly after the last inserted child. | |
96 int UpdateSectionHeaderRow(chromeos::NetworkTypePattern pattern, | |
97 bool enabled, | |
98 int child_index, | |
99 SectionHeaderRowView** view, | |
100 views::Separator** separator_view); | |
101 | |
102 // network_icon::AnimationObserver: | |
103 void NetworkIconChanged() override; | |
104 | |
105 // Returns true if the info should be updated to the view for network, | |
106 // otherwise false. | |
107 bool NeedUpdateViewForNetwork(const NetworkInfo& info) const; | |
108 | |
109 bool needs_relayout_; | |
110 NetworkListDelegate* delegate_; | |
111 | |
112 views::Label* no_wifi_networks_view_; | |
113 views::Label* no_cellular_networks_view_; | |
114 SectionHeaderRowView* cellular_header_view_; | |
115 SectionHeaderRowView* tether_header_view_; | |
116 SectionHeaderRowView* wifi_header_view_; | |
117 views::Separator* cellular_separator_view_; | |
118 views::Separator* tether_separator_view_; | |
119 views::Separator* wifi_separator_view_; | |
120 | |
121 // An owned list of network info. | |
122 std::vector<std::unique_ptr<NetworkInfo>> network_list_; | |
123 | |
124 using NetworkMap = std::map<views::View*, std::string>; | |
125 NetworkMap network_map_; | |
126 | |
127 // A map of network guids to their view. | |
128 using NetworkGuidMap = std::map<std::string, views::View*>; | |
129 NetworkGuidMap network_guid_map_; | |
130 | |
131 // Save a map of network guids to their infos against current |network_list_|. | |
132 using NetworkInfoMap = std::map<std::string, std::unique_ptr<NetworkInfo>>; | |
133 NetworkInfoMap last_network_info_map_; | |
134 | |
135 DISALLOW_COPY_AND_ASSIGN(NetworkListView); | |
136 }; | |
137 | |
138 } // namespace ash | |
139 | |
140 #endif // ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_NETWORK_LIST_H_ | |
OLD | NEW |