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->GetTetherNetworkList(0 /* no limit */, &tether_network_list); |
| 307 for (const auto& tether_network : tether_network_list) { |
| 308 network_list_.push_back( |
| 309 base::MakeUnique<NetworkInfo>(tether_network->guid())); |
| 310 } |
| 311 |
282 UpdateNetworkIcons(); | 312 UpdateNetworkIcons(); |
283 OrderNetworks(); | 313 OrderNetworks(); |
284 UpdateNetworkListInternal(); | 314 UpdateNetworkListInternal(); |
285 } | 315 } |
286 | 316 |
287 bool NetworkListViewMd::IsNetworkEntry(views::View* view, | 317 bool NetworkListViewMd::IsNetworkEntry(views::View* view, |
288 std::string* guid) const { | 318 std::string* guid) const { |
289 std::map<views::View*, std::string>::const_iterator found = | 319 std::map<views::View*, std::string>::const_iterator found = |
290 network_map_.find(view); | 320 network_map_.find(view); |
291 if (found == network_map_.end()) | 321 if (found == network_map_.end()) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 info->disable = | 399 info->disable = |
370 (network->activation_state() == shill::kActivationStateActivating) || | 400 (network->activation_state() == shill::kActivationStateActivating) || |
371 prohibited_by_policy; | 401 prohibited_by_policy; |
372 info->connected = network->IsConnectedState(); | 402 info->connected = network->IsConnectedState(); |
373 info->connecting = network->IsConnectingState(); | 403 info->connecting = network->IsConnectingState(); |
374 info->highlight = info->connected || info->connecting; | 404 info->highlight = info->connected || info->connecting; |
375 if (network->Matches(NetworkTypePattern::WiFi())) | 405 if (network->Matches(NetworkTypePattern::WiFi())) |
376 info->type = NetworkInfo::Type::WIFI; | 406 info->type = NetworkInfo::Type::WIFI; |
377 else if (network->Matches(NetworkTypePattern::Cellular())) | 407 else if (network->Matches(NetworkTypePattern::Cellular())) |
378 info->type = NetworkInfo::Type::CELLULAR; | 408 info->type = NetworkInfo::Type::CELLULAR; |
| 409 else if (network->Matches(NetworkTypePattern::Tether())) |
| 410 info->type = NetworkInfo::Type::TETHER; |
379 if (prohibited_by_policy) { | 411 if (prohibited_by_policy) { |
380 info->tooltip = | 412 info->tooltip = |
381 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); | 413 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); |
382 } | 414 } |
383 if (!animating && network->IsConnectingState()) | 415 if (!animating && network->IsConnectingState()) |
384 animating = true; | 416 animating = true; |
385 } | 417 } |
386 if (animating) | 418 if (animating) |
387 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 419 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
388 else | 420 else |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 if (message_id) | 489 if (message_id) |
458 ++index; | 490 ++index; |
459 | 491 |
460 // Add cellular networks. | 492 // Add cellular networks. |
461 std::unique_ptr<std::set<std::string>> new_cellular_guids = | 493 std::unique_ptr<std::set<std::string>> new_cellular_guids = |
462 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); | 494 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); |
463 index += new_cellular_guids->size(); | 495 index += new_cellular_guids->size(); |
464 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); | 496 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); |
465 } | 497 } |
466 | 498 |
| 499 // TODO (hansberry): Audit existing usage of NonVirtual and consider changing |
| 500 // it to include Tether. See crbug.com/693647. |
| 501 if (handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { |
| 502 index = UpdateSectionHeaderRow( |
| 503 NetworkTypePattern::Tether(), |
| 504 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()), index, |
| 505 &tether_header_view_, &tether_separator_view_); |
| 506 |
| 507 // TODO (hansberry): Should a message similar to |
| 508 // IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS be shown if Tether technology |
| 509 // is enabled but no networks are around? |
| 510 |
| 511 // Add Tether networks. |
| 512 std::unique_ptr<std::set<std::string>> new_tether_guids = |
| 513 UpdateNetworkChildren(NetworkInfo::Type::TETHER, index); |
| 514 index += new_tether_guids->size(); |
| 515 new_guids->insert(new_tether_guids->begin(), new_tether_guids->end()); |
| 516 } |
| 517 |
467 if (pattern.MatchesPattern(NetworkTypePattern::WiFi())) { | 518 if (pattern.MatchesPattern(NetworkTypePattern::WiFi())) { |
468 index = UpdateSectionHeaderRow( | 519 index = UpdateSectionHeaderRow( |
469 NetworkTypePattern::WiFi(), | 520 NetworkTypePattern::WiFi(), |
470 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, | 521 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, |
471 &wifi_header_view_, &wifi_separator_view_); | 522 &wifi_header_view_, &wifi_separator_view_); |
472 | 523 |
473 // "Wifi Enabled / Disabled". | 524 // "Wifi Enabled / Disabled". |
474 int message_id = 0; | 525 int message_id = 0; |
475 if (network_list_.empty()) { | 526 if (network_list_.empty()) { |
476 message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) | 527 message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 | 614 |
564 int NetworkListViewMd::UpdateSectionHeaderRow( | 615 int NetworkListViewMd::UpdateSectionHeaderRow( |
565 NetworkTypePattern pattern, | 616 NetworkTypePattern pattern, |
566 bool enabled, | 617 bool enabled, |
567 int child_index, | 618 int child_index, |
568 SectionHeaderRowView** view, | 619 SectionHeaderRowView** view, |
569 views::Separator** separator_view) { | 620 views::Separator** separator_view) { |
570 if (!*view) { | 621 if (!*view) { |
571 if (pattern.Equals(NetworkTypePattern::Cellular())) | 622 if (pattern.Equals(NetworkTypePattern::Cellular())) |
572 *view = new CellularHeaderRowView(); | 623 *view = new CellularHeaderRowView(); |
| 624 else if (pattern.Equals(NetworkTypePattern::Tether())) |
| 625 *view = new TetherHeaderRowView(); |
573 else if (pattern.Equals(NetworkTypePattern::WiFi())) | 626 else if (pattern.Equals(NetworkTypePattern::WiFi())) |
574 *view = new WifiHeaderRowView(delegate_); | 627 *view = new WifiHeaderRowView(delegate_); |
575 else | 628 else |
576 NOTREACHED(); | 629 NOTREACHED(); |
577 (*view)->Init(enabled); | 630 (*view)->Init(enabled); |
578 } | 631 } |
579 // Show or hide a separator above the header. The separator should only be | 632 // Show or hide a separator above the header. The separator should only be |
580 // visible when the header row is not at the top of the list. | 633 // visible when the header row is not at the top of the list. |
581 if (child_index > 0) { | 634 if (child_index > 0) { |
582 if (!*separator_view) | 635 if (!*separator_view) |
583 *separator_view = TrayPopupUtils::CreateListSubHeaderSeparator(); | 636 *separator_view = TrayPopupUtils::CreateListSubHeaderSeparator(); |
584 PlaceViewAtIndex(*separator_view, child_index++); | 637 PlaceViewAtIndex(*separator_view, child_index++); |
585 } else { | 638 } else { |
586 if (*separator_view) | 639 if (*separator_view) |
587 delete *separator_view; | 640 delete *separator_view; |
588 *separator_view = nullptr; | 641 *separator_view = nullptr; |
589 } | 642 } |
590 | 643 |
591 (*view)->SetEnabled(enabled); | 644 (*view)->SetEnabled(enabled); |
592 PlaceViewAtIndex(*view, child_index++); | 645 PlaceViewAtIndex(*view, child_index++); |
593 return child_index; | 646 return child_index; |
594 } | 647 } |
595 | 648 |
596 void NetworkListViewMd::NetworkIconChanged() { | 649 void NetworkListViewMd::NetworkIconChanged() { |
597 Update(); | 650 Update(); |
598 } | 651 } |
599 | 652 |
600 } // namespace ash | 653 } // namespace ash |
OLD | NEW |