Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Suppress unwanted VPN disconnection notifications
Browse files Browse the repository at this point in the history
Only show the VPN disconnection notification when the active VPN
disconnects without the user's knowledge.  In particular, do not
show a notification for either of these cases:

 * An extension adds a new VPN config, but the active VPN config
   remains connected.
 * The user is connected to a VPN and then switches to another
   config without explicitly disconnecting the first config.

BUG=580760
TEST=connect to third party VPN, then manually disconnect through the UI
TEST=connect to third party VPN, then call
     notifyConnectStateChanged("failure")
TEST=connect to third party VPN, then click on a different config

Signed-off-by: Kevin Cernekee <[email protected]>

Review URL: https://codereview.chromium.org/1625013002

Cr-Commit-Position: refs/heads/master@{#371302}
  • Loading branch information
cernekee authored and Commit bot committed Jan 25, 2016
1 parent d845b7e commit b7204f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
20 changes: 15 additions & 5 deletions ui/chromeos/network/network_state_notifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ const char NetworkStateNotifier::kNetworkOutOfCreditsNotificationId[] =
NetworkStateNotifier::NetworkStateNotifier(NetworkConnect* network_connect)
: network_connect_(network_connect),
did_show_out_of_credits_(false),
need_vpn_disconnection_notify_(false),
weak_ptr_factory_(this) {
if (!NetworkHandler::IsInitialized())
return;
Expand All @@ -123,6 +122,12 @@ NetworkStateNotifier::~NetworkStateNotifier() {

void NetworkStateNotifier::ConnectToNetworkRequested(
const std::string& service_path) {
const NetworkState* network =
NetworkHandler::Get()->network_state_handler()->GetNetworkState(
service_path);
if (network && network->type() == shill::kTypeVPN)
connected_vpn_.clear();

RemoveConnectNotification();
}

Expand Down Expand Up @@ -152,7 +157,7 @@ void NetworkStateNotifier::DisconnectRequested(
NetworkHandler::Get()->network_state_handler()->GetNetworkState(
service_path);
if (network && network->type() == shill::kTypeVPN)
need_vpn_disconnection_notify_ = false;
connected_vpn_.clear();
}

void NetworkStateNotifier::DefaultNetworkChanged(const NetworkState* network) {
Expand Down Expand Up @@ -191,9 +196,14 @@ bool NetworkStateNotifier::UpdateDefaultNetwork(const NetworkState* network) {
}

void NetworkStateNotifier::UpdateVpnConnectionState(const NetworkState* vpn) {
if (!vpn->IsConnectedState() && need_vpn_disconnection_notify_)
ShowVpnDisconnectedNotification(vpn);
need_vpn_disconnection_notify_ = vpn->IsConnectedState();
if (vpn->path() == connected_vpn_) {
if (!vpn->IsConnectedState()) {
ShowVpnDisconnectedNotification(vpn);
connected_vpn_.clear();
}
} else if (vpn->IsConnectedState()) {
connected_vpn_ = vpn->path();
}
}

void NetworkStateNotifier::UpdateCellularOutOfCredits(
Expand Down
3 changes: 2 additions & 1 deletion ui/chromeos/network/network_state_notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define UI_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_

#include <set>
#include <string>

#include "base/compiler_specific.h"
#include "base/macros.h"
Expand Down Expand Up @@ -108,7 +109,7 @@ class UI_CHROMEOS_EXPORT NetworkStateNotifier
bool did_show_out_of_credits_;
base::Time out_of_credits_notify_time_;
std::set<std::string> cellular_activating_;
bool need_vpn_disconnection_notify_;
std::string connected_vpn_;
base::WeakPtrFactory<NetworkStateNotifier> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier);
Expand Down

0 comments on commit b7204f8

Please sign in to comment.