| Index: net/base/network_change_notifier_mac.cc
|
| diff --git a/net/base/network_change_notifier_mac.cc b/net/base/network_change_notifier_mac.cc
|
| index ca314a199f9f6343b105a034bde290f5c55d3e72..20cbda7933aae29fef2cac4040919a06050e3bc3 100644
|
| --- a/net/base/network_change_notifier_mac.cc
|
| +++ b/net/base/network_change_notifier_mac.cc
|
| @@ -5,6 +5,11 @@
|
| #include "net/base/network_change_notifier_mac.h"
|
|
|
| #include <netinet/in.h>
|
| +#include <resolv.h>
|
| +
|
| +#ifndef _PATH_RESCONF // Normally defined in <resolv.h>
|
| +#define _PATH_RESCONF "/etc/resolv.conf"
|
| +#endif
|
|
|
| namespace net {
|
|
|
| @@ -17,10 +22,30 @@ static bool CalculateReachability(SCNetworkConnectionFlags flags) {
|
| NetworkChangeNotifierMac::NetworkChangeNotifierMac()
|
| : online_state_(UNINITIALIZED),
|
| initial_state_cv_(&online_state_lock_),
|
| - forwarder_(this) {
|
| + forwarder_(this),
|
| + watching_dns_(false) {
|
| // Must be initialized after the rest of this object, as it may call back into
|
| // SetInitialState().
|
| config_watcher_.reset(new NetworkConfigWatcherMac(&forwarder_));
|
| +
|
| + base::AutoLock lock(watching_dns_lock_);
|
| + watching_dns_ = true;
|
| + if (!resolv_watcher_.Watch(
|
| + FilePath(FILE_PATH_LITERAL(_PATH_RESCONF)),
|
| + base::Bind(&NetworkChangeNotifierMac::OnDNSFileChanged,
|
| + base::Unretained(this),
|
| + static_cast<unsigned>(CHANGE_DNS_SETTINGS)))) {
|
| + LOG(ERROR) << "Failed to setup watch for /etc/resolv.conf";
|
| + watching_dns_ = false;
|
| + }
|
| + if (!hosts_watcher_.Watch(
|
| + FilePath(FILE_PATH_LITERAL("/etc/hosts")),
|
| + base::Bind(&NetworkChangeNotifierMac::OnDNSFileChanged,
|
| + base::Unretained(this),
|
| + static_cast<unsigned>(CHANGE_DNS_HOSTS)))) {
|
| + LOG(ERROR) << "Failed to setup watch for /etc/hosts";
|
| + watching_dns_ = false;
|
| + }
|
| }
|
|
|
| NetworkChangeNotifierMac::~NetworkChangeNotifierMac() {
|
| @@ -46,6 +71,11 @@ bool NetworkChangeNotifierMac::IsCurrentlyOffline() const {
|
| return online_state_ == OFFLINE;
|
| }
|
|
|
| +bool NetworkChangeNotifierMac::IsCurrentlyWatchingDNS() const {
|
| + base::AutoLock lock(watching_dns_lock_);
|
| + return watching_dns_ == OFFLINE;
|
| +}
|
| +
|
| void NetworkChangeNotifierMac::SetInitialState() {
|
| // Called on notifier thread.
|
|
|
| @@ -143,6 +173,17 @@ void NetworkChangeNotifierMac::OnNetworkConfigChange(CFArrayRef changed_keys) {
|
| }
|
| }
|
|
|
| +void NetworkChangeNotifierMac::OnDNSFileChanged(unsigned detail,
|
| + bool watch_success) {
|
| + if (!watch_success) {
|
| + LOG(ERROR) << "DNS watch failed.";
|
| + base::AutoLock lock(watching_dns_lock_);
|
| + watching_dns_ = false;
|
| + }
|
| + // Always notify observers so that they can check IsWatchingDNS().
|
| + NetworkChangeNotifier::NotifyObserversOfDNSChange(detail);
|
| +}
|
| +
|
| // static
|
| void NetworkChangeNotifierMac::ReachabilityCallback(
|
| SCNetworkReachabilityRef target,
|
|
|