blob: 95fe5e14e297c7e18955d3b039d16480a33025e4 [file] [log] [blame]
[email protected]0adcb2b2012-08-15 21:30:461// 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.
4
5#ifndef NET_DNS_ADDRESS_SORTER_H_
6#define NET_DNS_ADDRESS_SORTER_H_
7
danakj22f90e72016-04-16 01:55:408#include <memory>
9
[email protected]0adcb2b2012-08-15 21:30:4610#include "base/callback.h"
Avi Drissman13fc8932015-12-20 04:40:4611#include "base/macros.h"
[email protected]0adcb2b2012-08-15 21:30:4612#include "net/base/net_export.h"
13
14namespace net {
15
Christian Dullweber1b2df5912021-11-03 11:37:3516class AddressList;
17
[email protected]0adcb2b2012-08-15 21:30:4618// Sorts AddressList according to RFC3484, by likelihood of successful
19// connection. Depending on the platform, the sort could be performed
20// asynchronously by the OS, or synchronously by local implementation.
21// AddressSorter does not necessarily preserve port numbers on the sorted list.
22class NET_EXPORT AddressSorter {
23 public:
Christian Dullweber1b2df5912021-11-03 11:37:3524 using CallbackType =
25 base::OnceCallback<void(bool success, const AddressList& list)>;
[email protected]0adcb2b2012-08-15 21:30:4626
Peter Boström293b1342021-09-22 17:31:4327 AddressSorter(const AddressSorter&) = delete;
28 AddressSorter& operator=(const AddressSorter&) = delete;
29
[email protected]0adcb2b2012-08-15 21:30:4630 virtual ~AddressSorter() {}
31
32 // Sorts |list|, which must include at least one IPv6 address.
33 // Calls |callback| upon completion. Could complete synchronously. Could
34 // complete after this AddressSorter is destroyed.
Bence Békyd5e474c2018-08-02 18:45:0835 virtual void Sort(const AddressList& list, CallbackType callback) const = 0;
[email protected]0adcb2b2012-08-15 21:30:4636
37 // Creates platform-dependent AddressSorter.
danakj22f90e72016-04-16 01:55:4038 static std::unique_ptr<AddressSorter> CreateAddressSorter();
[email protected]0adcb2b2012-08-15 21:30:4639
40 protected:
41 AddressSorter() {}
[email protected]0adcb2b2012-08-15 21:30:4642};
43
44} // namespace net
45
46#endif // NET_DNS_ADDRESS_SORTER_H_