Index: net/dns/dns_config_service.h |
diff --git a/net/dns/dns_config_service.h b/net/dns/dns_config_service.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f76cad3befd81aa993d6ff27276b96e3a46e6623 |
--- /dev/null |
+++ b/net/dns/dns_config_service.h |
@@ -0,0 +1,107 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef NET_DNS_CONFIG_SERVICE_H_ |
+#define NET_DNS_CONFIG_SERVICE_H_ |
+#pragma once |
+ |
+#include <list> |
+#include <map> |
+#include <string> |
+#include <vector> |
+ |
+#include "net/base/net_api.h" |
+#include "net/base/net_util.h" |
+ |
+namespace net { |
+ |
+class IPEndPoint; |
+ |
+// DnsConfig stores configuration of the system resolver. |
+struct DnsConfig { |
+ // Default values are taken from glibc resolv.h. |
+ DnsConfig() |
+ : ndots(1), |
+ timeout(5), |
+ attempts(2), |
+ rotate(false), |
+ edns0(false) {} |
+ |
+ // List of name server addresses. |
+ std::vector<IPEndPoint> nameservers; |
+ // Suffix search list overrides |domain| and is used on first lookup when |
+ // number of dots in given name is less than |ndots|. |
+ std::vector<std::string> search; |
+ |
+ // Resolver options; see man resolv.conf. |
+ // TODO(szym): use |ndots| and |search| to determine the sequence of FQDNs |
+ // to query given a specific name. |
+ |
+ // Min. number of dots before global resolution precedes |search|. |
cbentzel
2011/08/05 19:11:39
May as well spell out Minimum
szym
2011/08/15 14:27:42
Done.
|
+ int ndots; |
+ // Time (in seconds) between retransmissions, see res_state.retrans. |
+ int timeout; |
cbentzel
2011/08/05 19:11:39
Probably better to use a base::TimeDelta from base
szym
2011/08/15 14:27:42
Done.
|
+ // Max. number of retries, see res_state.retry. |
+ int attempts; |
+ // Round robin entries in |nameservers| for subsequent requests. |
+ bool rotate; |
+ // Enable EDNS0 extensions. |
+ bool edns0; |
+ |
+ bool Equals(const DnsConfig& d) const { |
+ return (nameservers == d.nameservers) && |
+ (search == d.search) && |
+ (ndots == d.ndots) && |
+ (timeout == d.timeout) && |
+ (attempts == d.attempts) && |
+ (rotate == d.rotate) && |
+ (edns0 == d.edns0); |
+ } |
+ |
+ bool Valid() const { |
+ return !nameservers.empty(); |
+ } |
+}; |
+ |
+// Service for watching when the system DNS settings have changed. |
+// Depending on the platform, watches files in /etc/ or win registry. |
+class DnsConfigService { |
+ public: |
+ // Callback interface for the client. The observer is called on the same |
+ // thread as Watch(). Observer must outlive the service. |
+ class Observer { |
+ public: |
+ virtual ~Observer() {} |
+ |
+ // Called only when |dns_config| is different from the last check. |
+ virtual void OnConfigChanged(const DnsConfig& dns_config) = 0; |
+ }; |
+ |
+ // Creates the platform-specific DnsConfigService. |
+ static DnsConfigService* CreateSystemService(); |
+ |
+ // Immediately starts watching system configuration for changes and attempts |
+ // to read the configuration. The current thread must have an IO loop |
+ // (for base::files::FilePathWatcher). |
+ DnsConfigService() {} |
+ virtual ~DnsConfigService() {} |
+ |
+ virtual void AddObserver(Observer* observer) = 0; |
+ virtual void RemoveObserver(Observer* observer) = 0; |
+ |
+ const DnsConfig& dns_config() { |
+ return dns_config_; |
+ } |
+ |
+ protected: |
cbentzel
2011/08/05 19:11:39
Why protected? In general I prefer public/private.
szym
2011/08/15 14:27:42
The derived class needs to set dns_config_ but I d
|
+ DnsConfig dns_config_; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(DnsConfigService); |
+}; |
+ |
+} // namespace net |
+ |
+#endif // NET_DNS_CONFIG_SERVICE_H_ |
+ |