| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/vpn_list_view.h" | 5 #include "ash/common/system/chromeos/network/vpn_list_view.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/common/ash_view_ids.h" | 11 #include "ash/common/ash_view_ids.h" |
| 12 #include "ash/common/material_design/material_design_controller.h" | 12 #include "ash/common/material_design/material_design_controller.h" |
| 13 #include "ash/common/system/chromeos/network/network_icon.h" | 13 #include "ash/common/system/chromeos/network/network_icon.h" |
| 14 #include "ash/common/system/chromeos/network/network_icon_animation.h" | 14 #include "ash/common/system/chromeos/network/network_icon_animation.h" |
| 15 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" | 15 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" |
| 16 #include "ash/common/system/chromeos/network/network_list_delegate.h" | 16 #include "ash/common/system/chromeos/network/network_list_delegate.h" |
| 17 #include "ash/common/system/chromeos/network/vpn_delegate.h" | 17 #include "ash/common/system/chromeos/network/vpn_list.h" |
| 18 #include "ash/common/system/tray/hover_highlight_view.h" | 18 #include "ash/common/system/tray/hover_highlight_view.h" |
| 19 #include "ash/common/system/tray/system_menu_button.h" | 19 #include "ash/common/system/tray/system_menu_button.h" |
| 20 #include "ash/common/system/tray/system_tray_delegate.h" | |
| 21 #include "ash/common/system/tray/tray_constants.h" | 20 #include "ash/common/system/tray/tray_constants.h" |
| 22 #include "ash/common/system/tray/tray_popup_label_button.h" | 21 #include "ash/common/system/tray/tray_popup_label_button.h" |
| 23 #include "ash/common/system/tray/tray_popup_utils.h" | 22 #include "ash/common/system/tray/tray_popup_utils.h" |
| 24 #include "ash/common/system/tray/tri_view.h" | 23 #include "ash/common/system/tray/tri_view.h" |
| 25 #include "ash/common/wm_shell.h" | 24 #include "ash/common/wm_shell.h" |
| 26 #include "ash/resources/vector_icons/vector_icons.h" | 25 #include "ash/resources/vector_icons/vector_icons.h" |
| 27 #include "base/bind.h" | 26 #include "base/bind.h" |
| 28 #include "base/bind_helpers.h" | 27 #include "base/bind_helpers.h" |
| 29 #include "base/logging.h" | 28 #include "base/logging.h" |
| 30 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 SetLayoutManager(layout); | 297 SetLayoutManager(layout); |
| 299 layout->SetDefaultFlex(0); | 298 layout->SetDefaultFlex(0); |
| 300 layout->SetFlexForView(text_label(), 1); | 299 layout->SetFlexForView(text_label(), 1); |
| 301 } | 300 } |
| 302 Layout(); | 301 Layout(); |
| 303 } | 302 } |
| 304 | 303 |
| 305 } // namespace | 304 } // namespace |
| 306 | 305 |
| 307 VPNListView::VPNListView(NetworkListDelegate* delegate) : delegate_(delegate) { | 306 VPNListView::VPNListView(NetworkListDelegate* delegate) : delegate_(delegate) { |
| 308 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->AddObserver(this); | 307 WmShell::Get()->vpn_list()->AddObserver(this); |
| 309 } | 308 } |
| 310 | 309 |
| 311 VPNListView::~VPNListView() { | 310 VPNListView::~VPNListView() { |
| 312 // We need the check as on shell destruction, the delegate is destroyed first. | 311 WmShell::Get()->vpn_list()->RemoveObserver(this); |
| 313 SystemTrayDelegate* const system_tray_delegate = | |
| 314 WmShell::Get()->system_tray_delegate(); | |
| 315 if (system_tray_delegate) { | |
| 316 VPNDelegate* const vpn_delegate = system_tray_delegate->GetVPNDelegate(); | |
| 317 if (vpn_delegate) | |
| 318 vpn_delegate->RemoveObserver(this); | |
| 319 } | |
| 320 } | 312 } |
| 321 | 313 |
| 322 void VPNListView::Update() { | 314 void VPNListView::Update() { |
| 323 // Before updating the list, determine whether the user was hovering over one | 315 // Before updating the list, determine whether the user was hovering over one |
| 324 // of the VPN provider or network entries. | 316 // of the VPN provider or network entries. |
| 325 std::unique_ptr<VPNProvider::Key> hovered_provider_key; | 317 std::unique_ptr<VPNProvider::Key> hovered_provider_key; |
| 326 std::string hovered_network_service_path; | 318 std::string hovered_network_service_path; |
| 327 for (const std::pair<const views::View* const, VPNProvider::Key>& provider : | 319 for (const std::pair<const views::View* const, VPNProvider::Key>& provider : |
| 328 provider_view_key_map_) { | 320 provider_view_key_map_) { |
| 329 if (static_cast<const HoverHighlightView*>(provider.first)->hover()) { | 321 if (static_cast<const HoverHighlightView*>(provider.first)->hover()) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 406 |
| 415 void VPNListView::OnViewClicked(views::View* sender) { | 407 void VPNListView::OnViewClicked(views::View* sender) { |
| 416 const auto& provider = provider_view_key_map_.find(sender); | 408 const auto& provider = provider_view_key_map_.find(sender); |
| 417 if (provider != provider_view_key_map_.end()) { | 409 if (provider != provider_view_key_map_.end()) { |
| 418 // If the user clicks on a provider entry, request that the "add network" | 410 // If the user clicks on a provider entry, request that the "add network" |
| 419 // dialog for this provider be shown. | 411 // dialog for this provider be shown. |
| 420 const VPNProvider::Key& key = provider->second; | 412 const VPNProvider::Key& key = provider->second; |
| 421 WmShell::Get()->RecordUserMetricsAction( | 413 WmShell::Get()->RecordUserMetricsAction( |
| 422 key.third_party ? UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED | 414 key.third_party ? UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED |
| 423 : UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED); | 415 : UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED); |
| 424 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->ShowAddPage(key); | 416 WmShell::Get()->vpn_list()->ShowAddPage(key); |
| 425 return; | 417 return; |
| 426 } | 418 } |
| 427 | 419 |
| 428 // If the user clicked on a network entry, let the |delegate_| trigger a | 420 // If the user clicked on a network entry, let the |delegate_| trigger a |
| 429 // connection attempt (if the network is currently disconnected) or show a | 421 // connection attempt (if the network is currently disconnected) or show a |
| 430 // configuration dialog (if the network is currently connected or connecting). | 422 // configuration dialog (if the network is currently connected or connecting). |
| 431 delegate_->OnNetworkEntryClicked(sender); | 423 delegate_->OnNetworkEntryClicked(sender); |
| 432 } | 424 } |
| 433 | 425 |
| 434 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { | 426 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 for (const chromeos::NetworkState* const& network : networks) { | 458 for (const chromeos::NetworkState* const& network : networks) { |
| 467 if (key.MatchesNetwork(*network)) | 459 if (key.MatchesNetwork(*network)) |
| 468 AddNetwork(network); | 460 AddNetwork(network); |
| 469 } | 461 } |
| 470 } | 462 } |
| 471 | 463 |
| 472 void VPNListView::AddProvidersAndNetworks( | 464 void VPNListView::AddProvidersAndNetworks( |
| 473 const chromeos::NetworkStateHandler::NetworkStateList& networks) { | 465 const chromeos::NetworkStateHandler::NetworkStateList& networks) { |
| 474 // Get the list of VPN providers enabled in the primary user's profile. | 466 // Get the list of VPN providers enabled in the primary user's profile. |
| 475 std::vector<VPNProvider> providers = | 467 std::vector<VPNProvider> providers = |
| 476 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->vpn_providers(); | 468 WmShell::Get()->vpn_list()->vpn_providers(); |
| 477 | 469 |
| 478 // Add providers with at least one configured network along with their | 470 // Add providers with at least one configured network along with their |
| 479 // networks. Providers are added in the order of their highest priority | 471 // networks. Providers are added in the order of their highest priority |
| 480 // network. | 472 // network. |
| 481 for (const chromeos::NetworkState* const& network : networks) { | 473 for (const chromeos::NetworkState* const& network : networks) { |
| 482 for (auto provider = providers.begin(); provider != providers.end(); | 474 for (auto provider = providers.begin(); provider != providers.end(); |
| 483 ++provider) { | 475 ++provider) { |
| 484 if (!provider->key.MatchesNetwork(*network)) | 476 if (!provider->key.MatchesNetwork(*network)) |
| 485 continue; | 477 continue; |
| 486 AddProviderAndNetworks(provider->key, provider->name, networks); | 478 AddProviderAndNetworks(provider->key, provider->name, networks); |
| 487 providers.erase(provider); | 479 providers.erase(provider); |
| 488 break; | 480 break; |
| 489 } | 481 } |
| 490 } | 482 } |
| 491 | 483 |
| 492 // Add providers without any configured networks, in the order that the | 484 // Add providers without any configured networks, in the order that the |
| 493 // providers were returned by the extensions system. | 485 // providers were returned by the extensions system. |
| 494 for (const VPNProvider& provider : providers) | 486 for (const VPNProvider& provider : providers) |
| 495 AddProviderAndNetworks(provider.key, provider.name, networks); | 487 AddProviderAndNetworks(provider.key, provider.name, networks); |
| 496 } | 488 } |
| 497 | 489 |
| 498 } // namespace ash | 490 } // namespace ash |
| OLD | NEW |