Chromium Code Reviews| 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 handler->SetTechnologyEnabled(NetworkTypePattern::Cellular(), is_on, |
| 223 chromeos::network_handler::ErrorCallback()); | 223 chromeos::network_handler::ErrorCallback()); |
| 224 handler->SetTechnologyEnabled(NetworkTypePattern::Tether(), is_on, | |
|
Ryan Hansberry
2017/05/17 20:46:18
This works fine in the case that the device has no
| |
| 225 chromeos::network_handler::ErrorCallback()); | |
| 224 } | 226 } |
| 225 | 227 |
| 226 private: | 228 private: |
| 227 DISALLOW_COPY_AND_ASSIGN(CellularHeaderRowView); | 229 DISALLOW_COPY_AND_ASSIGN(CellularHeaderRowView); |
| 228 }; | 230 }; |
| 229 | 231 |
| 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 | 232 |
| 248 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { | 233 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { |
| 249 public: | 234 public: |
| 250 WifiHeaderRowView() | 235 WifiHeaderRowView() |
| 251 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), | 236 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), |
| 252 join_(nullptr) {} | 237 join_(nullptr) {} |
| 253 | 238 |
| 254 ~WifiHeaderRowView() override {} | 239 ~WifiHeaderRowView() override {} |
| 255 | 240 |
| 256 void SetIsOn(bool enabled) override { | 241 void SetIsOn(bool enabled) override { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 } // namespace | 304 } // namespace |
| 320 | 305 |
| 321 // NetworkListView: | 306 // NetworkListView: |
| 322 | 307 |
| 323 NetworkListView::NetworkListView(SystemTrayItem* owner, LoginStatus login) | 308 NetworkListView::NetworkListView(SystemTrayItem* owner, LoginStatus login) |
| 324 : NetworkStateListDetailedView(owner, LIST_TYPE_NETWORK, login), | 309 : NetworkStateListDetailedView(owner, LIST_TYPE_NETWORK, login), |
| 325 needs_relayout_(false), | 310 needs_relayout_(false), |
| 326 no_wifi_networks_view_(nullptr), | 311 no_wifi_networks_view_(nullptr), |
| 327 no_cellular_networks_view_(nullptr), | 312 no_cellular_networks_view_(nullptr), |
| 328 cellular_header_view_(nullptr), | 313 cellular_header_view_(nullptr), |
| 329 tether_header_view_(nullptr), | |
| 330 wifi_header_view_(nullptr), | 314 wifi_header_view_(nullptr), |
| 331 cellular_separator_view_(nullptr), | 315 cellular_separator_view_(nullptr), |
| 332 tether_separator_view_(nullptr), | |
| 333 wifi_separator_view_(nullptr), | 316 wifi_separator_view_(nullptr), |
| 334 connection_warning_(nullptr) {} | 317 connection_warning_(nullptr) {} |
| 335 | 318 |
| 336 NetworkListView::~NetworkListView() { | 319 NetworkListView::~NetworkListView() { |
| 337 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 320 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 338 } | 321 } |
| 339 | 322 |
| 340 void NetworkListView::UpdateNetworkList() { | 323 void NetworkListView::UpdateNetworkList() { |
| 341 CHECK(scroll_content()); | 324 CHECK(scroll_content()); |
| 342 | 325 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 bool prohibited_by_policy = IsProhibitedByPolicy(network); | 433 bool prohibited_by_policy = IsProhibitedByPolicy(network); |
| 451 info->label = network_icon::GetLabelForNetwork( | 434 info->label = network_icon::GetLabelForNetwork( |
| 452 network, network_icon::ICON_TYPE_MENU_LIST); | 435 network, network_icon::ICON_TYPE_MENU_LIST); |
| 453 info->image = | 436 info->image = |
| 454 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); | 437 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); |
| 455 info->disable = | 438 info->disable = |
| 456 (network->activation_state() == shill::kActivationStateActivating) || | 439 (network->activation_state() == shill::kActivationStateActivating) || |
| 457 prohibited_by_policy; | 440 prohibited_by_policy; |
| 458 info->connected = network->IsConnectedState(); | 441 info->connected = network->IsConnectedState(); |
| 459 info->connecting = network->IsConnectingState(); | 442 info->connecting = network->IsConnectingState(); |
| 460 if (network->Matches(NetworkTypePattern::WiFi())) | 443 if (network->Matches(NetworkTypePattern::WiFi())) { |
| 461 info->type = NetworkInfo::Type::WIFI; | 444 info->type = NetworkInfo::Type::WIFI; |
| 462 else if (network->Matches(NetworkTypePattern::Cellular())) | 445 } else if (network->Matches(NetworkTypePattern::Cellular()) || |
| 446 network->Matches(NetworkTypePattern::Tether())) { | |
| 463 info->type = NetworkInfo::Type::CELLULAR; | 447 info->type = NetworkInfo::Type::CELLULAR; |
| 464 else if (network->Matches(NetworkTypePattern::Tether())) | 448 } |
| 465 info->type = NetworkInfo::Type::TETHER; | |
| 466 if (prohibited_by_policy) { | 449 if (prohibited_by_policy) { |
| 467 info->tooltip = | 450 info->tooltip = |
| 468 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); | 451 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); |
| 469 } | 452 } |
| 470 if (!animating && network->IsConnectingState()) | 453 if (!animating && network->IsConnectingState()) |
| 471 animating = true; | 454 animating = true; |
| 472 } | 455 } |
| 473 if (animating) | 456 if (animating) |
| 474 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 457 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 475 else | 458 else |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 if (!connection_warning_) | 519 if (!connection_warning_) |
| 537 connection_warning_ = CreateConnectionWarning(); | 520 connection_warning_ = CreateConnectionWarning(); |
| 538 PlaceViewAtIndex(connection_warning_, index++); | 521 PlaceViewAtIndex(connection_warning_, index++); |
| 539 } | 522 } |
| 540 | 523 |
| 541 // First add high-priority networks (not Wi-Fi nor cellular). | 524 // First add high-priority networks (not Wi-Fi nor cellular). |
| 542 std::unique_ptr<std::set<std::string>> new_guids = | 525 std::unique_ptr<std::set<std::string>> new_guids = |
| 543 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); | 526 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); |
| 544 index += new_guids->size(); | 527 index += new_guids->size(); |
| 545 | 528 |
| 546 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { | 529 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular()) || |
| 530 handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { | |
| 547 index = UpdateSectionHeaderRow( | 531 index = UpdateSectionHeaderRow( |
| 548 NetworkTypePattern::Cellular(), | 532 NetworkTypePattern::Cellular(), |
| 549 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, | 533 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()) || |
| 550 &cellular_header_view_, &cellular_separator_view_); | 534 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()), |
|
Ryan Hansberry
2017/05/17 20:46:18
Given my comment above, please change this to:
ha
| |
| 535 index, &cellular_header_view_, &cellular_separator_view_); | |
| 551 } | 536 } |
| 552 | 537 |
| 553 // Cellular initializing. | 538 // Cellular initializing. |
| 554 int cellular_message_id = network_icon::GetCellularUninitializedMsg(); | 539 int cellular_message_id = network_icon::GetCellularUninitializedMsg(); |
| 555 if (!cellular_message_id && | 540 if (!cellular_message_id && |
| 556 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && | 541 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && |
| 557 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { | 542 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { |
| 558 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; | 543 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; |
| 559 } | 544 } |
| 560 UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_); | 545 UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_); |
| 561 if (cellular_message_id) | 546 if (cellular_message_id) |
| 562 ++index; | 547 ++index; |
| 563 | 548 |
| 564 // Add cellular networks. | 549 // Add cellular and Tether networks. |
| 550 // TODO (hansberry): Audit existing usage of NonVirtual and consider changing | |
| 551 // it to include Tether. See crbug.com/693647. | |
| 565 std::unique_ptr<std::set<std::string>> new_cellular_guids = | 552 std::unique_ptr<std::set<std::string>> new_cellular_guids = |
| 566 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); | 553 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); |
| 554 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); | |
|
Ryan Hansberry
2017/05/17 20:46:18
Why did you move this line? (previously below 'ind
lesliewatkins
2017/05/22 22:57:37
An artifact of intermediate changes. It doesn't af
| |
| 567 index += new_cellular_guids->size(); | 555 index += new_cellular_guids->size(); |
| 568 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); | |
| 569 | |
| 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 | 556 |
| 589 index = UpdateSectionHeaderRow( | 557 index = UpdateSectionHeaderRow( |
| 590 NetworkTypePattern::WiFi(), | 558 NetworkTypePattern::WiFi(), |
| 591 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, | 559 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, |
| 592 &wifi_header_view_, &wifi_separator_view_); | 560 &wifi_header_view_, &wifi_separator_view_); |
| 593 | 561 |
| 594 // "Wifi Enabled / Disabled". | 562 // "Wifi Enabled / Disabled". |
| 595 int wifi_message_id = 0; | 563 int wifi_message_id = 0; |
| 596 if (network_list_.empty()) { | 564 if (network_list_.empty()) { |
| 597 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) | 565 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 741 PlaceViewAtIndex(label, insertion_index); | 709 PlaceViewAtIndex(label, insertion_index); |
| 742 *label_ptr = label; | 710 *label_ptr = label; |
| 743 } | 711 } |
| 744 | 712 |
| 745 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, | 713 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, |
| 746 bool enabled, | 714 bool enabled, |
| 747 int child_index, | 715 int child_index, |
| 748 SectionHeaderRowView** view, | 716 SectionHeaderRowView** view, |
| 749 views::Separator** separator_view) { | 717 views::Separator** separator_view) { |
| 750 if (!*view) { | 718 if (!*view) { |
| 751 if (pattern.Equals(NetworkTypePattern::Cellular())) | 719 if (pattern.Equals(NetworkTypePattern::Cellular()) || |
| 720 pattern.Equals(NetworkTypePattern::Tether())) | |
| 752 *view = new CellularHeaderRowView(); | 721 *view = new CellularHeaderRowView(); |
| 753 else if (pattern.Equals(NetworkTypePattern::Tether())) | |
| 754 *view = new TetherHeaderRowView(); | |
| 755 else if (pattern.Equals(NetworkTypePattern::WiFi())) | 722 else if (pattern.Equals(NetworkTypePattern::WiFi())) |
| 756 *view = new WifiHeaderRowView(); | 723 *view = new WifiHeaderRowView(); |
| 757 else | 724 else |
| 758 NOTREACHED(); | 725 NOTREACHED(); |
| 759 (*view)->Init(enabled); | 726 (*view)->Init(enabled); |
| 760 } | 727 } |
| 761 // Show or hide a separator above the header. The separator should only be | 728 // 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. | 729 // visible when the header row is not at the top of the list. |
| 763 if (child_index > 0) { | 730 if (child_index > 0) { |
| 764 if (!*separator_view) | 731 if (!*separator_view) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 815 style.SetupLabel(label); | 782 style.SetupLabel(label); |
| 816 connection_warning->AddView(TriView::Container::CENTER, label); | 783 connection_warning->AddView(TriView::Container::CENTER, label); |
| 817 | 784 |
| 818 // Nothing to the right of the text. | 785 // Nothing to the right of the text. |
| 819 connection_warning->SetContainerVisible(TriView::Container::END, false); | 786 connection_warning->SetContainerVisible(TriView::Container::END, false); |
| 820 return connection_warning; | 787 return connection_warning; |
| 821 } | 788 } |
| 822 | 789 |
| 823 } // namespace tray | 790 } // namespace tray |
| 824 } // namespace ash | 791 } // namespace ash |
| OLD | NEW |