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 8#include "base/basictypes.h" 9#include "base/callback.h" 10#include "base/memory/scoped_ptr.h" 11#include "net/base/net_export.h" 12 13namespace net { 14 15class AddressList; 16 17// Sorts AddressList according to RFC3484, by likelihood of successful 18// connection. Depending on the platform, the sort could be performed 19// asynchronously by the OS, or synchronously by local implementation. 20// AddressSorter does not necessarily preserve port numbers on the sorted list. 21class NET_EXPORT AddressSorter { 22 public: 23 typedef base::Callback<void(bool success, 24 const AddressList& list)> CallbackType; 25 26 virtual ~AddressSorter() {} 27 28 // Sorts |list|, which must include at least one IPv6 address. 29 // Calls |callback| upon completion. Could complete synchronously. Could 30 // complete after this AddressSorter is destroyed. 31 virtual void Sort(const AddressList& list, 32 const CallbackType& callback) const = 0; 33 34 // Creates platform-dependent AddressSorter. 35 static scoped_ptr<AddressSorter> CreateAddressSorter(); 36 37 protected: 38 AddressSorter() {} 39 40 private: 41 DISALLOW_COPY_AND_ASSIGN(AddressSorter); 42}; 43 44} // namespace net 45 46#endif // NET_DNS_ADDRESS_SORTER_H_ 47