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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_MOBILE) {} | 212 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_MOBILE) {} |
213 | 213 |
214 ~CellularHeaderRowView() override {} | 214 ~CellularHeaderRowView() override {} |
215 | 215 |
216 const char* GetClassName() const override { return "CellularHeaderRowView"; } | 216 const char* GetClassName() const override { return "CellularHeaderRowView"; } |
217 | 217 |
218 protected: | 218 protected: |
219 void OnToggleToggled(bool is_on) override { | 219 void OnToggleToggled(bool is_on) override { |
220 NetworkStateHandler* handler = | 220 NetworkStateHandler* handler = |
221 NetworkHandler::Get()->network_state_handler(); | 221 NetworkHandler::Get()->network_state_handler(); |
222 handler->SetTechnologyEnabled(NetworkTypePattern::Cellular(), is_on, | 222 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { |
Ryan Hansberry
2017/05/23 01:14:29
Awesome :). Please add a comment explaining this b
stevenjb
2017/05/23 22:11:07
Yes please. Specifically we should explain that wh
lesliewatkins
2017/05/26 23:49:32
Done.
| |
223 chromeos::network_handler::ErrorCallback()); | 223 handler->SetTechnologyEnabled(NetworkTypePattern::Cellular(), is_on, |
224 chromeos::network_handler::ErrorCallback()); | |
225 } else { | |
226 handler->SetTechnologyEnabled(NetworkTypePattern::Tether(), is_on, | |
227 chromeos::network_handler::ErrorCallback()); | |
228 } | |
224 } | 229 } |
225 | 230 |
226 private: | 231 private: |
227 DISALLOW_COPY_AND_ASSIGN(CellularHeaderRowView); | 232 DISALLOW_COPY_AND_ASSIGN(CellularHeaderRowView); |
228 }; | 233 }; |
229 | 234 |
230 class TetherHeaderRowView : public NetworkListView::SectionHeaderRowView { | |
231 public: | |
232 TetherHeaderRowView() | |
233 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_TETHER) {} | |
234 | |
235 ~TetherHeaderRowView() override {} | |
236 | |
237 const char* GetClassName() const override { return "TetherHeaderRowView"; } | |
238 | |
239 protected: | |
240 void OnToggleToggled(bool is_on) override { | |
241 // TODO (hansberry): Persist toggle to settings/preferences. | |
242 } | |
243 | |
244 private: | |
245 DISALLOW_COPY_AND_ASSIGN(TetherHeaderRowView); | |
246 }; | |
247 | 235 |
248 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { | 236 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { |
249 public: | 237 public: |
250 WifiHeaderRowView() | 238 WifiHeaderRowView() |
251 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), | 239 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), |
252 join_(nullptr) {} | 240 join_(nullptr) {} |
253 | 241 |
254 ~WifiHeaderRowView() override {} | 242 ~WifiHeaderRowView() override {} |
255 | 243 |
256 void SetIsOn(bool enabled) override { | 244 void SetIsOn(bool enabled) override { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 } // namespace | 307 } // namespace |
320 | 308 |
321 // NetworkListView: | 309 // NetworkListView: |
322 | 310 |
323 NetworkListView::NetworkListView(SystemTrayItem* owner, LoginStatus login) | 311 NetworkListView::NetworkListView(SystemTrayItem* owner, LoginStatus login) |
324 : NetworkStateListDetailedView(owner, LIST_TYPE_NETWORK, login), | 312 : NetworkStateListDetailedView(owner, LIST_TYPE_NETWORK, login), |
325 needs_relayout_(false), | 313 needs_relayout_(false), |
326 no_wifi_networks_view_(nullptr), | 314 no_wifi_networks_view_(nullptr), |
327 no_cellular_networks_view_(nullptr), | 315 no_cellular_networks_view_(nullptr), |
328 cellular_header_view_(nullptr), | 316 cellular_header_view_(nullptr), |
329 tether_header_view_(nullptr), | |
330 wifi_header_view_(nullptr), | 317 wifi_header_view_(nullptr), |
331 cellular_separator_view_(nullptr), | 318 cellular_separator_view_(nullptr), |
332 tether_separator_view_(nullptr), | |
333 wifi_separator_view_(nullptr), | 319 wifi_separator_view_(nullptr), |
334 connection_warning_(nullptr) {} | 320 connection_warning_(nullptr) {} |
335 | 321 |
336 NetworkListView::~NetworkListView() { | 322 NetworkListView::~NetworkListView() { |
337 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 323 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
338 } | 324 } |
339 | 325 |
340 void NetworkListView::UpdateNetworkList() { | 326 void NetworkListView::UpdateNetworkList() { |
341 CHECK(scroll_content()); | 327 CHECK(scroll_content()); |
342 | 328 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 bool prohibited_by_policy = IsProhibitedByPolicy(network); | 436 bool prohibited_by_policy = IsProhibitedByPolicy(network); |
451 info->label = network_icon::GetLabelForNetwork( | 437 info->label = network_icon::GetLabelForNetwork( |
452 network, network_icon::ICON_TYPE_MENU_LIST); | 438 network, network_icon::ICON_TYPE_MENU_LIST); |
453 info->image = | 439 info->image = |
454 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); | 440 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); |
455 info->disable = | 441 info->disable = |
456 (network->activation_state() == shill::kActivationStateActivating) || | 442 (network->activation_state() == shill::kActivationStateActivating) || |
457 prohibited_by_policy; | 443 prohibited_by_policy; |
458 info->connected = network->IsConnectedState(); | 444 info->connected = network->IsConnectedState(); |
459 info->connecting = network->IsConnectingState(); | 445 info->connecting = network->IsConnectingState(); |
460 if (network->Matches(NetworkTypePattern::WiFi())) | 446 if (network->Matches(NetworkTypePattern::WiFi())) { |
461 info->type = NetworkInfo::Type::WIFI; | 447 info->type = NetworkInfo::Type::WIFI; |
462 else if (network->Matches(NetworkTypePattern::Cellular())) | 448 } else if (network->Matches(NetworkTypePattern::Cellular()) || |
449 network->Matches(NetworkTypePattern::Tether())) { | |
stevenjb
2017/05/23 22:11:07
So, we discussed possible changes to NetworkTypePa
Ryan Hansberry
2017/05/27 00:16:22
Ping.
lesliewatkins
2017/05/30 18:29:51
Done.
| |
463 info->type = NetworkInfo::Type::CELLULAR; | 450 info->type = NetworkInfo::Type::CELLULAR; |
464 else if (network->Matches(NetworkTypePattern::Tether())) | 451 } |
465 info->type = NetworkInfo::Type::TETHER; | |
466 if (prohibited_by_policy) { | 452 if (prohibited_by_policy) { |
467 info->tooltip = | 453 info->tooltip = |
468 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); | 454 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); |
469 } | 455 } |
470 if (!animating && network->IsConnectingState()) | 456 if (!animating && network->IsConnectingState()) |
471 animating = true; | 457 animating = true; |
472 } | 458 } |
473 if (animating) | 459 if (animating) |
474 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 460 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
475 else | 461 else |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 if (!connection_warning_) | 522 if (!connection_warning_) |
537 connection_warning_ = CreateConnectionWarning(); | 523 connection_warning_ = CreateConnectionWarning(); |
538 PlaceViewAtIndex(connection_warning_, index++); | 524 PlaceViewAtIndex(connection_warning_, index++); |
539 } | 525 } |
540 | 526 |
541 // First add high-priority networks (not Wi-Fi nor cellular). | 527 // First add high-priority networks (not Wi-Fi nor cellular). |
542 std::unique_ptr<std::set<std::string>> new_guids = | 528 std::unique_ptr<std::set<std::string>> new_guids = |
543 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); | 529 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); |
544 index += new_guids->size(); | 530 index += new_guids->size(); |
545 | 531 |
546 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { | 532 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular()) || |
533 handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { | |
547 index = UpdateSectionHeaderRow( | 534 index = UpdateSectionHeaderRow( |
548 NetworkTypePattern::Cellular(), | 535 NetworkTypePattern::Cellular(), |
549 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, | 536 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()) || |
550 &cellular_header_view_, &cellular_separator_view_); | 537 (!handler->IsTechnologyAvailable(NetworkTypePattern::Cellular()) && |
Ryan Hansberry
2017/05/23 01:14:29
This is correct but might be confusing in the futu
stevenjb
2017/05/23 22:11:07
Or add an anonymous helper function: IsMobileTechn
lesliewatkins
2017/05/26 23:49:32
I'm not sure what you mean by this, as there is no
| |
538 handler->IsTechnologyEnabled(NetworkTypePattern::Tether())), | |
539 index, &cellular_header_view_, &cellular_separator_view_); | |
551 } | 540 } |
552 | 541 |
553 // Cellular initializing. | 542 // Cellular initializing. |
554 int cellular_message_id = network_icon::GetCellularUninitializedMsg(); | 543 int cellular_message_id = network_icon::GetCellularUninitializedMsg(); |
555 if (!cellular_message_id && | 544 if (!cellular_message_id && |
556 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && | 545 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && |
557 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { | 546 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { |
558 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; | 547 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; |
559 } | 548 } |
560 UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_); | 549 UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_); |
561 if (cellular_message_id) | 550 if (cellular_message_id) |
562 ++index; | 551 ++index; |
563 | 552 |
564 // Add cellular networks. | 553 // Add cellular and Tether networks. |
554 // TODO (hansberry): Audit existing usage of NonVirtual and consider changing | |
555 // it to include Tether. See crbug.com/693647. | |
565 std::unique_ptr<std::set<std::string>> new_cellular_guids = | 556 std::unique_ptr<std::set<std::string>> new_cellular_guids = |
566 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); | 557 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); |
567 index += new_cellular_guids->size(); | 558 index += new_cellular_guids->size(); |
568 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); | 559 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); |
569 | 560 |
570 // TODO (hansberry): Audit existing usage of NonVirtual and consider changing | |
571 // it to include Tether. See crbug.com/693647. | |
572 if (handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { | |
573 index = UpdateSectionHeaderRow( | |
574 NetworkTypePattern::Tether(), | |
575 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()), index, | |
576 &tether_header_view_, &tether_separator_view_); | |
577 | |
578 // TODO (hansberry): Should a message similar to | |
579 // IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS be shown if Tether technology is | |
580 // enabled but no networks are around? | |
581 | |
582 // Add Tether networks. | |
583 std::unique_ptr<std::set<std::string>> new_tether_guids = | |
584 UpdateNetworkChildren(NetworkInfo::Type::TETHER, index); | |
585 index += new_tether_guids->size(); | |
586 new_guids->insert(new_tether_guids->begin(), new_tether_guids->end()); | |
587 } | |
588 | |
589 index = UpdateSectionHeaderRow( | 561 index = UpdateSectionHeaderRow( |
590 NetworkTypePattern::WiFi(), | 562 NetworkTypePattern::WiFi(), |
591 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, | 563 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, |
592 &wifi_header_view_, &wifi_separator_view_); | 564 &wifi_header_view_, &wifi_separator_view_); |
593 | 565 |
594 // "Wifi Enabled / Disabled". | 566 // "Wifi Enabled / Disabled". |
595 int wifi_message_id = 0; | 567 int wifi_message_id = 0; |
596 if (network_list_.empty()) { | 568 if (network_list_.empty()) { |
597 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) | 569 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) |
598 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED | 570 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
741 PlaceViewAtIndex(label, insertion_index); | 713 PlaceViewAtIndex(label, insertion_index); |
742 *label_ptr = label; | 714 *label_ptr = label; |
743 } | 715 } |
744 | 716 |
745 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, | 717 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, |
746 bool enabled, | 718 bool enabled, |
747 int child_index, | 719 int child_index, |
748 SectionHeaderRowView** view, | 720 SectionHeaderRowView** view, |
749 views::Separator** separator_view) { | 721 views::Separator** separator_view) { |
750 if (!*view) { | 722 if (!*view) { |
751 if (pattern.Equals(NetworkTypePattern::Cellular())) | 723 if (pattern.Equals(NetworkTypePattern::Cellular()) || |
724 pattern.Equals(NetworkTypePattern::Tether())) | |
stevenjb
2017/05/23 22:11:07
This could use Pattern::Mobile and then we won't n
lesliewatkins
2017/05/30 18:29:51
Done.
| |
752 *view = new CellularHeaderRowView(); | 725 *view = new CellularHeaderRowView(); |
753 else if (pattern.Equals(NetworkTypePattern::Tether())) | |
754 *view = new TetherHeaderRowView(); | |
755 else if (pattern.Equals(NetworkTypePattern::WiFi())) | 726 else if (pattern.Equals(NetworkTypePattern::WiFi())) |
756 *view = new WifiHeaderRowView(); | 727 *view = new WifiHeaderRowView(); |
757 else | 728 else |
758 NOTREACHED(); | 729 NOTREACHED(); |
759 (*view)->Init(enabled); | 730 (*view)->Init(enabled); |
760 } | 731 } |
761 // Show or hide a separator above the header. The separator should only be | 732 // Show or hide a separator above the header. The separator should only be |
762 // visible when the header row is not at the top of the list. | 733 // visible when the header row is not at the top of the list. |
763 if (child_index > 0) { | 734 if (child_index > 0) { |
764 if (!*separator_view) | 735 if (!*separator_view) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
818 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( | 789 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( |
819 0, 0, 0, kTrayPopupLabelRightPadding))); | 790 0, 0, 0, kTrayPopupLabelRightPadding))); |
820 | 791 |
821 // Nothing to the right of the text. | 792 // Nothing to the right of the text. |
822 connection_warning->SetContainerVisible(TriView::Container::END, false); | 793 connection_warning->SetContainerVisible(TriView::Container::END, false); |
823 return connection_warning; | 794 return connection_warning; |
824 } | 795 } |
825 | 796 |
826 } // namespace tray | 797 } // namespace tray |
827 } // namespace ash | 798 } // namespace ash |
OLD | NEW |