vpn_list.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #ifndef ASH_SYSTEM_NETWORK_VPN_LIST_H_
  5. #define ASH_SYSTEM_NETWORK_VPN_LIST_H_
  6. #include <string>
  7. #include <vector>
  8. #include "ash/ash_export.h"
  9. #include "ash/system/network/tray_network_state_observer.h"
  10. #include "base/observer_list.h"
  11. #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h"
  12. namespace ash {
  13. class TrayNetworkStateModel;
  14. // This delegate provides UI code in ash, e.g. |VPNListView|, with access to the
  15. // list of VPN providers enabled in the primary user's profile. The delegate
  16. // furthermore allows the UI code to request that a VPN provider show its "add
  17. // network" dialog and allows UI code to request to launch Arc VPN provider.
  18. class ASH_EXPORT VpnList : public TrayNetworkStateObserver {
  19. public:
  20. using VpnProvider = chromeos::network_config::mojom::VpnProvider;
  21. using VpnProviderPtr = chromeos::network_config::mojom::VpnProviderPtr;
  22. using VpnType = chromeos::network_config::mojom::VpnType;
  23. // An observer that is notified whenever the list of VPN providers enabled in
  24. // the primary user's profile changes.
  25. class Observer {
  26. public:
  27. Observer& operator=(const Observer&) = delete;
  28. virtual void OnVpnProvidersChanged() = 0;
  29. protected:
  30. virtual ~Observer();
  31. };
  32. explicit VpnList(TrayNetworkStateModel* model);
  33. VpnList(const VpnList&) = delete;
  34. VpnList& operator=(const VpnList&) = delete;
  35. ~VpnList() override;
  36. const std::vector<VpnProviderPtr>& extension_vpn_providers() {
  37. return extension_vpn_providers_;
  38. }
  39. const std::vector<VpnProviderPtr>& arc_vpn_providers() {
  40. return arc_vpn_providers_;
  41. }
  42. // Returns |true| if at least one third-party VPN provider or at least one Arc
  43. // VPN provider is enabled in the primary user's profile, in addition to the
  44. // built-in OpenVPN/L2TP provider.
  45. bool HaveExtensionOrArcVpnProviders() const;
  46. void AddObserver(Observer* observer);
  47. void RemoveObserver(Observer* observer);
  48. // TrayNetworkStateObserver
  49. void ActiveNetworkStateChanged() override;
  50. void VpnProvidersChanged() override;
  51. void SetVpnProvidersForTest(std::vector<VpnProviderPtr> providers);
  52. private:
  53. void OnGetVpnProviders(std::vector<VpnProviderPtr> providers);
  54. // Notify observers that the list of VPN providers enabled in the primary
  55. // user's profile has changed.
  56. void NotifyObservers();
  57. // Adds the built-in OpenVPN/L2TP provider to |extension_vpn_providers_|.
  58. void AddBuiltInProvider();
  59. // Called when either ActiveNetworkStateChanged() or VpnProvidersChanged() is
  60. // called.
  61. void Update();
  62. TrayNetworkStateModel* model_;
  63. // Cache of VPN providers, including the built-in OpenVPN/L2TP provider and
  64. // other providers added by extensions in the primary user's profile.
  65. std::vector<VpnProviderPtr> extension_vpn_providers_;
  66. // Cache of Arc VPN providers. Will be sorted based on last launch time when
  67. // creating vpn list view.
  68. std::vector<VpnProviderPtr> arc_vpn_providers_;
  69. base::ObserverList<Observer>::Unchecked observer_list_;
  70. };
  71. } // namespace ash
  72. #endif // ASH_SYSTEM_NETWORK_VPN_LIST_H_