| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/dns/dns_config_service_posix.h" | 5 #include "net/dns/dns_config_service_posix.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 return CONFIG_PARSE_POSIX_OK; | 196 return CONFIG_PARSE_POSIX_OK; |
| 197 } | 197 } |
| 198 #endif | 198 #endif |
| 199 | 199 |
| 200 } // namespace | 200 } // namespace |
| 201 | 201 |
| 202 class DnsConfigServicePosix::Watcher { | 202 class DnsConfigServicePosix::Watcher { |
| 203 public: | 203 public: |
| 204 explicit Watcher(DnsConfigServicePosix* service) | 204 explicit Watcher(DnsConfigServicePosix* service) |
| 205 : weak_factory_(this), | 205 : service_(service), |
| 206 service_(service) {} | 206 weak_factory_(this) {} |
| 207 ~Watcher() {} | 207 ~Watcher() {} |
| 208 | 208 |
| 209 bool Watch() { | 209 bool Watch() { |
| 210 bool success = true; | 210 bool success = true; |
| 211 if (!config_watcher_.Watch(base::Bind(&Watcher::OnConfigChanged, | 211 if (!config_watcher_.Watch(base::Bind(&Watcher::OnConfigChanged, |
| 212 base::Unretained(this)))) { | 212 base::Unretained(this)))) { |
| 213 LOG(ERROR) << "DNS config watch failed to start."; | 213 LOG(ERROR) << "DNS config watch failed to start."; |
| 214 success = false; | 214 success = false; |
| 215 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.WatchStatus", | 215 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.WatchStatus", |
| 216 DNS_CONFIG_WATCH_FAILED_TO_START_CONFIG, | 216 DNS_CONFIG_WATCH_FAILED_TO_START_CONFIG, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 239 succeeded), | 239 succeeded), |
| 240 kDelay); | 240 kDelay); |
| 241 } | 241 } |
| 242 void OnConfigChangedDelayed(bool succeeded) { | 242 void OnConfigChangedDelayed(bool succeeded) { |
| 243 service_->OnConfigChanged(succeeded); | 243 service_->OnConfigChanged(succeeded); |
| 244 } | 244 } |
| 245 void OnHostsChanged(const base::FilePath& path, bool error) { | 245 void OnHostsChanged(const base::FilePath& path, bool error) { |
| 246 service_->OnHostsChanged(!error); | 246 service_->OnHostsChanged(!error); |
| 247 } | 247 } |
| 248 | 248 |
| 249 base::WeakPtrFactory<Watcher> weak_factory_; | |
| 250 DnsConfigServicePosix* service_; | 249 DnsConfigServicePosix* service_; |
| 251 DnsConfigWatcher config_watcher_; | 250 DnsConfigWatcher config_watcher_; |
| 252 base::FilePathWatcher hosts_watcher_; | 251 base::FilePathWatcher hosts_watcher_; |
| 253 | 252 |
| 253 base::WeakPtrFactory<Watcher> weak_factory_; |
| 254 |
| 254 DISALLOW_COPY_AND_ASSIGN(Watcher); | 255 DISALLOW_COPY_AND_ASSIGN(Watcher); |
| 255 }; | 256 }; |
| 256 | 257 |
| 257 // A SerialWorker that uses libresolv to initialize res_state and converts | 258 // A SerialWorker that uses libresolv to initialize res_state and converts |
| 258 // it to DnsConfig (except on Android, where it reads system properties | 259 // it to DnsConfig (except on Android, where it reads system properties |
| 259 // net.dns1 and net.dns2; see #if around ReadDnsConfig above.) | 260 // net.dns1 and net.dns2; see #if around ReadDnsConfig above.) |
| 260 class DnsConfigServicePosix::ConfigReader : public SerialWorker { | 261 class DnsConfigServicePosix::ConfigReader : public SerialWorker { |
| 261 public: | 262 public: |
| 262 explicit ConfigReader(DnsConfigServicePosix* service) | 263 explicit ConfigReader(DnsConfigServicePosix* service) |
| 263 : service_(service), success_(false) {} | 264 : service_(service), success_(false) {} |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 #endif // !defined(OS_ANDROID) | 490 #endif // !defined(OS_ANDROID) |
| 490 | 491 |
| 491 } // namespace internal | 492 } // namespace internal |
| 492 | 493 |
| 493 // static | 494 // static |
| 494 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() { | 495 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() { |
| 495 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServicePosix()); | 496 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServicePosix()); |
| 496 } | 497 } |
| 497 | 498 |
| 498 } // namespace net | 499 } // namespace net |
| OLD | NEW |