summaryrefslogtreecommitdiffstats
path: root/net/udp/udp_net_log_parameters.cc
blob: fb25b4c70a967c47125fc54421f18cfcf3114202 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/udp/udp_net_log_parameters.h"

#include "base/bind.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "net/base/ip_endpoint.h"

namespace net {

namespace {

base::Value* NetLogUDPDataTranferCallback(int byte_count,
                                          const char* bytes,
                                          const IPEndPoint* address,
                                          NetLogCaptureMode capture_mode) {
  base::DictionaryValue* dict = new base::DictionaryValue();
  dict->SetInteger("byte_count", byte_count);
  if (capture_mode.include_socket_bytes())
    dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count));
  if (address)
    dict->SetString("address", address->ToString());
  return dict;
}

base::Value* NetLogUDPConnectCallback(const IPEndPoint* address,
                                      NetLogCaptureMode /* capture_mode */) {
  base::DictionaryValue* dict = new base::DictionaryValue();
  dict->SetString("address", address->ToString());
  return dict;
}

}  // namespace

NetLog::ParametersCallback CreateNetLogUDPDataTranferCallback(
    int byte_count,
    const char* bytes,
    const IPEndPoint* address) {
  DCHECK(bytes);
  return base::Bind(&NetLogUDPDataTranferCallback, byte_count, bytes, address);
}

NetLog::ParametersCallback CreateNetLogUDPConnectCallback(
    const IPEndPoint* address) {
  DCHECK(address);
  return base::Bind(&NetLogUDPConnectCallback, address);
}

}  // namespace net