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/common/system/chromeos/network/network_list_md.h" | 5 #include "ash/common/system/chromeos/network/network_list_md.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "ash/common/system/chromeos/network/network_icon.h" | 9 #include "ash/common/system/chromeos/network/network_icon.h" |
10 #include "ash/common/system/chromeos/network/network_icon_animation.h" | 10 #include "ash/common/system/chromeos/network/network_icon_animation.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 NetworkStateHandler* handler = | 175 NetworkStateHandler* handler = |
176 NetworkHandler::Get()->network_state_handler(); | 176 NetworkHandler::Get()->network_state_handler(); |
177 handler->SetTechnologyEnabled(NetworkTypePattern::Cellular(), is_on, | 177 handler->SetTechnologyEnabled(NetworkTypePattern::Cellular(), is_on, |
178 chromeos::network_handler::ErrorCallback()); | 178 chromeos::network_handler::ErrorCallback()); |
179 } | 179 } |
180 | 180 |
181 private: | 181 private: |
182 DISALLOW_COPY_AND_ASSIGN(CellularHeaderRowView); | 182 DISALLOW_COPY_AND_ASSIGN(CellularHeaderRowView); |
183 }; | 183 }; |
184 | 184 |
185 class TetherHeaderRowView : public NetworkListViewMd::SectionHeaderRowView { | |
186 public: | |
187 TetherHeaderRowView() | |
188 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_TETHER) {} | |
189 | |
190 ~TetherHeaderRowView() override {} | |
191 | |
192 const char* GetClassName() const override { return "TetherHeaderRowView"; } | |
193 | |
194 protected: | |
195 void OnToggleToggled(bool is_on) override { | |
196 // TODO (hansberry): Persist toggle to settings/preferences. | |
197 } | |
198 | |
199 private: | |
200 DISALLOW_COPY_AND_ASSIGN(TetherHeaderRowView); | |
201 }; | |
202 | |
185 class WifiHeaderRowView : public NetworkListViewMd::SectionHeaderRowView { | 203 class WifiHeaderRowView : public NetworkListViewMd::SectionHeaderRowView { |
186 public: | 204 public: |
187 explicit WifiHeaderRowView(NetworkListDelegate* network_list_delegate) | 205 explicit WifiHeaderRowView(NetworkListDelegate* network_list_delegate) |
188 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), | 206 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), |
189 network_list_delegate_(network_list_delegate), | 207 network_list_delegate_(network_list_delegate), |
190 join_(nullptr) {} | 208 join_(nullptr) {} |
191 | 209 |
192 ~WifiHeaderRowView() override {} | 210 ~WifiHeaderRowView() override {} |
193 | 211 |
194 void SetEnabled(bool enabled) override { | 212 void SetEnabled(bool enabled) override { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 } // namespace | 274 } // namespace |
257 | 275 |
258 // NetworkListViewMd: | 276 // NetworkListViewMd: |
259 | 277 |
260 NetworkListViewMd::NetworkListViewMd(NetworkListDelegate* delegate) | 278 NetworkListViewMd::NetworkListViewMd(NetworkListDelegate* delegate) |
261 : needs_relayout_(false), | 279 : needs_relayout_(false), |
262 delegate_(delegate), | 280 delegate_(delegate), |
263 no_wifi_networks_view_(nullptr), | 281 no_wifi_networks_view_(nullptr), |
264 no_cellular_networks_view_(nullptr), | 282 no_cellular_networks_view_(nullptr), |
265 cellular_header_view_(nullptr), | 283 cellular_header_view_(nullptr), |
284 tether_header_view_(nullptr), | |
266 wifi_header_view_(nullptr), | 285 wifi_header_view_(nullptr), |
267 cellular_separator_view_(nullptr), | 286 cellular_separator_view_(nullptr), |
287 tether_separator_view_(nullptr), | |
268 wifi_separator_view_(nullptr) { | 288 wifi_separator_view_(nullptr) { |
269 CHECK(delegate_); | 289 CHECK(delegate_); |
270 } | 290 } |
271 | 291 |
272 NetworkListViewMd::~NetworkListViewMd() { | 292 NetworkListViewMd::~NetworkListViewMd() { |
273 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 293 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
274 } | 294 } |
275 | 295 |
276 void NetworkListViewMd::Update() { | 296 void NetworkListViewMd::Update() { |
277 CHECK(container()); | 297 CHECK(container()); |
298 | |
299 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | |
300 | |
278 NetworkStateHandler::NetworkStateList network_list; | 301 NetworkStateHandler::NetworkStateList network_list; |
279 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | |
280 handler->GetVisibleNetworkList(&network_list); | 302 handler->GetVisibleNetworkList(&network_list); |
281 UpdateNetworks(network_list); | 303 UpdateNetworks(network_list); |
304 | |
305 NetworkStateHandler::NetworkStateList tether_network_list; | |
306 handler->GetNetworkListByType( | |
307 NetworkTypePattern::Tether(), false /* configured_only */, | |
308 false /* visible_only */, 0 /* no limit */, &tether_network_list); | |
309 for (const auto& tether_network : tether_network_list) { | |
310 network_list_.push_back( | |
311 base::MakeUnique<NetworkInfo>(tether_network->guid())); | |
312 } | |
313 | |
282 UpdateNetworkIcons(); | 314 UpdateNetworkIcons(); |
283 OrderNetworks(); | 315 OrderNetworks(); |
284 UpdateNetworkListInternal(); | 316 UpdateNetworkListInternal(); |
285 } | 317 } |
286 | 318 |
287 bool NetworkListViewMd::IsNetworkEntry(views::View* view, | 319 bool NetworkListViewMd::IsNetworkEntry(views::View* view, |
288 std::string* service_path) const { | 320 std::string* service_path) const { |
289 std::map<views::View*, std::string>::const_iterator found = | 321 std::map<views::View*, std::string>::const_iterator found = |
290 network_map_.find(view); | 322 network_map_.find(view); |
291 if (found == network_map_.end()) | 323 if (found == network_map_.end()) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 info->disable = | 401 info->disable = |
370 (network->activation_state() == shill::kActivationStateActivating) || | 402 (network->activation_state() == shill::kActivationStateActivating) || |
371 prohibited_by_policy; | 403 prohibited_by_policy; |
372 info->connected = network->IsConnectedState(); | 404 info->connected = network->IsConnectedState(); |
373 info->connecting = network->IsConnectingState(); | 405 info->connecting = network->IsConnectingState(); |
374 info->highlight = info->connected || info->connecting; | 406 info->highlight = info->connected || info->connecting; |
375 if (network->Matches(NetworkTypePattern::WiFi())) | 407 if (network->Matches(NetworkTypePattern::WiFi())) |
376 info->type = NetworkInfo::Type::WIFI; | 408 info->type = NetworkInfo::Type::WIFI; |
377 else if (network->Matches(NetworkTypePattern::Cellular())) | 409 else if (network->Matches(NetworkTypePattern::Cellular())) |
378 info->type = NetworkInfo::Type::CELLULAR; | 410 info->type = NetworkInfo::Type::CELLULAR; |
411 else if (network->Matches(NetworkTypePattern::Tether())) | |
412 info->type = NetworkInfo::Type::TETHER; | |
379 if (prohibited_by_policy) { | 413 if (prohibited_by_policy) { |
380 info->tooltip = | 414 info->tooltip = |
381 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); | 415 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); |
382 } | 416 } |
383 if (!animating && network->IsConnectingState()) | 417 if (!animating && network->IsConnectingState()) |
384 animating = true; | 418 animating = true; |
385 } | 419 } |
386 if (animating) | 420 if (animating) |
387 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 421 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
388 else | 422 else |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 ++index; | 493 ++index; |
460 | 494 |
461 // Add cellular networks. | 495 // Add cellular networks. |
462 std::unique_ptr<std::set<std::string>> new_cellular_service_paths = | 496 std::unique_ptr<std::set<std::string>> new_cellular_service_paths = |
463 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); | 497 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); |
464 index += new_cellular_service_paths->size(); | 498 index += new_cellular_service_paths->size(); |
465 new_service_paths->insert(new_cellular_service_paths->begin(), | 499 new_service_paths->insert(new_cellular_service_paths->begin(), |
466 new_cellular_service_paths->end()); | 500 new_cellular_service_paths->end()); |
467 } | 501 } |
468 | 502 |
503 // TODO (hansberry): Can't check on the |pattern| here like with Wi-Fi and | |
504 // Cellular because Tether does not match NonVirtual. Is that okay? Should | |
505 // |delegate_|'s GetNetworkTypePattern be adjusted to match Tether? | |
stevenjb
2017/02/16 22:56:35
I would replace the question in the comment with s
Ryan Hansberry
2017/02/17 19:29:42
Done.
| |
506 if (handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { | |
507 index = UpdateSectionHeaderRow( | |
508 NetworkTypePattern::Tether(), | |
509 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()), index, | |
510 &tether_header_view_, &tether_separator_view_); | |
511 | |
512 // TODO (hansberry): Should a message similar to | |
513 // IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS be shown if Tether technology | |
514 // is enabled but no networks are around? | |
515 | |
516 // Add Tether networks. | |
517 std::unique_ptr<std::set<std::string>> new_tether_guids = | |
518 UpdateNetworkChildren(NetworkInfo::Type::TETHER, index); | |
519 index += new_tether_guids->size(); | |
520 new_service_paths->insert(new_tether_guids->begin(), | |
521 new_tether_guids->end()); | |
522 } | |
523 | |
469 if (pattern.MatchesPattern(NetworkTypePattern::WiFi())) { | 524 if (pattern.MatchesPattern(NetworkTypePattern::WiFi())) { |
470 index = UpdateSectionHeaderRow( | 525 index = UpdateSectionHeaderRow( |
471 NetworkTypePattern::WiFi(), | 526 NetworkTypePattern::WiFi(), |
472 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, | 527 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, |
473 &wifi_header_view_, &wifi_separator_view_); | 528 &wifi_header_view_, &wifi_separator_view_); |
474 | 529 |
475 // "Wifi Enabled / Disabled". | 530 // "Wifi Enabled / Disabled". |
476 int message_id = 0; | 531 int message_id = 0; |
477 if (network_list_.empty()) { | 532 if (network_list_.empty()) { |
478 message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) | 533 message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 | 623 |
569 int NetworkListViewMd::UpdateSectionHeaderRow( | 624 int NetworkListViewMd::UpdateSectionHeaderRow( |
570 NetworkTypePattern pattern, | 625 NetworkTypePattern pattern, |
571 bool enabled, | 626 bool enabled, |
572 int child_index, | 627 int child_index, |
573 SectionHeaderRowView** view, | 628 SectionHeaderRowView** view, |
574 views::Separator** separator_view) { | 629 views::Separator** separator_view) { |
575 if (!*view) { | 630 if (!*view) { |
576 if (pattern.Equals(NetworkTypePattern::Cellular())) | 631 if (pattern.Equals(NetworkTypePattern::Cellular())) |
577 *view = new CellularHeaderRowView(); | 632 *view = new CellularHeaderRowView(); |
633 else if (pattern.Equals(NetworkTypePattern::Tether())) | |
634 *view = new TetherHeaderRowView(); | |
578 else if (pattern.Equals(NetworkTypePattern::WiFi())) | 635 else if (pattern.Equals(NetworkTypePattern::WiFi())) |
579 *view = new WifiHeaderRowView(delegate_); | 636 *view = new WifiHeaderRowView(delegate_); |
580 else | 637 else |
581 NOTREACHED(); | 638 NOTREACHED(); |
582 (*view)->Init(enabled); | 639 (*view)->Init(enabled); |
583 } | 640 } |
584 // Show or hide a separator above the header. The separator should only be | 641 // Show or hide a separator above the header. The separator should only be |
585 // visible when the header row is not at the top of the list. | 642 // visible when the header row is not at the top of the list. |
586 if (child_index > 0) { | 643 if (child_index > 0) { |
587 if (!*separator_view) | 644 if (!*separator_view) |
588 *separator_view = TrayPopupUtils::CreateListSubHeaderSeparator(); | 645 *separator_view = TrayPopupUtils::CreateListSubHeaderSeparator(); |
589 PlaceViewAtIndex(*separator_view, child_index++); | 646 PlaceViewAtIndex(*separator_view, child_index++); |
590 } else { | 647 } else { |
591 if (*separator_view) | 648 if (*separator_view) |
592 delete *separator_view; | 649 delete *separator_view; |
593 *separator_view = nullptr; | 650 *separator_view = nullptr; |
594 } | 651 } |
595 | 652 |
596 (*view)->SetEnabled(enabled); | 653 (*view)->SetEnabled(enabled); |
597 PlaceViewAtIndex(*view, child_index++); | 654 PlaceViewAtIndex(*view, child_index++); |
598 return child_index; | 655 return child_index; |
599 } | 656 } |
600 | 657 |
601 void NetworkListViewMd::NetworkIconChanged() { | 658 void NetworkListViewMd::NetworkIconChanged() { |
602 Update(); | 659 Update(); |
603 } | 660 } |
604 | 661 |
605 } // namespace ash | 662 } // namespace ash |
OLD | NEW |