| 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/system/chromeos/network/vpn_list_view.h" | 5 #include "ash/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/system/tray/system_tray_delegate.h" | 11 #include "ash/common/system/tray/system_tray_delegate.h" |
| 12 #include "ash/common/system/tray/tray_constants.h" | 12 #include "ash/common/system/tray/tray_constants.h" |
| 13 #include "ash/common/wm_shell.h" |
| 13 #include "ash/metrics/user_metrics_recorder.h" | 14 #include "ash/metrics/user_metrics_recorder.h" |
| 14 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 15 #include "ash/system/chromeos/network/vpn_delegate.h" | 16 #include "ash/system/chromeos/network/vpn_delegate.h" |
| 16 #include "ash/system/tray/hover_highlight_view.h" | 17 #include "ash/system/tray/hover_highlight_view.h" |
| 17 #include "ash/system/tray/tray_popup_label_button.h" | 18 #include "ash/system/tray/tray_popup_label_button.h" |
| 18 #include "base/bind.h" | 19 #include "base/bind.h" |
| 19 #include "base/bind_helpers.h" | 20 #include "base/bind_helpers.h" |
| 20 #include "base/logging.h" | 21 #include "base/logging.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/values.h" | 23 #include "base/values.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 SetLayoutManager(layout); | 227 SetLayoutManager(layout); |
| 227 layout->SetDefaultFlex(0); | 228 layout->SetDefaultFlex(0); |
| 228 layout->SetFlexForView(text_label(), 1); | 229 layout->SetFlexForView(text_label(), 1); |
| 229 Layout(); | 230 Layout(); |
| 230 } | 231 } |
| 231 | 232 |
| 232 } // namespace | 233 } // namespace |
| 233 | 234 |
| 234 VPNListView::VPNListView(ui::NetworkListDelegate* delegate) | 235 VPNListView::VPNListView(ui::NetworkListDelegate* delegate) |
| 235 : delegate_(delegate) { | 236 : delegate_(delegate) { |
| 236 Shell::GetInstance()->system_tray_delegate()->GetVPNDelegate()->AddObserver( | 237 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->AddObserver(this); |
| 237 this); | |
| 238 } | 238 } |
| 239 | 239 |
| 240 VPNListView::~VPNListView() { | 240 VPNListView::~VPNListView() { |
| 241 // We need the check as on shell destruction, the delegate is destroyed first. | 241 // We need the check as on shell destruction, the delegate is destroyed first. |
| 242 SystemTrayDelegate* const system_tray_delegate = | 242 SystemTrayDelegate* const system_tray_delegate = |
| 243 Shell::GetInstance()->system_tray_delegate(); | 243 WmShell::Get()->system_tray_delegate(); |
| 244 if (system_tray_delegate) { | 244 if (system_tray_delegate) { |
| 245 VPNDelegate* const vpn_delegate = system_tray_delegate->GetVPNDelegate(); | 245 VPNDelegate* const vpn_delegate = system_tray_delegate->GetVPNDelegate(); |
| 246 if (vpn_delegate) | 246 if (vpn_delegate) |
| 247 vpn_delegate->RemoveObserver(this); | 247 vpn_delegate->RemoveObserver(this); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 void VPNListView::Update() { | 251 void VPNListView::Update() { |
| 252 // Before updating the list, determine whether the user was hovering over one | 252 // Before updating the list, determine whether the user was hovering over one |
| 253 // of the VPN provider or network entries. | 253 // of the VPN provider or network entries. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 void VPNListView::OnVPNProvidersChanged() { | 338 void VPNListView::OnVPNProvidersChanged() { |
| 339 Update(); | 339 Update(); |
| 340 } | 340 } |
| 341 | 341 |
| 342 void VPNListView::OnViewClicked(views::View* sender) { | 342 void VPNListView::OnViewClicked(views::View* sender) { |
| 343 const auto& provider = provider_view_key_map_.find(sender); | 343 const auto& provider = provider_view_key_map_.find(sender); |
| 344 if (provider != provider_view_key_map_.end()) { | 344 if (provider != provider_view_key_map_.end()) { |
| 345 // If the user clicks on a provider entry, request that the "add network" | 345 // If the user clicks on a provider entry, request that the "add network" |
| 346 // dialog for this provider be shown. | 346 // dialog for this provider be shown. |
| 347 const VPNProvider::Key& key = provider->second; | 347 const VPNProvider::Key& key = provider->second; |
| 348 Shell* shell = Shell::GetInstance(); | 348 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 349 shell->metrics()->RecordUserMetricsAction( | |
| 350 key.third_party ? UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED | 349 key.third_party ? UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED |
| 351 : UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED); | 350 : UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED); |
| 352 shell->system_tray_delegate()->GetVPNDelegate()->ShowAddPage(key); | 351 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->ShowAddPage(key); |
| 353 return; | 352 return; |
| 354 } | 353 } |
| 355 | 354 |
| 356 // If the user clicked on a network entry, let the |delegate_| trigger a | 355 // If the user clicked on a network entry, let the |delegate_| trigger a |
| 357 // connection attempt (if the network is currently disconnected) or show a | 356 // connection attempt (if the network is currently disconnected) or show a |
| 358 // configuration dialog (if the network is currently connected or connecting). | 357 // configuration dialog (if the network is currently connected or connecting). |
| 359 delegate_->OnViewClicked(sender); | 358 delegate_->OnViewClicked(sender); |
| 360 } | 359 } |
| 361 | 360 |
| 362 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { | 361 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 387 // by shill. | 386 // by shill. |
| 388 for (const chromeos::NetworkState* const& network : networks) { | 387 for (const chromeos::NetworkState* const& network : networks) { |
| 389 if (key.MatchesNetwork(*network)) | 388 if (key.MatchesNetwork(*network)) |
| 390 AddNetwork(network); | 389 AddNetwork(network); |
| 391 } | 390 } |
| 392 } | 391 } |
| 393 | 392 |
| 394 void VPNListView::AddProvidersAndNetworks( | 393 void VPNListView::AddProvidersAndNetworks( |
| 395 const chromeos::NetworkStateHandler::NetworkStateList& networks) { | 394 const chromeos::NetworkStateHandler::NetworkStateList& networks) { |
| 396 // Get the list of VPN providers enabled in the primary user's profile. | 395 // Get the list of VPN providers enabled in the primary user's profile. |
| 397 std::vector<VPNProvider> providers = Shell::GetInstance() | 396 std::vector<VPNProvider> providers = WmShell::Get() |
| 398 ->system_tray_delegate() | 397 ->system_tray_delegate() |
| 399 ->GetVPNDelegate() | 398 ->GetVPNDelegate() |
| 400 ->GetVPNProviders(); | 399 ->GetVPNProviders(); |
| 401 | 400 |
| 402 // Add providers with at least one configured network along with their | 401 // Add providers with at least one configured network along with their |
| 403 // networks. Providers are added in the order of their highest priority | 402 // networks. Providers are added in the order of their highest priority |
| 404 // network. | 403 // network. |
| 405 for (const chromeos::NetworkState* const& network : networks) { | 404 for (const chromeos::NetworkState* const& network : networks) { |
| 406 for (auto provider = providers.begin(); provider != providers.end(); | 405 for (auto provider = providers.begin(); provider != providers.end(); |
| 407 ++provider) { | 406 ++provider) { |
| 408 if (!provider->key.MatchesNetwork(*network)) | 407 if (!provider->key.MatchesNetwork(*network)) |
| 409 continue; | 408 continue; |
| 410 AddProviderAndNetworks(provider->key, provider->name, networks); | 409 AddProviderAndNetworks(provider->key, provider->name, networks); |
| 411 providers.erase(provider); | 410 providers.erase(provider); |
| 412 break; | 411 break; |
| 413 } | 412 } |
| 414 } | 413 } |
| 415 | 414 |
| 416 // Add providers without any configured networks, in the order that the | 415 // Add providers without any configured networks, in the order that the |
| 417 // providers were returned by the extensions system. | 416 // providers were returned by the extensions system. |
| 418 for (const VPNProvider& provider : providers) | 417 for (const VPNProvider& provider : providers) |
| 419 AddProviderAndNetworks(provider.key, provider.name, networks); | 418 AddProviderAndNetworks(provider.key, provider.name, networks); |
| 420 } | 419 } |
| 421 | 420 |
| 422 } // namespace ash | 421 } // namespace ash |
| OLD | NEW |