| 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 chromeos { | 17 namespace chromeos { |
| 16 class NetworkState; | 18 class NetworkState; |
| 17 } | 19 } |
| 18 | 20 |
| 19 namespace ash { | 21 namespace ash { |
| 20 | 22 |
| 21 // Describes a VPN provider. | 23 // Describes a VPN provider. |
| 22 struct ASH_EXPORT VPNProvider { | 24 struct ASH_EXPORT VPNProvider { |
| 23 struct Key { | 25 struct Key { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 48 Key key; | 50 Key key; |
| 49 | 51 |
| 50 // Human-readable name. | 52 // Human-readable name. |
| 51 std::string name; | 53 std::string name; |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 // This delegate provides UI code in ash, e.g. |VPNListView|, with access to the | 56 // 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 | 57 // 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 | 58 // furthermore allows the UI code to request that a VPN provider show its "add |
| 57 // network" dialog. | 59 // network" dialog. |
| 58 // TODO(jamescook): Rename this to VpnList as part of mojo conversion because it | 60 class ASH_EXPORT VpnList : public mojom::VpnList { |
| 59 // won't be a delegate anymore. | |
| 60 class ASH_EXPORT VPNDelegate { | |
| 61 public: | 61 public: |
| 62 // An observer that is notified whenever the list of VPN providers enabled in | 62 // An observer that is notified whenever the list of VPN providers enabled in |
| 63 // the primary user's profile changes. | 63 // the primary user's profile changes. |
| 64 class Observer { | 64 class Observer { |
| 65 public: | 65 public: |
| 66 virtual void OnVPNProvidersChanged() = 0; | 66 virtual void OnVPNProvidersChanged() = 0; |
| 67 | 67 |
| 68 protected: | 68 protected: |
| 69 virtual ~Observer(); | 69 virtual ~Observer(); |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 DISALLOW_ASSIGN(Observer); | 72 DISALLOW_ASSIGN(Observer); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 VPNDelegate(); | 75 VpnList(); |
| 76 virtual ~VPNDelegate(); | 76 ~VpnList() override; |
| 77 | 77 |
| 78 const std::vector<VPNProvider>& vpn_providers() { return vpn_providers_; } | 78 const std::vector<VPNProvider>& vpn_providers() { return vpn_providers_; } |
| 79 | 79 |
| 80 // Returns |true| if at least one third-party VPN provider is enabled in the | 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. | 81 // primary user's profile, in addition to the built-in OpenVPN/L2TP provider. |
| 82 bool HaveThirdPartyVPNProviders() const; | 82 bool HaveThirdPartyVPNProviders() const; |
| 83 | 83 |
| 84 // Requests that the VPN provider identified by |key| show its "add network" | 84 // Requests that the VPN provider identified by |key| show its "add network" |
| 85 // dialog. | 85 // dialog. |
| 86 virtual void ShowAddPage(const VPNProvider::Key& key) = 0; | 86 void ShowAddPage(const VPNProvider::Key& key); |
| 87 | 87 |
| 88 void AddObserver(Observer* observer); | 88 void AddObserver(Observer* observer); |
| 89 void RemoveObserver(Observer* observer); | 89 void RemoveObserver(Observer* observer); |
| 90 | 90 |
| 91 // Sets the list of extension-backed VPN providers. The list may be empty. | 91 // Binds the mojom::VpnList interface to this object. |
| 92 // Notifies observers. Public for testing. | 92 void BindRequest(mojom::VpnListRequest request); |
| 93 // TODO(jamescook): Convert to mojo interface. | 93 |
| 94 void SetThirdPartyVpnProviders(const std::vector<VPNProvider>& providers); | 94 // mojom::VpnList: |
| 95 void SetClient(mojom::VpnListClientPtr client) override; |
| 96 void SetThirdPartyVpnProviders( |
| 97 std::vector<mojom::ThirdPartyVpnProviderPtr> providers) override; |
| 95 | 98 |
| 96 private: | 99 private: |
| 97 // Notify observers that the list of VPN providers enabled in the primary | 100 // Notify observers that the list of VPN providers enabled in the primary |
| 98 // user's profile has changed. | 101 // user's profile has changed. |
| 99 void NotifyObservers(); | 102 void NotifyObservers(); |
| 100 | 103 |
| 101 // Adds the built-in OpenVPN/L2TP provider to |vpn_providers_|. | 104 // Adds the built-in OpenVPN/L2TP provider to |vpn_providers_|. |
| 102 void AddBuiltInProvider(); | 105 void AddBuiltInProvider(); |
| 103 | 106 |
| 107 // May be null in tests or when Chrome is not running. |
| 108 mojom::VpnListClientPtr vpn_list_client_; |
| 109 |
| 110 // Bindings for the mojom::VpnList interface. |
| 111 mojo::BindingSet<mojom::VpnList> bindings_; |
| 112 |
| 104 // Cache of VPN providers, including the built-in OpenVPN/L2TP provider and | 113 // Cache of VPN providers, including the built-in OpenVPN/L2TP provider and |
| 105 // other providers added by extensions in the primary user's profile. | 114 // other providers added by extensions in the primary user's profile. |
| 106 std::vector<VPNProvider> vpn_providers_; | 115 std::vector<VPNProvider> vpn_providers_; |
| 107 | 116 |
| 108 base::ObserverList<Observer> observer_list_; | 117 base::ObserverList<Observer> observer_list_; |
| 109 | 118 |
| 110 DISALLOW_COPY_AND_ASSIGN(VPNDelegate); | 119 DISALLOW_COPY_AND_ASSIGN(VpnList); |
| 111 }; | 120 }; |
| 112 | 121 |
| 113 } // namespace ash | 122 } // namespace ash |
| 114 | 123 |
| 115 #endif // ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_VPN_DELEGATE_H_ | 124 #endif // ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_VPN_LIST_H_ |
| OLD | NEW |