Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: net/dns/address_sorter_win.cc

Issue 1945583002: [NET] Del: Remove AddressSorterWinXP wrapper for AddressSorterWin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove not used function Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/socket/tcp_socket_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 std::unique_ptr<SOCKET_ADDRESS_LIST, base::FreeDeleter> input_buffer_; 133 std::unique_ptr<SOCKET_ADDRESS_LIST, base::FreeDeleter> input_buffer_;
134 std::unique_ptr<SOCKET_ADDRESS_LIST, base::FreeDeleter> output_buffer_; 134 std::unique_ptr<SOCKET_ADDRESS_LIST, base::FreeDeleter> output_buffer_;
135 bool success_; 135 bool success_;
136 136
137 DISALLOW_COPY_AND_ASSIGN(Job); 137 DISALLOW_COPY_AND_ASSIGN(Job);
138 }; 138 };
139 139
140 DISALLOW_COPY_AND_ASSIGN(AddressSorterWin); 140 DISALLOW_COPY_AND_ASSIGN(AddressSorterWin);
141 }; 141 };
142 142
143 // Merges |list_ipv4| and |list_ipv6| before passing it to |callback|, but
144 // only if |success| is true.
145 void MergeResults(const AddressSorter::CallbackType& callback,
146 const AddressList& list_ipv4,
147 bool success,
148 const AddressList& list_ipv6) {
149 if (!success) {
150 callback.Run(false, AddressList());
151 return;
152 }
153 AddressList list;
154 list.insert(list.end(), list_ipv6.begin(), list_ipv6.end());
155 list.insert(list.end(), list_ipv4.begin(), list_ipv4.end());
156 callback.Run(true, list);
157 }
158
159 // Wrapper for AddressSorterWin which does not sort IPv4 or IPv4-mapped
160 // addresses but always puts them at the end of the list. Needed because the
161 // SIO_ADDRESS_LIST_SORT does not support IPv4 addresses on Windows XP.
162 class AddressSorterWinXP : public AddressSorter {
163 public:
164 AddressSorterWinXP() {}
165 ~AddressSorterWinXP() override {}
166
167 // AddressSorter:
168 void Sort(const AddressList& list,
169 const CallbackType& callback) const override {
170 AddressList list_ipv4;
171 AddressList list_ipv6;
172 for (size_t i = 0; i < list.size(); ++i) {
173 const IPEndPoint& ipe = list[i];
174 if (ipe.GetFamily() == ADDRESS_FAMILY_IPV4) {
175 list_ipv4.push_back(ipe);
176 } else {
177 list_ipv6.push_back(ipe);
178 }
179 }
180 if (!list_ipv6.empty()) {
181 sorter_.Sort(list_ipv6, base::Bind(&MergeResults, callback, list_ipv4));
182 } else {
183 NOTREACHED() << "Should not be called with IPv4-only addresses.";
184 callback.Run(true, list);
185 }
186 }
187
188 private:
189 AddressSorterWin sorter_;
190
191 DISALLOW_COPY_AND_ASSIGN(AddressSorterWinXP);
192 };
193
194 } // namespace 143 } // namespace
195 144
196 // static 145 // static
197 std::unique_ptr<AddressSorter> AddressSorter::CreateAddressSorter() { 146 std::unique_ptr<AddressSorter> AddressSorter::CreateAddressSorter() {
198 if (base::win::GetVersion() < base::win::VERSION_VISTA)
199 return std::unique_ptr<AddressSorter>(new AddressSorterWinXP());
200 return std::unique_ptr<AddressSorter>(new AddressSorterWin()); 147 return std::unique_ptr<AddressSorter>(new AddressSorterWin());
201 } 148 }
202 149
203 } // namespace net 150 } // namespace net
204 151
OLDNEW
« no previous file with comments | « no previous file | net/socket/tcp_socket_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698