1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/socket/socket_net_log_params.h"
6
7 #include <utility>
8
9 #include "base/functional/bind.h"
10 #include "base/functional/callback.h"
11 #include "base/values.h"
12 #include "net/base/host_port_pair.h"
13 #include "net/base/ip_endpoint.h"
14 #include "net/log/net_log_capture_mode.h"
15 #include "net/log/net_log_with_source.h"
16
17 namespace net {
18
NetLogSocketErrorParams(int net_error,int os_error)19 base::Value::Dict NetLogSocketErrorParams(int net_error, int os_error) {
20 base::Value::Dict dict;
21 dict.Set("net_error", net_error);
22 dict.Set("os_error", os_error);
23 return dict;
24 }
25
NetLogSocketError(const NetLogWithSource & net_log,NetLogEventType type,int net_error,int os_error)26 void NetLogSocketError(const NetLogWithSource& net_log,
27 NetLogEventType type,
28 int net_error,
29 int os_error) {
30 net_log.AddEvent(
31 type, [&] { return NetLogSocketErrorParams(net_error, os_error); });
32 }
33
CreateNetLogHostPortPairParams(const HostPortPair * host_and_port)34 base::Value::Dict CreateNetLogHostPortPairParams(
35 const HostPortPair* host_and_port) {
36 base::Value::Dict dict;
37 dict.Set("host_and_port", host_and_port->ToString());
38 return dict;
39 }
40
CreateNetLogIPEndPointParams(const IPEndPoint * address)41 base::Value::Dict CreateNetLogIPEndPointParams(const IPEndPoint* address) {
42 base::Value::Dict dict;
43 dict.Set("address", address->ToString());
44 return dict;
45 }
46
CreateNetLogAddressPairParams(const net::IPEndPoint & local_address,const net::IPEndPoint & remote_address)47 base::Value::Dict CreateNetLogAddressPairParams(
48 const net::IPEndPoint& local_address,
49 const net::IPEndPoint& remote_address) {
50 base::Value::Dict dict;
51 dict.Set("local_address", local_address.ToString());
52 dict.Set("remote_address", remote_address.ToString());
53 return dict;
54 }
55
56 } // namespace net
57