blob: 57687fdd1a6fd21b425e4f15bdc34f72748ddd56 [file] [log] [blame]
Eric Orth9871aafa2018-10-02 19:59:181// Copyright 2018 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_HOST_RESOLVER_MDNS_TASK_H_
6#define NET_DNS_HOST_RESOLVER_MDNS_TASK_H_
7
8#include <memory>
9#include <string>
10#include <vector>
11
Matt Menkec35d1632018-11-29 12:43:4912#include "base/callback_forward.h"
Eric Orth9871aafa2018-10-02 19:59:1813#include "base/containers/unique_ptr_adapters.h"
Keishi Hattori0e45c022021-11-27 09:25:5214#include "base/memory/raw_ptr.h"
Eric Orth9871aafa2018-10-02 19:59:1815#include "base/memory/weak_ptr.h"
16#include "base/sequence_checker.h"
Matt Menkec35d1632018-11-29 12:43:4917#include "net/dns/host_cache.h"
Eric Orth9871aafa2018-10-02 19:59:1818#include "net/dns/host_resolver.h"
19#include "net/dns/mdns_client.h"
Eric Orth192e3bb2018-11-14 19:30:3220#include "net/dns/public/dns_query_type.h"
Eric Orth9871aafa2018-10-02 19:59:1821
22namespace net {
23
Eric Orth026776a2019-01-18 00:13:2824class RecordParsed;
25
Eric Orth9871aafa2018-10-02 19:59:1826// Representation of a single HostResolverImpl::Job task to resolve the hostname
27// using multicast DNS transactions. Destruction cancels the task and prevents
28// any callbacks from being invoked.
29class HostResolverMdnsTask {
30 public:
31 // |mdns_client| must outlive |this|.
Eric Orth192e3bb2018-11-14 19:30:3232 HostResolverMdnsTask(MDnsClient* mdns_client,
Eric Orthc4cca5d2021-07-02 19:59:0133 std::string hostname,
Dan McArdlee8b050552022-01-15 00:48:2334 DnsQueryTypeSet query_types);
Peter Boström293b1342021-09-22 17:31:4335
36 HostResolverMdnsTask(const HostResolverMdnsTask&) = delete;
37 HostResolverMdnsTask& operator=(const HostResolverMdnsTask&) = delete;
38
Eric Orth9871aafa2018-10-02 19:59:1839 ~HostResolverMdnsTask();
40
Matt Menkec35d1632018-11-29 12:43:4941 // Starts the task. |completion_closure| will be called asynchronously.
Eric Orth9871aafa2018-10-02 19:59:1842 //
43 // Should only be called once.
Matt Menkec35d1632018-11-29 12:43:4944 void Start(base::OnceClosure completion_closure);
Eric Orth9871aafa2018-10-02 19:59:1845
Matt Menkec35d1632018-11-29 12:43:4946 // Results only available after invocation of the completion closure.
47 HostCache::Entry GetResults() const;
Eric Orth9871aafa2018-10-02 19:59:1848
Eric Orth026776a2019-01-18 00:13:2849 static HostCache::Entry ParseResult(int error,
50 DnsQueryType query_type,
51 const RecordParsed* parsed,
52 const std::string& expected_hostname);
53
Eric Orth9871aafa2018-10-02 19:59:1854 private:
55 class Transaction;
56
57 void CheckCompletion(bool post_needed);
Matt Menkec35d1632018-11-29 12:43:4958 void Complete(bool post_needed);
Eric Orth9871aafa2018-10-02 19:59:1859
Keishi Hattori0e45c022021-11-27 09:25:5260 const raw_ptr<MDnsClient> mdns_client_;
Eric Orth9871aafa2018-10-02 19:59:1861
62 const std::string hostname_;
63
Eric Orth9871aafa2018-10-02 19:59:1864 std::vector<Transaction> transactions_;
65
Matt Menkec35d1632018-11-29 12:43:4966 base::OnceClosure completion_closure_;
Eric Orth9871aafa2018-10-02 19:59:1867
68 SEQUENCE_CHECKER(sequence_checker_);
69
Jeremy Romand54000b22019-07-08 18:40:1670 base::WeakPtrFactory<HostResolverMdnsTask> weak_ptr_factory_{this};
Eric Orth9871aafa2018-10-02 19:59:1871};
72
73} // namespace net
74
75#endif // NET_DNS_HOST_RESOLVER_MDNS_TASK_H_