| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/socket/fuzzed_socket.h" | 5 #include "net/socket/fuzzed_socket.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // writes. The first one is returned when no more input data remains, so it's | 29 // writes. The first one is returned when no more input data remains, so it's |
| 30 // one of the most common ones. | 30 // one of the most common ones. |
| 31 const Error kReadWriteErrors[] = {ERR_CONNECTION_CLOSED, ERR_FAILED, | 31 const Error kReadWriteErrors[] = {ERR_CONNECTION_CLOSED, ERR_FAILED, |
| 32 ERR_TIMED_OUT, ERR_CONNECTION_RESET}; | 32 ERR_TIMED_OUT, ERR_CONNECTION_RESET}; |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 FuzzedSocket::FuzzedSocket(base::FuzzedDataProvider* data_provider, | 36 FuzzedSocket::FuzzedSocket(base::FuzzedDataProvider* data_provider, |
| 37 net::NetLog* net_log) | 37 net::NetLog* net_log) |
| 38 : data_provider_(data_provider), | 38 : data_provider_(data_provider), |
| 39 bound_net_log_(BoundNetLog::Make(net_log, NetLogSourceType::SOCKET)), | 39 net_log_(NetLogWithSource::Make(net_log, NetLogSourceType::SOCKET)), |
| 40 remote_address_(IPEndPoint(IPAddress::IPv4Localhost(), 80)), | 40 remote_address_(IPEndPoint(IPAddress::IPv4Localhost(), 80)), |
| 41 weak_factory_(this) {} | 41 weak_factory_(this) {} |
| 42 | 42 |
| 43 FuzzedSocket::~FuzzedSocket() {} | 43 FuzzedSocket::~FuzzedSocket() {} |
| 44 | 44 |
| 45 int FuzzedSocket::Read(IOBuffer* buf, | 45 int FuzzedSocket::Read(IOBuffer* buf, |
| 46 int buf_len, | 46 int buf_len, |
| 47 const CompletionCallback& callback) { | 47 const CompletionCallback& callback) { |
| 48 DCHECK(!connect_pending_); | 48 DCHECK(!connect_pending_); |
| 49 DCHECK(!read_pending_); | 49 DCHECK(!read_pending_); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 return OK; | 200 return OK; |
| 201 } | 201 } |
| 202 | 202 |
| 203 int FuzzedSocket::GetLocalAddress(IPEndPoint* address) const { | 203 int FuzzedSocket::GetLocalAddress(IPEndPoint* address) const { |
| 204 if (!IsConnected()) | 204 if (!IsConnected()) |
| 205 return ERR_SOCKET_NOT_CONNECTED; | 205 return ERR_SOCKET_NOT_CONNECTED; |
| 206 *address = IPEndPoint(IPAddress(127, 0, 0, 1), 43434); | 206 *address = IPEndPoint(IPAddress(127, 0, 0, 1), 43434); |
| 207 return OK; | 207 return OK; |
| 208 } | 208 } |
| 209 | 209 |
| 210 const BoundNetLog& FuzzedSocket::NetLog() const { | 210 const NetLogWithSource& FuzzedSocket::NetLog() const { |
| 211 return bound_net_log_; | 211 return net_log_; |
| 212 } | 212 } |
| 213 | 213 |
| 214 void FuzzedSocket::SetSubresourceSpeculation() {} | 214 void FuzzedSocket::SetSubresourceSpeculation() {} |
| 215 | 215 |
| 216 void FuzzedSocket::SetOmniboxSpeculation() {} | 216 void FuzzedSocket::SetOmniboxSpeculation() {} |
| 217 | 217 |
| 218 bool FuzzedSocket::WasEverUsed() const { | 218 bool FuzzedSocket::WasEverUsed() const { |
| 219 return total_bytes_written_ != 0 || total_bytes_read_ != 0; | 219 return total_bytes_written_ != 0 || total_bytes_read_ != 0; |
| 220 } | 220 } |
| 221 | 221 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 void FuzzedSocket::OnConnectComplete(const CompletionCallback& callback, | 276 void FuzzedSocket::OnConnectComplete(const CompletionCallback& callback, |
| 277 int result) { | 277 int result) { |
| 278 CHECK(connect_pending_); | 278 CHECK(connect_pending_); |
| 279 connect_pending_ = false; | 279 connect_pending_ = false; |
| 280 if (result < 0) | 280 if (result < 0) |
| 281 error_pending_ = false; | 281 error_pending_ = false; |
| 282 callback.Run(result); | 282 callback.Run(result); |
| 283 } | 283 } |
| 284 | 284 |
| 285 } // namespace net | 285 } // namespace net |
| OLD | NEW |