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

Unified Diff: net/dns/dns_client.cc

Issue 9667025: [net/dns] Serve requests from HOSTS file if possible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added NumberOfAddresses checks. Created 8 years, 9 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_client.h ('k') | net/dns/dns_test_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_client.cc
diff --git a/net/dns/dns_client.cc b/net/dns/dns_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5381452f9e2c2713c7cd83d797f553eb10d2eac0
--- /dev/null
+++ b/net/dns/dns_client.cc
@@ -0,0 +1,58 @@
+// 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_client.h"
+
+#include "base/bind.h"
+#include "base/rand_util.h"
+#include "net/base/net_log.h"
+#include "net/dns/dns_config_service.h"
+#include "net/dns/dns_session.h"
+#include "net/dns/dns_transaction.h"
+#include "net/socket/client_socket_factory.h"
+
+namespace net {
+
+namespace {
+
+class DnsClientImpl : public DnsClient {
+ public:
+ explicit DnsClientImpl(NetLog* net_log) : net_log_(net_log) {}
+
+ virtual void SetConfig(const DnsConfig& config) OVERRIDE {
+ factory_.reset();
+ session_.release();
+ if (config.IsValid()) {
+ session_ = new DnsSession(config,
+ ClientSocketFactory::GetDefaultFactory(),
+ base::Bind(&base::RandInt),
+ net_log_);
+ factory_ = DnsTransactionFactory::CreateFactory(session_);
+ }
+ }
+
+ virtual const DnsConfig* GetConfig() const OVERRIDE {
+ return session_.get() ? &session_->config() : NULL;
+ }
+
+ virtual DnsTransactionFactory* GetTransactionFactory() OVERRIDE {
+ return session_.get() ? factory_.get() : NULL;
+ }
+
+ private:
+ scoped_refptr<DnsSession> session_;
+ scoped_ptr<DnsTransactionFactory> factory_;
+
+ NetLog* net_log_;
+};
+
+} // namespace
+
+// static
+scoped_ptr<DnsClient> DnsClient::CreateClient(NetLog* net_log) {
+ return scoped_ptr<DnsClient>(new DnsClientImpl(net_log));
+}
+
+} // namespace net
+
« no previous file with comments | « net/dns/dns_client.h ('k') | net/dns/dns_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698