blob: d157fe83667e8da2f4ca3a53075452bc5218014f [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
5#include "net/udp/udp_net_log_parameters.h"
6
dchengc7eeda422015-12-26 03:56:487#include <utility>
8
[email protected]2584ea132012-06-14 02:47:599#include "base/bind.h"
[email protected]4dc3ad4f2013-06-11 07:15:5010#include "base/strings/string_number_conversions.h"
[email protected]2584ea132012-06-14 02:47:5911#include "base/values.h"
12#include "net/base/ip_endpoint.h"
13
14namespace net {
15
16namespace {
17
estade5e5529d2015-05-21 20:59:1118scoped_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]2584ea132012-06-14 02:47:5924 dict->SetInteger("byte_count", byte_count);
eroman001c3742015-04-23 03:11:1725 if (capture_mode.include_socket_bytes())
[email protected]2584ea132012-06-14 02:47:5926 dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count));
27 if (address)
28 dict->SetString("address", address->ToString());
dchengc7eeda422015-12-26 03:56:4829 return std::move(dict);
[email protected]2584ea132012-06-14 02:47:5930}
31
estade5e5529d2015-05-21 20:59:1132scoped_ptr<base::Value> NetLogUDPConnectCallback(
33 const IPEndPoint* address,
34 NetLogCaptureMode /* capture_mode */) {
35 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
[email protected]2584ea132012-06-14 02:47:5936 dict->SetString("address", address->ToString());
dchengc7eeda422015-12-26 03:56:4837 return std::move(dict);
[email protected]2584ea132012-06-14 02:47:5938}
39
40} // namespace
41
42NetLog::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
50NetLog::ParametersCallback CreateNetLogUDPConnectCallback(
51 const IPEndPoint* address) {
52 DCHECK(address);
53 return base::Bind(&NetLogUDPConnectCallback, address);
54}
55
56} // namespace net