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

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

Issue 2910473005: Deprecate NonThreadSafe in net/ in favor of SequenceChecker/ThreadChecker. (Closed)
Patch Set: rebase on r476634 Created 3 years, 6 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 | « net/dns/address_sorter_posix.h ('k') | net/dns/dns_config_service.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_posix.h" 5 #include "net/dns/address_sorter_posix.h"
6 6
7 #include <netinet/in.h> 7 #include <netinet/in.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 arraysize(kDefaultPrecedenceTable))), 244 arraysize(kDefaultPrecedenceTable))),
245 label_table_(LoadPolicy(kDefaultLabelTable, 245 label_table_(LoadPolicy(kDefaultLabelTable,
246 arraysize(kDefaultLabelTable))), 246 arraysize(kDefaultLabelTable))),
247 ipv4_scope_table_(LoadPolicy(kDefaultIPv4ScopeTable, 247 ipv4_scope_table_(LoadPolicy(kDefaultIPv4ScopeTable,
248 arraysize(kDefaultIPv4ScopeTable))) { 248 arraysize(kDefaultIPv4ScopeTable))) {
249 NetworkChangeNotifier::AddIPAddressObserver(this); 249 NetworkChangeNotifier::AddIPAddressObserver(this);
250 OnIPAddressChanged(); 250 OnIPAddressChanged();
251 } 251 }
252 252
253 AddressSorterPosix::~AddressSorterPosix() { 253 AddressSorterPosix::~AddressSorterPosix() {
254 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
254 NetworkChangeNotifier::RemoveIPAddressObserver(this); 255 NetworkChangeNotifier::RemoveIPAddressObserver(this);
255 } 256 }
256 257
257 void AddressSorterPosix::Sort(const AddressList& list, 258 void AddressSorterPosix::Sort(const AddressList& list,
258 const CallbackType& callback) const { 259 const CallbackType& callback) const {
259 DCHECK(CalledOnValidThread()); 260 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
260 std::vector<std::unique_ptr<DestinationInfo>> sort_list; 261 std::vector<std::unique_ptr<DestinationInfo>> sort_list;
261 262
262 for (size_t i = 0; i < list.size(); ++i) { 263 for (size_t i = 0; i < list.size(); ++i) {
263 std::unique_ptr<DestinationInfo> info(new DestinationInfo()); 264 std::unique_ptr<DestinationInfo> info(new DestinationInfo());
264 info->address = list[i].address(); 265 info->address = list[i].address();
265 info->scope = GetScope(ipv4_scope_table_, info->address); 266 info->scope = GetScope(ipv4_scope_table_, info->address);
266 info->precedence = GetPolicyValue(precedence_table_, info->address); 267 info->precedence = GetPolicyValue(precedence_table_, info->address);
267 info->label = GetPolicyValue(label_table_, info->address); 268 info->label = GetPolicyValue(label_table_, info->address);
268 269
269 // Each socket can only be bound once. 270 // Each socket can only be bound once.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 std::stable_sort(sort_list.begin(), sort_list.end(), CompareDestinations); 309 std::stable_sort(sort_list.begin(), sort_list.end(), CompareDestinations);
309 310
310 AddressList result; 311 AddressList result;
311 for (size_t i = 0; i < sort_list.size(); ++i) 312 for (size_t i = 0; i < sort_list.size(); ++i)
312 result.push_back(IPEndPoint(sort_list[i]->address, 0 /* port */)); 313 result.push_back(IPEndPoint(sort_list[i]->address, 0 /* port */));
313 314
314 callback.Run(true, result); 315 callback.Run(true, result);
315 } 316 }
316 317
317 void AddressSorterPosix::OnIPAddressChanged() { 318 void AddressSorterPosix::OnIPAddressChanged() {
318 DCHECK(CalledOnValidThread()); 319 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
319 source_map_.clear(); 320 source_map_.clear();
320 #if defined(OS_LINUX) 321 #if defined(OS_LINUX)
321 const internal::AddressTrackerLinux* tracker = 322 const internal::AddressTrackerLinux* tracker =
322 NetworkChangeNotifier::GetAddressTracker(); 323 NetworkChangeNotifier::GetAddressTracker();
323 if (!tracker) 324 if (!tracker)
324 return; 325 return;
325 typedef internal::AddressTrackerLinux::AddressMap AddressMap; 326 typedef internal::AddressTrackerLinux::AddressMap AddressMap;
326 AddressMap map = tracker->GetAddressMap(); 327 AddressMap map = tracker->GetAddressMap();
327 for (AddressMap::const_iterator it = map.begin(); it != map.end(); ++it) { 328 for (AddressMap::const_iterator it = map.begin(); it != map.end(); ++it) {
328 const IPAddress& address = it->first; 329 const IPAddress& address = it->first;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 379 }
379 FillPolicy(src.address(), &info); 380 FillPolicy(src.address(), &info);
380 } 381 }
381 freeifaddrs(addrs); 382 freeifaddrs(addrs);
382 close(ioctl_socket); 383 close(ioctl_socket);
383 #endif 384 #endif
384 } 385 }
385 386
386 void AddressSorterPosix::FillPolicy(const IPAddress& address, 387 void AddressSorterPosix::FillPolicy(const IPAddress& address,
387 SourceAddressInfo* info) const { 388 SourceAddressInfo* info) const {
388 DCHECK(CalledOnValidThread()); 389 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
389 info->scope = GetScope(ipv4_scope_table_, address); 390 info->scope = GetScope(ipv4_scope_table_, address);
390 info->label = GetPolicyValue(label_table_, address); 391 info->label = GetPolicyValue(label_table_, address);
391 } 392 }
392 393
393 // static 394 // static
394 std::unique_ptr<AddressSorter> AddressSorter::CreateAddressSorter() { 395 std::unique_ptr<AddressSorter> AddressSorter::CreateAddressSorter() {
395 return std::unique_ptr<AddressSorter>( 396 return std::unique_ptr<AddressSorter>(
396 new AddressSorterPosix(ClientSocketFactory::GetDefaultFactory())); 397 new AddressSorterPosix(ClientSocketFactory::GetDefaultFactory()));
397 } 398 }
398 399
399 } // namespace net 400 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/address_sorter_posix.h ('k') | net/dns/dns_config_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698