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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_MOBILE) {} | 184 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_MOBILE) {} |
185 | 185 |
186 ~CellularHeaderRowView() override {} | 186 ~CellularHeaderRowView() override {} |
187 | 187 |
188 const char* GetClassName() const override { return "CellularHeaderRowView"; } | 188 const char* GetClassName() const override { return "CellularHeaderRowView"; } |
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, Tethering is |
Ryan Hansberry
2017/05/27 00:16:22
nit: Tether, not Tethering
lesliewatkins
2017/05/30 18:29:51
Done.
| |
195 chromeos::network_handler::ErrorCallback()); | 195 // treated as a subset of Cellular technology. Otherwise, Tethering has to |
Ryan Hansberry
2017/05/27 00:16:22
same nit here
lesliewatkins
2017/05/30 18:29:51
Done.
| |
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(CellularHeaderRowView); |
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 bool prohibited_by_policy = IsProhibitedByPolicy(network); | 411 bool prohibited_by_policy = IsProhibitedByPolicy(network); |
423 info->label = network_icon::GetLabelForNetwork( | 412 info->label = network_icon::GetLabelForNetwork( |
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::Cellular()) || |
424 network->Matches(NetworkTypePattern::Tether())) { | |
435 info->type = NetworkInfo::Type::CELLULAR; | 425 info->type = NetworkInfo::Type::CELLULAR; |
436 else if (network->Matches(NetworkTypePattern::Tether())) | 426 } |
437 info->type = NetworkInfo::Type::TETHER; | |
438 if (prohibited_by_policy) { | 427 if (prohibited_by_policy) { |
439 info->tooltip = | 428 info->tooltip = |
440 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); | 429 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); |
441 } | 430 } |
442 if (!animating && network->IsConnectingState()) | 431 if (!animating && network->IsConnectingState()) |
443 animating = true; | 432 animating = true; |
444 } | 433 } |
445 if (animating) | 434 if (animating) |
446 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 435 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
447 else | 436 else |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 if (!connection_warning_) | 497 if (!connection_warning_) |
509 connection_warning_ = CreateConnectionWarning(); | 498 connection_warning_ = CreateConnectionWarning(); |
510 PlaceViewAtIndex(connection_warning_, index++); | 499 PlaceViewAtIndex(connection_warning_, index++); |
511 } | 500 } |
512 | 501 |
513 // First add high-priority networks (not Wi-Fi nor cellular). | 502 // First add high-priority networks (not Wi-Fi nor cellular). |
514 std::unique_ptr<std::set<std::string>> new_guids = | 503 std::unique_ptr<std::set<std::string>> new_guids = |
515 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); | 504 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); |
516 index += new_guids->size(); | 505 index += new_guids->size(); |
517 | 506 |
518 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { | 507 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular()) || |
519 index = UpdateSectionHeaderRow( | 508 handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { |
520 NetworkTypePattern::Cellular(), | 509 bool is_enabled = |
521 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, | 510 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()) || |
Ryan Hansberry
2017/05/27 00:16:22
This is unfortunately now incorrect (it was previo
lesliewatkins
2017/05/30 18:29:51
I think it is correct, actually. Your if-statement
| |
522 &cellular_header_view_, &cellular_separator_view_); | 511 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()); |
512 | |
513 index = UpdateSectionHeaderRow(NetworkTypePattern::Cellular(), is_enabled, | |
514 index, &cellular_header_view_, | |
515 &cellular_separator_view_); | |
523 } | 516 } |
524 | 517 |
525 // Cellular initializing. | 518 // Cellular initializing. |
526 int cellular_message_id = network_icon::GetCellularUninitializedMsg(); | 519 int cellular_message_id = network_icon::GetCellularUninitializedMsg(); |
527 if (!cellular_message_id && | 520 if (!cellular_message_id && |
528 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && | 521 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && |
529 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { | 522 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { |
530 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; | 523 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; |
531 } | 524 } |
532 UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_); | 525 UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_); |
533 if (cellular_message_id) | 526 if (cellular_message_id) |
534 ++index; | 527 ++index; |
535 | 528 |
536 // Add cellular networks. | 529 // Add cellular and Tether networks. |
530 // TODO (hansberry): Audit existing usage of NonVirtual and consider changing | |
531 // it to include Tether. See crbug.com/693647. | |
537 std::unique_ptr<std::set<std::string>> new_cellular_guids = | 532 std::unique_ptr<std::set<std::string>> new_cellular_guids = |
538 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); | 533 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); |
539 index += new_cellular_guids->size(); | 534 index += new_cellular_guids->size(); |
540 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); | 535 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); |
541 | 536 |
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( | 537 index = UpdateSectionHeaderRow( |
562 NetworkTypePattern::WiFi(), | 538 NetworkTypePattern::WiFi(), |
563 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, | 539 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, |
564 &wifi_header_view_, &wifi_separator_view_); | 540 &wifi_header_view_, &wifi_separator_view_); |
565 | 541 |
566 // "Wifi Enabled / Disabled". | 542 // "Wifi Enabled / Disabled". |
567 int wifi_message_id = 0; | 543 int wifi_message_id = 0; |
568 if (network_list_.empty()) { | 544 if (network_list_.empty()) { |
569 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) | 545 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) |
570 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED | 546 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
694 PlaceViewAtIndex(label, insertion_index); | 670 PlaceViewAtIndex(label, insertion_index); |
695 *label_ptr = label; | 671 *label_ptr = label; |
696 } | 672 } |
697 | 673 |
698 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, | 674 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, |
699 bool enabled, | 675 bool enabled, |
700 int child_index, | 676 int child_index, |
701 SectionHeaderRowView** view, | 677 SectionHeaderRowView** view, |
702 views::Separator** separator_view) { | 678 views::Separator** separator_view) { |
703 if (!*view) { | 679 if (!*view) { |
704 if (pattern.Equals(NetworkTypePattern::Cellular())) | 680 if (pattern.Equals(NetworkTypePattern::Cellular()) || |
681 pattern.Equals(NetworkTypePattern::Tether())) | |
705 *view = new CellularHeaderRowView(); | 682 *view = new CellularHeaderRowView(); |
706 else if (pattern.Equals(NetworkTypePattern::Tether())) | |
707 *view = new TetherHeaderRowView(); | |
708 else if (pattern.Equals(NetworkTypePattern::WiFi())) | 683 else if (pattern.Equals(NetworkTypePattern::WiFi())) |
709 *view = new WifiHeaderRowView(); | 684 *view = new WifiHeaderRowView(); |
710 else | 685 else |
711 NOTREACHED(); | 686 NOTREACHED(); |
712 (*view)->Init(enabled); | 687 (*view)->Init(enabled); |
713 } | 688 } |
714 // Show or hide a separator above the header. The separator should only be | 689 // Show or hide a separator above the header. The separator should only be |
715 // visible when the header row is not at the top of the list. | 690 // visible when the header row is not at the top of the list. |
716 if (child_index > 0) { | 691 if (child_index > 0) { |
717 if (!*separator_view) | 692 if (!*separator_view) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
771 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( | 746 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( |
772 0, 0, 0, kTrayPopupLabelRightPadding))); | 747 0, 0, 0, kTrayPopupLabelRightPadding))); |
773 | 748 |
774 // Nothing to the right of the text. | 749 // Nothing to the right of the text. |
775 connection_warning->SetContainerVisible(TriView::Container::END, false); | 750 connection_warning->SetContainerVisible(TriView::Container::END, false); |
776 return connection_warning; | 751 return connection_warning; |
777 } | 752 } |
778 | 753 |
779 } // namespace tray | 754 } // namespace tray |
780 } // namespace ash | 755 } // namespace ash |
OLD | NEW |