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/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()); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 info->disable = | 389 info->disable = |
| 370 (network->activation_state() == shill::kActivationStateActivating) || | 390 (network->activation_state() == shill::kActivationStateActivating) || |
| 371 prohibited_by_policy; | 391 prohibited_by_policy; |
| 372 info->connected = network->IsConnectedState(); | 392 info->connected = network->IsConnectedState(); |
| 373 info->connecting = network->IsConnectingState(); | 393 info->connecting = network->IsConnectingState(); |
| 374 info->highlight = info->connected || info->connecting; | 394 info->highlight = info->connected || info->connecting; |
| 375 if (network->Matches(NetworkTypePattern::WiFi())) | 395 if (network->Matches(NetworkTypePattern::WiFi())) |
| 376 info->type = NetworkInfo::Type::WIFI; | 396 info->type = NetworkInfo::Type::WIFI; |
| 377 else if (network->Matches(NetworkTypePattern::Cellular())) | 397 else if (network->Matches(NetworkTypePattern::Cellular())) |
| 378 info->type = NetworkInfo::Type::CELLULAR; | 398 info->type = NetworkInfo::Type::CELLULAR; |
| 399 else if (network->Matches(NetworkTypePattern::Tether())) | |
| 400 info->type = NetworkInfo::Type::TETHER; | |
| 379 if (prohibited_by_policy) { | 401 if (prohibited_by_policy) { |
| 380 info->tooltip = | 402 info->tooltip = |
| 381 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); | 403 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); |
| 382 } | 404 } |
| 383 if (!animating && network->IsConnectingState()) | 405 if (!animating && network->IsConnectingState()) |
| 384 animating = true; | 406 animating = true; |
| 385 } | 407 } |
| 386 if (animating) | 408 if (animating) |
| 387 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 409 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 388 else | 410 else |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 ++index; | 481 ++index; |
| 460 | 482 |
| 461 // Add cellular networks. | 483 // Add cellular networks. |
| 462 std::unique_ptr<std::set<std::string>> new_cellular_service_paths = | 484 std::unique_ptr<std::set<std::string>> new_cellular_service_paths = |
| 463 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); | 485 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); |
| 464 index += new_cellular_service_paths->size(); | 486 index += new_cellular_service_paths->size(); |
| 465 new_service_paths->insert(new_cellular_service_paths->begin(), | 487 new_service_paths->insert(new_cellular_service_paths->begin(), |
| 466 new_cellular_service_paths->end()); | 488 new_cellular_service_paths->end()); |
| 467 } | 489 } |
| 468 | 490 |
| 491 // TODO (hansberry): Use a runtime flag? | |
| 492 bool isTetherEnabled = true; | |
|
stevenjb
2017/02/15 20:59:04
You will definitely want to set up a FeatureList f
Ryan Hansberry
2017/02/16 22:42:20
We already have a flag in chromeos::switches::kEna
stevenjb
2017/02/16 22:56:35
It looks like we already have a bunch of os specif
| |
| 493 if (isTetherEnabled && pattern.MatchesPattern(NetworkTypePattern::Tether())) { | |
| 494 // TODO (hansberry): Fetch isTetherTechnologyEnabled value from | |
| 495 // settings/preferences. | |
|
stevenjb
2017/02/15 20:59:04
We should leverage NetworkStateHandler::IsTechnolo
Ryan Hansberry
2017/02/16 22:42:20
Was worried about the appearance of interacting wi
stevenjb
2017/02/16 22:56:35
Acknowledged.
| |
| 496 bool isTetherTechnologyEnabled = true; | |
| 497 index = UpdateSectionHeaderRow( | |
| 498 NetworkTypePattern::Tether(), isTetherTechnologyEnabled, index, | |
| 499 &tether_header_view_, &tether_separator_view_); | |
| 500 | |
| 501 // Add Tether networks. | |
| 502 std::unique_ptr<std::set<std::string>> new_tether_service_paths = | |
|
stevenjb
2017/02/15 20:59:04
For teter these will be guids so i would name them
Ryan Hansberry
2017/02/16 22:42:20
Done.
| |
| 503 UpdateNetworkChildren(NetworkInfo::Type::TETHER, index); | |
| 504 index += new_tether_service_paths->size(); | |
| 505 new_service_paths->insert(new_tether_service_paths->begin(), | |
| 506 new_tether_service_paths->end()); | |
| 507 } | |
| 508 | |
| 469 if (pattern.MatchesPattern(NetworkTypePattern::WiFi())) { | 509 if (pattern.MatchesPattern(NetworkTypePattern::WiFi())) { |
| 470 index = UpdateSectionHeaderRow( | 510 index = UpdateSectionHeaderRow( |
| 471 NetworkTypePattern::WiFi(), | 511 NetworkTypePattern::WiFi(), |
| 472 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, | 512 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, |
| 473 &wifi_header_view_, &wifi_separator_view_); | 513 &wifi_header_view_, &wifi_separator_view_); |
| 474 | 514 |
| 475 // "Wifi Enabled / Disabled". | 515 // "Wifi Enabled / Disabled". |
| 476 int message_id = 0; | 516 int message_id = 0; |
| 477 if (network_list_.empty()) { | 517 if (network_list_.empty()) { |
| 478 message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) | 518 message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 | 608 |
| 569 int NetworkListViewMd::UpdateSectionHeaderRow( | 609 int NetworkListViewMd::UpdateSectionHeaderRow( |
| 570 NetworkTypePattern pattern, | 610 NetworkTypePattern pattern, |
| 571 bool enabled, | 611 bool enabled, |
| 572 int child_index, | 612 int child_index, |
| 573 SectionHeaderRowView** view, | 613 SectionHeaderRowView** view, |
| 574 views::Separator** separator_view) { | 614 views::Separator** separator_view) { |
| 575 if (!*view) { | 615 if (!*view) { |
| 576 if (pattern.Equals(NetworkTypePattern::Cellular())) | 616 if (pattern.Equals(NetworkTypePattern::Cellular())) |
| 577 *view = new CellularHeaderRowView(); | 617 *view = new CellularHeaderRowView(); |
| 618 else if (pattern.Equals(NetworkTypePattern::Tether())) | |
| 619 *view = new TetherHeaderRowView(); | |
| 578 else if (pattern.Equals(NetworkTypePattern::WiFi())) | 620 else if (pattern.Equals(NetworkTypePattern::WiFi())) |
| 579 *view = new WifiHeaderRowView(delegate_); | 621 *view = new WifiHeaderRowView(delegate_); |
| 580 else | 622 else |
| 581 NOTREACHED(); | 623 NOTREACHED(); |
| 582 (*view)->Init(enabled); | 624 (*view)->Init(enabled); |
| 583 } | 625 } |
| 584 // Show or hide a separator above the header. The separator should only be | 626 // 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. | 627 // visible when the header row is not at the top of the list. |
| 586 if (child_index > 0) { | 628 if (child_index > 0) { |
| 587 if (!*separator_view) | 629 if (!*separator_view) |
| 588 *separator_view = TrayPopupUtils::CreateListSubHeaderSeparator(); | 630 *separator_view = TrayPopupUtils::CreateListSubHeaderSeparator(); |
| 589 PlaceViewAtIndex(*separator_view, child_index++); | 631 PlaceViewAtIndex(*separator_view, child_index++); |
| 590 } else { | 632 } else { |
| 591 if (*separator_view) | 633 if (*separator_view) |
| 592 delete *separator_view; | 634 delete *separator_view; |
| 593 *separator_view = nullptr; | 635 *separator_view = nullptr; |
| 594 } | 636 } |
| 595 | 637 |
| 596 (*view)->SetEnabled(enabled); | 638 (*view)->SetEnabled(enabled); |
| 597 PlaceViewAtIndex(*view, child_index++); | 639 PlaceViewAtIndex(*view, child_index++); |
| 598 return child_index; | 640 return child_index; |
| 599 } | 641 } |
| 600 | 642 |
| 601 void NetworkListViewMd::NetworkIconChanged() { | 643 void NetworkListViewMd::NetworkIconChanged() { |
| 602 Update(); | 644 Update(); |
| 603 } | 645 } |
| 604 | 646 |
| 605 } // namespace ash | 647 } // namespace ash |
| OLD | NEW |