[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
tfarina | 5dd13c2 | 2016-11-16 12:08:26 | [diff] [blame] | 5 | #include "net/socket/udp_net_log_parameters.h" |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 6 | |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 9 | #include "base/values.h" |
| 10 | #include "net/base/ip_endpoint.h" |
Eric Roman | 45f155c | 2019-07-15 19:47:31 | [diff] [blame] | 11 | #include "net/log/net_log_values.h" |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame] | 12 | #include "net/log/net_log_with_source.h" |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 13 | |
| 14 | namespace net { |
| 15 | |
| 16 | namespace { |
| 17 | |
Eric Roman | 200db42 | 2019-07-18 23:58:55 | [diff] [blame] | 18 | base::Value NetLogUDPDataTransferParams(int byte_count, |
| 19 | const char* bytes, |
| 20 | const IPEndPoint* address, |
| 21 | NetLogCaptureMode capture_mode) { |
Matt Menke | ca721da | 2022-06-01 04:47:29 | [diff] [blame] | 22 | base::Value::Dict dict; |
| 23 | dict.Set("byte_count", byte_count); |
Eric Roman | 3124cde | 2019-07-10 22:26:15 | [diff] [blame] | 24 | if (NetLogCaptureIncludesSocketBytes(capture_mode)) |
Matt Menke | ca721da | 2022-06-01 04:47:29 | [diff] [blame] | 25 | dict.Set("bytes", NetLogBinaryValue(bytes, byte_count)); |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 26 | if (address) |
Matt Menke | ca721da | 2022-06-01 04:47:29 | [diff] [blame] | 27 | dict.Set("address", address->ToString()); |
| 28 | return base::Value(std::move(dict)); |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 29 | } |
| 30 | |
Stefano Duo | 6527ed4 | 2022-07-29 09:25:44 | [diff] [blame] | 31 | base::Value NetLogUDPConnectParams(const IPEndPoint& address, |
| 32 | handles::NetworkHandle network) { |
Matt Menke | ca721da | 2022-06-01 04:47:29 | [diff] [blame] | 33 | base::Value::Dict dict; |
| 34 | dict.Set("address", address.ToString()); |
Stefano Duo | 6527ed4 | 2022-07-29 09:25:44 | [diff] [blame] | 35 | if (network != handles::kInvalidNetworkHandle) |
Matt Menke | ca721da | 2022-06-01 04:47:29 | [diff] [blame] | 36 | dict.Set("bound_to_network", static_cast<int>(network)); |
| 37 | return base::Value(std::move(dict)); |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | } // namespace |
| 41 | |
Eric Roman | 200db42 | 2019-07-18 23:58:55 | [diff] [blame] | 42 | void NetLogUDPDataTransfer(const NetLogWithSource& net_log, |
| 43 | NetLogEventType type, |
| 44 | int byte_count, |
| 45 | const char* bytes, |
| 46 | const IPEndPoint* address) { |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 47 | DCHECK(bytes); |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame] | 48 | net_log.AddEvent(type, [&](NetLogCaptureMode capture_mode) { |
Eric Roman | 200db42 | 2019-07-18 23:58:55 | [diff] [blame] | 49 | return NetLogUDPDataTransferParams(byte_count, bytes, address, |
| 50 | capture_mode); |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame] | 51 | }); |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 52 | } |
| 53 | |
Stefano Duo | 6527ed4 | 2022-07-29 09:25:44 | [diff] [blame] | 54 | base::Value CreateNetLogUDPConnectParams(const IPEndPoint& address, |
| 55 | handles::NetworkHandle network) { |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame] | 56 | return NetLogUDPConnectParams(address, network); |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | } // namespace net |