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

Side by Side Diff: net/dns/dns_client.h

Issue 8762001: Isolates generic DnsClient from AsyncHostResolver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "base/string_piece.h"
15 #include "net/base/net_export.h"
16 #include "net/dns/dns_config_service.h"
17
18 namespace net {
19
20 class BoundNetLog;
21 class ClientSocketFactory;
22 class DnsResponse;
23 class DnsSession;
24
25 // DnsClient performs asynchronous DNS queries. DnsClient takes care of
26 // retransmissions, DNS server fallback (or round-robin), suffix search, and
27 // simple response validation ("does it match the query") to fight poisoning.
28 // It does NOT perform caching, aggregation or prioritization of requests.
29 //
30 // Destroying DnsClient does NOT affect any already created Requests.
31 //
32 // TODO(szym): consider adding flags to MakeRequest to indicate options:
33 // -- don't perform suffix search
34 // -- query both A and AAAA at once
35 // -- accept truncated response (and/or forbid TCP)
36 class NET_EXPORT_PRIVATE DnsClient {
37 public:
38 class Request;
39 // Callback for complete requests. Note that DnsResponse might be NULL if
40 // the DNS server(s) could not be reached.
41 typedef base::Callback<void(Request* req,
42 int result,
43 const DnsResponse* resp)> RequestCallback;
44
45 // A data-holder for a request made to the DnsClient.
46 // Destroying the request cancels the underlying network effort.
47 class NET_EXPORT_PRIVATE Request {
48 public:
49 Request(const base::StringPiece& qname,
50 uint16 qtype,
51 const RequestCallback& callback);
52 virtual ~Request();
53
54 const std::string& qname() const { return qname_; }
55
56 uint16 qtype() const { return qtype_; }
57
58 virtual int Start() = 0;
59
60 void DoCallback(int result, const DnsResponse* response) {
61 callback_.Run(this, result, response);
62 }
63
64 private:
65 std::string qname_;
66 uint16 qtype_;
67 RequestCallback callback_;
68
69 DISALLOW_COPY_AND_ASSIGN(Request);
70 };
mmenke 2011/12/02 00:53:55 Could you plut a linebreak here, to visually separ
szym 2011/12/05 23:06:28 Done.
71 virtual ~DnsClient() {}
72
73 // Makes asynchronous DNS query for the given |qname| and |qtype| (assuming
74 // QCLASS == IN). The caller is responsible for destroying the returned
75 // request whether to cancel it or after its completion.
76 // (Destroying DnsClient does not abort the requests.)
77 virtual Request* CreateRequest(
78 const base::StringPiece& qname,
79 uint16 qtype,
80 const RequestCallback& callback,
81 const BoundNetLog& source_net_log) WARN_UNUSED_RESULT = 0;
82
83 // Creates a socket-based DnsClient using the |session|.
84 static DnsClient* CreateClient(DnsSession* session) WARN_UNUSED_RESULT;
85 };
86
87 } // namespace net
88
89 #endif // NET_DNS_DNS_CLIENT_H_
90
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698