Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Unified Diff: net/base/network_change_notifier_mac.cc

Issue 9540011: [net] Add DNS-related signals and NetLog to NetworkChangeNotifier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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,

Powered by Google App Engine
This is Rietveld 408576698