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

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

Issue 2513673004: Reland: chromeos: Convert ash VPNDelegate interface to mojo (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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/common/system/chromeos/network/vpn_delegate.h"
6
7 #include "ash/common/strings/grit/ash_strings.h"
8 #include "chromeos/network/network_state.h"
9 #include "third_party/cros_system_api/dbus/service_constants.h"
10 #include "ui/base/l10n/l10n_util.h"
11
12 namespace ash {
13
14 VPNProvider::Key::Key() : third_party(false) {}
15
16 VPNProvider::Key::Key(const std::string& extension_id)
17 : third_party(true), extension_id(extension_id) {}
18
19 bool VPNProvider::Key::operator==(const Key& other) const {
20 return other.third_party == third_party && other.extension_id == extension_id;
21 }
22
23 bool VPNProvider::Key::MatchesNetwork(
24 const chromeos::NetworkState& network) const {
25 if (network.type() != shill::kTypeVPN)
26 return false;
27 const bool network_uses_third_party_provider =
28 network.vpn_provider_type() == shill::kProviderThirdPartyVpn;
29 if (!third_party)
30 return !network_uses_third_party_provider;
31 return network_uses_third_party_provider &&
32 network.third_party_vpn_provider_extension_id() == extension_id;
33 }
34
35 VPNProvider::VPNProvider(const Key& key, const std::string& name)
36 : key(key), name(name) {}
37
38 bool VPNProvider::operator==(const VPNProvider& other) const {
39 return key == other.key && name == other.name;
40 }
41
42 VPNDelegate::Observer::~Observer() {}
43
44 VPNDelegate::VPNDelegate() {
45 AddBuiltInProvider();
46 }
47
48 VPNDelegate::~VPNDelegate() {}
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
58 void VPNDelegate::AddObserver(Observer* observer) {
59 observer_list_.AddObserver(observer);
60 }
61
62 void VPNDelegate::RemoveObserver(Observer* observer) {
63 observer_list_.RemoveObserver(observer);
64 }
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();
71 NotifyObservers();
72 }
73
74 void VPNDelegate::NotifyObservers() {
75 for (auto& observer : observer_list_)
76 observer.OnVPNProvidersChanged();
77 }
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
87 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698