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