Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: ash/common/system/chromeos/network/vpn_list_view.cc

Issue 2522613004: Revert of chromeos: Convert ash VPNDelegate interface to mojo (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_list.h" 17 #include "ash/common/system/chromeos/network/vpn_delegate.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_controller.h" 20 #include "ash/common/system/tray/system_tray_delegate.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
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()->vpn_list()->AddObserver(this); 323 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->AddObserver(this);
324 } 324 }
325 325
326 VPNListView::~VPNListView() { 326 VPNListView::~VPNListView() {
327 WmShell::Get()->vpn_list()->RemoveObserver(this); 327 // We need the check as on shell destruction, the delegate is destroyed first.
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 }
328 } 335 }
329 336
330 void VPNListView::Update() { 337 void VPNListView::Update() {
331 // Before updating the list, determine whether the user was hovering over one 338 // Before updating the list, determine whether the user was hovering over one
332 // of the VPN provider or network entries. 339 // of the VPN provider or network entries.
333 std::unique_ptr<VPNProvider> hovered_provider; 340 std::unique_ptr<VPNProvider> hovered_provider;
334 std::string hovered_network_service_path; 341 std::string hovered_network_service_path;
335 for (const std::pair<const views::View* const, VPNProvider>& provider : 342 for (const std::pair<const views::View* const, VPNProvider>& provider :
336 provider_view_map_) { 343 provider_view_map_) {
337 if (static_cast<const HoverHighlightView*>(provider.first)->hover()) { 344 if (static_cast<const HoverHighlightView*>(provider.first)->hover()) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 void VPNListView::OnVPNProvidersChanged() { 426 void VPNListView::OnVPNProvidersChanged() {
420 Update(); 427 Update();
421 } 428 }
422 429
423 void VPNListView::OnViewClicked(views::View* sender) { 430 void VPNListView::OnViewClicked(views::View* sender) {
424 const auto& provider_iter = provider_view_map_.find(sender); 431 const auto& provider_iter = provider_view_map_.find(sender);
425 if (provider_iter != provider_view_map_.end()) { 432 if (provider_iter != provider_view_map_.end()) {
426 // If the user clicks on a provider entry, request that the "add network" 433 // If the user clicks on a provider entry, request that the "add network"
427 // dialog for this provider be shown. 434 // dialog for this provider be shown.
428 const VPNProvider& provider = provider_iter->second; 435 const VPNProvider& provider = provider_iter->second;
429 WmShell* shell = WmShell::Get(); 436 WmShell::Get()->RecordUserMetricsAction(
430 if (provider.third_party) { 437 provider.third_party ? UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED
431 shell->RecordUserMetricsAction( 438 : UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED);
432 UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED); 439 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->ShowAddPage(
433 shell->system_tray_controller()->ShowThirdPartyVpnCreate( 440 provider.extension_id);
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 }
439 return; 441 return;
440 } 442 }
441 443
442 // If the user clicked on a network entry, let the |delegate_| trigger a 444 // If the user clicked on a network entry, let the |delegate_| trigger a
443 // connection attempt (if the network is currently disconnected) or show a 445 // connection attempt (if the network is currently disconnected) or show a
444 // configuration dialog (if the network is currently connected or connecting). 446 // configuration dialog (if the network is currently connected or connecting).
445 delegate_->OnNetworkEntryClicked(sender); 447 delegate_->OnNetworkEntryClicked(sender);
446 } 448 }
447 449
448 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { 450 void VPNListView::AddNetwork(const chromeos::NetworkState* network) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 for (const chromeos::NetworkState* const& network : networks) { 486 for (const chromeos::NetworkState* const& network : networks) {
485 if (VpnProviderMatchesNetwork(vpn_provider, *network)) 487 if (VpnProviderMatchesNetwork(vpn_provider, *network))
486 AddNetwork(network); 488 AddNetwork(network);
487 } 489 }
488 } 490 }
489 491
490 void VPNListView::AddProvidersAndNetworks( 492 void VPNListView::AddProvidersAndNetworks(
491 const chromeos::NetworkStateHandler::NetworkStateList& networks) { 493 const chromeos::NetworkStateHandler::NetworkStateList& networks) {
492 // Get the list of VPN providers enabled in the primary user's profile. 494 // Get the list of VPN providers enabled in the primary user's profile.
493 std::vector<VPNProvider> providers = 495 std::vector<VPNProvider> providers =
494 WmShell::Get()->vpn_list()->vpn_providers(); 496 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->vpn_providers();
495 497
496 // Add providers with at least one configured network along with their 498 // Add providers with at least one configured network along with their
497 // networks. Providers are added in the order of their highest priority 499 // networks. Providers are added in the order of their highest priority
498 // network. 500 // network.
499 for (const chromeos::NetworkState* const& network : networks) { 501 for (const chromeos::NetworkState* const& network : networks) {
500 for (auto provider = providers.begin(); provider != providers.end(); 502 for (auto provider = providers.begin(); provider != providers.end();
501 ++provider) { 503 ++provider) {
502 if (!VpnProviderMatchesNetwork(*provider, *network)) 504 if (!VpnProviderMatchesNetwork(*provider, *network))
503 continue; 505 continue;
504 AddProviderAndNetworks(*provider, networks); 506 AddProviderAndNetworks(*provider, networks);
505 providers.erase(provider); 507 providers.erase(provider);
506 break; 508 break;
507 } 509 }
508 } 510 }
509 511
510 // Add providers without any configured networks, in the order that the 512 // Add providers without any configured networks, in the order that the
511 // providers were returned by the extensions system. 513 // providers were returned by the extensions system.
512 for (const VPNProvider& provider : providers) 514 for (const VPNProvider& provider : providers)
513 AddProviderAndNetworks(provider, networks); 515 AddProviderAndNetworks(provider, networks);
514 } 516 }
515 517
516 } // namespace ash 518 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/network/vpn_list_view.h ('k') | ash/common/system/tray/system_tray_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698