| 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" | 20 #include "ash/common/system/tray/system_tray_controller.h" |
| 21 #include "ash/common/system/tray/tray_constants.h" | 21 #include "ash/common/system/tray/tray_constants.h" |
| 22 #include "ash/common/system/tray/tray_popup_label_button.h" | 22 #include "ash/common/system/tray/tray_popup_label_button.h" |
| 23 #include "ash/common/system/tray/tray_popup_utils.h" | 23 #include "ash/common/system/tray/tray_popup_utils.h" |
| 24 #include "ash/common/system/tray/tri_view.h" | 24 #include "ash/common/system/tray/tri_view.h" |
| 25 #include "ash/common/wm_shell.h" | 25 #include "ash/common/wm_shell.h" |
| 26 #include "ash/resources/vector_icons/vector_icons.h" | 26 #include "ash/resources/vector_icons/vector_icons.h" |
| 27 #include "base/bind.h" | 27 #include "base/bind.h" |
| 28 #include "base/bind_helpers.h" | 28 #include "base/bind_helpers.h" |
| 29 #include "base/logging.h" | 29 #include "base/logging.h" |
| 30 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 SetLayoutManager(layout); | 313 SetLayoutManager(layout); |
| 314 layout->SetDefaultFlex(0); | 314 layout->SetDefaultFlex(0); |
| 315 layout->SetFlexForView(text_label(), 1); | 315 layout->SetFlexForView(text_label(), 1); |
| 316 } | 316 } |
| 317 Layout(); | 317 Layout(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 } // namespace | 320 } // namespace |
| 321 | 321 |
| 322 VPNListView::VPNListView(NetworkListDelegate* delegate) : delegate_(delegate) { | 322 VPNListView::VPNListView(NetworkListDelegate* delegate) : delegate_(delegate) { |
| 323 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->AddObserver(this); | 323 WmShell::Get()->vpn_list()->AddObserver(this); |
| 324 } | 324 } |
| 325 | 325 |
| 326 VPNListView::~VPNListView() { | 326 VPNListView::~VPNListView() { |
| 327 // We need the check as on shell destruction, the delegate is destroyed first. | 327 WmShell::Get()->vpn_list()->RemoveObserver(this); |
| 328 SystemTrayDelegate* const system_tray_delegate = | |
| 329 WmShell::Get()->system_tray_delegate(); | |
| 330 if (system_tray_delegate) { | |
| 331 VPNDelegate* const vpn_delegate = system_tray_delegate->GetVPNDelegate(); | |
| 332 if (vpn_delegate) | |
| 333 vpn_delegate->RemoveObserver(this); | |
| 334 } | |
| 335 } | 328 } |
| 336 | 329 |
| 337 void VPNListView::Update() { | 330 void VPNListView::Update() { |
| 338 // Before updating the list, determine whether the user was hovering over one | 331 // Before updating the list, determine whether the user was hovering over one |
| 339 // of the VPN provider or network entries. | 332 // of the VPN provider or network entries. |
| 340 std::unique_ptr<VPNProvider> hovered_provider; | 333 std::unique_ptr<VPNProvider> hovered_provider; |
| 341 std::string hovered_network_service_path; | 334 std::string hovered_network_service_path; |
| 342 for (const std::pair<const views::View* const, VPNProvider>& provider : | 335 for (const std::pair<const views::View* const, VPNProvider>& provider : |
| 343 provider_view_map_) { | 336 provider_view_map_) { |
| 344 if (static_cast<const HoverHighlightView*>(provider.first)->hover()) { | 337 if (static_cast<const HoverHighlightView*>(provider.first)->hover()) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 void VPNListView::OnVPNProvidersChanged() { | 419 void VPNListView::OnVPNProvidersChanged() { |
| 427 Update(); | 420 Update(); |
| 428 } | 421 } |
| 429 | 422 |
| 430 void VPNListView::OnViewClicked(views::View* sender) { | 423 void VPNListView::OnViewClicked(views::View* sender) { |
| 431 const auto& provider_iter = provider_view_map_.find(sender); | 424 const auto& provider_iter = provider_view_map_.find(sender); |
| 432 if (provider_iter != provider_view_map_.end()) { | 425 if (provider_iter != provider_view_map_.end()) { |
| 433 // If the user clicks on a provider entry, request that the "add network" | 426 // If the user clicks on a provider entry, request that the "add network" |
| 434 // dialog for this provider be shown. | 427 // dialog for this provider be shown. |
| 435 const VPNProvider& provider = provider_iter->second; | 428 const VPNProvider& provider = provider_iter->second; |
| 436 WmShell::Get()->RecordUserMetricsAction( | 429 WmShell* shell = WmShell::Get(); |
| 437 provider.third_party ? UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED | 430 if (provider.third_party) { |
| 438 : UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED); | 431 shell->RecordUserMetricsAction( |
| 439 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->ShowAddPage( | 432 UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED); |
| 440 provider.extension_id); | 433 shell->system_tray_controller()->ShowThirdPartyVpnCreate( |
| 434 provider.extension_id); |
| 435 } else { |
| 436 shell->RecordUserMetricsAction(UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED); |
| 437 shell->system_tray_controller()->ShowNetworkCreate(shill::kTypeVPN); |
| 438 } |
| 441 return; | 439 return; |
| 442 } | 440 } |
| 443 | 441 |
| 444 // If the user clicked on a network entry, let the |delegate_| trigger a | 442 // If the user clicked on a network entry, let the |delegate_| trigger a |
| 445 // connection attempt (if the network is currently disconnected) or show a | 443 // connection attempt (if the network is currently disconnected) or show a |
| 446 // configuration dialog (if the network is currently connected or connecting). | 444 // configuration dialog (if the network is currently connected or connecting). |
| 447 delegate_->OnNetworkEntryClicked(sender); | 445 delegate_->OnNetworkEntryClicked(sender); |
| 448 } | 446 } |
| 449 | 447 |
| 450 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { | 448 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 for (const chromeos::NetworkState* const& network : networks) { | 484 for (const chromeos::NetworkState* const& network : networks) { |
| 487 if (VpnProviderMatchesNetwork(vpn_provider, *network)) | 485 if (VpnProviderMatchesNetwork(vpn_provider, *network)) |
| 488 AddNetwork(network); | 486 AddNetwork(network); |
| 489 } | 487 } |
| 490 } | 488 } |
| 491 | 489 |
| 492 void VPNListView::AddProvidersAndNetworks( | 490 void VPNListView::AddProvidersAndNetworks( |
| 493 const chromeos::NetworkStateHandler::NetworkStateList& networks) { | 491 const chromeos::NetworkStateHandler::NetworkStateList& networks) { |
| 494 // Get the list of VPN providers enabled in the primary user's profile. | 492 // Get the list of VPN providers enabled in the primary user's profile. |
| 495 std::vector<VPNProvider> providers = | 493 std::vector<VPNProvider> providers = |
| 496 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->vpn_providers(); | 494 WmShell::Get()->vpn_list()->vpn_providers(); |
| 497 | 495 |
| 498 // Add providers with at least one configured network along with their | 496 // Add providers with at least one configured network along with their |
| 499 // networks. Providers are added in the order of their highest priority | 497 // networks. Providers are added in the order of their highest priority |
| 500 // network. | 498 // network. |
| 501 for (const chromeos::NetworkState* const& network : networks) { | 499 for (const chromeos::NetworkState* const& network : networks) { |
| 502 for (auto provider = providers.begin(); provider != providers.end(); | 500 for (auto provider = providers.begin(); provider != providers.end(); |
| 503 ++provider) { | 501 ++provider) { |
| 504 if (!VpnProviderMatchesNetwork(*provider, *network)) | 502 if (!VpnProviderMatchesNetwork(*provider, *network)) |
| 505 continue; | 503 continue; |
| 506 AddProviderAndNetworks(*provider, networks); | 504 AddProviderAndNetworks(*provider, networks); |
| 507 providers.erase(provider); | 505 providers.erase(provider); |
| 508 break; | 506 break; |
| 509 } | 507 } |
| 510 } | 508 } |
| 511 | 509 |
| 512 // Add providers without any configured networks, in the order that the | 510 // Add providers without any configured networks, in the order that the |
| 513 // providers were returned by the extensions system. | 511 // providers were returned by the extensions system. |
| 514 for (const VPNProvider& provider : providers) | 512 for (const VPNProvider& provider : providers) |
| 515 AddProviderAndNetworks(provider, networks); | 513 AddProviderAndNetworks(provider, networks); |
| 516 } | 514 } |
| 517 | 515 |
| 518 } // namespace ash | 516 } // namespace ash |
| OLD | NEW |