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..7a7c1f0612c3be817f7ccbed7d1130e43e6e8f3d |
--- /dev/null |
+++ b/net/dns/dns_config_service.h |
@@ -0,0 +1,109 @@ |
+// 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" |
+ |
+namespace net { |
+ |
+class IPEndPoint; |
+ |
+// DnsConfig stores configuration of the system resolver. |
+// To be used with AsyncHostResolver. |
+// TODO(szym): determine the next query for a given host according to settings. |
+struct NET_API DnsConfig { |
cbentzel
2011/08/01 19:52:26
I don't know if these will need NET_API - these ar
szym
2011/08/01 20:22:01
Done.
|
+ public: |
cbentzel
2011/08/01 19:52:26
Nit: public by default on structs.
szym
2011/08/01 20:22:01
Done.
|
+ // resolv.conf stuff -- standard on POSIX/glibc systems |
+ // win stores a subset of those in the registry |
cbentzel
2011/08/01 19:52:26
I'd want a default constructor due to the int/bool
szym
2011/08/01 20:22:01
Done.
|
+ |
+ // list of name server addresses |
+ std::vector<IPEndPoint> nameservers; |
+ // suffix search list, overrides |domain|, |
+ // used on first lookup when #dots in given name < |ndots| |
+ std::vector<std::string> search; |
+ // use only if |search| is empty |
+ std::string domain; |
+ |
+ // options; see man resolv.conf |
+ // min. number of dots before global resolution precedes |search| |
+ int ndots; |
+ // in seconds between retransmissions |
+ int timeout; |
+ // max. number of retries |
+ int attempts; |
+ // round robin in |nameservers| |
+ bool rotate; |
+ // enable EDNS0 |
+ bool edns0; |
+ |
+ // /etc/hosts stuff |
+ // NOTE: HostCache stores these in reverse order: hostname -> AddressList |
+ std::map<IPAddressNumber, std::list<std::string> > hosts; |
+ |
+ // so that we only notify on real change |
cbentzel
2011/08/01 19:52:26
Another style thing - we tend to avoid operator ov
szym
2011/08/01 20:22:01
This is inspired by ProxyConfig. There's a dozen o
|
+ bool operator==(const DnsConfig& d) const { |
+ return (nameservers == d.nameservers) && |
+ (search == d.search) && |
+ (domain == d.domain) && |
+ (ndots == d.ndots) && |
+ (timeout == d.timeout) && |
+ (attempts == d.attempts) && |
+ (rotate == d.rotate) && |
+ (edns0 == d.edns0); |
+ } |
+ |
+ bool operator!=(const DnsConfig& d) const { |
+ return !(*this == d); |
+ } |
+}; |
+ |
+// Reads the current config now, separate for testability |
cbentzel
2011/08/01 19:52:26
This probably doesn't need to be defined here - im
szym
2011/08/01 20:22:01
I planned a Windows implementation that reads the
|
+class NET_API DnsConfigReader { |
+ public: |
+ virtual bool Read(DnsConfig*) = 0; // blocking |
+}; |
+ |
+// DnsConfigService fetches system DNS configuration as DnsConfig |
+// Depending on the platform, watches files in /etc/ or win registry. |
+class NET_API DnsConfigService { |
+ public: |
+ // Callback interface for the client. The delegate is called on the same |
+ // thread as Watch(). Delegate must outlive the service. |
+ class Delegate { |
+ public: |
+ virtual ~Delegate() {} |
+ |
+ // Called only when |dns_config| is different from the last check. |
+ virtual void OnConfigChanged(const DnsConfig& dns_config) = 0; |
+ |
+ // Called when config could not be accessed/parsed. |
+ virtual void OnConfigError() = 0; |
cbentzel
2011/08/01 19:52:26
Does this need to be exposed? I'd remove it until
szym
2011/08/01 20:22:01
Not sure how to handle FilePathWatcher::Delegate::
|
+ }; |
+ |
+ // Creates the platform-specific DnsConfigService. |
+ static DnsConfigService* CreateSystemService(); |
+ |
+ DnsConfigService() {} |
+ virtual ~DnsConfigService() {} |
+ |
+ // Starts watching system configuration for changes. Call at most once. |
+ // The current thread must have an IO loop (for base::files::FilePathWatcher). |
+ virtual bool Watch(Delegate* delegate) = 0; |
cbentzel
2011/08/01 19:52:26
What does the return value indicate? When would th
szym
2011/08/01 20:22:01
When FilePathWatcher::Watch fails, possibly when t
|
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(DnsConfigService); |
+}; |
+ |
+} // namespace net |
+ |
+#endif // NET_DNS_CONFIG_SERVICE_H_ |
+ |