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/base/address_list.h" | 5 #include "net/base/address_list.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
11 #include "net/base/sys_addrinfo.h" | 11 #include "net/base/sys_addrinfo.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 base::Value* NetLogAddressListCallback(const AddressList* address_list, | 17 base::Value* NetLogAddressListCallback(const AddressList* address_list, |
18 NetLog::LogLevel log_level) { | 18 NetLog::LogLevel log_level) { |
19 base::DictionaryValue* dict = new base::DictionaryValue(); | 19 base::DictionaryValue* dict = new base::DictionaryValue(); |
20 base::ListValue* list = new base::ListValue(); | 20 base::ListValue* list = new base::ListValue(); |
21 | 21 |
22 for (AddressList::const_iterator it = address_list->begin(); | 22 for (AddressList::const_iterator it = address_list->begin(); |
23 it != address_list->end(); ++it) { | 23 it != address_list->end(); |
| 24 ++it) { |
24 list->Append(new base::StringValue(it->ToString())); | 25 list->Append(new base::StringValue(it->ToString())); |
25 } | 26 } |
26 | 27 |
27 dict->Set("address_list", list); | 28 dict->Set("address_list", list); |
28 return dict; | 29 return dict; |
29 } | 30 } |
30 | 31 |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 AddressList::AddressList() {} | 34 AddressList::AddressList() { |
| 35 } |
34 | 36 |
35 AddressList::~AddressList() {} | 37 AddressList::~AddressList() { |
| 38 } |
36 | 39 |
37 AddressList::AddressList(const IPEndPoint& endpoint) { | 40 AddressList::AddressList(const IPEndPoint& endpoint) { |
38 push_back(endpoint); | 41 push_back(endpoint); |
39 } | 42 } |
40 | 43 |
41 // static | 44 // static |
42 AddressList AddressList::CreateFromIPAddress(const IPAddressNumber& address, | 45 AddressList AddressList::CreateFromIPAddress(const IPAddressNumber& address, |
43 uint16 port) { | 46 uint16 port) { |
44 return AddressList(IPEndPoint(address, port)); | 47 return AddressList(IPEndPoint(address, port)); |
45 } | 48 } |
46 | 49 |
47 // static | 50 // static |
48 AddressList AddressList::CreateFromIPAddressList( | 51 AddressList AddressList::CreateFromIPAddressList( |
49 const IPAddressList& addresses, | 52 const IPAddressList& addresses, |
50 const std::string& canonical_name) { | 53 const std::string& canonical_name) { |
51 AddressList list; | 54 AddressList list; |
52 list.set_canonical_name(canonical_name); | 55 list.set_canonical_name(canonical_name); |
53 for (IPAddressList::const_iterator iter = addresses.begin(); | 56 for (IPAddressList::const_iterator iter = addresses.begin(); |
54 iter != addresses.end(); ++iter) { | 57 iter != addresses.end(); |
| 58 ++iter) { |
55 list.push_back(IPEndPoint(*iter, 0)); | 59 list.push_back(IPEndPoint(*iter, 0)); |
56 } | 60 } |
57 return list; | 61 return list; |
58 } | 62 } |
59 | 63 |
60 // static | 64 // static |
61 AddressList AddressList::CreateFromAddrinfo(const struct addrinfo* head) { | 65 AddressList AddressList::CreateFromAddrinfo(const struct addrinfo* head) { |
62 DCHECK(head); | 66 DCHECK(head); |
63 AddressList list; | 67 AddressList list; |
64 if (head->ai_canonname) | 68 if (head->ai_canonname) |
(...skipping 21 matching lines...) Expand all Loading... |
86 void AddressList::SetDefaultCanonicalName() { | 90 void AddressList::SetDefaultCanonicalName() { |
87 DCHECK(!empty()); | 91 DCHECK(!empty()); |
88 set_canonical_name(front().ToStringWithoutPort()); | 92 set_canonical_name(front().ToStringWithoutPort()); |
89 } | 93 } |
90 | 94 |
91 NetLog::ParametersCallback AddressList::CreateNetLogCallback() const { | 95 NetLog::ParametersCallback AddressList::CreateNetLogCallback() const { |
92 return base::Bind(&NetLogAddressListCallback, this); | 96 return base::Bind(&NetLogAddressListCallback, this); |
93 } | 97 } |
94 | 98 |
95 } // namespace net | 99 } // namespace net |
OLD | NEW |