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/socket/socket_error_params.h" | 5 #include "net/socket/socket_net_log_params.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "net/base/host_port_pair.h" |
| 10 #include "net/base/ip_endpoint.h" |
| 11 #include "net/base/net_util.h" |
8 | 12 |
9 namespace net { | 13 namespace net { |
10 | 14 |
11 SocketErrorParams::SocketErrorParams(int net_error, int os_error) | 15 namespace { |
12 : net_error_(net_error), | |
13 os_error_(os_error) { | |
14 } | |
15 | 16 |
16 Value* SocketErrorParams::ToValue() const { | 17 Value* NetLogSocketErrorCallback(int net_error, |
| 18 int os_error, |
| 19 NetLog::LogLevel /* log_level */) { |
17 DictionaryValue* dict = new DictionaryValue(); | 20 DictionaryValue* dict = new DictionaryValue(); |
18 dict->SetInteger("net_error", net_error_); | 21 dict->SetInteger("net_error", net_error); |
19 dict->SetInteger("os_error", os_error_); | 22 dict->SetInteger("os_error", os_error); |
20 return dict; | 23 return dict; |
21 } | 24 } |
22 | 25 |
23 SocketErrorParams::~SocketErrorParams() {} | 26 Value* NetLogHostPortPairCallback(const HostPortPair* host_and_port, |
| 27 NetLog::LogLevel /* log_level */) { |
| 28 DictionaryValue* dict = new DictionaryValue(); |
| 29 dict->SetString("host_and_port", host_and_port->ToString()); |
| 30 return dict; |
| 31 } |
| 32 |
| 33 Value* NetLogIPEndPointCallback(const IPEndPoint* address, |
| 34 NetLog::LogLevel /* log_level */) { |
| 35 DictionaryValue* dict = new DictionaryValue(); |
| 36 dict->SetString("address", address->ToString()); |
| 37 return dict; |
| 38 } |
| 39 |
| 40 Value* NetLogSourceAddressCallback(const struct sockaddr* net_address, |
| 41 socklen_t address_len, |
| 42 NetLog::LogLevel /* log_level */) { |
| 43 DictionaryValue* dict = new DictionaryValue(); |
| 44 dict->SetString("source_address", |
| 45 NetAddressToStringWithPort(net_address, address_len)); |
| 46 return dict; |
| 47 } |
| 48 |
| 49 } // namespace |
| 50 |
| 51 NetLog::ParametersCallback CreateNetLogSocketErrorCallback(int net_error, |
| 52 int os_error) { |
| 53 return base::Bind(&NetLogSocketErrorCallback, net_error, os_error); |
| 54 } |
| 55 |
| 56 NetLog::ParametersCallback CreateNetLogHostPortPairCallback( |
| 57 const HostPortPair* host_and_port) { |
| 58 return base::Bind(&NetLogHostPortPairCallback, host_and_port); |
| 59 } |
| 60 |
| 61 NetLog::ParametersCallback CreateNetLogIPEndPointCallback( |
| 62 const IPEndPoint* address) { |
| 63 return base::Bind(&NetLogIPEndPointCallback, address); |
| 64 } |
| 65 |
| 66 NetLog::ParametersCallback CreateNetLogSourceAddressCallback( |
| 67 const struct sockaddr* net_address, |
| 68 socklen_t address_len) { |
| 69 return base::Bind(&NetLogSourceAddressCallback, net_address, address_len); |
| 70 } |
24 | 71 |
25 } // namespace net | 72 } // namespace net |
OLD | NEW |