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

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

Issue 2510083006: chromeos: Move ownership of ash VPN provider list from chrome into ash (Closed)
Patch Set: rebase 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_delegate.h" 5 #include "ash/common/system/chromeos/network/vpn_delegate.h"
6 6
7 #include "ash/common/strings/grit/ash_strings.h"
7 #include "chromeos/network/network_state.h" 8 #include "chromeos/network/network_state.h"
8 #include "third_party/cros_system_api/dbus/service_constants.h" 9 #include "third_party/cros_system_api/dbus/service_constants.h"
10 #include "ui/base/l10n/l10n_util.h"
9 11
10 namespace ash { 12 namespace ash {
11 13
12 VPNProvider::Key::Key() : third_party(false) {} 14 VPNProvider::Key::Key() : third_party(false) {}
13 15
14 VPNProvider::Key::Key(const std::string& extension_id) 16 VPNProvider::Key::Key(const std::string& extension_id)
15 : third_party(true), extension_id(extension_id) {} 17 : third_party(true), extension_id(extension_id) {}
16 18
17 bool VPNProvider::Key::operator==(const Key& other) const { 19 bool VPNProvider::Key::operator==(const Key& other) const {
18 return other.third_party == third_party && other.extension_id == extension_id; 20 return other.third_party == third_party && other.extension_id == extension_id;
19 } 21 }
20 22
21 bool VPNProvider::Key::MatchesNetwork( 23 bool VPNProvider::Key::MatchesNetwork(
22 const chromeos::NetworkState& network) const { 24 const chromeos::NetworkState& network) const {
23 if (network.type() != shill::kTypeVPN) 25 if (network.type() != shill::kTypeVPN)
24 return false; 26 return false;
25 const bool network_uses_third_party_provider = 27 const bool network_uses_third_party_provider =
26 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; 28 network.vpn_provider_type() == shill::kProviderThirdPartyVpn;
27 if (!third_party) 29 if (!third_party)
28 return !network_uses_third_party_provider; 30 return !network_uses_third_party_provider;
29 return network_uses_third_party_provider && 31 return network_uses_third_party_provider &&
30 network.third_party_vpn_provider_extension_id() == extension_id; 32 network.third_party_vpn_provider_extension_id() == extension_id;
31 } 33 }
stevenjb 2016/11/21 20:23:17 This appears to be only used in vpn_list_view.cc,
James Cook 2016/11/21 23:58:37 Done.
32 34
33 VPNProvider::VPNProvider(const Key& key, const std::string& name) 35 VPNProvider::VPNProvider(const Key& key, const std::string& name)
34 : key(key), name(name) {} 36 : key(key), name(name) {}
35 37
38 bool VPNProvider::operator==(const VPNProvider& other) const {
39 return key == other.key && name == other.name;
40 }
41
36 VPNDelegate::Observer::~Observer() {} 42 VPNDelegate::Observer::~Observer() {}
37 43
38 VPNDelegate::VPNDelegate() {} 44 VPNDelegate::VPNDelegate() {
45 AddBuiltInProvider();
46 }
39 47
40 VPNDelegate::~VPNDelegate() {} 48 VPNDelegate::~VPNDelegate() {}
41 49
50 bool VPNDelegate::HaveThirdPartyVPNProviders() const {
51 for (const VPNProvider& provider : vpn_providers_) {
52 if (provider.key.third_party)
53 return true;
54 }
55 return false;
56 }
57
42 void VPNDelegate::AddObserver(Observer* observer) { 58 void VPNDelegate::AddObserver(Observer* observer) {
43 observer_list_.AddObserver(observer); 59 observer_list_.AddObserver(observer);
44 } 60 }
45 61
46 void VPNDelegate::RemoveObserver(Observer* observer) { 62 void VPNDelegate::RemoveObserver(Observer* observer) {
47 observer_list_.RemoveObserver(observer); 63 observer_list_.RemoveObserver(observer);
48 } 64 }
49 65
66 void VPNDelegate::SetThirdPartyVpnProviders(
67 const std::vector<VPNProvider>& providers) {
68 // Reset the list with the extension-backed providers.
69 vpn_providers_ = providers;
70 AddBuiltInProvider();
stevenjb 2016/11/21 20:23:17 nit: Even though I'm not sure that the order matte
James Cook 2016/11/21 23:58:37 Done.
71 NotifyObservers();
72 }
73
50 void VPNDelegate::NotifyObservers() { 74 void VPNDelegate::NotifyObservers() {
51 for (auto& observer : observer_list_) 75 for (auto& observer : observer_list_)
52 observer.OnVPNProvidersChanged(); 76 observer.OnVPNProvidersChanged();
53 } 77 }
54 78
79 void VPNDelegate::AddBuiltInProvider() {
80 // The VPNProvider::Key() constructor generates a key that identifies that
81 // built-in provider and has no extension ID.
82 vpn_providers_.push_back(VPNProvider(
83 VPNProvider::Key(),
84 l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_VPN_BUILT_IN_PROVIDER)));
85 }
86
55 } // namespace ash 87 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/network/vpn_delegate.h ('k') | ash/common/system/chromeos/network/vpn_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698