Roll src/third_party/WebKit 57aef96:a1089e6 (svn 201978:201979)
[chromium-blink-merge.git] / net / udp / udp_net_log_parameters.cc
blob423f074605c1a1180607155b74ed1bc8fe27a6ab
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.
5 #include "net/udp/udp_net_log_parameters.h"
7 #include "base/bind.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/values.h"
10 #include "net/base/ip_endpoint.h"
12 namespace net {
14 namespace {
16 scoped_ptr<base::Value> NetLogUDPDataTranferCallback(
17 int byte_count,
18 const char* bytes,
19 const IPEndPoint* address,
20 NetLogCaptureMode capture_mode) {
21 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
22 dict->SetInteger("byte_count", byte_count);
23 if (capture_mode.include_socket_bytes())
24 dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count));
25 if (address)
26 dict->SetString("address", address->ToString());
27 return dict.Pass();
30 scoped_ptr<base::Value> NetLogUDPConnectCallback(
31 const IPEndPoint* address,
32 NetLogCaptureMode /* capture_mode */) {
33 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
34 dict->SetString("address", address->ToString());
35 return dict.Pass();
38 } // namespace
40 NetLog::ParametersCallback CreateNetLogUDPDataTranferCallback(
41 int byte_count,
42 const char* bytes,
43 const IPEndPoint* address) {
44 DCHECK(bytes);
45 return base::Bind(&NetLogUDPDataTranferCallback, byte_count, bytes, address);
48 NetLog::ParametersCallback CreateNetLogUDPConnectCallback(
49 const IPEndPoint* address) {
50 DCHECK(address);
51 return base::Bind(&NetLogUDPConnectCallback, address);
54 } // namespace net