[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 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. | ||||
4 | |||||
5 | #ifndef NET_DNS_ADDRESS_SORTER_H_ | ||||
6 | #define NET_DNS_ADDRESS_SORTER_H_ | ||||
7 | |||||
danakj | 22f90e7 | 2016-04-16 01:55:40 | [diff] [blame] | 8 | #include <memory> |
9 | |||||
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 10 | #include "base/callback.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 12 | #include "net/base/net_export.h" |
13 | |||||
14 | namespace net { | ||||
15 | |||||
Christian Dullweber | 1b2df591 | 2021-11-03 11:37:35 | [diff] [blame^] | 16 | class AddressList; |
17 | |||||
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 18 | // 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. | ||||
22 | class NET_EXPORT AddressSorter { | ||||
23 | public: | ||||
Christian Dullweber | 1b2df591 | 2021-11-03 11:37:35 | [diff] [blame^] | 24 | using CallbackType = |
25 | base::OnceCallback<void(bool success, const AddressList& list)>; | ||||
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 26 | |
Peter Boström | 293b134 | 2021-09-22 17:31:43 | [diff] [blame] | 27 | AddressSorter(const AddressSorter&) = delete; |
28 | AddressSorter& operator=(const AddressSorter&) = delete; | ||||
29 | |||||
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 30 | 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éky | d5e474c | 2018-08-02 18:45:08 | [diff] [blame] | 35 | virtual void Sort(const AddressList& list, CallbackType callback) const = 0; |
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 36 | |
37 | // Creates platform-dependent AddressSorter. | ||||
danakj | 22f90e7 | 2016-04-16 01:55:40 | [diff] [blame] | 38 | static std::unique_ptr<AddressSorter> CreateAddressSorter(); |
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 39 | |
40 | protected: | ||||
41 | AddressSorter() {} | ||||
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 42 | }; |
43 | |||||
44 | } // namespace net | ||||
45 | |||||
46 | #endif // NET_DNS_ADDRESS_SORTER_H_ |