Commit aa19e2ff authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Request VPN list in TrayNetworkStateModel

Currently we do not show the VPN feature pod unless a VPN is connected.
This fixes that by requesting the list of configured VPNs and showing
the button if any exist.

Bug: 982222
Change-Id: I939f2eb9ee74771c47468aad7256b5884640cc5e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1815222
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Auto-Submit: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698530}
parent c0fadd6b
...@@ -59,6 +59,8 @@ TrayNetworkStateModel::TrayNetworkStateModel() ...@@ -59,6 +59,8 @@ TrayNetworkStateModel::TrayNetworkStateModel()
cros_network_config_observer_receiver_.Bind(mojo::MakeRequest(&observer_ptr)); cros_network_config_observer_receiver_.Bind(mojo::MakeRequest(&observer_ptr));
remote_cros_network_config_->AddObserver(std::move(observer_ptr)); remote_cros_network_config_->AddObserver(std::move(observer_ptr));
GetActiveNetworks();
GetVirtualNetworks();
GetDeviceStateList(); GetDeviceStateList();
} }
...@@ -105,6 +107,7 @@ void TrayNetworkStateModel::OnNetworkStateChanged( ...@@ -105,6 +107,7 @@ void TrayNetworkStateModel::OnNetworkStateChanged(
void TrayNetworkStateModel::OnNetworkStateListChanged() { void TrayNetworkStateModel::OnNetworkStateListChanged() {
NotifyNetworkListChanged(); NotifyNetworkListChanged();
GetVirtualNetworks();
} }
void TrayNetworkStateModel::OnDeviceStateListChanged() { void TrayNetworkStateModel::OnDeviceStateListChanged() {
...@@ -195,6 +198,20 @@ void TrayNetworkStateModel::UpdateActiveNetworks( ...@@ -195,6 +198,20 @@ void TrayNetworkStateModel::UpdateActiveNetworks(
GetConnectingOrConnected(connecting_non_cellular, connected_non_cellular); GetConnectingOrConnected(connecting_non_cellular, connected_non_cellular);
} }
void TrayNetworkStateModel::GetVirtualNetworks() {
DCHECK(remote_cros_network_config_);
remote_cros_network_config_->GetNetworkStateList(
NetworkFilter::New(FilterType::kConfigured, NetworkType::kVPN,
/*limit=*/0),
base::BindOnce(&TrayNetworkStateModel::OnGetVirtualNetworks,
base::Unretained(this)));
}
void TrayNetworkStateModel::OnGetVirtualNetworks(
std::vector<NetworkStatePropertiesPtr> networks) {
has_vpn_ = !networks.empty();
}
void TrayNetworkStateModel::NotifyNetworkListChanged() { void TrayNetworkStateModel::NotifyNetworkListChanged() {
if (timer_.IsRunning()) if (timer_.IsRunning())
return; return;
......
...@@ -64,6 +64,7 @@ class ASH_EXPORT TrayNetworkStateModel ...@@ -64,6 +64,7 @@ class ASH_EXPORT TrayNetworkStateModel
const { const {
return active_vpn_.get(); return active_vpn_.get();
} }
bool has_vpn() const { return has_vpn_; }
private: private:
// CrosNetworkConfigObserver // CrosNetworkConfigObserver
...@@ -87,6 +88,11 @@ class ASH_EXPORT TrayNetworkStateModel ...@@ -87,6 +88,11 @@ class ASH_EXPORT TrayNetworkStateModel
std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr> std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr>
networks); networks);
void GetVirtualNetworks();
void OnGetVirtualNetworks(
std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr>
networks);
void NotifyNetworkListChanged(); void NotifyNetworkListChanged();
void SendActiveNetworkStateChanged(); void SendActiveNetworkStateChanged();
void SendNetworkListChanged(); void SendNetworkListChanged();
...@@ -114,6 +120,7 @@ class ASH_EXPORT TrayNetworkStateModel ...@@ -114,6 +120,7 @@ class ASH_EXPORT TrayNetworkStateModel
active_non_cellular_; active_non_cellular_;
chromeos::network_config::mojom::NetworkStatePropertiesPtr active_cellular_; chromeos::network_config::mojom::NetworkStatePropertiesPtr active_cellular_;
chromeos::network_config::mojom::NetworkStatePropertiesPtr active_vpn_; chromeos::network_config::mojom::NetworkStatePropertiesPtr active_vpn_;
bool has_vpn_ = false;
DISALLOW_COPY_AND_ASSIGN(TrayNetworkStateModel); DISALLOW_COPY_AND_ASSIGN(TrayNetworkStateModel);
}; };
......
...@@ -36,7 +36,7 @@ bool IsVPNVisibleInSystemTray() { ...@@ -36,7 +36,7 @@ bool IsVPNVisibleInSystemTray() {
return true; return true;
// Also show the VPN entry if at least one VPN network is configured. // Also show the VPN entry if at least one VPN network is configured.
return Shell::Get()->system_tray_model()->network_state_model()->active_vpn(); return Shell::Get()->system_tray_model()->network_state_model()->has_vpn();
} }
} // namespace } // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment