| OLD | NEW |
| (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 #ifndef ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_VPN_DELEGATE_H_ | |
| 6 #define ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_VPN_DELEGATE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "ash/ash_export.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/observer_list.h" | |
| 14 | |
| 15 namespace chromeos { | |
| 16 class NetworkState; | |
| 17 } | |
| 18 | |
| 19 namespace ash { | |
| 20 | |
| 21 // Describes a VPN provider. | |
| 22 struct ASH_EXPORT VPNProvider { | |
| 23 struct Key { | |
| 24 // Constructs a key for the built-in VPN provider. | |
| 25 Key(); | |
| 26 | |
| 27 // Constructs a key for a third-party VPN provider. | |
| 28 explicit Key(const std::string& extension_id); | |
| 29 | |
| 30 bool operator==(const Key& other) const; | |
| 31 | |
| 32 // Indicates whether |network| belongs to this VPN provider. | |
| 33 bool MatchesNetwork(const chromeos::NetworkState& network) const; | |
| 34 | |
| 35 // Whether this key represents a built-in or third-party VPN provider. | |
| 36 bool third_party; | |
| 37 | |
| 38 // ID of the extension that implements this provider. Used for third-party | |
| 39 // VPN providers only. | |
| 40 std::string extension_id; | |
| 41 }; | |
| 42 | |
| 43 VPNProvider(const Key& key, const std::string& name); | |
| 44 | |
| 45 bool operator==(const VPNProvider& other) const; | |
| 46 | |
| 47 // Key that uniquely identifies this VPN provider. | |
| 48 Key key; | |
| 49 | |
| 50 // Human-readable name. | |
| 51 std::string name; | |
| 52 }; | |
| 53 | |
| 54 // This delegate provides UI code in ash, e.g. |VPNListView|, with access to the | |
| 55 // list of VPN providers enabled in the primary user's profile. The delegate | |
| 56 // furthermore allows the UI code to request that a VPN provider show its "add | |
| 57 // network" dialog. | |
| 58 // TODO(jamescook): Rename this to VpnList as part of mojo conversion because it | |
| 59 // won't be a delegate anymore. | |
| 60 class ASH_EXPORT VPNDelegate { | |
| 61 public: | |
| 62 // An observer that is notified whenever the list of VPN providers enabled in | |
| 63 // the primary user's profile changes. | |
| 64 class Observer { | |
| 65 public: | |
| 66 virtual void OnVPNProvidersChanged() = 0; | |
| 67 | |
| 68 protected: | |
| 69 virtual ~Observer(); | |
| 70 | |
| 71 private: | |
| 72 DISALLOW_ASSIGN(Observer); | |
| 73 }; | |
| 74 | |
| 75 VPNDelegate(); | |
| 76 virtual ~VPNDelegate(); | |
| 77 | |
| 78 const std::vector<VPNProvider>& vpn_providers() { return vpn_providers_; } | |
| 79 | |
| 80 // Returns |true| if at least one third-party VPN provider is enabled in the | |
| 81 // primary user's profile, in addition to the built-in OpenVPN/L2TP provider. | |
| 82 bool HaveThirdPartyVPNProviders() const; | |
| 83 | |
| 84 // Requests that the VPN provider identified by |key| show its "add network" | |
| 85 // dialog. | |
| 86 virtual void ShowAddPage(const VPNProvider::Key& key) = 0; | |
| 87 | |
| 88 void AddObserver(Observer* observer); | |
| 89 void RemoveObserver(Observer* observer); | |
| 90 | |
| 91 // Sets the list of extension-backed VPN providers. The list may be empty. | |
| 92 // Notifies observers. Public for testing. | |
| 93 // TODO(jamescook): Convert to mojo interface. | |
| 94 void SetThirdPartyVpnProviders(const std::vector<VPNProvider>& providers); | |
| 95 | |
| 96 private: | |
| 97 // Notify observers that the list of VPN providers enabled in the primary | |
| 98 // user's profile has changed. | |
| 99 void NotifyObservers(); | |
| 100 | |
| 101 // Adds the built-in OpenVPN/L2TP provider to |vpn_providers_|. | |
| 102 void AddBuiltInProvider(); | |
| 103 | |
| 104 // Cache of VPN providers, including the built-in OpenVPN/L2TP provider and | |
| 105 // other providers added by extensions in the primary user's profile. | |
| 106 std::vector<VPNProvider> vpn_providers_; | |
| 107 | |
| 108 base::ObserverList<Observer> observer_list_; | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(VPNDelegate); | |
| 111 }; | |
| 112 | |
| 113 } // namespace ash | |
| 114 | |
| 115 #endif // ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_VPN_DELEGATE_H_ | |
| OLD | NEW |