[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 | |
| 5 | #include "net/udp/udp_net_log_parameters.h" |
| 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/bind.h" |
[email protected] | 4dc3ad4f | 2013-06-11 07:15:50 | [diff] [blame] | 10 | #include "base/strings/string_number_conversions.h" |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 11 | #include "base/values.h" |
| 12 | #include "net/base/ip_endpoint.h" |
| 13 | |
| 14 | namespace net { |
| 15 | |
| 16 | namespace { |
| 17 | |
estade | 5e5529d | 2015-05-21 20:59:11 | [diff] [blame] | 18 | scoped_ptr<base::Value> NetLogUDPDataTranferCallback( |
| 19 | int byte_count, |
| 20 | const char* bytes, |
| 21 | const IPEndPoint* address, |
| 22 | NetLogCaptureMode capture_mode) { |
| 23 | scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 24 | dict->SetInteger("byte_count", byte_count); |
eroman | 001c374 | 2015-04-23 03:11:17 | [diff] [blame] | 25 | if (capture_mode.include_socket_bytes()) |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 26 | dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count)); |
| 27 | if (address) |
| 28 | dict->SetString("address", address->ToString()); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 29 | return std::move(dict); |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 30 | } |
| 31 | |
estade | 5e5529d | 2015-05-21 20:59:11 | [diff] [blame] | 32 | scoped_ptr<base::Value> NetLogUDPConnectCallback( |
| 33 | const IPEndPoint* address, |
| 34 | NetLogCaptureMode /* capture_mode */) { |
| 35 | scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 36 | dict->SetString("address", address->ToString()); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 37 | return std::move(dict); |
[email protected] | 2584ea13 | 2012-06-14 02:47:59 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | } // namespace |
| 41 | |
| 42 | NetLog::ParametersCallback CreateNetLogUDPDataTranferCallback( |
| 43 | int byte_count, |
| 44 | const char* bytes, |
| 45 | const IPEndPoint* address) { |
| 46 | DCHECK(bytes); |
| 47 | return base::Bind(&NetLogUDPDataTranferCallback, byte_count, bytes, address); |
| 48 | } |
| 49 | |
| 50 | NetLog::ParametersCallback CreateNetLogUDPConnectCallback( |
| 51 | const IPEndPoint* address) { |
| 52 | DCHECK(address); |
| 53 | return base::Bind(&NetLogUDPConnectCallback, address); |
| 54 | } |
| 55 | |
| 56 | } // namespace net |