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/udp_net_log_parameters.h"
6
7 #include <utility>
8
9 #include "base/values.h"
10 #include "net/base/ip_endpoint.h"
11 #include "net/log/net_log_values.h"
12 #include "net/log/net_log_with_source.h"
13
14 namespace net {
15
16 namespace {
17
NetLogUDPDataTransferParams(int byte_count,const char * bytes,const IPEndPoint * address,NetLogCaptureMode capture_mode)18 base::Value::Dict NetLogUDPDataTransferParams(int byte_count,
19 const char* bytes,
20 const IPEndPoint* address,
21 NetLogCaptureMode capture_mode) {
22 base::Value::Dict dict;
23 dict.Set("byte_count", byte_count);
24 if (NetLogCaptureIncludesSocketBytes(capture_mode))
25 dict.Set("bytes", NetLogBinaryValue(bytes, byte_count));
26 if (address)
27 dict.Set("address", address->ToString());
28 return dict;
29 }
30
NetLogUDPConnectParams(const IPEndPoint & address,handles::NetworkHandle network)31 base::Value::Dict NetLogUDPConnectParams(const IPEndPoint& address,
32 handles::NetworkHandle network) {
33 base::Value::Dict dict;
34 dict.Set("address", address.ToString());
35 if (network != handles::kInvalidNetworkHandle)
36 dict.Set("bound_to_network", static_cast<int>(network));
37 return dict;
38 }
39
40 } // namespace
41
NetLogUDPDataTransfer(const NetLogWithSource & net_log,NetLogEventType type,int byte_count,const char * bytes,const IPEndPoint * address)42 void NetLogUDPDataTransfer(const NetLogWithSource& net_log,
43 NetLogEventType type,
44 int byte_count,
45 const char* bytes,
46 const IPEndPoint* address) {
47 DCHECK(bytes);
48 net_log.AddEvent(type, [&](NetLogCaptureMode capture_mode) {
49 return NetLogUDPDataTransferParams(byte_count, bytes, address,
50 capture_mode);
51 });
52 }
53
CreateNetLogUDPConnectParams(const IPEndPoint & address,handles::NetworkHandle network)54 base::Value::Dict CreateNetLogUDPConnectParams(const IPEndPoint& address,
55 handles::NetworkHandle network) {
56 return NetLogUDPConnectParams(address, network);
57 }
58
59 } // namespace net
60