blob: b58ab71b2edbbeb60dc15eace0ea5339ff1dd92a [file] [log] [blame]
[email protected]2584ea132012-06-14 02:47:591// 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
3// found in the LICENSE file.
4
tfarina5dd13c22016-11-16 12:08:265#include "net/socket/udp_net_log_parameters.h"
[email protected]2584ea132012-06-14 02:47:596
dchengc7eeda422015-12-26 03:56:487#include <utility>
8
[email protected]2584ea132012-06-14 02:47:599#include "base/values.h"
10#include "net/base/ip_endpoint.h"
Eric Roman45f155c2019-07-15 19:47:3111#include "net/log/net_log_values.h"
Eric Roman06bd9742019-07-13 15:19:1312#include "net/log/net_log_with_source.h"
[email protected]2584ea132012-06-14 02:47:5913
14namespace net {
15
16namespace {
17
Eric Roman200db422019-07-18 23:58:5518base::Value NetLogUDPDataTransferParams(int byte_count,
19 const char* bytes,
20 const IPEndPoint* address,
21 NetLogCaptureMode capture_mode) {
Matt Menkeca721da2022-06-01 04:47:2922 base::Value::Dict dict;
23 dict.Set("byte_count", byte_count);
Eric Roman3124cde2019-07-10 22:26:1524 if (NetLogCaptureIncludesSocketBytes(capture_mode))
Matt Menkeca721da2022-06-01 04:47:2925 dict.Set("bytes", NetLogBinaryValue(bytes, byte_count));
[email protected]2584ea132012-06-14 02:47:5926 if (address)
Matt Menkeca721da2022-06-01 04:47:2927 dict.Set("address", address->ToString());
28 return base::Value(std::move(dict));
[email protected]2584ea132012-06-14 02:47:5929}
30
Stefano Duo6527ed42022-07-29 09:25:4431base::Value NetLogUDPConnectParams(const IPEndPoint& address,
32 handles::NetworkHandle network) {
Matt Menkeca721da2022-06-01 04:47:2933 base::Value::Dict dict;
34 dict.Set("address", address.ToString());
Stefano Duo6527ed42022-07-29 09:25:4435 if (network != handles::kInvalidNetworkHandle)
Matt Menkeca721da2022-06-01 04:47:2936 dict.Set("bound_to_network", static_cast<int>(network));
37 return base::Value(std::move(dict));
[email protected]2584ea132012-06-14 02:47:5938}
39
40} // namespace
41
Eric Roman200db422019-07-18 23:58:5542void NetLogUDPDataTransfer(const NetLogWithSource& net_log,
43 NetLogEventType type,
44 int byte_count,
45 const char* bytes,
46 const IPEndPoint* address) {
[email protected]2584ea132012-06-14 02:47:5947 DCHECK(bytes);
Eric Roman06bd9742019-07-13 15:19:1348 net_log.AddEvent(type, [&](NetLogCaptureMode capture_mode) {
Eric Roman200db422019-07-18 23:58:5549 return NetLogUDPDataTransferParams(byte_count, bytes, address,
50 capture_mode);
Eric Roman06bd9742019-07-13 15:19:1351 });
[email protected]2584ea132012-06-14 02:47:5952}
53
Stefano Duo6527ed42022-07-29 09:25:4454base::Value CreateNetLogUDPConnectParams(const IPEndPoint& address,
55 handles::NetworkHandle network) {
Eric Roman06bd9742019-07-13 15:19:1356 return NetLogUDPConnectParams(address, network);
[email protected]2584ea132012-06-14 02:47:5957}
58
59} // namespace net