Work on Windows GN component build.
[chromium-blink-merge.git] / net / base / address_list.h
blobf271dfcd4cf93a7b8d0fe861eae22c06c1ecf2af
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
3 // found in the LICENSE file.
5 #ifndef NET_BASE_ADDRESS_LIST_H_
6 #define NET_BASE_ADDRESS_LIST_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "net/base/ip_endpoint.h"
14 #include "net/base/net_export.h"
15 #include "net/base/net_util.h"
16 #include "net/log/net_log.h"
18 struct addrinfo;
20 namespace net {
22 class NET_EXPORT AddressList
23 : NON_EXPORTED_BASE(private std::vector<IPEndPoint>) {
24 public:
25 AddressList();
26 ~AddressList();
28 // Creates an address list for a single IP literal.
29 explicit AddressList(const IPEndPoint& endpoint);
31 static AddressList CreateFromIPAddress(const IPAddressNumber& address,
32 uint16 port);
34 static AddressList CreateFromIPAddressList(
35 const IPAddressList& addresses,
36 const std::string& canonical_name);
38 // Copies the data from |head| and the chained list into an AddressList.
39 static AddressList CreateFromAddrinfo(const struct addrinfo* head);
41 // Returns a copy of |list| with port on each element set to |port|.
42 static AddressList CopyWithPort(const AddressList& list, uint16 port);
44 // TODO(szym): Remove all three. http://crbug.com/126134
45 const std::string& canonical_name() const {
46 return canonical_name_;
49 void set_canonical_name(const std::string& canonical_name) {
50 canonical_name_ = canonical_name;
53 // Sets canonical name to the literal of the first IP address on the list.
54 void SetDefaultCanonicalName();
56 // Creates a callback for use with the NetLog that returns a Value
57 // representation of the address list. The callback must be destroyed before
58 // |this| is.
59 NetLog::ParametersCallback CreateNetLogCallback() const;
61 // Exposed methods from std::vector.
62 using std::vector<IPEndPoint>::size;
63 using std::vector<IPEndPoint>::empty;
64 using std::vector<IPEndPoint>::clear;
65 using std::vector<IPEndPoint>::reserve;
66 using std::vector<IPEndPoint>::capacity;
67 using std::vector<IPEndPoint>::operator[];
68 using std::vector<IPEndPoint>::front;
69 using std::vector<IPEndPoint>::back;
70 using std::vector<IPEndPoint>::push_back;
71 using std::vector<IPEndPoint>::insert;
72 using std::vector<IPEndPoint>::erase;
73 using std::vector<IPEndPoint>::iterator;
74 using std::vector<IPEndPoint>::const_iterator;
75 using std::vector<IPEndPoint>::begin;
76 using std::vector<IPEndPoint>::end;
77 using std::vector<IPEndPoint>::rbegin;
78 using std::vector<IPEndPoint>::rend;
80 private:
81 // TODO(szym): Remove. http://crbug.com/126134
82 std::string canonical_name_;
85 } // namespace net
87 #endif // NET_BASE_ADDRESS_LIST_H_