Revert 208429 "Disable AutofillQueryXmlParserTest.ParseAutofillF..."
[chromium-blink-merge.git] / net / dns / dns_transaction.h
blobedbb7a7af570b9db7e2df0350a4bc172fcfd168a
1 // Copyright (c) 2012 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.
5 #ifndef NET_DNS_DNS_TRANSACTION_H_
6 #define NET_DNS_DNS_TRANSACTION_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "net/base/net_export.h"
15 namespace net {
17 class BoundNetLog;
18 class DnsResponse;
19 class DnsSession;
21 // DnsTransaction implements a stub DNS resolver as defined in RFC 1034.
22 // The DnsTransaction takes care of retransmissions, name server fallback (or
23 // round-robin), suffix search, and simple response validation ("does it match
24 // the query") to fight poisoning.
26 // Destroying DnsTransaction cancels the underlying network effort.
27 class NET_EXPORT_PRIVATE DnsTransaction {
28 public:
29 virtual ~DnsTransaction() {}
31 // Returns the original |hostname|.
32 virtual const std::string& GetHostname() const = 0;
34 // Returns the |qtype|.
35 virtual uint16 GetType() const = 0;
37 // Starts the transaction. Returns the net error on synchronous failure or
38 // ERR_IO_PENDING in which case the result will be passed via the callback.
39 // Can be called at most once.
40 virtual int Start() = 0;
43 // Creates DnsTransaction which performs asynchronous DNS search.
44 // It does NOT perform caching, aggregation or prioritization of transactions.
46 // Destroying the factory does NOT affect any already created DnsTransactions.
47 class NET_EXPORT_PRIVATE DnsTransactionFactory {
48 public:
49 // Called with the response or NULL if no matching response was received.
50 // Note that the |GetDottedName()| of the response may be different than the
51 // original |hostname| as a result of suffix search.
52 typedef base::Callback<void(DnsTransaction* transaction,
53 int neterror,
54 const DnsResponse* response)> CallbackType;
56 virtual ~DnsTransactionFactory() {}
58 // Creates DnsTransaction for the given |hostname| and |qtype| (assuming
59 // QCLASS is IN). |hostname| should be in the dotted form. A dot at the end
60 // implies the domain name is fully-qualified and will be exempt from suffix
61 // search. |hostname| should not be an IP literal.
63 // The transaction will run |callback| upon asynchronous completion.
64 // The |net_log| is used as the parent log.
65 virtual scoped_ptr<DnsTransaction> CreateTransaction(
66 const std::string& hostname,
67 uint16 qtype,
68 const CallbackType& callback,
69 const BoundNetLog& net_log) WARN_UNUSED_RESULT = 0;
71 // Creates a DnsTransactionFactory which creates DnsTransactionImpl using the
72 // |session|.
73 static scoped_ptr<DnsTransactionFactory> CreateFactory(
74 DnsSession* session) WARN_UNUSED_RESULT;
77 } // namespace net
79 #endif // NET_DNS_DNS_TRANSACTION_H_