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

Unified 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: Addressing lint errors. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/dns/dns_config_service_posix.h » ('j') | net/dns/dns_config_service_posix.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..79ea62fabba14a728483f9be2ae07505473f52dc
--- /dev/null
+++ b/net/dns/dns_config_service.h
@@ -0,0 +1,105 @@
+// 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_
cbentzel 2011/08/15 18:16:34 This needs to be NET_DNS_DNS_CONFIG_SERVICE_H fo
szym 2011/08/15 22:02:01 Done.
+#define NET_DNS_CONFIG_SERVICE_H_
+#pragma once
+
+#include <list>
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/time.h"
+#include "net/base/net_api.h"
+#include "net/base/net_util.h"
cbentzel 2011/08/15 18:16:34 Do you need the net_util.h include?
szym 2011/08/15 22:02:01 Done.
+
+namespace net {
+
+class IPEndPoint;
+
+// DnsConfig stores configuration of the system resolver.
+struct DnsConfig {
cbentzel 2011/08/15 18:16:34 This will need to be NET_EXPORT_PRIVATE for unit t
szym 2011/08/15 22:02:01 Done.
+ // Default values are taken from glibc resolv.h.
+ DnsConfig()
+ : ndots(1),
+ timeout(base::TimeDelta::FromSeconds(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.
+
+ // Minimum number of dots before global resolution precedes |search|.
+ int ndots;
+ // Time between retransmissions, see res_state.retrans.
+ base::TimeDelta timeout;
+ // Maximum 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 {
cbentzel 2011/08/15 18:16:34 Nit: methods are ordered before variables. http:/
cbentzel 2011/08/15 18:16:34 I'm also not sure if this should be inlined, as it
szym 2011/08/15 22:02:01 Done.
+ 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 {
cbentzel 2011/08/15 18:16:34 This will also need to be NET_EXPORT_PRIVATE for u
szym 2011/08/15 22:02:01 Done.
+ 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();
+
+ DnsConfigService() {}
+ virtual ~DnsConfigService() {}
+
+ // Immediately starts watching system configuration for changes and attempts
+ // to read the configuration. For some platform implementations, the current
+ // thread must have an IO loop (for base::files::FilePathWatcher).
+ virtual void Watch() = 0;
+
+ // If a config is available, |observer| will immediately be called with
+ // OnConfigChanged.
+ virtual void AddObserver(Observer* observer) = 0;
+ virtual void RemoveObserver(Observer* observer) = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DnsConfigService);
+};
+
+} // namespace net
+
+#endif // NET_DNS_CONFIG_SERVICE_H_
+
« no previous file with comments | « no previous file | net/dns/dns_config_service_posix.h » ('j') | net/dns/dns_config_service_posix.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698