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 #include "net/base/net_util.h" | |
16 | |
17 namespace net { | |
18 | |
19 class IPEndPoint; | |
20 | |
21 // DnsConfig stores configuration of the system resolver. | |
22 // To be used with AsyncHostResolver. | |
cbentzel
2011/08/04 18:09:27
Nit: Remove the comment about "To be used with Asy
szym
2011/08/04 18:55:10
Done.
cbentzel
2011/08/05 13:01:25
It doesn't look like you uploaded a patch with thi
| |
23 // TODO(szym): determine the next query for a given host according to settings. | |
cbentzel
2011/08/04 18:09:27
What is this TODO about?
szym
2011/08/04 18:55:10
Options |ndots| and |search| determine a sequence
| |
24 struct DnsConfig { | |
25 // resolv.conf stuff -- standard on POSIX/glibc systems | |
cbentzel
2011/08/04 18:09:27
Nit: I'd remove this comment as it's intended to b
szym
2011/08/04 18:55:10
Done.
| |
26 // win stores a subset of those in the registry | |
27 | |
28 DnsConfig() | |
29 : ndots(1), | |
30 timeout(5), // see resolv.h RES_TIMEOUT | |
31 attempts(2), // see resolv.h RES_DFLRETRY | |
32 rotate(false), | |
33 edns0(false) {} | |
34 | |
35 // list of name server addresses | |
cbentzel
2011/08/04 18:09:27
General issue throughout this CL - the comments do
szym
2011/08/04 18:55:10
Done.
| |
36 std::vector<IPEndPoint> nameservers; | |
37 // suffix search list, overrides |domain|, | |
38 // used on first lookup when #dots in given name < |ndots| | |
39 std::vector<std::string> search; | |
40 // use only if |search| is empty | |
41 std::string domain; | |
42 | |
43 // options; see man resolv.conf | |
44 // min. number of dots before global resolution precedes |search| | |
45 int ndots; | |
46 // in seconds between retransmissions, see res_state.retrans | |
47 int timeout; | |
48 // max. number of retries, see res_state.retry | |
49 int attempts; | |
50 // round robin in |nameservers| | |
51 bool rotate; | |
52 // enable EDNS0 | |
53 bool edns0; | |
54 | |
55 // /etc/hosts stuff | |
56 // NOTE: HostCache stores these in reverse order: hostname -> AddressList | |
57 std::map<IPAddressNumber, std::list<std::string> > hosts; | |
cbentzel
2011/08/04 18:09:27
This isn't filled in right now - I'd remove until
szym
2011/08/04 18:55:10
Done.
| |
58 | |
59 // so that we only notify on real change | |
60 bool operator==(const DnsConfig& d) const { | |
cbentzel
2011/08/04 18:09:27
Style guide explicitly is against using operator==
szym
2011/08/04 18:55:10
Done.
| |
61 return (nameservers == d.nameservers) && | |
62 (search == d.search) && | |
63 (domain == d.domain) && | |
64 (ndots == d.ndots) && | |
65 (timeout == d.timeout) && | |
66 (attempts == d.attempts) && | |
67 (rotate == d.rotate) && | |
68 (edns0 == d.edns0); | |
69 } | |
70 | |
71 bool operator!=(const DnsConfig& d) const { | |
72 return !(*this == d); | |
73 } | |
74 }; | |
75 | |
76 // DnsConfigService fetches system DNS configuration as DnsConfig | |
cbentzel
2011/08/04 18:09:27
Nit: period at the end.
Maybe clearer to document
szym
2011/08/04 18:55:10
Done.
| |
77 // Depending on the platform, watches files in /etc/ or win registry. | |
78 class DnsConfigService { | |
79 public: | |
80 // Callback interface for the client. The delegate is called on the same | |
cbentzel
2011/08/04 18:09:27
You mentioned using an observer approach before -
szym
2011/08/04 18:55:10
Are we talking about just a name change? Delegate
cbentzel
2011/08/04 20:01:21
No - actually do an AddObserver/RemoveObserver on
| |
81 // thread as Watch(). Delegate must outlive the service. | |
82 class Delegate { | |
83 public: | |
84 virtual ~Delegate() {} | |
85 | |
86 // Called only when |dns_config| is different from the last check. | |
87 virtual void OnConfigChanged(const DnsConfig& dns_config) = 0; | |
88 | |
89 // Called when config could not be accessed/parsed. | |
90 virtual void OnConfigError() = 0; | |
cbentzel
2011/08/04 18:09:27
CONCERN: Does this actually need to be escalated a
szym
2011/08/04 18:55:10
The a) and b) conditions for OnConfigChanged are a
cbentzel
2011/08/04 20:01:21
Yeah.
| |
91 }; | |
92 | |
93 // Creates the platform-specific DnsConfigService. | |
94 static DnsConfigService* CreateSystemService(); | |
95 | |
96 DnsConfigService() {} | |
97 virtual ~DnsConfigService() {} | |
98 | |
99 // Starts watching system configuration for changes. Also attempts to read the | |
100 // configuration immediately and pass the result to |delegate|. | |
101 // NOTE: Call at most once. The current thread must have an IO loop | |
102 // (for base::files::FilePathWatcher). | |
103 virtual bool Watch(Delegate* delegate) = 0; | |
104 | |
105 private: | |
106 DISALLOW_COPY_AND_ASSIGN(DnsConfigService); | |
107 }; | |
108 | |
109 } // namespace net | |
110 | |
111 #endif // NET_DNS_CONFIG_SERVICE_H_ | |
112 | |
OLD | NEW |