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

Side by Side Diff: net/dns/dns_config_service.h

Issue 7518028: DnsConfigService and a posix implementation (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Changed Delegate -> Observer(List); internal handling of Watch failures. Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/dns/dns_config_service_posix.cc » ('j') | net/dns/dns_config_service_posix.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 struct DnsConfig {
23 // Default values are taken from glibc resolv.h.
24 DnsConfig()
25 : ndots(1),
26 timeout(5),
27 attempts(2),
28 rotate(false),
29 edns0(false) {}
30
31 // List of name server addresses.
32 std::vector<IPEndPoint> nameservers;
33 // Suffix search list overrides |domain| and is used on first lookup when
34 // number of dots in given name is less than |ndots|.
35 std::vector<std::string> search;
36
37 // Resolver options; see man resolv.conf.
38 // TODO(szym): use |ndots| and |search| to determine the sequence of FQDNs
39 // to query given a specific name.
40
41 // 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.
42 int ndots;
43 // Time (in seconds) between retransmissions, see res_state.retrans.
44 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.
45 // Max. number of retries, see res_state.retry.
46 int attempts;
47 // Round robin entries in |nameservers| for subsequent requests.
48 bool rotate;
49 // Enable EDNS0 extensions.
50 bool edns0;
51
52 bool Equals(const DnsConfig& d) const {
53 return (nameservers == d.nameservers) &&
54 (search == d.search) &&
55 (ndots == d.ndots) &&
56 (timeout == d.timeout) &&
57 (attempts == d.attempts) &&
58 (rotate == d.rotate) &&
59 (edns0 == d.edns0);
60 }
61
62 bool Valid() const {
63 return !nameservers.empty();
64 }
65 };
66
67 // Service for watching when the system DNS settings have changed.
68 // Depending on the platform, watches files in /etc/ or win registry.
69 class DnsConfigService {
70 public:
71 // Callback interface for the client. The observer is called on the same
72 // thread as Watch(). Observer must outlive the service.
73 class Observer {
74 public:
75 virtual ~Observer() {}
76
77 // Called only when |dns_config| is different from the last check.
78 virtual void OnConfigChanged(const DnsConfig& dns_config) = 0;
79 };
80
81 // Creates the platform-specific DnsConfigService.
82 static DnsConfigService* CreateSystemService();
83
84 // Immediately starts watching system configuration for changes and attempts
85 // to read the configuration. The current thread must have an IO loop
86 // (for base::files::FilePathWatcher).
87 DnsConfigService() {}
88 virtual ~DnsConfigService() {}
89
90 virtual void AddObserver(Observer* observer) = 0;
91 virtual void RemoveObserver(Observer* observer) = 0;
92
93 const DnsConfig& dns_config() {
94 return dns_config_;
95 }
96
97 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
98 DnsConfig dns_config_;
99
100 private:
101 DISALLOW_COPY_AND_ASSIGN(DnsConfigService);
102 };
103
104 } // namespace net
105
106 #endif // NET_DNS_CONFIG_SERVICE_H_
107
OLDNEW
« no previous file with comments | « no previous file | net/dns/dns_config_service_posix.cc » ('j') | net/dns/dns_config_service_posix.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698