vpn_list_view.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_VIEW_H_
  5. #define ASH_SYSTEM_NETWORK_VPN_LIST_VIEW_H_
  6. #include <map>
  7. #include <string>
  8. #include "ash/system/network/network_state_list_detailed_view.h"
  9. #include "ash/system/network/vpn_list.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h"
  12. class PrefRegistrySimple;
  13. namespace views {
  14. class View;
  15. }
  16. namespace ash {
  17. // A list of VPN providers and networks that shows VPN providers and networks in
  18. // a hierarchical layout, allowing the user to see at a glance which provider a
  19. // network belongs to. The only exception is the currently connected or
  20. // connecting network, which is detached from its provider and moved to the top.
  21. // If there is a connected network, a disconnect button is shown next to its
  22. // name.
  23. //
  24. // Disconnected networks are arranged in shill's priority order within each
  25. // provider and the providers are arranged in the order of their highest
  26. // priority network. Clicking on a disconnected network triggers a connection
  27. // attempt. Clicking on the currently connected or connecting network shows its
  28. // configuration dialog. Clicking on a provider shows the provider's "add
  29. // network" dialog.
  30. class VPNListView : public NetworkStateListDetailedView,
  31. public VpnList::Observer {
  32. public:
  33. using VpnProviderPtr = chromeos::network_config::mojom::VpnProviderPtr;
  34. VPNListView(DetailedViewDelegate* delegate, LoginStatus login);
  35. VPNListView(const VPNListView&) = delete;
  36. VPNListView& operator=(const VPNListView&) = delete;
  37. ~VPNListView() override;
  38. // NetworkStateListDetailedView:
  39. void UpdateNetworkList() override;
  40. bool IsNetworkEntry(views::View* view, std::string* guid) const override;
  41. // VpnList::Observer:
  42. void OnVpnProvidersChanged() override;
  43. // See Shell::RegisterProfilePrefs().
  44. static void RegisterProfilePrefs(PrefRegistrySimple* registry);
  45. // views::View:
  46. const char* GetClassName() const override;
  47. private:
  48. using NetworkStateList =
  49. std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr>;
  50. void OnGetNetworkStateList(NetworkStateList networks);
  51. // Adds a network to the list.
  52. void AddNetwork(
  53. const chromeos::network_config::mojom::NetworkStateProperties* network);
  54. // Adds the VPN provider identified by |vpn_provider| to the list, along with
  55. // any networks that may belong to this provider. Takes ownership of
  56. // |vpn_provider|.
  57. void AddProviderAndNetworks(VpnProviderPtr vpn_provider,
  58. const NetworkStateList& networks);
  59. // Finds VPN provider from |providers| that matches given |network|. Then adds
  60. // the VPN provider along with any networks that belong to this provider. Will
  61. // also remove the match from |providers| to avoid showing duplicate provider
  62. // entry in VPN list view.
  63. // Returns true if finds a match, returns false otherwise.
  64. bool ProcessProviderForNetwork(
  65. const chromeos::network_config::mojom::NetworkStateProperties* network,
  66. const NetworkStateList& networks,
  67. std::vector<VpnProviderPtr>* providers);
  68. // Adds all available VPN providers and networks to the list.
  69. void AddProvidersAndNetworks(const NetworkStateList& networks);
  70. // A mapping from each VPN provider's list entry to the provider.
  71. std::map<const views::View* const, VpnProviderPtr> provider_view_map_;
  72. // A mapping from each network's list entry to the network's guid.
  73. std::map<const views::View* const, std::string> network_view_guid_map_;
  74. // Whether the list is currently empty (i.e., the next entry added will become
  75. // the topmost entry).
  76. bool list_empty_ = true;
  77. base::WeakPtrFactory<VPNListView> weak_ptr_factory_{this};
  78. };
  79. } // namespace ash
  80. #endif // ASH_SYSTEM_NETWORK_VPN_LIST_VIEW_H_