| 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 NetworkStateHandler::NetworkStateList network_list; | 278 NetworkStateHandler::NetworkStateList network_list; |
| 279 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 279 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 280 handler->GetVisibleNetworkList(&network_list); | 280 handler->GetVisibleNetworkList(&network_list); |
| 281 UpdateNetworks(network_list); | 281 UpdateNetworks(network_list); |
| 282 UpdateNetworkIcons(); | 282 UpdateNetworkIcons(); |
| 283 OrderNetworks(); | 283 OrderNetworks(); |
| 284 UpdateNetworkListInternal(); | 284 UpdateNetworkListInternal(); |
| 285 } | 285 } |
| 286 | 286 |
| 287 bool NetworkListViewMd::IsNetworkEntry(views::View* view, | 287 bool NetworkListViewMd::IsNetworkEntry(views::View* view, |
| 288 std::string* service_path) const { | 288 std::string* guid) const { |
| 289 std::map<views::View*, std::string>::const_iterator found = | 289 std::map<views::View*, std::string>::const_iterator found = |
| 290 network_map_.find(view); | 290 network_map_.find(view); |
| 291 if (found == network_map_.end()) | 291 if (found == network_map_.end()) |
| 292 return false; | 292 return false; |
| 293 *service_path = found->second; | 293 *guid = found->second; |
| 294 return true; | 294 return true; |
| 295 } | 295 } |
| 296 | 296 |
| 297 void NetworkListViewMd::UpdateNetworks( | 297 void NetworkListViewMd::UpdateNetworks( |
| 298 const NetworkStateHandler::NetworkStateList& networks) { | 298 const NetworkStateHandler::NetworkStateList& networks) { |
| 299 SCOPED_NET_LOG_IF_SLOW(); | 299 SCOPED_NET_LOG_IF_SLOW(); |
| 300 network_list_.clear(); | 300 network_list_.clear(); |
| 301 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); | 301 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); |
| 302 for (const auto& network : networks) { | 302 for (const auto& network : networks) { |
| 303 if (pattern.MatchesType(network->type())) | 303 if (pattern.MatchesType(network->type())) |
| 304 network_list_.push_back(base::MakeUnique<NetworkInfo>(network->path())); | 304 network_list_.push_back(base::MakeUnique<NetworkInfo>(network->guid())); |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 | 307 |
| 308 void NetworkListViewMd::OrderNetworks() { | 308 void NetworkListViewMd::OrderNetworks() { |
| 309 struct CompareNetwork { | 309 struct CompareNetwork { |
| 310 explicit CompareNetwork(NetworkStateHandler* handler) : handler_(handler) {} | 310 explicit CompareNetwork(NetworkStateHandler* handler) : handler_(handler) {} |
| 311 | 311 |
| 312 // Returns true if |network1| is less than (i.e. is ordered before) | 312 // Returns true if |network1| is less than (i.e. is ordered before) |
| 313 // |network2|. | 313 // |network2|. |
| 314 bool operator()(const std::unique_ptr<NetworkInfo>& network1, | 314 bool operator()(const std::unique_ptr<NetworkInfo>& network1, |
| 315 const std::unique_ptr<NetworkInfo>& network2) { | 315 const std::unique_ptr<NetworkInfo>& network2) { |
| 316 const int order1 = | 316 const int order1 = |
| 317 GetOrder(handler_->GetNetworkState(network1->service_path)); | 317 GetOrder(handler_->GetNetworkStateFromGuid(network1->guid)); |
| 318 const int order2 = | 318 const int order2 = |
| 319 GetOrder(handler_->GetNetworkState(network2->service_path)); | 319 GetOrder(handler_->GetNetworkStateFromGuid(network2->guid)); |
| 320 if (order1 != order2) | 320 if (order1 != order2) |
| 321 return order1 < order2; | 321 return order1 < order2; |
| 322 if (network1->connected != network2->connected) | 322 if (network1->connected != network2->connected) |
| 323 return network1->connected; | 323 return network1->connected; |
| 324 if (network1->connecting != network2->connecting) | 324 if (network1->connecting != network2->connecting) |
| 325 return network1->connecting; | 325 return network1->connecting; |
| 326 if (network1->highlight != network2->highlight) | 326 if (network1->highlight != network2->highlight) |
| 327 return network1->highlight; | 327 return network1->highlight; |
| 328 return network1->service_path.compare(network2->service_path) < 0; | 328 return network1->guid.compare(network2->guid) < 0; |
| 329 } | 329 } |
| 330 | 330 |
| 331 private: | 331 private: |
| 332 static int GetOrder(const chromeos::NetworkState* network) { | 332 static int GetOrder(const chromeos::NetworkState* network) { |
| 333 if (!network) | 333 if (!network) |
| 334 return 999; | 334 return 999; |
| 335 if (network->Matches(NetworkTypePattern::Ethernet())) | 335 if (network->Matches(NetworkTypePattern::Ethernet())) |
| 336 return 0; | 336 return 0; |
| 337 if (network->Matches(NetworkTypePattern::Cellular())) | 337 if (network->Matches(NetworkTypePattern::Cellular())) |
| 338 return 1; | 338 return 1; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 351 | 351 |
| 352 void NetworkListViewMd::UpdateNetworkIcons() { | 352 void NetworkListViewMd::UpdateNetworkIcons() { |
| 353 SCOPED_NET_LOG_IF_SLOW(); | 353 SCOPED_NET_LOG_IF_SLOW(); |
| 354 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 354 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 355 | 355 |
| 356 // First, update state for all networks. | 356 // First, update state for all networks. |
| 357 bool animating = false; | 357 bool animating = false; |
| 358 | 358 |
| 359 for (auto& info : network_list_) { | 359 for (auto& info : network_list_) { |
| 360 const chromeos::NetworkState* network = | 360 const chromeos::NetworkState* network = |
| 361 handler->GetNetworkState(info->service_path); | 361 handler->GetNetworkStateFromGuid(info->guid); |
| 362 if (!network) | 362 if (!network) |
| 363 continue; | 363 continue; |
| 364 bool prohibited_by_policy = IsProhibitedByPolicy(network); | 364 bool prohibited_by_policy = IsProhibitedByPolicy(network); |
| 365 info->label = network_icon::GetLabelForNetwork( | 365 info->label = network_icon::GetLabelForNetwork( |
| 366 network, network_icon::ICON_TYPE_MENU_LIST); | 366 network, network_icon::ICON_TYPE_MENU_LIST); |
| 367 info->image = | 367 info->image = |
| 368 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); | 368 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); |
| 369 info->disable = | 369 info->disable = |
| 370 (network->activation_state() == shill::kActivationStateActivating) || | 370 (network->activation_state() == shill::kActivationStateActivating) || |
| 371 prohibited_by_policy; | 371 prohibited_by_policy; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 387 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 387 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 388 else | 388 else |
| 389 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 389 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 390 } | 390 } |
| 391 | 391 |
| 392 void NetworkListViewMd::UpdateNetworkListInternal() { | 392 void NetworkListViewMd::UpdateNetworkListInternal() { |
| 393 SCOPED_NET_LOG_IF_SLOW(); | 393 SCOPED_NET_LOG_IF_SLOW(); |
| 394 // Get the updated list entries. | 394 // Get the updated list entries. |
| 395 needs_relayout_ = false; | 395 needs_relayout_ = false; |
| 396 network_map_.clear(); | 396 network_map_.clear(); |
| 397 std::unique_ptr<std::set<std::string>> new_service_paths = | 397 std::unique_ptr<std::set<std::string>> new_guids = UpdateNetworkListEntries(); |
| 398 UpdateNetworkListEntries(); | |
| 399 | 398 |
| 400 // Remove old children. | 399 // Remove old children. |
| 401 std::set<std::string> remove_service_paths; | 400 std::set<std::string> remove_guids; |
| 402 for (const auto& iter : service_path_map_) { | 401 for (const auto& iter : network_guid_map_) { |
| 403 if (new_service_paths->find(iter.first) == new_service_paths->end()) { | 402 if (new_guids->find(iter.first) == new_guids->end()) { |
| 404 remove_service_paths.insert(iter.first); | 403 remove_guids.insert(iter.first); |
| 405 network_map_.erase(iter.second); | 404 network_map_.erase(iter.second); |
| 406 delete iter.second; | 405 delete iter.second; |
| 407 needs_relayout_ = true; | 406 needs_relayout_ = true; |
| 408 } | 407 } |
| 409 } | 408 } |
| 410 | 409 |
| 411 for (const auto& remove_iter : remove_service_paths) | 410 for (const auto& remove_iter : remove_guids) |
| 412 service_path_map_.erase(remove_iter); | 411 network_guid_map_.erase(remove_iter); |
| 413 | 412 |
| 414 if (!needs_relayout_) | 413 if (!needs_relayout_) |
| 415 return; | 414 return; |
| 416 | 415 |
| 417 views::View* selected_view = nullptr; | 416 views::View* selected_view = nullptr; |
| 418 for (const auto& iter : service_path_map_) { | 417 for (const auto& iter : network_guid_map_) { |
| 419 if (delegate_->IsViewHovered(iter.second)) { | 418 if (delegate_->IsViewHovered(iter.second)) { |
| 420 selected_view = iter.second; | 419 selected_view = iter.second; |
| 421 break; | 420 break; |
| 422 } | 421 } |
| 423 } | 422 } |
| 424 container()->SizeToPreferredSize(); | 423 container()->SizeToPreferredSize(); |
| 425 delegate_->RelayoutScrollList(); | 424 delegate_->RelayoutScrollList(); |
| 426 if (selected_view) | 425 if (selected_view) |
| 427 container()->ScrollRectToVisible(selected_view->bounds()); | 426 container()->ScrollRectToVisible(selected_view->bounds()); |
| 428 } | 427 } |
| 429 | 428 |
| 430 std::unique_ptr<std::set<std::string>> | 429 std::unique_ptr<std::set<std::string>> |
| 431 NetworkListViewMd::UpdateNetworkListEntries() { | 430 NetworkListViewMd::UpdateNetworkListEntries() { |
| 432 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 431 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 433 | 432 |
| 434 // First add high-priority networks (not Wi-Fi nor cellular). | 433 // First add high-priority networks (not Wi-Fi nor cellular). |
| 435 std::unique_ptr<std::set<std::string>> new_service_paths = | 434 std::unique_ptr<std::set<std::string>> new_guids = |
| 436 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, 0); | 435 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, 0); |
| 437 | 436 |
| 438 // Keep an index where the next child should be inserted. | 437 // Keep an index where the next child should be inserted. |
| 439 int index = new_service_paths->size(); | 438 int index = new_guids->size(); |
| 440 | 439 |
| 441 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); | 440 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); |
| 442 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) { | 441 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) { |
| 443 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { | 442 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { |
| 444 index = UpdateSectionHeaderRow( | 443 index = UpdateSectionHeaderRow( |
| 445 NetworkTypePattern::Cellular(), | 444 NetworkTypePattern::Cellular(), |
| 446 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, | 445 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, |
| 447 &cellular_header_view_, &cellular_separator_view_); | 446 &cellular_header_view_, &cellular_separator_view_); |
| 448 } | 447 } |
| 449 | 448 |
| 450 // Cellular initializing. | 449 // Cellular initializing. |
| 451 int message_id = network_icon::GetCellularUninitializedMsg(); | 450 int message_id = network_icon::GetCellularUninitializedMsg(); |
| 452 if (!message_id && | 451 if (!message_id && |
| 453 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && | 452 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && |
| 454 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { | 453 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { |
| 455 message_id = IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS; | 454 message_id = IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS; |
| 456 } | 455 } |
| 457 UpdateInfoLabel(message_id, index, &no_cellular_networks_view_); | 456 UpdateInfoLabel(message_id, index, &no_cellular_networks_view_); |
| 458 if (message_id) | 457 if (message_id) |
| 459 ++index; | 458 ++index; |
| 460 | 459 |
| 461 // Add cellular networks. | 460 // Add cellular networks. |
| 462 std::unique_ptr<std::set<std::string>> new_cellular_service_paths = | 461 std::unique_ptr<std::set<std::string>> new_cellular_guids = |
| 463 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); | 462 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); |
| 464 index += new_cellular_service_paths->size(); | 463 index += new_cellular_guids->size(); |
| 465 new_service_paths->insert(new_cellular_service_paths->begin(), | 464 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); |
| 466 new_cellular_service_paths->end()); | |
| 467 } | 465 } |
| 468 | 466 |
| 469 if (pattern.MatchesPattern(NetworkTypePattern::WiFi())) { | 467 if (pattern.MatchesPattern(NetworkTypePattern::WiFi())) { |
| 470 index = UpdateSectionHeaderRow( | 468 index = UpdateSectionHeaderRow( |
| 471 NetworkTypePattern::WiFi(), | 469 NetworkTypePattern::WiFi(), |
| 472 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, | 470 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, |
| 473 &wifi_header_view_, &wifi_separator_view_); | 471 &wifi_header_view_, &wifi_separator_view_); |
| 474 | 472 |
| 475 // "Wifi Enabled / Disabled". | 473 // "Wifi Enabled / Disabled". |
| 476 int message_id = 0; | 474 int message_id = 0; |
| 477 if (network_list_.empty()) { | 475 if (network_list_.empty()) { |
| 478 message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) | 476 message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) |
| 479 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED | 477 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED |
| 480 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; | 478 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; |
| 481 } | 479 } |
| 482 UpdateInfoLabel(message_id, index, &no_wifi_networks_view_); | 480 UpdateInfoLabel(message_id, index, &no_wifi_networks_view_); |
| 483 if (message_id) | 481 if (message_id) |
| 484 ++index; | 482 ++index; |
| 485 | 483 |
| 486 // Add Wi-Fi networks. | 484 // Add Wi-Fi networks. |
| 487 std::unique_ptr<std::set<std::string>> new_wifi_service_paths = | 485 std::unique_ptr<std::set<std::string>> new_wifi_guids = |
| 488 UpdateNetworkChildren(NetworkInfo::Type::WIFI, index); | 486 UpdateNetworkChildren(NetworkInfo::Type::WIFI, index); |
| 489 index += new_wifi_service_paths->size(); | 487 index += new_wifi_guids->size(); |
| 490 new_service_paths->insert(new_wifi_service_paths->begin(), | 488 new_guids->insert(new_wifi_guids->begin(), new_wifi_guids->end()); |
| 491 new_wifi_service_paths->end()); | |
| 492 } | 489 } |
| 493 | 490 |
| 494 // No networks or other messages (fallback). | 491 // No networks or other messages (fallback). |
| 495 if (index == 0) { | 492 if (index == 0) { |
| 496 UpdateInfoLabel(IDS_ASH_STATUS_TRAY_NO_NETWORKS, index, | 493 UpdateInfoLabel(IDS_ASH_STATUS_TRAY_NO_NETWORKS, index, |
| 497 &no_wifi_networks_view_); | 494 &no_wifi_networks_view_); |
| 498 } | 495 } |
| 499 | 496 |
| 500 return new_service_paths; | 497 return new_guids; |
| 501 } | 498 } |
| 502 | 499 |
| 503 std::unique_ptr<std::set<std::string>> NetworkListViewMd::UpdateNetworkChildren( | 500 std::unique_ptr<std::set<std::string>> NetworkListViewMd::UpdateNetworkChildren( |
| 504 NetworkInfo::Type type, | 501 NetworkInfo::Type type, |
| 505 int index) { | 502 int index) { |
| 506 std::unique_ptr<std::set<std::string>> new_service_paths( | 503 std::unique_ptr<std::set<std::string>> new_guids(new std::set<std::string>); |
| 507 new std::set<std::string>); | |
| 508 for (const auto& info : network_list_) { | 504 for (const auto& info : network_list_) { |
| 509 if (info->type != type) | 505 if (info->type != type) |
| 510 continue; | 506 continue; |
| 511 UpdateNetworkChild(index++, info.get()); | 507 UpdateNetworkChild(index++, info.get()); |
| 512 new_service_paths->insert(info->service_path); | 508 new_guids->insert(info->guid); |
| 513 } | 509 } |
| 514 return new_service_paths; | 510 return new_guids; |
| 515 } | 511 } |
| 516 | 512 |
| 517 void NetworkListViewMd::UpdateNetworkChild(int index, const NetworkInfo* info) { | 513 void NetworkListViewMd::UpdateNetworkChild(int index, const NetworkInfo* info) { |
| 518 views::View* network_view = nullptr; | 514 views::View* network_view = nullptr; |
| 519 ServicePathMap::const_iterator found = | 515 NetworkGuidMap::const_iterator found = network_guid_map_.find(info->guid); |
| 520 service_path_map_.find(info->service_path); | 516 if (found == network_guid_map_.end()) { |
| 521 if (found == service_path_map_.end()) { | |
| 522 network_view = delegate_->CreateViewForNetwork(*info); | 517 network_view = delegate_->CreateViewForNetwork(*info); |
| 523 } else { | 518 } else { |
| 524 network_view = found->second; | 519 network_view = found->second; |
| 525 network_view->RemoveAllChildViews(true); | 520 network_view->RemoveAllChildViews(true); |
| 526 delegate_->UpdateViewForNetwork(network_view, *info); | 521 delegate_->UpdateViewForNetwork(network_view, *info); |
| 527 network_view->Layout(); | 522 network_view->Layout(); |
| 528 network_view->SchedulePaint(); | 523 network_view->SchedulePaint(); |
| 529 } | 524 } |
| 530 PlaceViewAtIndex(network_view, index); | 525 PlaceViewAtIndex(network_view, index); |
| 531 if (info->disable) | 526 if (info->disable) |
| 532 network_view->SetEnabled(false); | 527 network_view->SetEnabled(false); |
| 533 network_map_[network_view] = info->service_path; | 528 network_map_[network_view] = info->guid; |
| 534 service_path_map_[info->service_path] = network_view; | 529 network_guid_map_[info->guid] = network_view; |
| 535 } | 530 } |
| 536 | 531 |
| 537 void NetworkListViewMd::PlaceViewAtIndex(views::View* view, int index) { | 532 void NetworkListViewMd::PlaceViewAtIndex(views::View* view, int index) { |
| 538 if (view->parent() != container()) { | 533 if (view->parent() != container()) { |
| 539 container()->AddChildViewAt(view, index); | 534 container()->AddChildViewAt(view, index); |
| 540 } else { | 535 } else { |
| 541 if (container()->child_at(index) == view) | 536 if (container()->child_at(index) == view) |
| 542 return; | 537 return; |
| 543 container()->ReorderChildView(view, index); | 538 container()->ReorderChildView(view, index); |
| 544 } | 539 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 (*view)->SetEnabled(enabled); | 591 (*view)->SetEnabled(enabled); |
| 597 PlaceViewAtIndex(*view, child_index++); | 592 PlaceViewAtIndex(*view, child_index++); |
| 598 return child_index; | 593 return child_index; |
| 599 } | 594 } |
| 600 | 595 |
| 601 void NetworkListViewMd::NetworkIconChanged() { | 596 void NetworkListViewMd::NetworkIconChanged() { |
| 602 Update(); | 597 Update(); |
| 603 } | 598 } |
| 604 | 599 |
| 605 } // namespace ash | 600 } // namespace ash |
| OLD | NEW |