xref: /aosp_15_r20/external/cronet/net/socket/socket_net_log_params.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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   return base::Value::Dict()
21       .Set("net_error", net_error)
22       .Set("os_error", os_error);
23 }
24 
NetLogSocketError(const NetLogWithSource & net_log,NetLogEventType type,int net_error,int os_error)25 void NetLogSocketError(const NetLogWithSource& net_log,
26                        NetLogEventType type,
27                        int net_error,
28                        int os_error) {
29   net_log.AddEvent(
30       type, [&] { return NetLogSocketErrorParams(net_error, os_error); });
31 }
32 
CreateNetLogHostPortPairParams(const HostPortPair * host_and_port)33 base::Value::Dict CreateNetLogHostPortPairParams(
34     const HostPortPair* host_and_port) {
35   return base::Value::Dict().Set("host_and_port", host_and_port->ToString());
36 }
37 
CreateNetLogIPEndPointParams(const IPEndPoint * address)38 base::Value::Dict CreateNetLogIPEndPointParams(const IPEndPoint* address) {
39   return base::Value::Dict().Set("address", address->ToString());
40 }
41 
CreateNetLogAddressPairParams(const net::IPEndPoint & local_address,const net::IPEndPoint & remote_address)42 base::Value::Dict CreateNetLogAddressPairParams(
43     const net::IPEndPoint& local_address,
44     const net::IPEndPoint& remote_address) {
45   return base::Value::Dict()
46       .Set("local_address", local_address.ToString())
47       .Set("remote_address", remote_address.ToString());
48 }
49 
50 }  // namespace net
51