OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_list.h" | 5 #include "ash/system/network/network_list.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_port.h" | 10 #include "ash/shell_port.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 views::ToggleButton* toggle_; | 171 views::ToggleButton* toggle_; |
172 | 172 |
173 // TrayPopupItemStyle used to configure labels and buttons. | 173 // TrayPopupItemStyle used to configure labels and buttons. |
174 std::unique_ptr<TrayPopupItemStyle> style_; | 174 std::unique_ptr<TrayPopupItemStyle> style_; |
175 | 175 |
176 DISALLOW_COPY_AND_ASSIGN(SectionHeaderRowView); | 176 DISALLOW_COPY_AND_ASSIGN(SectionHeaderRowView); |
177 }; | 177 }; |
178 | 178 |
179 namespace { | 179 namespace { |
180 | 180 |
181 class CellularHeaderRowView : public NetworkListView::SectionHeaderRowView { | 181 class MobileHeaderRowView : public NetworkListView::SectionHeaderRowView { |
182 public: | 182 public: |
183 CellularHeaderRowView() | 183 MobileHeaderRowView() |
184 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_MOBILE) {} | 184 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_MOBILE) {} |
185 | 185 |
186 ~CellularHeaderRowView() override {} | 186 ~MobileHeaderRowView() override {} |
187 | 187 |
188 const char* GetClassName() const override { return "CellularHeaderRowView"; } | 188 const char* GetClassName() const override { return "MobileHeaderRowView"; } |
189 | 189 |
190 protected: | 190 protected: |
191 void OnToggleToggled(bool is_on) override { | 191 void OnToggleToggled(bool is_on) override { |
192 NetworkStateHandler* handler = | 192 NetworkStateHandler* handler = |
193 NetworkHandler::Get()->network_state_handler(); | 193 NetworkHandler::Get()->network_state_handler(); |
194 handler->SetTechnologyEnabled(NetworkTypePattern::Cellular(), is_on, | 194 // When cellular network technology is available on a device, Tether is |
195 chromeos::network_handler::ErrorCallback()); | 195 // treated as a subset of Cellular technology. Otherwise, Tether has to |
| 196 // be explicity enabled and disabled. |
| 197 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { |
| 198 handler->SetTechnologyEnabled(NetworkTypePattern::Cellular(), is_on, |
| 199 chromeos::network_handler::ErrorCallback()); |
| 200 } else { |
| 201 handler->SetTechnologyEnabled(NetworkTypePattern::Tether(), is_on, |
| 202 chromeos::network_handler::ErrorCallback()); |
| 203 } |
196 } | 204 } |
197 | 205 |
198 private: | 206 private: |
199 DISALLOW_COPY_AND_ASSIGN(CellularHeaderRowView); | 207 DISALLOW_COPY_AND_ASSIGN(MobileHeaderRowView); |
200 }; | 208 }; |
201 | 209 |
202 class TetherHeaderRowView : public NetworkListView::SectionHeaderRowView { | |
203 public: | |
204 TetherHeaderRowView() | |
205 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_TETHER) {} | |
206 | |
207 ~TetherHeaderRowView() override {} | |
208 | |
209 const char* GetClassName() const override { return "TetherHeaderRowView"; } | |
210 | |
211 protected: | |
212 void OnToggleToggled(bool is_on) override { | |
213 // TODO (hansberry): Persist toggle to settings/preferences. | |
214 } | |
215 | |
216 private: | |
217 DISALLOW_COPY_AND_ASSIGN(TetherHeaderRowView); | |
218 }; | |
219 | 210 |
220 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { | 211 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { |
221 public: | 212 public: |
222 WifiHeaderRowView() | 213 WifiHeaderRowView() |
223 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), | 214 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), |
224 join_(nullptr) {} | 215 join_(nullptr) {} |
225 | 216 |
226 ~WifiHeaderRowView() override {} | 217 ~WifiHeaderRowView() override {} |
227 | 218 |
228 void SetIsOn(bool enabled) override { | 219 void SetIsOn(bool enabled) override { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 } // namespace | 282 } // namespace |
292 | 283 |
293 // NetworkListView: | 284 // NetworkListView: |
294 | 285 |
295 NetworkListView::NetworkListView(SystemTrayItem* owner, LoginStatus login) | 286 NetworkListView::NetworkListView(SystemTrayItem* owner, LoginStatus login) |
296 : NetworkStateListDetailedView(owner, LIST_TYPE_NETWORK, login), | 287 : NetworkStateListDetailedView(owner, LIST_TYPE_NETWORK, login), |
297 needs_relayout_(false), | 288 needs_relayout_(false), |
298 no_wifi_networks_view_(nullptr), | 289 no_wifi_networks_view_(nullptr), |
299 no_cellular_networks_view_(nullptr), | 290 no_cellular_networks_view_(nullptr), |
300 cellular_header_view_(nullptr), | 291 cellular_header_view_(nullptr), |
301 tether_header_view_(nullptr), | |
302 wifi_header_view_(nullptr), | 292 wifi_header_view_(nullptr), |
303 cellular_separator_view_(nullptr), | 293 cellular_separator_view_(nullptr), |
304 tether_separator_view_(nullptr), | |
305 wifi_separator_view_(nullptr), | 294 wifi_separator_view_(nullptr), |
306 connection_warning_(nullptr) {} | 295 connection_warning_(nullptr) {} |
307 | 296 |
308 NetworkListView::~NetworkListView() { | 297 NetworkListView::~NetworkListView() { |
309 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 298 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
310 } | 299 } |
311 | 300 |
312 void NetworkListView::UpdateNetworkList() { | 301 void NetworkListView::UpdateNetworkList() { |
313 CHECK(scroll_content()); | 302 CHECK(scroll_content()); |
314 | 303 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 network, network_icon::ICON_TYPE_MENU_LIST); | 413 network, network_icon::ICON_TYPE_MENU_LIST); |
425 info->image = | 414 info->image = |
426 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); | 415 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); |
427 info->disable = | 416 info->disable = |
428 (network->activation_state() == shill::kActivationStateActivating) || | 417 (network->activation_state() == shill::kActivationStateActivating) || |
429 prohibited_by_policy; | 418 prohibited_by_policy; |
430 info->connected = network->IsConnectedState(); | 419 info->connected = network->IsConnectedState(); |
431 info->connecting = network->IsConnectingState(); | 420 info->connecting = network->IsConnectingState(); |
432 if (network->Matches(NetworkTypePattern::WiFi())) | 421 if (network->Matches(NetworkTypePattern::WiFi())) |
433 info->type = NetworkInfo::Type::WIFI; | 422 info->type = NetworkInfo::Type::WIFI; |
434 else if (network->Matches(NetworkTypePattern::Cellular())) | 423 else if (network->Matches(NetworkTypePattern::Mobile())) |
435 info->type = NetworkInfo::Type::CELLULAR; | 424 info->type = NetworkInfo::Type::MOBILE; |
436 else if (network->Matches(NetworkTypePattern::Tether())) | |
437 info->type = NetworkInfo::Type::TETHER; | |
438 if (prohibited_by_policy) { | 425 if (prohibited_by_policy) { |
439 info->tooltip = | 426 info->tooltip = |
440 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); | 427 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); |
441 } | 428 } |
442 if (!animating && network->IsConnectingState()) | 429 if (!animating && network->IsConnectingState()) |
443 animating = true; | 430 animating = true; |
444 } | 431 } |
445 if (animating) | 432 if (animating) |
446 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 433 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
447 else | 434 else |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 if (!connection_warning_) | 495 if (!connection_warning_) |
509 connection_warning_ = CreateConnectionWarning(); | 496 connection_warning_ = CreateConnectionWarning(); |
510 PlaceViewAtIndex(connection_warning_, index++); | 497 PlaceViewAtIndex(connection_warning_, index++); |
511 } | 498 } |
512 | 499 |
513 // First add high-priority networks (not Wi-Fi nor cellular). | 500 // First add high-priority networks (not Wi-Fi nor cellular). |
514 std::unique_ptr<std::set<std::string>> new_guids = | 501 std::unique_ptr<std::set<std::string>> new_guids = |
515 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); | 502 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); |
516 index += new_guids->size(); | 503 index += new_guids->size(); |
517 | 504 |
518 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { | 505 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular()) || |
519 index = UpdateSectionHeaderRow( | 506 handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { |
520 NetworkTypePattern::Cellular(), | 507 bool is_enabled = |
521 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, | 508 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()) || |
522 &cellular_header_view_, &cellular_separator_view_); | 509 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()); |
| 510 |
| 511 index = UpdateSectionHeaderRow(NetworkTypePattern::Cellular(), is_enabled, |
| 512 index, &cellular_header_view_, |
| 513 &cellular_separator_view_); |
523 } | 514 } |
524 | 515 |
525 // Cellular initializing. | 516 // Cellular initializing. |
526 int cellular_message_id = network_icon::GetCellularUninitializedMsg(); | 517 int cellular_message_id = network_icon::GetCellularUninitializedMsg(); |
527 if (!cellular_message_id && | 518 if (!cellular_message_id && |
528 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && | 519 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && |
529 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { | 520 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { |
530 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; | 521 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; |
531 } | 522 } |
532 UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_); | 523 UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_); |
533 if (cellular_message_id) | 524 if (cellular_message_id) |
534 ++index; | 525 ++index; |
535 | 526 |
536 // Add cellular networks. | 527 // Add cellular and Tether networks. |
537 std::unique_ptr<std::set<std::string>> new_cellular_guids = | 528 std::unique_ptr<std::set<std::string>> new_cellular_guids = |
538 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); | 529 UpdateNetworkChildren(NetworkInfo::Type::MOBILE, index); |
539 index += new_cellular_guids->size(); | 530 index += new_cellular_guids->size(); |
540 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); | 531 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); |
541 | 532 |
542 // TODO (hansberry): Audit existing usage of NonVirtual and consider changing | |
543 // it to include Tether. See crbug.com/693647. | |
544 if (handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { | |
545 index = UpdateSectionHeaderRow( | |
546 NetworkTypePattern::Tether(), | |
547 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()), index, | |
548 &tether_header_view_, &tether_separator_view_); | |
549 | |
550 // TODO (hansberry): Should a message similar to | |
551 // IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS be shown if Tether technology is | |
552 // enabled but no networks are around? | |
553 | |
554 // Add Tether networks. | |
555 std::unique_ptr<std::set<std::string>> new_tether_guids = | |
556 UpdateNetworkChildren(NetworkInfo::Type::TETHER, index); | |
557 index += new_tether_guids->size(); | |
558 new_guids->insert(new_tether_guids->begin(), new_tether_guids->end()); | |
559 } | |
560 | |
561 index = UpdateSectionHeaderRow( | 533 index = UpdateSectionHeaderRow( |
562 NetworkTypePattern::WiFi(), | 534 NetworkTypePattern::WiFi(), |
563 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, | 535 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, |
564 &wifi_header_view_, &wifi_separator_view_); | 536 &wifi_header_view_, &wifi_separator_view_); |
565 | 537 |
566 // "Wifi Enabled / Disabled". | 538 // "Wifi Enabled / Disabled". |
567 int wifi_message_id = 0; | 539 int wifi_message_id = 0; |
568 if (network_list_.empty()) { | 540 if (network_list_.empty()) { |
569 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) | 541 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) |
570 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED | 542 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 PlaceViewAtIndex(info_label, insertion_index); | 658 PlaceViewAtIndex(info_label, insertion_index); |
687 *info_label_ptr = info_label; | 659 *info_label_ptr = info_label; |
688 } | 660 } |
689 | 661 |
690 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, | 662 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, |
691 bool enabled, | 663 bool enabled, |
692 int child_index, | 664 int child_index, |
693 SectionHeaderRowView** view, | 665 SectionHeaderRowView** view, |
694 views::Separator** separator_view) { | 666 views::Separator** separator_view) { |
695 if (!*view) { | 667 if (!*view) { |
696 if (pattern.Equals(NetworkTypePattern::Cellular())) | 668 if (pattern.MatchesPattern(NetworkTypePattern::Mobile())) |
697 *view = new CellularHeaderRowView(); | 669 *view = new MobileHeaderRowView(); |
698 else if (pattern.Equals(NetworkTypePattern::Tether())) | |
699 *view = new TetherHeaderRowView(); | |
700 else if (pattern.Equals(NetworkTypePattern::WiFi())) | 670 else if (pattern.Equals(NetworkTypePattern::WiFi())) |
701 *view = new WifiHeaderRowView(); | 671 *view = new WifiHeaderRowView(); |
702 else | 672 else |
703 NOTREACHED(); | 673 NOTREACHED(); |
704 (*view)->Init(enabled); | 674 (*view)->Init(enabled); |
705 } | 675 } |
706 // Show or hide a separator above the header. The separator should only be | 676 // Show or hide a separator above the header. The separator should only be |
707 // visible when the header row is not at the top of the list. | 677 // visible when the header row is not at the top of the list. |
708 if (child_index > 0) { | 678 if (child_index > 0) { |
709 if (!*separator_view) | 679 if (!*separator_view) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( | 733 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( |
764 0, 0, 0, kTrayPopupLabelRightPadding))); | 734 0, 0, 0, kTrayPopupLabelRightPadding))); |
765 | 735 |
766 // Nothing to the right of the text. | 736 // Nothing to the right of the text. |
767 connection_warning->SetContainerVisible(TriView::Container::END, false); | 737 connection_warning->SetContainerVisible(TriView::Container::END, false); |
768 return connection_warning; | 738 return connection_warning; |
769 } | 739 } |
770 | 740 |
771 } // namespace tray | 741 } // namespace tray |
772 } // namespace ash | 742 } // namespace ash |
OLD | NEW |