Commit d04e7062 authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Re-check Windows proxy settings on network change.

Bug: 1054414
Change-Id: Iede646dd272413fcc8c2f9951a9ff7d663708b88
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2151887Reviewed-by: default avatarMatt Mueller <mattm@chromium.org>
Commit-Queue: Eric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760182}
parent ac4d5270
......@@ -39,9 +39,12 @@ ProxyConfigServiceWin::ProxyConfigServiceWin(
const NetworkTrafficAnnotationTag& traffic_annotation)
: PollingProxyConfigService(base::TimeDelta::FromSeconds(kPollIntervalSec),
&ProxyConfigServiceWin::GetCurrentProxyConfig,
traffic_annotation) {}
traffic_annotation) {
NetworkChangeNotifier::AddNetworkChangeObserver(this);
}
ProxyConfigServiceWin::~ProxyConfigServiceWin() {
NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
// The registry functions below will end up going to disk. TODO: Do this on
// another thread to avoid slowing the current thread. http://crbug.com/61453
base::ThreadRestrictions::ScopedAllowIO allow_io;
......@@ -56,6 +59,20 @@ void ProxyConfigServiceWin::AddObserver(Observer* observer) {
PollingProxyConfigService::AddObserver(observer);
}
void ProxyConfigServiceWin::OnNetworkChanged(
NetworkChangeNotifier::ConnectionType type) {
// Proxy settings on Windows may change when the active connection changes.
// For instance, after connecting to a VPN, the proxy settings for the active
// connection will be that for the VPN. (And ProxyConfigService only reports
// proxy settings for the default connection).
// This is conditioned on CONNECTION_NONE to avoid duplicating work, as
// NetworkChangeNotifier additionally sends it preceding completion.
// See https://crbug.com/1071901.
if (type == NetworkChangeNotifier::CONNECTION_NONE)
CheckForChangesNow();
}
void ProxyConfigServiceWin::StartWatchingRegistryForChanges() {
if (!keys_to_watch_.empty())
return; // Already initialized.
......
......@@ -15,6 +15,7 @@
#include "base/gtest_prod_util.h"
#include "base/strings/string16.h"
#include "net/base/net_export.h"
#include "net/base/network_change_notifier.h"
#include "net/proxy_resolution/polling_proxy_config_service.h"
#include "net/proxy_resolution/proxy_config_with_annotation.h"
......@@ -49,7 +50,8 @@ namespace net {
// change, or in case we got it wrong (and are not checking all possible
// registry dependencies).
class NET_EXPORT_PRIVATE ProxyConfigServiceWin
: public PollingProxyConfigService {
: public PollingProxyConfigService,
public NetworkChangeNotifier::NetworkChangeObserver {
public:
ProxyConfigServiceWin(const NetworkTrafficAnnotationTag& traffic_annotation);
~ProxyConfigServiceWin() override;
......@@ -57,6 +59,9 @@ class NET_EXPORT_PRIVATE ProxyConfigServiceWin
// Overrides a function from PollingProxyConfigService.
void AddObserver(Observer* observer) override;
// NetworkChangeObserver implementation.
void OnNetworkChanged(NetworkChangeNotifier::ConnectionType type) override;
private:
FRIEND_TEST_ALL_PREFIXES(ProxyConfigServiceWinTest, SetFromIEConfig);
......
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