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

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: applied review 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"
mmenke 2011/12/06 20:43:01 Can you just use a forward declaration instead of
szym 2011/12/06 21:06:43 Done.
15 #include "net/base/net_export.h"
16 #include "net/dns/dns_config_service.h"
mmenke 2011/12/06 20:43:01 Don't think this is needed.
szym 2011/12/06 21:06:43 Done.
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 };
71
72 virtual ~DnsClient() {}
73
74 // Makes asynchronous DNS query for the given |qname| and |qtype| (assuming
75 // QCLASS == IN). The caller is responsible for destroying the returned
76 // request whether to cancel it or after its completion.
77 // (Destroying DnsClient does not abort the requests.)
78 virtual Request* CreateRequest(
79 const base::StringPiece& qname,
80 uint16 qtype,
81 const RequestCallback& callback,
82 const BoundNetLog& source_net_log) WARN_UNUSED_RESULT = 0;
83
84 // Creates a socket-based DnsClient using the |session|.
85 static DnsClient* CreateClient(DnsSession* session) WARN_UNUSED_RESULT;
86 };
87
88 } // namespace net
89
90 #endif // NET_DNS_DNS_CLIENT_H_
91
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698