Chromium Code Reviews| 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_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 <vector> | |
|
mmenke
2015/12/11 14:32:49
I think this should go down with <algorithm> (Inc
| |
| 10 | |
| 11 #include "base/memory/scoped_ptr.h" | |
|
mmenke
2015/12/11 14:32:49
I think these should go just above logging.h
| |
| 12 | |
| 9 #if defined(OS_MACOSX) || defined(OS_BSD) | 13 #if defined(OS_MACOSX) || defined(OS_BSD) |
| 10 #include <sys/socket.h> // Must be included before ifaddrs.h. | 14 #include <sys/socket.h> // Must be included before ifaddrs.h. |
| 11 #include <ifaddrs.h> | 15 #include <ifaddrs.h> |
| 12 #include <net/if.h> | 16 #include <net/if.h> |
| 13 #include <netinet/in_var.h> | 17 #include <netinet/in_var.h> |
| 14 #include <string.h> | 18 #include <string.h> |
| 15 #include <sys/ioctl.h> | 19 #include <sys/ioctl.h> |
| 16 #endif | 20 #endif |
| 17 | 21 |
| 18 #include <algorithm> | 22 #include <algorithm> |
| 19 | 23 |
| 20 #include "base/logging.h" | 24 #include "base/logging.h" |
| 21 #include "base/memory/scoped_vector.h" | |
| 22 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 23 #include "net/socket/client_socket_factory.h" | 26 #include "net/socket/client_socket_factory.h" |
| 24 #include "net/udp/datagram_client_socket.h" | 27 #include "net/udp/datagram_client_socket.h" |
| 25 | 28 |
| 26 #if defined(OS_LINUX) | 29 #if defined(OS_LINUX) |
| 27 #include "net/base/address_tracker_linux.h" | 30 #include "net/base/address_tracker_linux.h" |
| 28 #endif | 31 #endif |
| 29 | 32 |
| 30 namespace net { | 33 namespace net { |
| 31 | 34 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 IPAddressNumber address; | 182 IPAddressNumber address; |
| 180 AddressSorterPosix::AddressScope scope; | 183 AddressSorterPosix::AddressScope scope; |
| 181 unsigned precedence; | 184 unsigned precedence; |
| 182 unsigned label; | 185 unsigned label; |
| 183 const AddressSorterPosix::SourceAddressInfo* src; | 186 const AddressSorterPosix::SourceAddressInfo* src; |
| 184 unsigned common_prefix_length; | 187 unsigned common_prefix_length; |
| 185 }; | 188 }; |
| 186 | 189 |
| 187 // Returns true iff |dst_a| should precede |dst_b| in the address list. | 190 // Returns true iff |dst_a| should precede |dst_b| in the address list. |
| 188 // RFC 3484, section 6. | 191 // RFC 3484, section 6. |
| 189 bool CompareDestinations(const DestinationInfo* dst_a, | 192 bool CompareDestinations(const scoped_ptr<DestinationInfo>& dst_a, |
| 190 const DestinationInfo* dst_b) { | 193 const scoped_ptr<DestinationInfo>& dst_b) { |
| 191 // Rule 1: Avoid unusable destinations. | 194 // Rule 1: Avoid unusable destinations. |
| 192 // Unusable destinations are already filtered out. | 195 // Unusable destinations are already filtered out. |
| 193 DCHECK(dst_a->src); | 196 DCHECK(dst_a->src); |
| 194 DCHECK(dst_b->src); | 197 DCHECK(dst_b->src); |
| 195 | 198 |
| 196 // Rule 2: Prefer matching scope. | 199 // Rule 2: Prefer matching scope. |
| 197 bool scope_match1 = (dst_a->src->scope == dst_a->scope); | 200 bool scope_match1 = (dst_a->src->scope == dst_a->scope); |
| 198 bool scope_match2 = (dst_b->src->scope == dst_b->scope); | 201 bool scope_match2 = (dst_b->src->scope == dst_b->scope); |
| 199 if (scope_match1 != scope_match2) | 202 if (scope_match1 != scope_match2) |
| 200 return scope_match1; | 203 return scope_match1; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 OnIPAddressChanged(); | 253 OnIPAddressChanged(); |
| 251 } | 254 } |
| 252 | 255 |
| 253 AddressSorterPosix::~AddressSorterPosix() { | 256 AddressSorterPosix::~AddressSorterPosix() { |
| 254 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 257 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 255 } | 258 } |
| 256 | 259 |
| 257 void AddressSorterPosix::Sort(const AddressList& list, | 260 void AddressSorterPosix::Sort(const AddressList& list, |
| 258 const CallbackType& callback) const { | 261 const CallbackType& callback) const { |
| 259 DCHECK(CalledOnValidThread()); | 262 DCHECK(CalledOnValidThread()); |
| 260 ScopedVector<DestinationInfo> sort_list; | 263 std::vector<scoped_ptr<DestinationInfo>> sort_list; |
| 261 | 264 |
| 262 for (size_t i = 0; i < list.size(); ++i) { | 265 for (size_t i = 0; i < list.size(); ++i) { |
| 263 scoped_ptr<DestinationInfo> info(new DestinationInfo()); | 266 scoped_ptr<DestinationInfo> info(new DestinationInfo()); |
| 264 info->address = list[i].address(); | 267 info->address = list[i].address(); |
| 265 info->scope = GetScope(ipv4_scope_table_, info->address); | 268 info->scope = GetScope(ipv4_scope_table_, info->address); |
| 266 info->precedence = GetPolicyValue(precedence_table_, info->address); | 269 info->precedence = GetPolicyValue(precedence_table_, info->address); |
| 267 info->label = GetPolicyValue(label_table_, info->address); | 270 info->label = GetPolicyValue(label_table_, info->address); |
| 268 | 271 |
| 269 // Each socket can only be bound once. | 272 // Each socket can only be bound once. |
| 270 scoped_ptr<DatagramClientSocket> socket( | 273 scoped_ptr<DatagramClientSocket> socket( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 } | 396 } |
| 394 | 397 |
| 395 // static | 398 // static |
| 396 scoped_ptr<AddressSorter> AddressSorter::CreateAddressSorter() { | 399 scoped_ptr<AddressSorter> AddressSorter::CreateAddressSorter() { |
| 397 return scoped_ptr<AddressSorter>( | 400 return scoped_ptr<AddressSorter>( |
| 398 new AddressSorterPosix(ClientSocketFactory::GetDefaultFactory())); | 401 new AddressSorterPosix(ClientSocketFactory::GetDefaultFactory())); |
| 399 } | 402 } |
| 400 | 403 |
| 401 } // namespace net | 404 } // namespace net |
| 402 | 405 |
| OLD | NEW |