Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_DNS_CONFIG_SERVICE_H_ | |
| 6 #define NET_DNS_CONFIG_SERVICE_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <list> | |
| 10 #include <map> | |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "net/base/net_api.h" | |
| 15 | |
| 16 namespace net { | |
| 17 | |
| 18 class IPEndPoint; | |
| 19 | |
| 20 // DnsConfig stores configuration of the system resolver. | |
| 21 // To be used with AsyncHostResolver. | |
| 22 // TODO(szym): determine the next query for a given host according to settings. | |
| 23 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.
| |
| 24 public: | |
|
cbentzel
2011/08/01 19:52:26
Nit: public by default on structs.
szym
2011/08/01 20:22:01
Done.
| |
| 25 // resolv.conf stuff -- standard on POSIX/glibc systems | |
| 26 // 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.
| |
| 27 | |
| 28 // list of name server addresses | |
| 29 std::vector<IPEndPoint> nameservers; | |
| 30 // suffix search list, overrides |domain|, | |
| 31 // used on first lookup when #dots in given name < |ndots| | |
| 32 std::vector<std::string> search; | |
| 33 // use only if |search| is empty | |
| 34 std::string domain; | |
| 35 | |
| 36 // options; see man resolv.conf | |
| 37 // min. number of dots before global resolution precedes |search| | |
| 38 int ndots; | |
| 39 // in seconds between retransmissions | |
| 40 int timeout; | |
| 41 // max. number of retries | |
| 42 int attempts; | |
| 43 // round robin in |nameservers| | |
| 44 bool rotate; | |
| 45 // enable EDNS0 | |
| 46 bool edns0; | |
| 47 | |
| 48 // /etc/hosts stuff | |
| 49 // NOTE: HostCache stores these in reverse order: hostname -> AddressList | |
| 50 std::map<IPAddressNumber, std::list<std::string> > hosts; | |
| 51 | |
| 52 // 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
| |
| 53 bool operator==(const DnsConfig& d) const { | |
| 54 return (nameservers == d.nameservers) && | |
| 55 (search == d.search) && | |
| 56 (domain == d.domain) && | |
| 57 (ndots == d.ndots) && | |
| 58 (timeout == d.timeout) && | |
| 59 (attempts == d.attempts) && | |
| 60 (rotate == d.rotate) && | |
| 61 (edns0 == d.edns0); | |
| 62 } | |
| 63 | |
| 64 bool operator!=(const DnsConfig& d) const { | |
| 65 return !(*this == d); | |
| 66 } | |
| 67 }; | |
| 68 | |
| 69 // 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
| |
| 70 class NET_API DnsConfigReader { | |
| 71 public: | |
| 72 virtual bool Read(DnsConfig*) = 0; // blocking | |
| 73 }; | |
| 74 | |
| 75 // DnsConfigService fetches system DNS configuration as DnsConfig | |
| 76 // Depending on the platform, watches files in /etc/ or win registry. | |
| 77 class NET_API DnsConfigService { | |
| 78 public: | |
| 79 // Callback interface for the client. The delegate is called on the same | |
| 80 // thread as Watch(). Delegate must outlive the service. | |
| 81 class Delegate { | |
| 82 public: | |
| 83 virtual ~Delegate() {} | |
| 84 | |
| 85 // Called only when |dns_config| is different from the last check. | |
| 86 virtual void OnConfigChanged(const DnsConfig& dns_config) = 0; | |
| 87 | |
| 88 // Called when config could not be accessed/parsed. | |
| 89 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::
| |
| 90 }; | |
| 91 | |
| 92 // Creates the platform-specific DnsConfigService. | |
| 93 static DnsConfigService* CreateSystemService(); | |
| 94 | |
| 95 DnsConfigService() {} | |
| 96 virtual ~DnsConfigService() {} | |
| 97 | |
| 98 // Starts watching system configuration for changes. Call at most once. | |
| 99 // The current thread must have an IO loop (for base::files::FilePathWatcher). | |
| 100 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
| |
| 101 | |
| 102 private: | |
| 103 DISALLOW_COPY_AND_ASSIGN(DnsConfigService); | |
| 104 }; | |
| 105 | |
| 106 } // namespace net | |
| 107 | |
| 108 #endif // NET_DNS_CONFIG_SERVICE_H_ | |
| 109 | |
| OLD | NEW |