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

Unified Diff: net/dns/dns_config_watcher_posix.cc

Issue 10873018: [net] Move DnsConfigService to NetworkChangeNotifier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add comment Created 8 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 | « net/dns/dns_config_watcher.h ('k') | net/dns/dns_config_watcher_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_config_watcher_posix.cc
diff --git a/net/dns/dns_config_watcher_posix.cc b/net/dns/dns_config_watcher_posix.cc
deleted file mode 100644
index 3c0d118d464e2c0ef3a42fa33ef3dfe416854122..0000000000000000000000000000000000000000
--- a/net/dns/dns_config_watcher_posix.cc
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "net/dns/dns_config_watcher.h"
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/bind.h"
-#include "base/callback.h"
-#include "base/files/file_path_watcher.h"
-#include "base/file_path.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "net/base/network_change_notifier.h"
-
-#if defined(OS_MACOSX)
-#include "net/dns/notify_watcher_mac.h"
-#endif
-
-namespace net {
-namespace internal {
-
-namespace {
-
-const FilePath::CharType* kFilePathHosts = FILE_PATH_LITERAL("/etc/hosts");
-
-#if defined(OS_MACOSX)
-// From 10.7.3 configd-395.10/dnsinfo/dnsinfo.h
-static const char* kDnsNotifyKey =
- "com.apple.system.SystemConfiguration.dns_configuration";
-
-class ConfigWatcher {
- public:
- bool Watch(const base::Callback<void(bool succeeded)>& callback) {
- return watcher_.Watch(kDnsNotifyKey, callback);
- }
-
- private:
- NotifyWatcherMac watcher_;
-};
-#else
-
-#ifndef _PATH_RESCONF // Normally defined in <resolv.h>
-#define _PATH_RESCONF "/etc/resolv.conf"
-#endif
-
-static const FilePath::CharType* kFilePathConfig =
- FILE_PATH_LITERAL(_PATH_RESCONF);
-
-class ConfigWatcher {
- public:
- typedef base::Callback<void(bool succeeded)> CallbackType;
-
- bool Watch(const CallbackType& callback) {
- callback_ = callback;
- return watcher_.Watch(FilePath(kFilePathConfig),
- base::Bind(&ConfigWatcher::OnCallback,
- base::Unretained(this)));
- }
-
- private:
- void OnCallback(const FilePath& path, bool error) {
- callback_.Run(!error);
- }
-
- base::files::FilePathWatcher watcher_;
- CallbackType callback_;
-};
-#endif
-
-} // namespace
-
-class DnsConfigWatcher::Core {
- public:
- Core() {}
- ~Core() {}
-
- bool Watch() {
- bool success = true;
- if (!config_watcher_.Watch(base::Bind(&Core::OnConfigChanged,
- base::Unretained(this)))) {
- LOG(ERROR) << "DNS config watch failed to start.";
- success = false;
- }
- if (!hosts_watcher_.Watch(FilePath(kFilePathHosts),
- base::Bind(&Core::OnHostsChanged,
- base::Unretained(this)))) {
- LOG(ERROR) << "DNS hosts watch failed to start.";
- success = false;
- }
- return success;
- }
-
- private:
- void OnConfigChanged(bool succeeded) {
- if (succeeded) {
- NetworkChangeNotifier::NotifyObserversOfDNSChange(
- NetworkChangeNotifier::CHANGE_DNS_SETTINGS);
- } else {
- LOG(ERROR) << "DNS config watch failed.";
- NetworkChangeNotifier::NotifyObserversOfDNSChange(
- NetworkChangeNotifier::CHANGE_DNS_WATCH_FAILED);
- }
- }
-
- void OnHostsChanged(const FilePath& path, bool error) {
- if (!error) {
- NetworkChangeNotifier::NotifyObserversOfDNSChange(
- NetworkChangeNotifier::CHANGE_DNS_HOSTS);
- } else {
- LOG(ERROR) << "DNS hosts watch failed.";
- NetworkChangeNotifier::NotifyObserversOfDNSChange(
- NetworkChangeNotifier::CHANGE_DNS_WATCH_FAILED);
- }
- }
-
- ConfigWatcher config_watcher_;
- base::files::FilePathWatcher hosts_watcher_;
-
- DISALLOW_COPY_AND_ASSIGN(Core);
-};
-
-DnsConfigWatcher::DnsConfigWatcher() {}
-
-DnsConfigWatcher::~DnsConfigWatcher() {}
-
-void DnsConfigWatcher::Init() {
- core_.reset(new Core());
- if (core_->Watch()) {
- NetworkChangeNotifier::NotifyObserversOfDNSChange(
- NetworkChangeNotifier::CHANGE_DNS_WATCH_STARTED);
- }
- // TODO(szym): re-start watcher if that makes sense. http://crbug.com/116139
-}
-
-void DnsConfigWatcher::CleanUp() {
- core_.reset();
-}
-
-} // namespace internal
-} // namespace net
« no previous file with comments | « net/dns/dns_config_watcher.h ('k') | net/dns/dns_config_watcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698