diff options
Diffstat (limited to 'net/dns/dns_config_service.h')
-rw-r--r-- | net/dns/dns_config_service.h | 67 |
1 files changed, 11 insertions, 56 deletions
diff --git a/net/dns/dns_config_service.h b/net/dns/dns_config_service.h index 6ceeaa6..535dcc1 100644 --- a/net/dns/dns_config_service.h +++ b/net/dns/dns_config_service.h @@ -6,20 +6,16 @@ #define NET_DNS_DNS_CONFIG_SERVICE_H_ #pragma once -#include <map> #include <string> #include <vector> -#include "base/gtest_prod_util.h" -#include "base/observer_list.h" #include "base/time.h" -#include "net/base/ip_endpoint.h" // win requires size of IPEndPoint #include "net/base/net_export.h" -#include "net/dns/dns_hosts.h" -#include "net/dns/watching_file_reader.h" namespace net { +class IPEndPoint; + // DnsConfig stores configuration of the system resolver. struct NET_EXPORT_PRIVATE DnsConfig { DnsConfig(); @@ -27,9 +23,7 @@ struct NET_EXPORT_PRIVATE DnsConfig { bool Equals(const DnsConfig& d) const; - bool EqualsIgnoreHosts(const DnsConfig& d) const; - - bool IsValid() const { + bool Valid() const { return !nameservers.empty(); } @@ -39,12 +33,9 @@ struct NET_EXPORT_PRIVATE DnsConfig { // is less than |ndots|. std::vector<std::string> search; - DnsHosts hosts; - // Resolver options; see man resolv.conf. // TODO(szym): use |ndots| and |search| to determine the sequence of FQDNs // to query given a specific name. - // TODO(szym): implement DNS Devolution for windows // Minimum number of dots before global resolution precedes |search|. int ndots; @@ -58,11 +49,9 @@ struct NET_EXPORT_PRIVATE DnsConfig { bool edns0; }; - // Service for watching when the system DNS settings have changed. // Depending on the platform, watches files in /etc/ or win registry. -class NET_EXPORT_PRIVATE DnsConfigService - : NON_EXPORTED_BASE(public base::NonThreadSafe) { +class NET_EXPORT_PRIVATE DnsConfigService { public: // Callback interface for the client. The observer is called on the same // thread as Watch(). Observer must outlive the service. @@ -70,62 +59,28 @@ class NET_EXPORT_PRIVATE DnsConfigService public: virtual ~Observer() {} - // Called only when |dns_config| is different from the last call. + // 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(); + 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() {} + virtual void Watch() = 0; // If a config is available, |observer| will immediately be called with // OnConfigChanged. - void AddObserver(Observer* observer); - void RemoveObserver(Observer* observer); - - protected: - FRIEND_TEST_ALL_PREFIXES(DnsConfigServiceTest, NotifyOnChange); - friend class DnsHostsReader; - // To be called with new config. |config|.hosts is ignored. - virtual void OnConfigRead(const DnsConfig& config); - // To be called with new hosts. Rest of the config is assumed unchanged. - virtual void OnHostsRead(const DnsHosts& hosts); - - DnsConfig dns_config_; - // True after first OnConfigRead and OnHostsRead; indicate complete config. - bool have_config_; - bool have_hosts_; - - ObserverList<Observer> observers_; - private: - DISALLOW_COPY_AND_ASSIGN(DnsConfigService); -}; - -// A WatchingFileReader that reads a HOSTS file and notifies -// DnsConfigService::OnHostsRead(). -class DnsHostsReader : public WatchingFileReader { - public: - explicit DnsHostsReader(DnsConfigService* service); - - virtual void DoRead() OVERRIDE; - virtual void OnReadFinished() OVERRIDE; + virtual void AddObserver(Observer* observer) = 0; + virtual void RemoveObserver(Observer* observer) = 0; private: - virtual ~DnsHostsReader(); - - DnsConfigService* service_; - // Written in DoRead, read in OnReadFinished, no locking necessary. - DnsHosts dns_hosts_; - bool success_; - - DISALLOW_COPY_AND_ASSIGN(DnsHostsReader); + DISALLOW_COPY_AND_ASSIGN(DnsConfigService); }; } // namespace net |