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 CellularHeaderRowView : public NetworkListView::SectionHeaderRowView { |
khorimoto
2017/05/30 22:35:16
Isn't this called the Mobile section now? If so, y
lesliewatkins
2017/05/31 00:43:27
Done.
| |
182 public: | 182 public: |
183 CellularHeaderRowView() | 183 CellularHeaderRowView() |
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, Tether is |
khorimoto
2017/05/30 22:35:15
This comment is a bit vague. Can you explain it mo
lesliewatkins
2017/05/31 00:43:27
Done.
Kyle Horimoto
2017/05/31 20:13:59
Not actually done.
lesliewatkins
2017/05/31 22:06:28
Done.
| |
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, | |
khorimoto
2017/05/30 22:35:16
Above this line, you should DCHECK(handler->IsTech
lesliewatkins
2017/05/31 00:43:27
Done.
Kyle Horimoto
2017/05/31 20:13:58
Not actually done.
lesliewatkins
2017/05/31 22:06:28
Done.
| |
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 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. |
528 // TODO (hansberry): Audit existing usage of NonVirtual and consider changing | |
khorimoto
2017/05/30 22:35:16
We are using Mobile instead of NonVirtual now, so
lesliewatkins
2017/05/31 16:41:05
Done! Also closed the associated bug.
| |
529 // it to include Tether. See crbug.com/693647. | |
537 std::unique_ptr<std::set<std::string>> new_cellular_guids = | 530 std::unique_ptr<std::set<std::string>> new_cellular_guids = |
538 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); | 531 UpdateNetworkChildren(NetworkInfo::Type::MOBILE, index); |
539 index += new_cellular_guids->size(); | 532 index += new_cellular_guids->size(); |
540 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); | 533 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); |
541 | 534 |
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( | 535 index = UpdateSectionHeaderRow( |
562 NetworkTypePattern::WiFi(), | 536 NetworkTypePattern::WiFi(), |
563 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, | 537 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, |
564 &wifi_header_view_, &wifi_separator_view_); | 538 &wifi_header_view_, &wifi_separator_view_); |
565 | 539 |
566 // "Wifi Enabled / Disabled". | 540 // "Wifi Enabled / Disabled". |
567 int wifi_message_id = 0; | 541 int wifi_message_id = 0; |
568 if (network_list_.empty()) { | 542 if (network_list_.empty()) { |
569 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) | 543 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) |
570 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED | 544 ? 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); | 668 PlaceViewAtIndex(label, insertion_index); |
695 *label_ptr = label; | 669 *label_ptr = label; |
696 } | 670 } |
697 | 671 |
698 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, | 672 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, |
699 bool enabled, | 673 bool enabled, |
700 int child_index, | 674 int child_index, |
701 SectionHeaderRowView** view, | 675 SectionHeaderRowView** view, |
702 views::Separator** separator_view) { | 676 views::Separator** separator_view) { |
703 if (!*view) { | 677 if (!*view) { |
704 if (pattern.Equals(NetworkTypePattern::Cellular())) | 678 if (pattern.MatchesPattern(NetworkTypePattern::Mobile())) |
705 *view = new CellularHeaderRowView(); | 679 *view = new CellularHeaderRowView(); |
706 else if (pattern.Equals(NetworkTypePattern::Tether())) | |
707 *view = new TetherHeaderRowView(); | |
708 else if (pattern.Equals(NetworkTypePattern::WiFi())) | 680 else if (pattern.Equals(NetworkTypePattern::WiFi())) |
709 *view = new WifiHeaderRowView(); | 681 *view = new WifiHeaderRowView(); |
710 else | 682 else |
711 NOTREACHED(); | 683 NOTREACHED(); |
712 (*view)->Init(enabled); | 684 (*view)->Init(enabled); |
713 } | 685 } |
714 // Show or hide a separator above the header. The separator should only be | 686 // 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. | 687 // visible when the header row is not at the top of the list. |
716 if (child_index > 0) { | 688 if (child_index > 0) { |
717 if (!*separator_view) | 689 if (!*separator_view) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
771 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( | 743 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( |
772 0, 0, 0, kTrayPopupLabelRightPadding))); | 744 0, 0, 0, kTrayPopupLabelRightPadding))); |
773 | 745 |
774 // Nothing to the right of the text. | 746 // Nothing to the right of the text. |
775 connection_warning->SetContainerVisible(TriView::Container::END, false); | 747 connection_warning->SetContainerVisible(TriView::Container::END, false); |
776 return connection_warning; | 748 return connection_warning; |
777 } | 749 } |
778 | 750 |
779 } // namespace tray | 751 } // namespace tray |
780 } // namespace ash | 752 } // namespace ash |
OLD | NEW |