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

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

Issue 9190031: DnsClient refactoring + features (timeout, suffix search, server rotation). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Delinted. Created 8 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/dns/async_host_resolver_unittest.cc ('k') | net/dns/dns_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
17 namespace net {
18
19 class BoundNetLog;
20 class ClientSocketFactory;
21 class DnsResponse;
22 class DnsSession;
23
24 // DnsClient performs asynchronous DNS queries. DnsClient takes care of
25 // retransmissions, DNS server fallback (or round-robin), suffix search, and
26 // simple response validation ("does it match the query") to fight poisoning.
27 // It does NOT perform caching, aggregation or prioritization of requests.
28 //
29 // Destroying DnsClient does NOT affect any already created Requests.
30 //
31 // TODO(szym): consider adding flags to MakeRequest to indicate options:
32 // -- don't perform suffix search
33 // -- query both A and AAAA at once
34 // -- accept truncated response (and/or forbid TCP)
35 class NET_EXPORT_PRIVATE DnsClient {
36 public:
37 class Request;
38 // Callback for complete requests. Note that DnsResponse might be NULL if
39 // the DNS server(s) could not be reached.
40 typedef base::Callback<void(Request* req,
41 int result,
42 const DnsResponse* resp)> RequestCallback;
43
44 // A data-holder for a request made to the DnsClient.
45 // Destroying the request cancels the underlying network effort.
46 class NET_EXPORT_PRIVATE Request {
47 public:
48 Request(const base::StringPiece& qname,
49 uint16 qtype,
50 const RequestCallback& callback);
51 virtual ~Request();
52
53 const std::string& qname() const { return qname_; }
54
55 uint16 qtype() const { return qtype_; }
56
57 virtual int Start() = 0;
58
59 void DoCallback(int result, const DnsResponse* response) {
60 callback_.Run(this, result, response);
61 }
62
63 private:
64 std::string qname_;
65 uint16 qtype_;
66 RequestCallback callback_;
67
68 DISALLOW_COPY_AND_ASSIGN(Request);
69 };
70
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
« no previous file with comments | « net/dns/async_host_resolver_unittest.cc ('k') | net/dns/dns_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698