diff options
author | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-01 06:09:30 +0000 |
---|---|---|
committer | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-01 06:09:30 +0000 |
commit | 9490734d8a4fc608b690bdbb06c97bfdc87fff22 (patch) | |
tree | 828b05d72987bc318067517215a0eb7b3c853bf9 /net/dns/dns_config_service.cc | |
parent | aae4c8d74f2367bfe9e02253cc42d3e1be07f13a (diff) | |
download | chromium_src-9490734d8a4fc608b690bdbb06c97bfdc87fff22.zip chromium_src-9490734d8a4fc608b690bdbb06c97bfdc87fff22.tar.gz chromium_src-9490734d8a4fc608b690bdbb06c97bfdc87fff22.tar.bz2 |
Revert 99135 - Refactoring and remaining work on DnsConfigService:
- Isolate WatchingFileReader for reusability and testability
- ParseHosts to parse /etc/hosts
- tests
BUG=90881
TEST=./net_unittests --gtest_filter='DnsConfig*:DnsHosts*:WatchingFileReader*'
Review URL: http://codereview.chromium.org/7753027
TBR=szym@chromium.org
Review URL: http://codereview.chromium.org/7829001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99138 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/dns/dns_config_service.cc')
-rw-r--r-- | net/dns/dns_config_service.cc | 83 |
1 files changed, 1 insertions, 82 deletions
diff --git a/net/dns/dns_config_service.cc b/net/dns/dns_config_service.cc index b3a27d7..f32f293 100644 --- a/net/dns/dns_config_service.cc +++ b/net/dns/dns_config_service.cc @@ -4,8 +4,6 @@ #include "net/dns/dns_config_service.h" -#include "base/file_util.h" -#include "net/base/io_buffer.h" #include "net/base/ip_endpoint.h" namespace net { @@ -20,7 +18,7 @@ DnsConfig::DnsConfig() DnsConfig::~DnsConfig() {} -bool DnsConfig::EqualsIgnoreHosts(const DnsConfig& d) const { +bool DnsConfig::Equals(const DnsConfig& d) const { return (nameservers == d.nameservers) && (search == d.search) && (ndots == d.ndots) && @@ -30,84 +28,5 @@ bool DnsConfig::EqualsIgnoreHosts(const DnsConfig& d) const { (edns0 == d.edns0); } -bool DnsConfig::Equals(const DnsConfig& d) const { - return EqualsIgnoreHosts(d) && (hosts == d.hosts); -} - -DnsConfigService::DnsConfigService() - : have_config_(false), - have_hosts_(false) {} - -DnsConfigService::~DnsConfigService() {} - -void DnsConfigService::AddObserver(Observer* observer) { - DCHECK(CalledOnValidThread()); - observers_.AddObserver(observer); - if (have_config_ && have_hosts_) { - observer->OnConfigChanged(dns_config_); - } -} - -void DnsConfigService::RemoveObserver(Observer* observer) { - DCHECK(CalledOnValidThread()); - observers_.RemoveObserver(observer); -} - -void DnsConfigService::OnConfigRead(const DnsConfig& config) { - DCHECK(CalledOnValidThread()); - if (!config.EqualsIgnoreHosts(dns_config_)) { - DnsConfig copy = config; - copy.hosts.swap(dns_config_.hosts); - dns_config_ = copy; - have_config_ = true; - if (have_hosts_) { - FOR_EACH_OBSERVER(Observer, observers_, OnConfigChanged(dns_config_)); - } - } -} - -void DnsConfigService::OnHostsRead(const DnsHosts& hosts) { - DCHECK(CalledOnValidThread()); - if (hosts != dns_config_.hosts || !have_hosts_) { - dns_config_.hosts = hosts; - have_hosts_ = true; - if (have_config_) { - FOR_EACH_OBSERVER(Observer, observers_, OnConfigChanged(dns_config_)); - } - } -} - -DnsHostsReader::DnsHostsReader(DnsConfigService* service) - : service_(service), - success_(false) { - DCHECK(service); -} - -// Reads the contents of the file at |path| into |str| if the total length is -// less than |size|. -static bool ReadFile(const FilePath& path, int64 size, std::string* str) { - int64 sz; - if (!file_util::GetFileSize(path, &sz) || sz > size) - return false; - return file_util::ReadFileToString(path, str); -} - -void DnsHostsReader::DoRead() { - success_ = false; - std::string contents; - const int64 kMaxHostsSize = 1 << 16; - if (ReadFile(get_path(), kMaxHostsSize, &contents)) { - success_ = true; - ParseHosts(contents, &dns_hosts_); - } -} - -void DnsHostsReader::OnReadFinished() { - if (success_) - service_->OnHostsRead(dns_hosts_); -} - -DnsHostsReader::~DnsHostsReader() {} - } // namespace net |