OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_DNS_DNS_CLIENT_H_ |
| 6 #define NET_DNS_DNS_CLIENT_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "net/base/net_export.h" |
| 15 |
| 16 namespace base { |
| 17 class StringPiece; |
| 18 } |
| 19 |
| 20 namespace net { |
| 21 |
| 22 class BoundNetLog; |
| 23 class ClientSocketFactory; |
| 24 class DnsResponse; |
| 25 class DnsSession; |
| 26 |
| 27 // DnsClient performs asynchronous DNS queries. DnsClient takes care of |
| 28 // retransmissions, DNS server fallback (or round-robin), suffix search, and |
| 29 // simple response validation ("does it match the query") to fight poisoning. |
| 30 // It does NOT perform caching, aggregation or prioritization of requests. |
| 31 // |
| 32 // Destroying DnsClient does NOT affect any already created Requests. |
| 33 // |
| 34 // TODO(szym): consider adding flags to MakeRequest to indicate options: |
| 35 // -- don't perform suffix search |
| 36 // -- query both A and AAAA at once |
| 37 // -- accept truncated response (and/or forbid TCP) |
| 38 class NET_EXPORT_PRIVATE DnsClient { |
| 39 public: |
| 40 class Request; |
| 41 // Callback for complete requests. Note that DnsResponse might be NULL if |
| 42 // the DNS server(s) could not be reached. |
| 43 typedef base::Callback<void(Request* req, |
| 44 int result, |
| 45 const DnsResponse* resp)> RequestCallback; |
| 46 |
| 47 // A data-holder for a request made to the DnsClient. |
| 48 // Destroying the request cancels the underlying network effort. |
| 49 class NET_EXPORT_PRIVATE Request { |
| 50 public: |
| 51 Request(const base::StringPiece& qname, |
| 52 uint16 qtype, |
| 53 const RequestCallback& callback); |
| 54 virtual ~Request(); |
| 55 |
| 56 const std::string& qname() const { return qname_; } |
| 57 |
| 58 uint16 qtype() const { return qtype_; } |
| 59 |
| 60 virtual int Start() = 0; |
| 61 |
| 62 void DoCallback(int result, const DnsResponse* response) { |
| 63 callback_.Run(this, result, response); |
| 64 } |
| 65 |
| 66 private: |
| 67 std::string qname_; |
| 68 uint16 qtype_; |
| 69 RequestCallback callback_; |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(Request); |
| 72 }; |
| 73 |
| 74 virtual ~DnsClient() {} |
| 75 |
| 76 // Makes asynchronous DNS query for the given |qname| and |qtype| (assuming |
| 77 // QCLASS == IN). The caller is responsible for destroying the returned |
| 78 // request whether to cancel it or after its completion. |
| 79 // (Destroying DnsClient does not abort the requests.) |
| 80 virtual Request* CreateRequest( |
| 81 const base::StringPiece& qname, |
| 82 uint16 qtype, |
| 83 const RequestCallback& callback, |
| 84 const BoundNetLog& source_net_log) WARN_UNUSED_RESULT = 0; |
| 85 |
| 86 // Creates a socket-based DnsClient using the |session|. |
| 87 static DnsClient* CreateClient(DnsSession* session) WARN_UNUSED_RESULT; |
| 88 }; |
| 89 |
| 90 } // namespace net |
| 91 |
| 92 #endif // NET_DNS_DNS_CLIENT_H_ |
| 93 |
OLD | NEW |