OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/dns/address_sorter.h" | 5 #include "net/dns/address_sorter.h" |
6 | 6 |
7 #include <winsock2.h> | 7 #include <winsock2.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 class AddressSorterWin : public AddressSorter { | 24 class AddressSorterWin : public AddressSorter { |
25 public: | 25 public: |
26 AddressSorterWin() { | 26 AddressSorterWin() { |
27 EnsureWinsockInit(); | 27 EnsureWinsockInit(); |
28 } | 28 } |
29 | 29 |
30 virtual ~AddressSorterWin() {} | 30 virtual ~AddressSorterWin() {} |
31 | 31 |
32 // AddressSorter: | 32 // AddressSorter: |
33 virtual void Sort(const AddressList& list, | 33 virtual void Sort(const AddressList& list, |
34 const CallbackType& callback) const OVERRIDE { | 34 const CallbackType& callback) const override { |
35 DCHECK(!list.empty()); | 35 DCHECK(!list.empty()); |
36 scoped_refptr<Job> job = new Job(list, callback); | 36 scoped_refptr<Job> job = new Job(list, callback); |
37 } | 37 } |
38 | 38 |
39 private: | 39 private: |
40 // Executes the SIO_ADDRESS_LIST_SORT ioctl on the WorkerPool, and | 40 // Executes the SIO_ADDRESS_LIST_SORT ioctl on the WorkerPool, and |
41 // performs the necessary conversions to/from AddressList. | 41 // performs the necessary conversions to/from AddressList. |
42 class Job : public base::RefCountedThreadSafe<Job> { | 42 class Job : public base::RefCountedThreadSafe<Job> { |
43 public: | 43 public: |
44 Job(const AddressList& list, const CallbackType& callback) | 44 Job(const AddressList& list, const CallbackType& callback) |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // Wrapper for AddressSorterWin which does not sort IPv4 or IPv4-mapped | 153 // Wrapper for AddressSorterWin which does not sort IPv4 or IPv4-mapped |
154 // addresses but always puts them at the end of the list. Needed because the | 154 // addresses but always puts them at the end of the list. Needed because the |
155 // SIO_ADDRESS_LIST_SORT does not support IPv4 addresses on Windows XP. | 155 // SIO_ADDRESS_LIST_SORT does not support IPv4 addresses on Windows XP. |
156 class AddressSorterWinXP : public AddressSorter { | 156 class AddressSorterWinXP : public AddressSorter { |
157 public: | 157 public: |
158 AddressSorterWinXP() {} | 158 AddressSorterWinXP() {} |
159 virtual ~AddressSorterWinXP() {} | 159 virtual ~AddressSorterWinXP() {} |
160 | 160 |
161 // AddressSorter: | 161 // AddressSorter: |
162 virtual void Sort(const AddressList& list, | 162 virtual void Sort(const AddressList& list, |
163 const CallbackType& callback) const OVERRIDE { | 163 const CallbackType& callback) const override { |
164 AddressList list_ipv4; | 164 AddressList list_ipv4; |
165 AddressList list_ipv6; | 165 AddressList list_ipv6; |
166 for (size_t i = 0; i < list.size(); ++i) { | 166 for (size_t i = 0; i < list.size(); ++i) { |
167 const IPEndPoint& ipe = list[i]; | 167 const IPEndPoint& ipe = list[i]; |
168 if (ipe.GetFamily() == ADDRESS_FAMILY_IPV4) { | 168 if (ipe.GetFamily() == ADDRESS_FAMILY_IPV4) { |
169 list_ipv4.push_back(ipe); | 169 list_ipv4.push_back(ipe); |
170 } else { | 170 } else { |
171 list_ipv6.push_back(ipe); | 171 list_ipv6.push_back(ipe); |
172 } | 172 } |
173 } | 173 } |
(...skipping 15 matching lines...) Expand all Loading... |
189 | 189 |
190 // static | 190 // static |
191 scoped_ptr<AddressSorter> AddressSorter::CreateAddressSorter() { | 191 scoped_ptr<AddressSorter> AddressSorter::CreateAddressSorter() { |
192 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 192 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
193 return scoped_ptr<AddressSorter>(new AddressSorterWinXP()); | 193 return scoped_ptr<AddressSorter>(new AddressSorterWinXP()); |
194 return scoped_ptr<AddressSorter>(new AddressSorterWin()); | 194 return scoped_ptr<AddressSorter>(new AddressSorterWin()); |
195 } | 195 } |
196 | 196 |
197 } // namespace net | 197 } // namespace net |
198 | 198 |
OLD | NEW |