| 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 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include "ui/views/view.h" | 51 #include "ui/views/view.h" |
| 52 | 52 |
| 53 namespace ash { | 53 namespace ash { |
| 54 | 54 |
| 55 namespace { | 55 namespace { |
| 56 | 56 |
| 57 bool UseMd() { | 57 bool UseMd() { |
| 58 return MaterialDesignController::IsSystemTrayMenuMaterial(); | 58 return MaterialDesignController::IsSystemTrayMenuMaterial(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void IgnoreDisconnectError(const std::string& error_name, |
| 62 std::unique_ptr<base::DictionaryValue> error_data) {} |
| 63 |
| 61 // Indicates whether |network| belongs to this VPN provider. | 64 // Indicates whether |network| belongs to this VPN provider. |
| 62 bool VpnProviderMatchesNetwork(const VPNProvider& provider, | 65 bool VpnProviderMatchesNetwork(const VPNProvider& provider, |
| 63 const chromeos::NetworkState& network) { | 66 const chromeos::NetworkState& network) { |
| 64 if (network.type() != shill::kTypeVPN) | 67 if (network.type() != shill::kTypeVPN) |
| 65 return false; | 68 return false; |
| 66 const bool network_uses_third_party_provider = | 69 const bool network_uses_third_party_provider = |
| 67 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; | 70 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; |
| 68 if (!provider.third_party) | 71 if (!provider.third_party) |
| 69 return !network_uses_third_party_provider; | 72 return !network_uses_third_party_provider; |
| 70 return network_uses_third_party_provider && | 73 return network_uses_third_party_provider && |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 class VPNListNetworkEntry : public VPNListEntryBase, | 152 class VPNListNetworkEntry : public VPNListEntryBase, |
| 150 public network_icon::AnimationObserver { | 153 public network_icon::AnimationObserver { |
| 151 public: | 154 public: |
| 152 VPNListNetworkEntry(VPNListView* parent, | 155 VPNListNetworkEntry(VPNListView* parent, |
| 153 const chromeos::NetworkState* network); | 156 const chromeos::NetworkState* network); |
| 154 ~VPNListNetworkEntry() override; | 157 ~VPNListNetworkEntry() override; |
| 155 | 158 |
| 156 // network_icon::AnimationObserver: | 159 // network_icon::AnimationObserver: |
| 157 void NetworkIconChanged() override; | 160 void NetworkIconChanged() override; |
| 158 | 161 |
| 162 // views::ButtonListener: |
| 163 void ButtonPressed(Button* sender, const ui::Event& event) override; |
| 164 |
| 159 private: | 165 private: |
| 160 void UpdateFromNetworkState(const chromeos::NetworkState* network); | 166 void UpdateFromNetworkState(const chromeos::NetworkState* network); |
| 161 void SetupConnectedItemMd(const base::string16& text, | 167 void SetupConnectedItemMd(const base::string16& text, |
| 162 const gfx::ImageSkia& image); | 168 const gfx::ImageSkia& image); |
| 163 void SetupConnectingItemMd(const base::string16& text, | 169 void SetupConnectingItemMd(const base::string16& text, |
| 164 const gfx::ImageSkia& image); | 170 const gfx::ImageSkia& image); |
| 165 | 171 |
| 166 const std::string guid_; | 172 const std::string guid_; |
| 167 | 173 |
| 168 views::LabelButton* disconnect_button_ = nullptr; | 174 views::LabelButton* disconnect_button_ = nullptr; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 185 VPNListNetworkEntry::~VPNListNetworkEntry() { | 191 VPNListNetworkEntry::~VPNListNetworkEntry() { |
| 186 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 192 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 187 } | 193 } |
| 188 | 194 |
| 189 void VPNListNetworkEntry::NetworkIconChanged() { | 195 void VPNListNetworkEntry::NetworkIconChanged() { |
| 190 UpdateFromNetworkState(chromeos::NetworkHandler::Get() | 196 UpdateFromNetworkState(chromeos::NetworkHandler::Get() |
| 191 ->network_state_handler() | 197 ->network_state_handler() |
| 192 ->GetNetworkStateFromGuid(guid_)); | 198 ->GetNetworkStateFromGuid(guid_)); |
| 193 } | 199 } |
| 194 | 200 |
| 201 void VPNListNetworkEntry::ButtonPressed(Button* sender, |
| 202 const ui::Event& event) { |
| 203 if (sender != disconnect_button_) { |
| 204 VPNListEntryBase::ButtonPressed(sender, event); |
| 205 return; |
| 206 } |
| 207 |
| 208 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get() |
| 209 ->network_state_handler() |
| 210 ->GetNetworkStateFromGuid(guid_); |
| 211 if (!network) |
| 212 return; |
| 213 WmShell::Get()->RecordUserMetricsAction( |
| 214 UMA_STATUS_AREA_VPN_DISCONNECT_CLICKED); |
| 215 chromeos::NetworkHandler::Get() |
| 216 ->network_connection_handler() |
| 217 ->DisconnectNetwork(network->path(), base::Bind(&base::DoNothing), |
| 218 base::Bind(&IgnoreDisconnectError)); |
| 219 } |
| 220 |
| 195 void VPNListNetworkEntry::UpdateFromNetworkState( | 221 void VPNListNetworkEntry::UpdateFromNetworkState( |
| 196 const chromeos::NetworkState* network) { | 222 const chromeos::NetworkState* network) { |
| 197 if (network && network->IsConnectingState()) | 223 if (network && network->IsConnectingState()) |
| 198 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 224 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 199 else | 225 else |
| 200 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 226 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 201 | 227 |
| 202 if (!network) { | 228 if (!network) { |
| 203 // This is a transient state where the network has been removed already but | 229 // This is a transient state where the network has been removed already but |
| 204 // the network list in the UI has not been updated yet. | 230 // the network list in the UI has not been updated yet. |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 } | 457 } |
| 432 } | 458 } |
| 433 | 459 |
| 434 // Add providers without any configured networks, in the order that the | 460 // Add providers without any configured networks, in the order that the |
| 435 // providers were returned by the extensions system. | 461 // providers were returned by the extensions system. |
| 436 for (const VPNProvider& provider : providers) | 462 for (const VPNProvider& provider : providers) |
| 437 AddProviderAndNetworks(provider, networks); | 463 AddProviderAndNetworks(provider, networks); |
| 438 } | 464 } |
| 439 | 465 |
| 440 } // namespace ash | 466 } // namespace ash |
| OLD | NEW |