summaryrefslogtreecommitdiffstats
path: root/net/dns/dns_hosts.h
diff options
context:
space:
mode:
authorszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 17:13:11 +0000
committerszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 17:13:11 +0000
commitb4481b2296ce6035e52db00c8011cf20c165d7b6 (patch)
tree6a5b751c14fdc713b4ae76e407ac29c82d9f1df5 /net/dns/dns_hosts.h
parente1c39ae523ad5cce2f6d8d9e0dd177c2d5358676 (diff)
downloadchromium_src-b4481b2296ce6035e52db00c8011cf20c165d7b6.zip
chromium_src-b4481b2296ce6035e52db00c8011cf20c165d7b6.tar.gz
chromium_src-b4481b2296ce6035e52db00c8011cf20c165d7b6.tar.bz2
[net/dns] Refactoring of DnsConfigService.
- Replaces Observer with Callback. - The Callback is run within 100ms of any config change, not only on successful read. It is also run on errors in watches (registry and files). This allows HostResolverImpl to withdraw from using DnsTask until DnsConfig is read successfully. - Moves DnsHostsReader to dns_hosts.{h,cc}). - Handles missing HOSTS files. - Respects network adapter binding order in DnsConfigServiceWin. - Adds NetLog source for DnsConfig-related events. BUG=112856, 115460, 115494 TEST=./net_unittests --gtest_filter=DnsConfig* Review URL: http://codereview.chromium.org/9597029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127190 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/dns/dns_hosts.h')
-rw-r--r--net/dns/dns_hosts.h31
1 files changed, 30 insertions, 1 deletions
diff --git a/net/dns/dns_hosts.h b/net/dns/dns_hosts.h
index fda7733..91c35ba 100644
--- a/net/dns/dns_hosts.h
+++ b/net/dns/dns_hosts.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -11,9 +11,12 @@
#include <utility>
#include <vector>
+#include "base/callback.h"
+#include "base/file_path.h"
#include "net/base/address_family.h"
#include "net/base/net_export.h"
#include "net/base/net_util.h" // can't forward-declare IPAddressNumber
+#include "net/dns/serial_worker.h"
namespace net {
@@ -35,6 +38,32 @@ typedef std::map<DnsHostsKey, IPAddressNumber> DnsHosts;
void NET_EXPORT_PRIVATE ParseHosts(const std::string& contents,
DnsHosts* dns_hosts);
+// A SerialWorker that reads a HOSTS file and runs Callback.
+// Call WorkNow() to indicate file needs to be re-read.
+// Call Cancel() to disable the callback.
+class NET_EXPORT_PRIVATE DnsHostsReader
+ : NON_EXPORTED_BASE(public SerialWorker) {
+ public:
+ typedef base::Callback<void(const DnsHosts& hosts)> CallbackType;
+
+ DnsHostsReader(const FilePath& path, const CallbackType& callback);
+
+ private:
+ virtual ~DnsHostsReader();
+
+ virtual void DoWork() OVERRIDE;
+ virtual void OnWorkFinished() OVERRIDE;
+
+ FilePath path_;
+ CallbackType callback_;
+ // Written in DoWork, read in OnWorkFinished, no locking necessary.
+ DnsHosts dns_hosts_;
+ bool success_;
+
+ DISALLOW_COPY_AND_ASSIGN(DnsHostsReader);
+};
+
+
} // namespace net
#endif // NET_DNS_DNS_HOSTS_H_