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

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

Issue 2768973002: [ash-md] Restores handler for VPN Disconnect button in system menu (Closed)
Patch Set: [ash-md] Restores handler for VPN Disconnect button in system menu (not caching service_path) Created 3 years, 9 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 13 matching lines...) Expand all
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 "ash/shell.h" 27 #include "ash/shell.h"
28 #include "ash/strings/grit/ash_strings.h" 28 #include "ash/strings/grit/ash_strings.h"
29 #include "base/bind.h" 29 #include "base/bind.h"
30 #include "base/bind_helpers.h" 30 #include "base/bind_helpers.h"
31 #include "base/logging.h" 31 #include "base/logging.h"
32 #include "base/strings/utf_string_conversions.h" 32 #include "base/strings/utf_string_conversions.h"
33 #include "base/values.h" 33 #include "base/values.h"
34 #include "chromeos/network/network_connection_handler.h" 34 #include "chromeos/network/network_connection_handler.h"
stevenjb 2017/03/23 18:33:13 We should actually remove this and depend on chrom
35 #include "chromeos/network/network_handler.h" 35 #include "chromeos/network/network_handler.h"
36 #include "chromeos/network/network_state.h" 36 #include "chromeos/network/network_state.h"
37 #include "chromeos/network/network_type_pattern.h" 37 #include "chromeos/network/network_type_pattern.h"
38 #include "third_party/cros_system_api/dbus/service_constants.h" 38 #include "third_party/cros_system_api/dbus/service_constants.h"
39 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
40 #include "ui/base/resource/resource_bundle.h" 40 #include "ui/base/resource/resource_bundle.h"
41 #include "ui/gfx/geometry/rect.h" 41 #include "ui/gfx/geometry/rect.h"
42 #include "ui/gfx/image/image_skia.h" 42 #include "ui/gfx/image/image_skia.h"
43 #include "ui/gfx/paint_vector_icon.h" 43 #include "ui/gfx/paint_vector_icon.h"
44 #include "ui/gfx/text_constants.h" 44 #include "ui/gfx/text_constants.h"
45 #include "ui/views/border.h" 45 #include "ui/views/border.h"
46 #include "ui/views/controls/button/button.h" 46 #include "ui/views/controls/button/button.h"
47 #include "ui/views/controls/button/label_button.h" 47 #include "ui/views/controls/button/label_button.h"
48 #include "ui/views/controls/label.h" 48 #include "ui/views/controls/label.h"
49 #include "ui/views/controls/separator.h" 49 #include "ui/views/controls/separator.h"
50 #include "ui/views/layout/box_layout.h" 50 #include "ui/views/layout/box_layout.h"
51 #include "ui/views/layout/fill_layout.h" 51 #include "ui/views/layout/fill_layout.h"
52 #include "ui/views/view.h" 52 #include "ui/views/view.h"
53 53
54 namespace ash { 54 namespace ash {
55 55
56 namespace { 56 namespace {
57 57
58 bool UseMd() { 58 bool UseMd() {
59 return MaterialDesignController::IsSystemTrayMenuMaterial(); 59 return MaterialDesignController::IsSystemTrayMenuMaterial();
60 } 60 }
61 61
62 void IgnoreDisconnectError(const std::string& error_name,
63 std::unique_ptr<base::DictionaryValue> error_data) {}
64
62 // Indicates whether |network| belongs to this VPN provider. 65 // Indicates whether |network| belongs to this VPN provider.
63 bool VpnProviderMatchesNetwork(const VPNProvider& provider, 66 bool VpnProviderMatchesNetwork(const VPNProvider& provider,
64 const chromeos::NetworkState& network) { 67 const chromeos::NetworkState& network) {
65 if (network.type() != shill::kTypeVPN) 68 if (network.type() != shill::kTypeVPN)
66 return false; 69 return false;
67 const bool network_uses_third_party_provider = 70 const bool network_uses_third_party_provider =
68 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; 71 network.vpn_provider_type() == shill::kProviderThirdPartyVpn;
69 if (!provider.third_party) 72 if (!provider.third_party)
70 return !network_uses_third_party_provider; 73 return !network_uses_third_party_provider;
71 return network_uses_third_party_provider && 74 return network_uses_third_party_provider &&
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 class VPNListNetworkEntry : public VPNListEntryBase, 153 class VPNListNetworkEntry : public VPNListEntryBase,
151 public network_icon::AnimationObserver { 154 public network_icon::AnimationObserver {
152 public: 155 public:
153 VPNListNetworkEntry(VPNListView* parent, 156 VPNListNetworkEntry(VPNListView* parent,
154 const chromeos::NetworkState* network); 157 const chromeos::NetworkState* network);
155 ~VPNListNetworkEntry() override; 158 ~VPNListNetworkEntry() override;
156 159
157 // network_icon::AnimationObserver: 160 // network_icon::AnimationObserver:
158 void NetworkIconChanged() override; 161 void NetworkIconChanged() override;
159 162
163 // views::ButtonListener:
164 void ButtonPressed(Button* sender, const ui::Event& event) override;
165
160 private: 166 private:
161 void UpdateFromNetworkState(const chromeos::NetworkState* network); 167 void UpdateFromNetworkState(const chromeos::NetworkState* network);
162 void SetupConnectedItemMd(const base::string16& text, 168 void SetupConnectedItemMd(const base::string16& text,
163 const gfx::ImageSkia& image); 169 const gfx::ImageSkia& image);
164 void SetupConnectingItemMd(const base::string16& text, 170 void SetupConnectingItemMd(const base::string16& text,
165 const gfx::ImageSkia& image); 171 const gfx::ImageSkia& image);
166 172
167 const std::string guid_; 173 const std::string guid_;
168 174
169 views::LabelButton* disconnect_button_ = nullptr; 175 views::LabelButton* disconnect_button_ = nullptr;
(...skipping 16 matching lines...) Expand all
186 VPNListNetworkEntry::~VPNListNetworkEntry() { 192 VPNListNetworkEntry::~VPNListNetworkEntry() {
187 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 193 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
188 } 194 }
189 195
190 void VPNListNetworkEntry::NetworkIconChanged() { 196 void VPNListNetworkEntry::NetworkIconChanged() {
191 UpdateFromNetworkState(chromeos::NetworkHandler::Get() 197 UpdateFromNetworkState(chromeos::NetworkHandler::Get()
192 ->network_state_handler() 198 ->network_state_handler()
193 ->GetNetworkStateFromGuid(guid_)); 199 ->GetNetworkStateFromGuid(guid_));
194 } 200 }
195 201
202 void VPNListNetworkEntry::ButtonPressed(Button* sender,
203 const ui::Event& event) {
204 if (sender != disconnect_button_) {
205 VPNListEntryBase::ButtonPressed(sender, event);
206 return;
207 }
208
209 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get()
210 ->network_state_handler()
211 ->GetNetworkStateFromGuid(guid_);
212 if (!network)
213 return;
214 WmShell::Get()->RecordUserMetricsAction(
215 UMA_STATUS_AREA_VPN_DISCONNECT_CLICKED);
216 chromeos::NetworkHandler::Get()
217 ->network_connection_handler()
218 ->DisconnectNetwork(network->path(), base::Bind(&base::DoNothing),
219 base::Bind(&IgnoreDisconnectError));
stevenjb 2017/03/23 18:33:13 Yeah, so, what we really want is: chromeos::Netwo
varkha 2017/03/23 19:03:26 Agreed. It seems like NetworkConnect::ConnectToNet
stevenjb 2017/03/23 19:14:05 "string ID" == guid.
varkha 2017/03/23 19:20:50 Oh I see. I think I misread the code in NetworkSta
220 }
221
196 void VPNListNetworkEntry::UpdateFromNetworkState( 222 void VPNListNetworkEntry::UpdateFromNetworkState(
197 const chromeos::NetworkState* network) { 223 const chromeos::NetworkState* network) {
198 if (network && network->IsConnectingState()) 224 if (network && network->IsConnectingState())
199 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 225 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
200 else 226 else
201 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 227 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
202 228
203 if (!network) { 229 if (!network) {
204 // This is a transient state where the network has been removed already but 230 // This is a transient state where the network has been removed already but
205 // the network list in the UI has not been updated yet. 231 // the network list in the UI has not been updated yet.
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } 459 }
434 } 460 }
435 461
436 // Add providers without any configured networks, in the order that the 462 // Add providers without any configured networks, in the order that the
437 // providers were returned by the extensions system. 463 // providers were returned by the extensions system.
438 for (const VPNProvider& provider : providers) 464 for (const VPNProvider& provider : providers)
439 AddProviderAndNetworks(provider, networks); 465 AddProviderAndNetworks(provider, networks);
440 } 466 }
441 467
442 } // namespace ash 468 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698