diff options
author | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-14 02:47:59 +0000 |
---|---|---|
committer | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-14 02:47:59 +0000 |
commit | 2584ea13f563336f9d6cb3d238b18bb2ddf258a7 (patch) | |
tree | 48e06bb23ef5656c9fb18579cc5d982732ff03f0 /net/udp | |
parent | 29906c566b079bfefd50994d768565d9d6332512 (diff) | |
download | chromium_src-2584ea13f563336f9d6cb3d238b18bb2ddf258a7.zip chromium_src-2584ea13f563336f9d6cb3d238b18bb2ddf258a7.tar.gz chromium_src-2584ea13f563336f9d6cb3d238b18bb2ddf258a7.tar.bz2 |
NetLogEventParameter to Callback refactoring 4.
Get rid of all uses of NetLogEventParameters in net/udp and
net/dns.
R=eroman@chromium.org
BUG=126243
Review URL: https://chromiumcodereview.appspot.com/10546133
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142076 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/udp')
-rw-r--r-- | net/udp/udp_data_transfer_param.cc | 35 | ||||
-rw-r--r-- | net/udp/udp_data_transfer_param.h | 44 | ||||
-rw-r--r-- | net/udp/udp_net_log_parameters.cc | 52 | ||||
-rw-r--r-- | net/udp/udp_net_log_parameters.h | 32 | ||||
-rw-r--r-- | net/udp/udp_socket_libevent.cc | 29 | ||||
-rw-r--r-- | net/udp/udp_socket_win.cc | 29 |
6 files changed, 106 insertions, 115 deletions
diff --git a/net/udp/udp_data_transfer_param.cc b/net/udp/udp_data_transfer_param.cc deleted file mode 100644 index cd4da88..0000000 --- a/net/udp/udp_data_transfer_param.cc +++ /dev/null @@ -1,35 +0,0 @@ -// 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 "base/string_number_conversions.h" -#include "base/values.h" -#include "net/base/ip_endpoint.h" -#include "net/udp/udp_data_transfer_param.h" - -namespace net { - -UDPDataTransferNetLogParam::UDPDataTransferNetLogParam( - int byte_count, - const char* bytes, - bool log_bytes, - const IPEndPoint* address) - : byte_count_(byte_count), - hex_encoded_bytes_(log_bytes ? base::HexEncode(bytes, byte_count) : "") { - if (address) - address_.reset(new IPEndPoint(*address)); -} - -Value* UDPDataTransferNetLogParam::ToValue() const { - DictionaryValue* dict = new DictionaryValue(); - dict->SetInteger("byte_count", byte_count_); - if (!hex_encoded_bytes_.empty()) - dict->SetString("hex_encoded_bytes", hex_encoded_bytes_); - if (address_.get()) - dict->SetString("address", address_->ToString()); - return dict; -} - -UDPDataTransferNetLogParam::~UDPDataTransferNetLogParam() {} - -} // namespace net diff --git a/net/udp/udp_data_transfer_param.h b/net/udp/udp_data_transfer_param.h deleted file mode 100644 index 02cbcea..0000000 --- a/net/udp/udp_data_transfer_param.h +++ /dev/null @@ -1,44 +0,0 @@ -// 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. - -#ifndef NET_UDP_UDP_DATA_TRANSFER_PARAM_H_ -#define NET_UDP_UDP_DATA_TRANSFER_PARAM_H_ -#pragma once - -#include <string> - -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "net/base/net_log.h" - -namespace net { - -class IPEndPoint; - -// NetLog parameter to describe a UDP receive/send event. Each event has a -// byte count, and may optionally have transferred bytes and an IPEndPoint as -// well. -class UDPDataTransferNetLogParam : public NetLog::EventParameters { - public: - // |bytes| are only logged when |log_bytes| is non-NULL. - // |address| may be NULL. - UDPDataTransferNetLogParam(int byte_count, - const char* bytes, - bool log_bytes, - const IPEndPoint* address); - - virtual base::Value* ToValue() const OVERRIDE; - - protected: - virtual ~UDPDataTransferNetLogParam(); - - private: - const int byte_count_; - const std::string hex_encoded_bytes_; - scoped_ptr<IPEndPoint> address_; -}; - -} // namespace net - -#endif // NET_UDP_UDP_DATA_TRANSFER_PARAM_H_ diff --git a/net/udp/udp_net_log_parameters.cc b/net/udp/udp_net_log_parameters.cc new file mode 100644 index 0000000..5f841b8 --- /dev/null +++ b/net/udp/udp_net_log_parameters.cc @@ -0,0 +1,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/string_number_conversions.h" +#include "base/values.h" +#include "net/base/ip_endpoint.h" + +namespace net { + +namespace { + +Value* NetLogUDPDataTranferCallback(int byte_count, + const char* bytes, + const IPEndPoint* address, + NetLog::LogLevel log_level) { + DictionaryValue* dict = new DictionaryValue(); + dict->SetInteger("byte_count", byte_count); + if (NetLog::IsLoggingBytes(log_level)) + dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count)); + if (address) + dict->SetString("address", address->ToString()); + return dict; +} + +Value* NetLogUDPConnectCallback(const IPEndPoint* address, + NetLog::LogLevel /* log_level */) { + DictionaryValue* dict = new 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 diff --git a/net/udp/udp_net_log_parameters.h b/net/udp/udp_net_log_parameters.h new file mode 100644 index 0000000..0db1b87 --- /dev/null +++ b/net/udp/udp_net_log_parameters.h @@ -0,0 +1,32 @@ +// 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. + +#ifndef NET_UDP_UDP_NET_LOG_PARAMETERS_H_ +#define NET_UDP_UDP_NET_LOG_PARAMETERS_H_ +#pragma once + +#include "net/base/net_log.h" + +namespace net { + +class IPEndPoint; + +// Creates a NetLog callback that returns parameters describing a UDP +// receive/send event. |bytes| are only logged when byte logging is +// enabled. |address| may be NULL. |address| (if given) and |bytes| +// must be valid for the life of the callback. +NetLog::ParametersCallback CreateNetLogUDPDataTranferCallback( + int byte_count, + const char* bytes, + const IPEndPoint* address); + +// Creates a NetLog callback that returns parameters describing a UDP +// connect event. |address| cannot be NULL, and must remain valid for +// the lifetime of the callback. +NetLog::ParametersCallback CreateNetLogUDPConnectCallback( + const IPEndPoint* address); + +} // namespace net + +#endif // NET_UDP_UDP_NET_LOG_PARAMETERS_H_ diff --git a/net/udp/udp_socket_libevent.cc b/net/udp/udp_socket_libevent.cc index 13196d2..bb1cf91 100644 --- a/net/udp/udp_socket_libevent.cc +++ b/net/udp/udp_socket_libevent.cc @@ -9,6 +9,7 @@ #include <netdb.h> #include <sys/socket.h> +#include "base/callback.h" #include "base/eintr_wrapper.h" #include "base/logging.h" #include "base/message_loop.h" @@ -19,7 +20,7 @@ #include "net/base/net_errors.h" #include "net/base/net_log.h" #include "net/base/net_util.h" -#include "net/udp/udp_data_transfer_param.h" +#include "net/udp/udp_net_log_parameters.h" #if defined(OS_POSIX) #include <netinet/in.h> #endif @@ -48,17 +49,15 @@ UDPSocketLibevent::UDPSocketLibevent( recv_from_address_(NULL), write_buf_len_(0), net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_UDP_SOCKET)) { - scoped_refptr<NetLog::EventParameters> params; - if (source.is_valid()) - params = new NetLogSourceParameter("source_dependency", source); - net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, params); + net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, + source.ToEventParametersCallback()); if (bind_type == DatagramSocket::RANDOM_BIND) DCHECK(!rand_int_cb.is_null()); } UDPSocketLibevent::~UDPSocketLibevent() { Close(); - net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE, NULL); + net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE); } void UDPSocketLibevent::Close() { @@ -212,10 +211,8 @@ int UDPSocketLibevent::SendToOrWrite(IOBuffer* buf, } int UDPSocketLibevent::Connect(const IPEndPoint& address) { - net_log_.BeginEvent( - NetLog::TYPE_UDP_CONNECT, - make_scoped_refptr(new NetLogStringParameter("address", - address.ToString()))); + net_log_.BeginEvent(NetLog::TYPE_UDP_CONNECT, + CreateNetLogUDPConnectCallback(&address)); int rv = InternalConnect(address); net_log_.EndEventWithNetErrorCode(NetLog::TYPE_UDP_CONNECT, rv); return rv; @@ -326,10 +323,9 @@ void UDPSocketLibevent::LogRead(int result, bool is_address_valid = address.FromSockAddr(addr, addr_len); net_log_.AddEvent( NetLog::TYPE_UDP_BYTES_RECEIVED, - make_scoped_refptr( - new UDPDataTransferNetLogParam( - result, bytes, net_log_.IsLoggingBytes(), - is_address_valid ? &address : NULL))); + CreateNetLogUDPDataTranferCallback( + result, bytes, + is_address_valid ? &address : NULL)); } base::StatsCounter read_bytes("udp.read_bytes"); @@ -372,10 +368,7 @@ void UDPSocketLibevent::LogWrite(int result, if (net_log_.IsLoggingAllEvents()) { net_log_.AddEvent( NetLog::TYPE_UDP_BYTES_SENT, - make_scoped_refptr( - new UDPDataTransferNetLogParam(result, bytes, - net_log_.IsLoggingBytes(), - address))); + CreateNetLogUDPDataTranferCallback(result, bytes, address)); } base::StatsCounter write_bytes("udp.write_bytes"); diff --git a/net/udp/udp_socket_win.cc b/net/udp/udp_socket_win.cc index 4ed85ec..a7a11bf 100644 --- a/net/udp/udp_socket_win.cc +++ b/net/udp/udp_socket_win.cc @@ -6,6 +6,7 @@ #include <mstcpip.h> +#include "base/callback.h" #include "base/eintr_wrapper.h" #include "base/logging.h" #include "base/message_loop.h" @@ -18,7 +19,7 @@ #include "net/base/net_util.h" #include "net/base/winsock_init.h" #include "net/base/winsock_util.h" -#include "net/udp/udp_data_transfer_param.h" +#include "net/udp/udp_net_log_parameters.h" namespace { @@ -52,10 +53,8 @@ UDPSocketWin::UDPSocketWin(DatagramSocket::BindType bind_type, recv_from_address_(NULL), net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_UDP_SOCKET)) { EnsureWinsockInit(); - scoped_refptr<NetLog::EventParameters> params; - if (source.is_valid()) - params = new NetLogSourceParameter("source_dependency", source); - net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, params); + net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, + source.ToEventParametersCallback()); memset(&read_overlapped_, 0, sizeof(read_overlapped_)); read_overlapped_.hEvent = WSACreateEvent(); memset(&write_overlapped_, 0, sizeof(write_overlapped_)); @@ -66,7 +65,7 @@ UDPSocketWin::UDPSocketWin(DatagramSocket::BindType bind_type, UDPSocketWin::~UDPSocketWin() { Close(); - net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE, NULL); + net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE); } void UDPSocketWin::Close() { @@ -192,10 +191,8 @@ int UDPSocketWin::SendToOrWrite(IOBuffer* buf, } int UDPSocketWin::Connect(const IPEndPoint& address) { - net_log_.BeginEvent( - NetLog::TYPE_UDP_CONNECT, - make_scoped_refptr(new NetLogStringParameter("address", - address.ToString()))); + net_log_.BeginEvent(NetLog::TYPE_UDP_CONNECT, + CreateNetLogUDPConnectCallback(&address)); int rv = InternalConnect(address); net_log_.EndEventWithNetErrorCode(NetLog::TYPE_UDP_CONNECT, rv); return rv; @@ -312,10 +309,9 @@ void UDPSocketWin::LogRead(int result, const char* bytes) const { bool is_address_valid = ReceiveAddressToIPEndpoint(&address); net_log_.AddEvent( NetLog::TYPE_UDP_BYTES_RECEIVED, - make_scoped_refptr( - new UDPDataTransferNetLogParam( - result, bytes, net_log_.IsLoggingBytes(), - is_address_valid ? &address : NULL))); + CreateNetLogUDPDataTranferCallback( + result, bytes, + is_address_valid ? &address : NULL)); } base::StatsCounter read_bytes("udp.read_bytes"); @@ -346,10 +342,7 @@ void UDPSocketWin::LogWrite(int result, if (net_log_.IsLoggingAllEvents()) { net_log_.AddEvent( NetLog::TYPE_UDP_BYTES_SENT, - make_scoped_refptr( - new UDPDataTransferNetLogParam(result, bytes, - net_log_.IsLoggingBytes(), - address))); + CreateNetLogUDPDataTranferCallback(result, bytes, address)); } base::StatsCounter write_bytes("udp.write_bytes"); |