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

Side by Side Diff: extensions/browser/api/socket/socket.cc

Issue 1837713002: Migrate extensions/* to net::IPAddress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added a DCHECK Created 4 years, 8 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 | « extensions/browser/api/cast_channel/logger.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/socket/socket.h" 5 #include "extensions/browser/api/socket/socket.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "extensions/browser/api/api_resource_manager.h" 9 #include "extensions/browser/api/api_resource_manager.h"
10 #include "net/base/address_list.h" 10 #include "net/base/address_list.h"
11 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
12 #include "net/base/ip_address.h"
12 #include "net/base/ip_endpoint.h" 13 #include "net/base/ip_endpoint.h"
13 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
14 #include "net/socket/socket.h" 15 #include "net/socket/socket.h"
15 16
16 namespace extensions { 17 namespace extensions {
17 18
18 const char kSocketTypeNotSupported[] = "Socket type does not support this API"; 19 const char kSocketTypeNotSupported[] = "Socket type does not support this API";
19 20
20 static base::LazyInstance< 21 static base::LazyInstance<
21 BrowserContextKeyedAPIFactory<ApiResourceManager<Socket> > > g_factory = 22 BrowserContextKeyedAPIFactory<ApiResourceManager<Socket> > > g_factory =
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 100
100 void Socket::Accept(const AcceptCompletionCallback& callback) { 101 void Socket::Accept(const AcceptCompletionCallback& callback) {
101 callback.Run(net::ERR_FAILED, NULL); 102 callback.Run(net::ERR_FAILED, NULL);
102 } 103 }
103 104
104 // static 105 // static
105 bool Socket::StringAndPortToIPEndPoint(const std::string& ip_address_str, 106 bool Socket::StringAndPortToIPEndPoint(const std::string& ip_address_str,
106 uint16_t port, 107 uint16_t port,
107 net::IPEndPoint* ip_end_point) { 108 net::IPEndPoint* ip_end_point) {
108 DCHECK(ip_end_point); 109 DCHECK(ip_end_point);
109 net::IPAddressNumber ip_number; 110 net::IPAddress ip_address;
110 if (!net::ParseIPLiteralToNumber(ip_address_str, &ip_number)) 111 if (!ip_address.AssignFromIPLiteral(ip_address_str))
111 return false; 112 return false;
112 113
113 *ip_end_point = net::IPEndPoint(ip_number, port); 114 *ip_end_point = net::IPEndPoint(ip_address, port);
114 return true; 115 return true;
115 } 116 }
116 117
117 void Socket::IPEndPointToStringAndPort(const net::IPEndPoint& address, 118 void Socket::IPEndPointToStringAndPort(const net::IPEndPoint& address,
118 std::string* ip_address_str, 119 std::string* ip_address_str,
119 uint16_t* port) { 120 uint16_t* port) {
120 DCHECK(ip_address_str); 121 DCHECK(ip_address_str);
121 DCHECK(port); 122 DCHECK(port);
122 *ip_address_str = address.ToStringWithoutPort(); 123 *ip_address_str = address.ToStringWithoutPort();
123 if (ip_address_str->empty()) { 124 if (ip_address_str->empty()) {
124 *port = 0; 125 *port = 0;
125 } else { 126 } else {
126 *port = address.port(); 127 *port = address.port();
127 } 128 }
128 } 129 }
129 130
130 Socket::WriteRequest::WriteRequest(scoped_refptr<net::IOBuffer> io_buffer, 131 Socket::WriteRequest::WriteRequest(scoped_refptr<net::IOBuffer> io_buffer,
131 int byte_count, 132 int byte_count,
132 const CompletionCallback& callback) 133 const CompletionCallback& callback)
133 : io_buffer(io_buffer), 134 : io_buffer(io_buffer),
134 byte_count(byte_count), 135 byte_count(byte_count),
135 callback(callback), 136 callback(callback),
136 bytes_written(0) {} 137 bytes_written(0) {}
137 138
138 Socket::WriteRequest::WriteRequest(const WriteRequest& other) = default; 139 Socket::WriteRequest::WriteRequest(const WriteRequest& other) = default;
139 140
140 Socket::WriteRequest::~WriteRequest() {} 141 Socket::WriteRequest::~WriteRequest() {}
141 142
142 } // namespace extensions 143 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/cast_channel/logger.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698