| 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 #ifndef NET_DNS_ADDRESS_SORTER_POSIX_H_ | 5 #ifndef NET_DNS_ADDRESS_SORTER_POSIX_H_ |
| 6 #define NET_DNS_ADDRESS_SORTER_POSIX_H_ | 6 #define NET_DNS_ADDRESS_SORTER_POSIX_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
| 12 #include "net/base/address_list.h" | 12 #include "net/base/address_list.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
| 15 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 16 #include "net/base/network_change_notifier.h" | 16 #include "net/base/network_change_notifier.h" |
| 17 #include "net/dns/address_sorter.h" | 17 #include "net/dns/address_sorter.h" |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 | 20 |
| 21 class ClientSocketFactory; | 21 class ClientSocketFactory; |
| 22 | 22 |
| 23 // This implementation uses explicit policy to perform the sorting. It is not | 23 // This implementation uses explicit policy to perform the sorting. It is not |
| 24 // thread-safe and always completes synchronously. | 24 // thread-safe and always completes synchronously. |
| 25 class NET_EXPORT_PRIVATE AddressSorterPosix | 25 class NET_EXPORT_PRIVATE AddressSorterPosix |
| 26 : public AddressSorter, | 26 : public AddressSorter, |
| 27 public base::NonThreadSafe, | 27 public base::NonThreadSafe, |
| 28 public NetworkChangeNotifier::IPAddressObserver { | 28 public NetworkChangeNotifier::NetworkChangeObserver { |
| 29 public: | 29 public: |
| 30 // Generic policy entry. | 30 // Generic policy entry. |
| 31 struct PolicyEntry { | 31 struct PolicyEntry { |
| 32 // IPv4 addresses must be mapped to IPv6. | 32 // IPv4 addresses must be mapped to IPv6. |
| 33 unsigned char prefix[kIPv6AddressSize]; | 33 unsigned char prefix[kIPv6AddressSize]; |
| 34 unsigned prefix_length; | 34 unsigned prefix_length; |
| 35 unsigned value; | 35 unsigned value; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 typedef std::vector<PolicyEntry> PolicyTable; | 38 typedef std::vector<PolicyEntry> PolicyTable; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 63 explicit AddressSorterPosix(ClientSocketFactory* socket_factory); | 63 explicit AddressSorterPosix(ClientSocketFactory* socket_factory); |
| 64 virtual ~AddressSorterPosix(); | 64 virtual ~AddressSorterPosix(); |
| 65 | 65 |
| 66 // AddressSorter: | 66 // AddressSorter: |
| 67 virtual void Sort(const AddressList& list, | 67 virtual void Sort(const AddressList& list, |
| 68 const CallbackType& callback) const OVERRIDE; | 68 const CallbackType& callback) const OVERRIDE; |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 friend class AddressSorterPosixTest; | 71 friend class AddressSorterPosixTest; |
| 72 | 72 |
| 73 // NetworkChangeNotifier::IPAddressObserver: | 73 // NetworkChangeNotifier::NetworkChangeObserver: |
| 74 virtual void OnIPAddressChanged() OVERRIDE; | 74 virtual void OnNetworkChanged( |
| 75 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 75 | 76 |
| 76 // Fills |info| with values for |address| from policy tables. | 77 // Fills |info| with values for |address| from policy tables. |
| 77 void FillPolicy(const IPAddressNumber& address, | 78 void FillPolicy(const IPAddressNumber& address, |
| 78 SourceAddressInfo* info) const; | 79 SourceAddressInfo* info) const; |
| 79 | 80 |
| 80 // Mutable to allow using default values for source addresses which were not | 81 // Mutable to allow using default values for source addresses which were not |
| 81 // found in most recent OnIPAddressChanged. | 82 // found in most recent OnIPAddressChanged. |
| 82 mutable SourceAddressMap source_map_; | 83 mutable SourceAddressMap source_map_; |
| 83 | 84 |
| 84 ClientSocketFactory* socket_factory_; | 85 ClientSocketFactory* socket_factory_; |
| 85 PolicyTable precedence_table_; | 86 PolicyTable precedence_table_; |
| 86 PolicyTable label_table_; | 87 PolicyTable label_table_; |
| 87 PolicyTable ipv4_scope_table_; | 88 PolicyTable ipv4_scope_table_; |
| 88 | 89 |
| 89 DISALLOW_COPY_AND_ASSIGN(AddressSorterPosix); | 90 DISALLOW_COPY_AND_ASSIGN(AddressSorterPosix); |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 } // namespace net | 93 } // namespace net |
| 93 | 94 |
| 94 #endif // NET_DNS_ADDRESS_SORTER_POSIX_H_ | 95 #endif // NET_DNS_ADDRESS_SORTER_POSIX_H_ |
| OLD | NEW |