summaryrefslogtreecommitdiffstats
path: root/net/socket
diff options
context:
space:
mode:
authormmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-14 21:02:31 +0000
committermmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-14 21:02:31 +0000
commit3aa4af04f4b8ba653e135d01988edcc783f296d7 (patch)
tree6014e603e7a3fbbc0fdb0ada6a51874e4a0814fb /net/socket
parent3031d8b7c9db7d26ce73961b8cb3b4ce125d6bc4 (diff)
downloadchromium_src-3aa4af04f4b8ba653e135d01988edcc783f296d7.zip
chromium_src-3aa4af04f4b8ba653e135d01988edcc783f296d7.tar.gz
chromium_src-3aa4af04f4b8ba653e135d01988edcc783f296d7.tar.bz2
NetLogEventParameter to Callback refactoring 9.
Get rid of all uses of NetLogEventParameters in net/socket. R=eroman@chromium.org BUG=126243 Review URL: https://chromiumcodereview.appspot.com/10546162 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142224 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket')
-rw-r--r--net/socket/client_socket_handle.cc5
-rw-r--r--net/socket/client_socket_pool_base.cc44
-rw-r--r--net/socket/nss_ssl_util.cc49
-rw-r--r--net/socket/socket_error_params.cc25
-rw-r--r--net/socket/socket_error_params.h30
-rw-r--r--net/socket/socket_net_log_params.cc72
-rw-r--r--net/socket/socket_net_log_params.h39
-rw-r--r--net/socket/socks5_client_socket.cc48
-rw-r--r--net/socket/socks_client_socket.cc2
-rw-r--r--net/socket/ssl_client_socket_mac.cc4
-rw-r--r--net/socket/ssl_client_socket_nss.cc164
-rw-r--r--net/socket/ssl_client_socket_openssl.cc4
-rw-r--r--net/socket/ssl_client_socket_win.cc8
-rw-r--r--net/socket/ssl_error_params.cc23
-rw-r--r--net/socket/ssl_error_params.h17
-rw-r--r--net/socket/ssl_server_socket_nss.cc15
-rw-r--r--net/socket/tcp_client_socket_libevent.cc39
-rw-r--r--net/socket/tcp_client_socket_win.cc42
-rw-r--r--net/socket/tcp_server_socket_libevent.cc14
-rw-r--r--net/socket/tcp_server_socket_win.cc14
-rw-r--r--net/socket/transport_client_socket_pool.cc11
21 files changed, 310 insertions, 359 deletions
diff --git a/net/socket/client_socket_handle.cc b/net/socket/client_socket_handle.cc
index ba30151..20ab672 100644
--- a/net/socket/client_socket_handle.cc
+++ b/net/socket/client_socket_handle.cc
@@ -40,7 +40,7 @@ void ClientSocketHandle::ResetInternal(bool cancel) {
if (is_initialized()) {
// Because of http://crbug.com/37810 we may not have a pool, but have
// just a raw socket.
- socket_->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE, NULL);
+ socket_->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE);
if (pool_)
// If we've still got a socket, release it back to the ClientSocketPool so
// it can be deleted or reused.
@@ -147,8 +147,7 @@ void ClientSocketHandle::HandleInitCompletion(int result) {
DCHECK(socket_.get());
socket_->NetLog().BeginEvent(
NetLog::TYPE_SOCKET_IN_USE,
- make_scoped_refptr(new NetLogSourceParameter(
- "source_dependency", requesting_source_)));
+ requesting_source_.ToEventParametersCallback());
}
} // namespace net
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
index 90f52f7..8c11782 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -77,11 +77,11 @@ ConnectJob::ConnectJob(const std::string& group_name,
idle_(true) {
DCHECK(!group_name.empty());
DCHECK(delegate);
- net_log.BeginEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL);
+ net_log.BeginEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB);
}
ConnectJob::~ConnectJob() {
- net_log().EndEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL);
+ net_log().EndEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB);
}
int ConnectJob::Connect() {
@@ -104,9 +104,8 @@ int ConnectJob::Connect() {
void ConnectJob::set_socket(StreamSocket* socket) {
if (socket) {
- net_log().AddEvent(NetLog::TYPE_CONNECT_JOB_SET_SOCKET, make_scoped_refptr(
- new NetLogSourceParameter("source_dependency",
- socket->NetLog().source())));
+ net_log().AddEvent(NetLog::TYPE_CONNECT_JOB_SET_SOCKET,
+ socket->NetLog().source().ToEventParametersCallback());
}
socket_.reset(socket);
}
@@ -127,7 +126,7 @@ void ConnectJob::ResetTimer(base::TimeDelta remaining_time) {
void ConnectJob::LogConnectStart() {
net_log().BeginEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT,
- make_scoped_refptr(new NetLogStringParameter("group_name", group_name_)));
+ NetLog::StringCallback("group_name", &group_name_));
}
void ConnectJob::LogConnectCompletion(int net_error) {
@@ -139,7 +138,7 @@ void ConnectJob::OnTimeout() {
// Make sure the socket is NULL before calling into |delegate|.
set_socket(NULL);
- net_log_.AddEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT, NULL);
+ net_log_.AddEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT);
NotifyDelegateOfCompletion(ERR_TIMED_OUT);
}
@@ -248,7 +247,7 @@ int ClientSocketPoolBaseHelper::RequestSocket(
if (!use_cleanup_timer_)
CleanupIdleSockets(false);
- request->net_log().BeginEvent(NetLog::TYPE_SOCKET_POOL, NULL);
+ request->net_log().BeginEvent(NetLog::TYPE_SOCKET_POOL);
Group* group = GetOrCreateGroup(group_name);
int rv = RequestSocketInternal(group_name, request);
@@ -279,8 +278,7 @@ void ClientSocketPoolBaseHelper::RequestSockets(
request.net_log().BeginEvent(
NetLog::TYPE_SOCKET_POOL_CONNECTING_N_SOCKETS,
- make_scoped_refptr(new NetLogIntegerParameter(
- "num_sockets", num_sockets)));
+ NetLog::IntegerCallback("num_sockets", num_sockets));
Group* group = GetOrCreateGroup(group_name);
@@ -343,7 +341,7 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal(
// reuse that socket then if we needed one and wouldn't make it down to this
// layer.
request->net_log().AddEvent(
- NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS_PER_GROUP, NULL);
+ NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS_PER_GROUP);
return ERR_IO_PENDING;
}
@@ -360,8 +358,7 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal(
} else {
// We could check if we really have a stalled group here, but it requires
// a scan of all groups, so just flip a flag here, and do the check later.
- request->net_log().AddEvent(
- NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS, NULL);
+ request->net_log().AddEvent(NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS);
return ERR_IO_PENDING;
}
}
@@ -481,10 +478,8 @@ bool ClientSocketPoolBaseHelper::AssignIdleSocketToRequest(
// static
void ClientSocketPoolBaseHelper::LogBoundConnectJobToRequest(
const NetLog::Source& connect_job_source, const Request* request) {
- request->net_log().AddEvent(
- NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
- make_scoped_refptr(new NetLogSourceParameter(
- "source_dependency", connect_job_source)));
+ request->net_log().AddEvent(NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
+ connect_job_source.ToEventParametersCallback());
}
void ClientSocketPoolBaseHelper::CancelRequest(
@@ -511,8 +506,8 @@ void ClientSocketPoolBaseHelper::CancelRequest(
for (; it != group->pending_requests().end(); ++it) {
if ((*it)->handle() == handle) {
scoped_ptr<const Request> req(RemoveRequestFromQueue(it, group));
- req->net_log().AddEvent(NetLog::TYPE_CANCELLED, NULL);
- req->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL);
+ req->net_log().AddEvent(NetLog::TYPE_CANCELLED);
+ req->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL);
// We let the job run, unless we're at the socket limit.
if (group->jobs().size() && ReachedMaxSocketsLimit()) {
@@ -862,7 +857,7 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete(
HandOutSocket(
socket.release(), false /* unused socket */, r->handle(),
base::TimeDelta(), group, r->net_log());
- r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL);
+ r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL);
InvokeUserCallbackLater(r->handle(), r->callback(), result);
} else {
AddIdleSocket(socket.release(), group);
@@ -985,13 +980,12 @@ void ClientSocketPoolBaseHelper::HandOutSocket(
if (reused) {
net_log.AddEvent(
NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET,
- make_scoped_refptr(new NetLogIntegerParameter(
- "idle_ms", static_cast<int>(idle_time.InMilliseconds()))));
+ NetLog::IntegerCallback(
+ "idle_ms", static_cast<int>(idle_time.InMilliseconds())));
}
net_log.AddEvent(NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET,
- make_scoped_refptr(new NetLogSourceParameter(
- "source_dependency", socket->NetLog().source())));
+ socket->NetLog().source().ToEventParametersCallback());
handed_out_socket_count_++;
group->IncrementActiveSocketCount();
@@ -1205,7 +1199,7 @@ void ClientSocketPoolBaseHelper::Group::OnBackupSocketTimerFired(
ConnectJob* backup_job = pool->connect_job_factory_->NewConnectJob(
group_name, **pending_requests_.begin(), pool);
- backup_job->net_log().AddEvent(NetLog::TYPE_SOCKET_BACKUP_CREATED, NULL);
+ backup_job->net_log().AddEvent(NetLog::TYPE_SOCKET_BACKUP_CREATED);
SIMPLE_STATS_COUNTER("socket.backup_created");
int rv = backup_job->Connect();
pool->connecting_socket_count_++;
diff --git a/net/socket/nss_ssl_util.cc b/net/socket/nss_ssl_util.cc
index b92600a..d262f93 100644
--- a/net/socket/nss_ssl_util.cc
+++ b/net/socket/nss_ssl_util.cc
@@ -11,6 +11,7 @@
#include <string>
+#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
@@ -220,41 +221,31 @@ int MapNSSError(PRErrorCode err) {
}
}
-// Extra parameters to attach to the NetLog when we receive an error in response
-// to a call to an NSS function. Used instead of SSLErrorParams with
-// events of type TYPE_SSL_NSS_ERROR. Automatically looks up last PR error.
-class SSLFailedNSSFunctionParams : public NetLog::EventParameters {
- public:
- // |param| is ignored if it has a length of 0.
- SSLFailedNSSFunctionParams(const std::string& function,
- const std::string& param)
- : function_(function), param_(param), ssl_lib_error_(PR_GetError()) {
- }
-
- virtual Value* ToValue() const {
- DictionaryValue* dict = new DictionaryValue();
- dict->SetString("function", function_);
- if (!param_.empty())
- dict->SetString("param", param_);
- dict->SetInteger("ssl_lib_error", ssl_lib_error_);
- return dict;
- }
-
- protected:
- virtual ~SSLFailedNSSFunctionParams() {}
-
- private:
- const std::string function_;
- const std::string param_;
- const PRErrorCode ssl_lib_error_;
-};
+// Returns parameters to attach to the NetLog when we receive an error in
+// response to a call to an NSS function. Used instead of
+// NetLogSSLErrorCallback with events of type TYPE_SSL_NSS_ERROR.
+Value* NetLogSSLFailedNSSFunctionCallback(
+ const char* function,
+ const char* param,
+ int ssl_lib_error,
+ NetLog::LogLevel /* log_level */) {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetString("function", function);
+ if (param[0] != '\0')
+ dict->SetString("param", param);
+ dict->SetInteger("ssl_lib_error", ssl_lib_error);
+ return dict;
+}
void LogFailedNSSFunction(const BoundNetLog& net_log,
const char* function,
const char* param) {
+ DCHECK(function);
+ DCHECK(param);
net_log.AddEvent(
NetLog::TYPE_SSL_NSS_ERROR,
- make_scoped_refptr(new SSLFailedNSSFunctionParams(function, param)));
+ base::Bind(&NetLogSSLFailedNSSFunctionCallback,
+ function, param, PR_GetError()));
}
} // namespace net
diff --git a/net/socket/socket_error_params.cc b/net/socket/socket_error_params.cc
deleted file mode 100644
index a805646..0000000
--- a/net/socket/socket_error_params.cc
+++ /dev/null
@@ -1,25 +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 "net/socket/socket_error_params.h"
-
-#include "base/values.h"
-
-namespace net {
-
-SocketErrorParams::SocketErrorParams(int net_error, int os_error)
- : net_error_(net_error),
- os_error_(os_error) {
-}
-
-Value* SocketErrorParams::ToValue() const {
- DictionaryValue* dict = new DictionaryValue();
- dict->SetInteger("net_error", net_error_);
- dict->SetInteger("os_error", os_error_);
- return dict;
-}
-
-SocketErrorParams::~SocketErrorParams() {}
-
-} // namespace net
diff --git a/net/socket/socket_error_params.h b/net/socket/socket_error_params.h
deleted file mode 100644
index 1e86012..0000000
--- a/net/socket/socket_error_params.h
+++ /dev/null
@@ -1,30 +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_SOCKET_SOCKET_ERROR_PARAMS_H_
-#define NET_SOCKET_SOCKET_ERROR_PARAMS_H_
-#pragma once
-
-#include "net/base/net_log.h"
-
-namespace net {
-
-// Extra parameters to attach to the NetLog when we receive a socket error.
-class SocketErrorParams : public NetLog::EventParameters {
- public:
- SocketErrorParams(int net_error, int os_error);
-
- virtual base::Value* ToValue() const OVERRIDE;
-
- protected:
- virtual ~SocketErrorParams();
-
- private:
- const int net_error_;
- const int os_error_;
-};
-
-} // namespace net
-
-#endif // NET_SOCKET_SOCKET_ERROR_PARAMS_H_
diff --git a/net/socket/socket_net_log_params.cc b/net/socket/socket_net_log_params.cc
new file mode 100644
index 0000000..c075ec5
--- /dev/null
+++ b/net/socket/socket_net_log_params.cc
@@ -0,0 +1,72 @@
+// 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/socket/socket_net_log_params.h"
+
+#include "base/bind.h"
+#include "base/values.h"
+#include "net/base/host_port_pair.h"
+#include "net/base/ip_endpoint.h"
+#include "net/base/net_util.h"
+
+namespace net {
+
+namespace {
+
+Value* NetLogSocketErrorCallback(int net_error,
+ int os_error,
+ NetLog::LogLevel /* log_level */) {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetInteger("net_error", net_error);
+ dict->SetInteger("os_error", os_error);
+ return dict;
+}
+
+Value* NetLogHostPortPairCallback(const HostPortPair* host_and_port,
+ NetLog::LogLevel /* log_level */) {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetString("host_and_port", host_and_port->ToString());
+ return dict;
+}
+
+Value* NetLogIPEndPointCallback(const IPEndPoint* address,
+ NetLog::LogLevel /* log_level */) {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetString("address", address->ToString());
+ return dict;
+}
+
+Value* NetLogSourceAddressCallback(const struct sockaddr* net_address,
+ socklen_t address_len,
+ NetLog::LogLevel /* log_level */) {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetString("source_address",
+ NetAddressToStringWithPort(net_address, address_len));
+ return dict;
+}
+
+} // namespace
+
+NetLog::ParametersCallback CreateNetLogSocketErrorCallback(int net_error,
+ int os_error) {
+ return base::Bind(&NetLogSocketErrorCallback, net_error, os_error);
+}
+
+NetLog::ParametersCallback CreateNetLogHostPortPairCallback(
+ const HostPortPair* host_and_port) {
+ return base::Bind(&NetLogHostPortPairCallback, host_and_port);
+}
+
+NetLog::ParametersCallback CreateNetLogIPEndPointCallback(
+ const IPEndPoint* address) {
+ return base::Bind(&NetLogIPEndPointCallback, address);
+}
+
+NetLog::ParametersCallback CreateNetLogSourceAddressCallback(
+ const struct sockaddr* net_address,
+ socklen_t address_len) {
+ return base::Bind(&NetLogSourceAddressCallback, net_address, address_len);
+}
+
+} // namespace net
diff --git a/net/socket/socket_net_log_params.h b/net/socket/socket_net_log_params.h
new file mode 100644
index 0000000..b08a3a4
--- /dev/null
+++ b/net/socket/socket_net_log_params.h
@@ -0,0 +1,39 @@
+// 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_SOCKET_SOCKET_NET_LOG_PARAMS_H_
+#define NET_SOCKET_SOCKET_NET_LOG_PARAMS_H_
+#pragma once
+
+#include "net/base/net_log.h"
+#include "net/base/sys_addrinfo.h"
+
+namespace net {
+
+class HostPortPair;
+class IPEndPoint;
+
+// Creates a NetLog callback for socket error events.
+NetLog::ParametersCallback CreateNetLogSocketErrorCallback(int net_error,
+ int os_error);
+
+// Creates a NetLog callback for a HostPortPair.
+// |host_and_port| must remain valid for the lifetime of the returned callback.
+NetLog::ParametersCallback CreateNetLogHostPortPairCallback(
+ const HostPortPair* host_and_port);
+
+// Creates a NetLog callback for an IPEndPoint.
+// |address| must remain valid for the lifetime of the returned callback.
+NetLog::ParametersCallback CreateNetLogIPEndPointCallback(
+ const IPEndPoint* address);
+
+// Creates a NetLog callback for the source sockaddr on connect events.
+// |net_address| must remain valid for the lifetime of the returned callback.
+NetLog::ParametersCallback CreateNetLogSourceAddressCallback(
+ const struct sockaddr* net_address,
+ socklen_t address_len);
+
+} // namespace net
+
+#endif // NET_SOCKET_SOCKET_NET_LOG_PARAMS_H_
diff --git a/net/socket/socks5_client_socket.cc b/net/socket/socks5_client_socket.cc
index 9755756..1b020d7 100644
--- a/net/socket/socks5_client_socket.cc
+++ b/net/socket/socks5_client_socket.cc
@@ -74,7 +74,7 @@ int SOCKS5ClientSocket::Connect(const CompletionCallback& callback) {
if (completed_handshake_)
return OK;
- net_log_.BeginEvent(NetLog::TYPE_SOCKS5_CONNECT, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_SOCKS5_CONNECT);
next_state_ = STATE_GREET_WRITE;
buffer_.clear();
@@ -211,7 +211,7 @@ void SOCKS5ClientSocket::OnIOComplete(int result) {
DCHECK_NE(STATE_NONE, next_state_);
int rv = DoLoop(result);
if (rv != ERR_IO_PENDING) {
- net_log_.EndEvent(NetLog::TYPE_SOCKS5_CONNECT, NULL);
+ net_log_.EndEvent(NetLog::TYPE_SOCKS5_CONNECT);
DoCallback(rv);
}
}
@@ -225,7 +225,7 @@ int SOCKS5ClientSocket::DoLoop(int last_io_result) {
switch (state) {
case STATE_GREET_WRITE:
DCHECK_EQ(OK, rv);
- net_log_.BeginEvent(NetLog::TYPE_SOCKS5_GREET_WRITE, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_SOCKS5_GREET_WRITE);
rv = DoGreetWrite();
break;
case STATE_GREET_WRITE_COMPLETE:
@@ -234,7 +234,7 @@ int SOCKS5ClientSocket::DoLoop(int last_io_result) {
break;
case STATE_GREET_READ:
DCHECK_EQ(OK, rv);
- net_log_.BeginEvent(NetLog::TYPE_SOCKS5_GREET_READ, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_SOCKS5_GREET_READ);
rv = DoGreetRead();
break;
case STATE_GREET_READ_COMPLETE:
@@ -243,7 +243,7 @@ int SOCKS5ClientSocket::DoLoop(int last_io_result) {
break;
case STATE_HANDSHAKE_WRITE:
DCHECK_EQ(OK, rv);
- net_log_.BeginEvent(NetLog::TYPE_SOCKS5_HANDSHAKE_WRITE, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_SOCKS5_HANDSHAKE_WRITE);
rv = DoHandshakeWrite();
break;
case STATE_HANDSHAKE_WRITE_COMPLETE:
@@ -253,7 +253,7 @@ int SOCKS5ClientSocket::DoLoop(int last_io_result) {
break;
case STATE_HANDSHAKE_READ:
DCHECK_EQ(OK, rv);
- net_log_.BeginEvent(NetLog::TYPE_SOCKS5_HANDSHAKE_READ, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_SOCKS5_HANDSHAKE_READ);
rv = DoHandshakeRead();
break;
case STATE_HANDSHAKE_READ_COMPLETE:
@@ -277,7 +277,7 @@ int SOCKS5ClientSocket::DoGreetWrite() {
// Since we only have 1 byte to send the hostname length in, if the
// URL has a hostname longer than 255 characters we can't send it.
if (0xFF < host_request_info_.hostname().size()) {
- net_log_.AddEvent(NetLog::TYPE_SOCKS_HOSTNAME_TOO_BIG, NULL);
+ net_log_.AddEvent(NetLog::TYPE_SOCKS_HOSTNAME_TOO_BIG);
return ERR_SOCKS_CONNECTION_FAILED;
}
@@ -324,8 +324,7 @@ int SOCKS5ClientSocket::DoGreetReadComplete(int result) {
return result;
if (result == 0) {
- net_log_.AddEvent(NetLog::TYPE_SOCKS_UNEXPECTEDLY_CLOSED_DURING_GREETING,
- NULL);
+ net_log_.AddEvent(NetLog::TYPE_SOCKS_UNEXPECTEDLY_CLOSED_DURING_GREETING);
return ERR_SOCKS_CONNECTION_FAILED;
}
@@ -338,15 +337,13 @@ int SOCKS5ClientSocket::DoGreetReadComplete(int result) {
// Got the greet data.
if (buffer_[0] != kSOCKS5Version) {
- net_log_.AddEvent(
- NetLog::TYPE_SOCKS_UNEXPECTED_VERSION,
- make_scoped_refptr(new NetLogIntegerParameter("version", buffer_[0])));
+ net_log_.AddEvent(NetLog::TYPE_SOCKS_UNEXPECTED_VERSION,
+ NetLog::IntegerCallback("version", buffer_[0]));
return ERR_SOCKS_CONNECTION_FAILED;
}
if (buffer_[1] != 0x00) {
- net_log_.AddEvent(
- NetLog::TYPE_SOCKS_UNEXPECTED_AUTH,
- make_scoped_refptr(new NetLogIntegerParameter("method", buffer_[1])));
+ net_log_.AddEvent(NetLog::TYPE_SOCKS_UNEXPECTED_AUTH,
+ NetLog::IntegerCallback("method", buffer_[1]));
return ERR_SOCKS_CONNECTION_FAILED;
}
@@ -437,8 +434,7 @@ int SOCKS5ClientSocket::DoHandshakeReadComplete(int result) {
// The underlying socket closed unexpectedly.
if (result == 0) {
- net_log_.AddEvent(NetLog::TYPE_SOCKS_UNEXPECTEDLY_CLOSED_DURING_HANDSHAKE,
- NULL);
+ net_log_.AddEvent(NetLog::TYPE_SOCKS_UNEXPECTEDLY_CLOSED_DURING_HANDSHAKE);
return ERR_SOCKS_CONNECTION_FAILED;
}
@@ -449,17 +445,13 @@ int SOCKS5ClientSocket::DoHandshakeReadComplete(int result) {
// and accordingly increase them
if (bytes_received_ == kReadHeaderSize) {
if (buffer_[0] != kSOCKS5Version || buffer_[2] != kNullByte) {
- net_log_.AddEvent(
- NetLog::TYPE_SOCKS_UNEXPECTED_VERSION,
- make_scoped_refptr(
- new NetLogIntegerParameter("version", buffer_[0])));
+ net_log_.AddEvent(NetLog::TYPE_SOCKS_UNEXPECTED_VERSION,
+ NetLog::IntegerCallback("version", buffer_[0]));
return ERR_SOCKS_CONNECTION_FAILED;
}
if (buffer_[1] != 0x00) {
- net_log_.AddEvent(
- NetLog::TYPE_SOCKS_SERVER_ERROR,
- make_scoped_refptr(
- new NetLogIntegerParameter("error_code", buffer_[1])));
+ net_log_.AddEvent(NetLog::TYPE_SOCKS_SERVER_ERROR,
+ NetLog::IntegerCallback("error_code", buffer_[1]));
return ERR_SOCKS_CONNECTION_FAILED;
}
@@ -477,10 +469,8 @@ int SOCKS5ClientSocket::DoHandshakeReadComplete(int result) {
else if (address_type == kEndPointResolvedIPv6)
read_header_size += sizeof(struct in6_addr) - 1;
else {
- net_log_.AddEvent(
- NetLog::TYPE_SOCKS_UNKNOWN_ADDRESS_TYPE,
- make_scoped_refptr(
- new NetLogIntegerParameter("address_type", buffer_[3])));
+ net_log_.AddEvent(NetLog::TYPE_SOCKS_UNKNOWN_ADDRESS_TYPE,
+ NetLog::IntegerCallback("address_type", buffer_[3]));
return ERR_SOCKS_CONNECTION_FAILED;
}
diff --git a/net/socket/socks_client_socket.cc b/net/socket/socks_client_socket.cc
index 7a9f2f7..6776b71 100644
--- a/net/socket/socks_client_socket.cc
+++ b/net/socket/socks_client_socket.cc
@@ -98,7 +98,7 @@ int SOCKSClientSocket::Connect(const CompletionCallback& callback) {
next_state_ = STATE_RESOLVE_HOST;
- net_log_.BeginEvent(NetLog::TYPE_SOCKS_CONNECT, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_SOCKS_CONNECT);
int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING) {
diff --git a/net/socket/ssl_client_socket_mac.cc b/net/socket/ssl_client_socket_mac.cc
index 907b05e..f51079f 100644
--- a/net/socket/ssl_client_socket_mac.cc
+++ b/net/socket/ssl_client_socket_mac.cc
@@ -554,7 +554,7 @@ int SSLClientSocketMac::Connect(const CompletionCallback& callback) {
DCHECK(next_handshake_state_ == STATE_NONE);
DCHECK(user_connect_callback_.is_null());
- net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT);
int rv = InitializeSSLContext();
if (rv != OK) {
@@ -1142,7 +1142,7 @@ int SSLClientSocketMac::DoHandshake() {
}
net_log_.AddEvent(NetLog::TYPE_SSL_HANDSHAKE_ERROR,
- new SSLErrorParams(net_error, status));
+ CreateNetLogSSLErrorCallback(net_error, status));
return net_error;
}
diff --git a/net/socket/ssl_client_socket_nss.cc b/net/socket/ssl_client_socket_nss.cc
index ba49875..32e70f8 100644
--- a/net/socket/ssl_client_socket_nss.cc
+++ b/net/socket/ssl_client_socket_nss.cc
@@ -382,11 +382,16 @@ void DestroyCertificates(CERTCertificate** certs, size_t len) {
CERT_DestroyCertificate(certs[i]);
}
+// Helper functions to make it possible to log events from within the
+// SSLClientSocketNSS::Core.
+void AddLogEvent(BoundNetLog* net_log, NetLog::EventType event_type) {
+ if (!net_log)
+ return;
+ net_log->AddEvent(event_type);
+}
+
// Helper function to make it possible to log events from within the
-// SSLClientSocketNSS::Core. Can't use Bind with BoundNetLog::AddEntry directly
-// on Windows because it is overloaded.
-// TODO(mmenke): Other than shutdown, NetLog is threadsafe. Figure out if this
-// is needed.
+// SSLClientSocketNSS::Core.
void AddLogEventWithCallback(BoundNetLog* net_log,
NetLog::EventType event_type,
const NetLog::ParametersCallback& callback) {
@@ -395,18 +400,6 @@ void AddLogEventWithCallback(BoundNetLog* net_log,
net_log->AddEvent(event_type, callback);
}
-// Helper functions to make it possible to log events from within the
-// SSLClientSocketNSS::Core. Can't use Bind with BoundNetLog::AddEntry directly
-// on Windows because it is overloaded.
-// TODO(mmenke): This function is deprecated, delete it.
-void AddLogEvent(BoundNetLog* net_log,
- NetLog::EventType event_type,
- const scoped_refptr<NetLog::EventParameters>& event_params) {
- if (!net_log)
- return;
- net_log->AddEvent(event_type, event_params);
-}
-
// Helper function to make it easier to call BoundNetLog::AddByteTransferEvent
// from within the SSLClientSocketNSS::Core.
// AddByteTransferEvent expects to receive a const char*, which within the
@@ -911,6 +904,10 @@ class SSLClientSocketNSS::Core : public base::RefCountedThreadSafe<Core> {
void PostOrRunCallback(const tracked_objects::Location& location,
const base::Closure& callback);
+ // Uses PostOrRunCallback and |weak_net_log_| to try and log a
+ // SSL_CLIENT_CERT_PROVIDED event, with the indicated count.
+ void AddCertProvidedEvent(int cert_count);
+
////////////////////////////////////////////////////////////////////////////
// Members that are ONLY accessed on the network task runner:
////////////////////////////////////////////////////////////////////////////
@@ -1318,8 +1315,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
core->PostOrRunCallback(
FROM_HERE,
base::Bind(&AddLogEvent, core->weak_net_log_,
- NetLog::TYPE_SSL_CLIENT_CERT_REQUESTED,
- scoped_refptr<NetLog::EventParameters>()));
+ NetLog::TYPE_SSL_CLIENT_CERT_REQUESTED));
const SECItem* cert_types = SSL_GetRequestedClientCertificateTypes(socket);
@@ -1362,12 +1358,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
if (!user_cert) {
// Importing the certificate can fail for reasons including a serial
// number collision. See crbug.com/97355.
- core->PostOrRunCallback(
- FROM_HERE,
- base::Bind(&AddLogEvent, core->weak_net_log_,
- NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
- make_scoped_refptr(
- new NetLogIntegerParameter("cert_count", 0))));
+ core->AddCertProvidedEvent(0);
return SECFailure;
}
CERTCertList* cert_chain = CERT_NewCertList();
@@ -1385,12 +1376,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
db_handle, &der_cert, NULL, PR_FALSE, PR_TRUE);
if (!intermediate) {
CERT_DestroyCertList(cert_chain);
- core->PostOrRunCallback(
- FROM_HERE,
- base::Bind(&AddLogEvent, core->weak_net_log_,
- NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
- make_scoped_refptr(
- new NetLogIntegerParameter("cert_count", 0))));
+ core->AddCertProvidedEvent(0);
return SECFailure;
}
CERT_AddCertToListTail(cert_chain, intermediate);
@@ -1408,25 +1394,14 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
*result_certs = cert_chain;
int cert_count = 1 + intermediates.size();
- core->PostOrRunCallback(
- FROM_HERE,
- base::Bind(&AddLogEvent, core->weak_net_log_,
- NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
- make_scoped_refptr(
- new NetLogIntegerParameter("cert_count",
- cert_count))));
+ core->AddCertProvidedEvent(cert_count);
return SECSuccess;
}
LOG(WARNING) << "Client cert found without private key";
}
// Send no client certificate.
- core->PostOrRunCallback(
- FROM_HERE,
- base::Bind(&AddLogEvent, core->weak_net_log_,
- NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
- make_scoped_refptr(
- new NetLogIntegerParameter("cert_count", 0))));
+ core->AddCertProvidedEvent(0);
return SECFailure;
}
@@ -1443,12 +1418,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
if (!my_cert_store) {
PLOG(ERROR) << "Could not open the \"MY\" system certificate store";
- core->PostOrRunCallback(
- FROM_HERE,
- base::Bind(&AddLogEvent, core->weak_net_log_,
- NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
- make_scoped_refptr(
- new NetLogIntegerParameter("cert_count", 0))));
+ core->AddCertProvidedEvent(0);
return SECFailure;
}
@@ -1588,13 +1558,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
cert_count = CFArrayGetCount(chain);
CFRelease(chain);
}
- core->PostOrRunCallback(
- FROM_HERE,
- base::Bind(&AddLogEvent, core->weak_net_log_,
- NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
- make_scoped_refptr(
- new NetLogIntegerParameter("cert_count",
- cert_count))));
+ core->AddCertProvidedEvent(cert_count);
return SECSuccess;
}
OSSTATUS_LOG(WARNING, os_error)
@@ -1612,12 +1576,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
}
// Send no client certificate.
- core->PostOrRunCallback(
- FROM_HERE,
- base::Bind(&AddLogEvent, core->weak_net_log_,
- NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
- make_scoped_refptr(
- new NetLogIntegerParameter("cert_count", 0))));
+ core->AddCertProvidedEvent(0);
return SECFailure;
}
@@ -1670,8 +1629,7 @@ SECStatus SSLClientSocketNSS::Core::ClientAuthHandler(
core->PostOrRunCallback(
FROM_HERE,
base::Bind(&AddLogEvent, core->weak_net_log_,
- NetLog::TYPE_SSL_CLIENT_CERT_REQUESTED,
- scoped_refptr<NetLog::EventParameters>()));
+ NetLog::TYPE_SSL_CLIENT_CERT_REQUESTED));
const SECItem* cert_types = SSL_GetRequestedClientCertificateTypes(socket);
@@ -1699,24 +1657,14 @@ SECStatus SSLClientSocketNSS::Core::ClientAuthHandler(
*result_private_key = privkey;
// A cert_count of -1 means the number of certificates is unknown.
// NSS will construct the certificate chain.
- core->PostOrRunCallback(
- FROM_HERE,
- base::Bind(&AddLogEvent, core->weak_net_log_,
- NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
- make_scoped_refptr(
- new NetLogIntegerParameter("cert_count", -1))));
+ core->AddCertProvidedEvent(-1);
return SECSuccess;
}
LOG(WARNING) << "Client cert found without private key";
}
// Send no client certificate.
- core->PostOrRunCallback(
- FROM_HERE,
- base::Bind(&AddLogEvent, core->weak_net_log_,
- NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
- make_scoped_refptr(
- new NetLogIntegerParameter("cert_count", 0))));
+ core->AddCertProvidedEvent(0);
return SECFailure;
}
@@ -1964,9 +1912,9 @@ int SSLClientSocketNSS::Core::DoReadLoop(int result) {
int rv = ERR_UNEXPECTED;
PostOrRunCallback(
FROM_HERE,
- base::Bind(&AddLogEvent, weak_net_log_,
+ base::Bind(&AddLogEventWithCallback, weak_net_log_,
NetLog::TYPE_SSL_READ_ERROR,
- make_scoped_refptr(new SSLErrorParams(rv, 0))));
+ CreateNetLogSSLErrorCallback(rv, 0)));
return rv;
}
@@ -1993,9 +1941,9 @@ int SSLClientSocketNSS::Core::DoWriteLoop(int result) {
int rv = ERR_UNEXPECTED;
PostOrRunCallback(
FROM_HERE,
- base::Bind(&AddLogEvent, weak_net_log_,
+ base::Bind(&AddLogEventWithCallback, weak_net_log_,
NetLog::TYPE_SSL_READ_ERROR,
- make_scoped_refptr(new SSLErrorParams(rv, 0))));
+ CreateNetLogSSLErrorCallback(rv, 0)));
return rv;
}
@@ -2028,9 +1976,9 @@ int SSLClientSocketNSS::Core::DoHandshake() {
net_error = ERR_SSL_CLIENT_AUTH_CERT_NEEDED;
PostOrRunCallback(
FROM_HERE,
- base::Bind(&AddLogEvent, weak_net_log_,
+ base::Bind(&AddLogEventWithCallback, weak_net_log_,
NetLog::TYPE_SSL_HANDSHAKE_ERROR,
- make_scoped_refptr(new SSLErrorParams(net_error, 0))));
+ CreateNetLogSSLErrorCallback(net_error, 0)));
// If the handshake already succeeded (because the server requests but
// doesn't require a client cert), we need to invalidate the SSL session
@@ -2048,10 +1996,9 @@ int SSLClientSocketNSS::Core::DoHandshake() {
net_error = ERR_SSL_PROTOCOL_ERROR;
PostOrRunCallback(
FROM_HERE,
- base::Bind(&AddLogEvent, weak_net_log_,
+ base::Bind(&AddLogEventWithCallback, weak_net_log_,
NetLog::TYPE_SSL_HANDSHAKE_ERROR,
- make_scoped_refptr(
- new SSLErrorParams(net_error, 0))));
+ CreateNetLogSSLErrorCallback(net_error, 0)));
} else {
#if defined(SSL_ENABLE_OCSP_STAPLING)
// TODO(agl): figure out how to plumb an OCSP response into the Mac
@@ -2126,10 +2073,9 @@ int SSLClientSocketNSS::Core::DoHandshake() {
} else {
PostOrRunCallback(
FROM_HERE,
- base::Bind(&AddLogEvent, weak_net_log_,
+ base::Bind(&AddLogEventWithCallback, weak_net_log_,
NetLog::TYPE_SSL_HANDSHAKE_ERROR,
- make_scoped_refptr(
- new SSLErrorParams(net_error, prerr))));
+ CreateNetLogSSLErrorCallback(net_error, prerr)));
}
}
@@ -2165,13 +2111,7 @@ int SSLClientSocketNSS::Core::DoGetDBCertComplete(int result) {
CERTCertificateList* cert_chain =
CERT_CertChainFromCert(cert, certUsageSSLClient, PR_FALSE);
- PostOrRunCallback(
- FROM_HERE,
- base::Bind(&AddLogEvent, weak_net_log_,
- NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
- make_scoped_refptr(
- new NetLogIntegerParameter("cert_count",
- cert_chain->len))));
+ AddCertProvidedEvent(cert_chain->len);
rv = SSL_RestartHandshakeAfterCertReq(nss_fd_, cert, key, cert_chain);
if (rv != SECSuccess)
@@ -2193,9 +2133,9 @@ int SSLClientSocketNSS::Core::DoPayloadRead() {
rv = ERR_SSL_CLIENT_AUTH_CERT_NEEDED;
PostOrRunCallback(
FROM_HERE,
- base::Bind(&AddLogEvent, weak_net_log_,
+ base::Bind(&AddLogEventWithCallback, weak_net_log_,
NetLog::TYPE_SSL_READ_ERROR,
- make_scoped_refptr(new SSLErrorParams(rv, 0))));
+ CreateNetLogSSLErrorCallback(rv, 0)));
return rv;
}
if (rv >= 0) {
@@ -2213,9 +2153,9 @@ int SSLClientSocketNSS::Core::DoPayloadRead() {
rv = HandleNSSError(prerr, false);
PostOrRunCallback(
FROM_HERE,
- base::Bind(&AddLogEvent, weak_net_log_,
+ base::Bind(&AddLogEventWithCallback, weak_net_log_,
NetLog::TYPE_SSL_READ_ERROR,
- make_scoped_refptr(new SSLErrorParams(rv, prerr))));
+ CreateNetLogSSLErrorCallback(rv, prerr)));
return rv;
}
@@ -2240,9 +2180,9 @@ int SSLClientSocketNSS::Core::DoPayloadWrite() {
rv = HandleNSSError(prerr, false);
PostOrRunCallback(
FROM_HERE,
- base::Bind(&AddLogEvent, weak_net_log_,
+ base::Bind(&AddLogEventWithCallback, weak_net_log_,
NetLog::TYPE_SSL_WRITE_ERROR,
- make_scoped_refptr(new SSLErrorParams(rv, prerr))));
+ CreateNetLogSSLErrorCallback(rv, prerr)));
return rv;
}
@@ -2486,13 +2426,7 @@ SECStatus SSLClientSocketNSS::Core::DomainBoundClientAuthHandler(
}
int cert_count = (rv == SECSuccess) ? 1 : 0;
- PostOrRunCallback(
- FROM_HERE,
- base::Bind(&AddLogEvent, weak_net_log_,
- NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
- make_scoped_refptr(
- new NetLogIntegerParameter("cert_count",
- cert_count))));
+ AddCertProvidedEvent(cert_count);
return rv;
}
@@ -2697,7 +2631,7 @@ int SSLClientSocketNSS::Core::DoGetDomainBoundCert(
if (detached_)
return ERR_FAILED;
- weak_net_log_->BeginEvent(NetLog::TYPE_SSL_GET_DOMAIN_BOUND_CERT, NULL);
+ weak_net_log_->BeginEvent(NetLog::TYPE_SSL_GET_DOMAIN_BOUND_CERT);
int rv = server_bound_cert_service_->GetDomainBoundCert(
origin,
@@ -2810,6 +2744,14 @@ void SSLClientSocketNSS::Core::PostOrRunCallback(
task.Run();
}
+void SSLClientSocketNSS::Core::AddCertProvidedEvent(int cert_count) {
+ PostOrRunCallback(
+ FROM_HERE,
+ base::Bind(&AddLogEventWithCallback, weak_net_log_,
+ NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
+ NetLog::IntegerCallback("cert_count", cert_count)));
+}
+
SSLClientSocketNSS::SSLClientSocketNSS(
base::SingleThreadTaskRunner* nss_task_runner,
ClientSocketHandle* transport_socket,
@@ -2942,7 +2884,7 @@ int SSLClientSocketNSS::Connect(const CompletionCallback& callback) {
EnsureThreadIdAssigned();
- net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT);
int rv = Init();
if (rv != OK) {
@@ -3529,7 +3471,7 @@ int SSLClientSocketNSS::DoVerifyCert(int result) {
// server then it will have optimistically started a verification of that
// chain. So, if the prediction was correct, we should wait for that
// verification to finish rather than start our own.
- net_log_.AddEvent(NetLog::TYPE_SSL_VERIFICATION_MERGED, NULL);
+ net_log_.AddEvent(NetLog::TYPE_SSL_VERIFICATION_MERGED);
UMA_HISTOGRAM_ENUMERATION("Net.SSLVerificationMerged", 1 /* true */, 2);
base::TimeTicks end_time = ssl_host_info_->verification_end_time();
if (end_time.is_null())
diff --git a/net/socket/ssl_client_socket_openssl.cc b/net/socket/ssl_client_socket_openssl.cc
index 1d379ec..dc8cdff 100644
--- a/net/socket/ssl_client_socket_openssl.cc
+++ b/net/socket/ssl_client_socket_openssl.cc
@@ -695,7 +695,7 @@ void SSLClientSocketOpenSSL::DoWriteCallback(int rv) {
// StreamSocket implementation.
int SSLClientSocketOpenSSL::Connect(const CompletionCallback& callback) {
- net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT);
// Set up new ssl object.
if (!Init()) {
@@ -842,7 +842,7 @@ int SSLClientSocketOpenSSL::DoHandshake() {
<< ", net_error " << net_error;
net_log_.AddEvent(
NetLog::TYPE_SSL_HANDSHAKE_ERROR,
- make_scoped_refptr(new SSLErrorParams(net_error, ssl_error)));
+ CreateNetLogSSLErrorCallback(net_error, ssl_error));
}
}
return net_error;
diff --git a/net/socket/ssl_client_socket_win.cc b/net/socket/ssl_client_socket_win.cc
index fa7e848..ce24192 100644
--- a/net/socket/ssl_client_socket_win.cc
+++ b/net/socket/ssl_client_socket_win.cc
@@ -568,11 +568,11 @@ int SSLClientSocketWin::Connect(const CompletionCallback& callback) {
DCHECK(next_state_ == STATE_NONE);
DCHECK(user_connect_callback_.is_null());
- net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT);
int rv = InitializeSSLContext();
if (rv != OK) {
- net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT, NULL);
+ net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT);
return rv;
}
@@ -582,7 +582,7 @@ int SSLClientSocketWin::Connect(const CompletionCallback& callback) {
if (rv == ERR_IO_PENDING) {
user_connect_callback_ = callback;
} else {
- net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT, NULL);
+ net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT);
}
return rv;
}
@@ -857,7 +857,7 @@ void SSLClientSocketWin::OnHandshakeIOComplete(int result) {
c.Run(rv);
return;
}
- net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT, NULL);
+ net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT);
CompletionCallback c = user_connect_callback_;
user_connect_callback_.Reset();
c.Run(rv);
diff --git a/net/socket/ssl_error_params.cc b/net/socket/ssl_error_params.cc
index fc2a0f3..8fc381f 100644
--- a/net/socket/ssl_error_params.cc
+++ b/net/socket/ssl_error_params.cc
@@ -4,23 +4,28 @@
#include "net/socket/ssl_error_params.h"
+#include "base/bind.h"
#include "base/values.h"
namespace net {
-SSLErrorParams::SSLErrorParams(int net_error, int ssl_lib_error)
- : net_error_(net_error),
- ssl_lib_error_(ssl_lib_error) {
-}
+namespace {
-Value* SSLErrorParams::ToValue() const {
+Value* NetLogSSLErrorCallback(int net_error,
+ int ssl_lib_error,
+ NetLog::LogLevel /* log_level */) {
DictionaryValue* dict = new DictionaryValue();
- dict->SetInteger("net_error", net_error_);
- if (ssl_lib_error_)
- dict->SetInteger("ssl_lib_error", ssl_lib_error_);
+ dict->SetInteger("net_error", net_error);
+ if (ssl_lib_error)
+ dict->SetInteger("ssl_lib_error", ssl_lib_error);
return dict;
}
-SSLErrorParams::~SSLErrorParams() {}
+} // namespace
+
+NetLog::ParametersCallback CreateNetLogSSLErrorCallback(int net_error,
+ int ssl_lib_error) {
+ return base::Bind(&NetLogSSLErrorCallback, net_error, ssl_lib_error);
+}
} // namespace net
diff --git a/net/socket/ssl_error_params.h b/net/socket/ssl_error_params.h
index a623b3fd..ad26e56 100644
--- a/net/socket/ssl_error_params.h
+++ b/net/socket/ssl_error_params.h
@@ -10,20 +10,9 @@
namespace net {
-// Extra parameters to attach to the NetLog when we receive an SSL error.
-class SSLErrorParams : public NetLog::EventParameters {
- public:
- SSLErrorParams(int net_error, int ssl_lib_error);
-
- virtual base::Value* ToValue() const OVERRIDE;
-
- protected:
- virtual ~SSLErrorParams();
-
- private:
- const int net_error_;
- const int ssl_lib_error_;
-};
+// Creates NetLog callback for when we receive an SSL error.
+NetLog::ParametersCallback CreateNetLogSSLErrorCallback(int net_error,
+ int ssl_lib_error);
} // namespace net
diff --git a/net/socket/ssl_server_socket_nss.cc b/net/socket/ssl_server_socket_nss.cc
index 84e63ac..35ccdd6 100644
--- a/net/socket/ssl_server_socket_nss.cc
+++ b/net/socket/ssl_server_socket_nss.cc
@@ -118,7 +118,7 @@ SSLServerSocketNSS::~SSLServerSocketNSS() {
}
int SSLServerSocketNSS::Handshake(const CompletionCallback& callback) {
- net_log_.BeginEvent(NetLog::TYPE_SSL_SERVER_HANDSHAKE, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_SSL_SERVER_HANDSHAKE);
int rv = Init();
if (rv != OK) {
@@ -609,7 +609,7 @@ int SSLServerSocketNSS::DoPayloadRead() {
}
rv = MapNSSError(prerr);
net_log_.AddEvent(NetLog::TYPE_SSL_READ_ERROR,
- make_scoped_refptr(new SSLErrorParams(rv, prerr)));
+ CreateNetLogSSLErrorCallback(rv, prerr));
return rv;
}
@@ -624,7 +624,7 @@ int SSLServerSocketNSS::DoPayloadWrite() {
}
rv = MapNSSError(prerr);
net_log_.AddEvent(NetLog::TYPE_SSL_WRITE_ERROR,
- make_scoped_refptr(new SSLErrorParams(rv, prerr)));
+ CreateNetLogSSLErrorCallback(rv, prerr));
return rv;
}
@@ -672,7 +672,7 @@ int SSLServerSocketNSS::DoReadLoop(int result) {
LOG(DFATAL) << "!nss_bufs_";
int rv = ERR_UNEXPECTED;
net_log_.AddEvent(NetLog::TYPE_SSL_READ_ERROR,
- make_scoped_refptr(new SSLErrorParams(rv, 0)));
+ CreateNetLogSSLErrorCallback(rv, 0));
return rv;
}
@@ -696,7 +696,7 @@ int SSLServerSocketNSS::DoWriteLoop(int result) {
LOG(DFATAL) << "!nss_bufs_";
int rv = ERR_UNEXPECTED;
net_log_.AddEvent(NetLog::TYPE_SSL_WRITE_ERROR,
- make_scoped_refptr(new SSLErrorParams(rv, 0)));
+ CreateNetLogSSLErrorCallback(rv, 0));
return rv;
}
@@ -725,9 +725,8 @@ int SSLServerSocketNSS::DoHandshake() {
} else {
LOG(ERROR) << "handshake failed; NSS error code " << prerr
<< ", net_error " << net_error;
- net_log_.AddEvent(
- NetLog::TYPE_SSL_HANDSHAKE_ERROR,
- make_scoped_refptr(new SSLErrorParams(net_error, prerr)));
+ net_log_.AddEvent(NetLog::TYPE_SSL_HANDSHAKE_ERROR,
+ CreateNetLogSSLErrorCallback(net_error, prerr));
}
}
return net_error;
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc
index f77a691..d139a54 100644
--- a/net/socket/tcp_client_socket_libevent.cc
+++ b/net/socket/tcp_client_socket_libevent.cc
@@ -25,7 +25,7 @@
#include "net/base/net_log.h"
#include "net/base/net_util.h"
#include "net/base/network_change_notifier.h"
-#include "net/socket/socket_error_params.h"
+#include "net/socket/socket_net_log_params.h"
namespace net {
@@ -139,10 +139,8 @@ TCPClientSocketLibevent::TCPClientSocketLibevent(
use_tcp_fastopen_(false),
tcp_fastopen_connected_(false),
num_bytes_read_(0) {
- 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 (is_tcp_fastopen_enabled())
use_tcp_fastopen_ = true;
@@ -150,7 +148,7 @@ TCPClientSocketLibevent::TCPClientSocketLibevent(
TCPClientSocketLibevent::~TCPClientSocketLibevent() {
Disconnect();
- net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE, NULL);
+ net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE);
}
int TCPClientSocketLibevent::AdoptSocket(int socket) {
@@ -270,9 +268,7 @@ int TCPClientSocketLibevent::DoConnect() {
}
net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT,
- make_scoped_refptr(new NetLogStringParameter(
- "address",
- endpoint.ToString())));
+ CreateNetLogIPEndPointCallback(&endpoint));
next_connect_state_ = CONNECT_STATE_CONNECT_COMPLETE;
@@ -334,10 +330,12 @@ int TCPClientSocketLibevent::DoConnectComplete(int result) {
// Log the end of this attempt (and any OS error it threw).
int os_error = connect_os_error_;
connect_os_error_ = 0;
- scoped_refptr<NetLog::EventParameters> params;
- if (result != OK)
- params = new NetLogIntegerParameter("os_error", os_error);
- net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, params);
+ if (result != OK) {
+ net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT,
+ NetLog::IntegerCallback("os_error", os_error));
+ } else {
+ net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT);
+ }
if (result == OK) {
connect_time_micros_ = base::TimeTicks::Now() - connect_start_time_;
@@ -453,7 +451,7 @@ int TCPClientSocketLibevent::Read(IOBuffer* buf,
if (errno != EAGAIN && errno != EWOULDBLOCK) {
int net_error = MapSystemError(errno);
net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR,
- make_scoped_refptr(new SocketErrorParams(net_error, errno)));
+ CreateNetLogSocketErrorCallback(net_error, errno));
return net_error;
}
@@ -494,7 +492,7 @@ int TCPClientSocketLibevent::Write(IOBuffer* buf,
if (errno != EAGAIN && errno != EWOULDBLOCK) {
int net_error = MapSystemError(errno);
net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR,
- make_scoped_refptr(new SocketErrorParams(net_error, errno)));
+ CreateNetLogSocketErrorCallback(net_error, errno));
return net_error;
}
@@ -598,12 +596,9 @@ void TCPClientSocketLibevent::LogConnectCompletion(int net_error) {
return;
}
- const std::string source_address_str =
- NetAddressToStringWithPort(storage.addr, storage.addr_len);
net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT,
- make_scoped_refptr(new NetLogStringParameter(
- "source address",
- source_address_str)));
+ CreateNetLogSourceAddressCallback(storage.addr,
+ storage.addr_len));
}
void TCPClientSocketLibevent::DoReadCallback(int rv) {
@@ -668,7 +663,7 @@ void TCPClientSocketLibevent::DidCompleteRead() {
result = MapSystemError(errno);
if (result != ERR_IO_PENDING) {
net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR,
- make_scoped_refptr(new SocketErrorParams(result, errno)));
+ CreateNetLogSocketErrorCallback(result, errno));
}
}
@@ -699,7 +694,7 @@ void TCPClientSocketLibevent::DidCompleteWrite() {
result = MapSystemError(errno);
if (result != ERR_IO_PENDING) {
net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR,
- make_scoped_refptr(new SocketErrorParams(result, errno)));
+ CreateNetLogSocketErrorCallback(result, errno));
}
}
diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc
index c518c2b..aed2adb 100644
--- a/net/socket/tcp_client_socket_win.cc
+++ b/net/socket/tcp_client_socket_win.cc
@@ -21,7 +21,7 @@
#include "net/base/network_change_notifier.h"
#include "net/base/winsock_init.h"
#include "net/base/winsock_util.h"
-#include "net/socket/socket_error_params.h"
+#include "net/socket/socket_net_log_params.h"
namespace net {
@@ -335,16 +335,14 @@ TCPClientSocketWin::TCPClientSocketWin(const AddressList& addresses,
net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)),
previously_disconnected_(false),
num_bytes_read_(0) {
- 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());
EnsureWinsockInit();
}
TCPClientSocketWin::~TCPClientSocketWin() {
Disconnect();
- net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE, NULL);
+ net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE);
}
int TCPClientSocketWin::AdoptSocket(SOCKET socket) {
@@ -463,8 +461,7 @@ int TCPClientSocketWin::DoConnect() {
}
net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT,
- new NetLogStringParameter("address",
- endpoint.ToString()));
+ CreateNetLogIPEndPointCallback(&endpoint));
next_connect_state_ = CONNECT_STATE_CONNECT_COMPLETE;
@@ -528,10 +525,12 @@ int TCPClientSocketWin::DoConnectComplete(int result) {
// Log the end of this attempt (and any OS error it threw).
int os_error = connect_os_error_;
connect_os_error_ = 0;
- scoped_refptr<NetLog::EventParameters> params;
- if (result != OK)
- params = new NetLogIntegerParameter("os_error", os_error);
- net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, params);
+ if (result != OK) {
+ net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT,
+ NetLog::IntegerCallback("os_error", os_error));
+ } else {
+ net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT);
+ }
if (result == OK) {
connect_time_micros_ = base::TimeTicks::Now() - connect_start_time_;
@@ -724,7 +723,7 @@ int TCPClientSocketWin::Read(IOBuffer* buf,
if (os_error != WSA_IO_PENDING) {
int net_error = MapSystemError(os_error);
net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR,
- make_scoped_refptr(new SocketErrorParams(net_error, os_error)));
+ CreateNetLogSocketErrorCallback(net_error, os_error));
return net_error;
}
}
@@ -780,7 +779,7 @@ int TCPClientSocketWin::Write(IOBuffer* buf,
if (os_error != WSA_IO_PENDING) {
int net_error = MapSystemError(os_error);
net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR,
- make_scoped_refptr(new SocketErrorParams(net_error, os_error)));
+ CreateNetLogSocketErrorCallback(net_error, os_error));
return net_error;
}
}
@@ -830,14 +829,11 @@ void TCPClientSocketWin::LogConnectCompletion(int net_error) {
return;
}
- const std::string source_address_str =
- NetAddressToStringWithPort(
+ net_log_.EndEvent(
+ NetLog::TYPE_TCP_CONNECT,
+ CreateNetLogSourceAddressCallback(
reinterpret_cast<const struct sockaddr*>(&source_address),
- sizeof(source_address));
- net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT,
- make_scoped_refptr(new NetLogStringParameter(
- "source_address",
- source_address_str)));
+ sizeof(source_address)));
}
void TCPClientSocketWin::DoReadCallback(int rv) {
@@ -910,7 +906,7 @@ void TCPClientSocketWin::DidCompleteRead() {
int os_error = WSAGetLastError();
rv = MapSystemError(os_error);
net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR,
- make_scoped_refptr(new SocketErrorParams(rv, os_error)));
+ CreateNetLogSocketErrorCallback(rv, os_error));
}
DoReadCallback(rv);
}
@@ -928,7 +924,7 @@ void TCPClientSocketWin::DidCompleteWrite() {
int os_error = WSAGetLastError();
rv = MapSystemError(os_error);
net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR,
- make_scoped_refptr(new SocketErrorParams(rv, os_error)));
+ CreateNetLogSocketErrorCallback(rv, os_error));
} else {
rv = static_cast<int>(num_bytes);
if (rv > core_->write_buffer_length_ || rv < 0) {
diff --git a/net/socket/tcp_server_socket_libevent.cc b/net/socket/tcp_server_socket_libevent.cc
index 34b8283..ef8d1b1 100644
--- a/net/socket/tcp_server_socket_libevent.cc
+++ b/net/socket/tcp_server_socket_libevent.cc
@@ -19,6 +19,7 @@
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
+#include "net/socket/socket_net_log_params.h"
#include "net/socket/tcp_client_socket.h"
namespace net {
@@ -35,16 +36,14 @@ TCPServerSocketLibevent::TCPServerSocketLibevent(
: socket_(kInvalidSocket),
accept_socket_(NULL),
net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_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());
}
TCPServerSocketLibevent::~TCPServerSocketLibevent() {
if (socket_ != kInvalidSocket)
Close();
- net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE, NULL);
+ net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE);
}
int TCPServerSocketLibevent::Listen(const IPEndPoint& address, int backlog) {
@@ -107,7 +106,7 @@ int TCPServerSocketLibevent::Accept(
DCHECK(!callback.is_null());
DCHECK(accept_callback_.is_null());
- net_log_.BeginEvent(NetLog::TYPE_TCP_ACCEPT, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_TCP_ACCEPT);
int result = AcceptInternal(socket);
@@ -159,8 +158,7 @@ int TCPServerSocketLibevent::AcceptInternal(
}
socket->reset(tcp_socket.release());
net_log_.EndEvent(NetLog::TYPE_TCP_ACCEPT,
- make_scoped_refptr(new NetLogStringParameter(
- "address", address.ToString())));
+ CreateNetLogIPEndPointCallback(&address));
return OK;
}
diff --git a/net/socket/tcp_server_socket_win.cc b/net/socket/tcp_server_socket_win.cc
index 5b88233..eb15ffb 100644
--- a/net/socket/tcp_server_socket_win.cc
+++ b/net/socket/tcp_server_socket_win.cc
@@ -11,6 +11,7 @@
#include "net/base/net_util.h"
#include "net/base/winsock_init.h"
#include "net/base/winsock_util.h"
+#include "net/socket/socket_net_log_params.h"
#include "net/socket/tcp_client_socket.h"
namespace net {
@@ -21,16 +22,14 @@ TCPServerSocketWin::TCPServerSocketWin(net::NetLog* net_log,
socket_event_(WSA_INVALID_EVENT),
accept_socket_(NULL),
net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_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());
EnsureWinsockInit();
}
TCPServerSocketWin::~TCPServerSocketWin() {
Close();
- net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE, NULL);
+ net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE);
}
int TCPServerSocketWin::Listen(const IPEndPoint& address, int backlog) {
@@ -100,7 +99,7 @@ int TCPServerSocketWin::Accept(
DCHECK(!callback.is_null());
DCHECK(accept_callback_.is_null());
- net_log_.BeginEvent(NetLog::TYPE_TCP_ACCEPT, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_TCP_ACCEPT);
int result = AcceptInternal(socket);
@@ -146,8 +145,7 @@ int TCPServerSocketWin::AcceptInternal(scoped_ptr<StreamSocket>* socket) {
}
socket->reset(tcp_socket.release());
net_log_.EndEvent(NetLog::TYPE_TCP_ACCEPT,
- make_scoped_refptr(new NetLogStringParameter(
- "address", address.ToString())));
+ CreateNetLogIPEndPointCallback(&address));
return OK;
}
diff --git a/net/socket/transport_client_socket_pool.cc b/net/socket/transport_client_socket_pool.cc
index dee8b57..0dd4782 100644
--- a/net/socket/transport_client_socket_pool.cc
+++ b/net/socket/transport_client_socket_pool.cc
@@ -19,6 +19,7 @@
#include "net/socket/client_socket_factory.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/client_socket_pool_base.h"
+#include "net/socket/socket_net_log_params.h"
#include "net/socket/tcp_client_socket.h"
using base::TimeDelta;
@@ -378,9 +379,8 @@ int TransportClientSocketPool::RequestSocket(
// TODO(eroman): Split out the host and port parameters.
net_log.AddEvent(
NetLog::TYPE_TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET,
- make_scoped_refptr(new NetLogStringParameter(
- "host_and_port",
- casted_params->get()->destination().host_port_pair().ToString())));
+ CreateNetLogHostPortPairCallback(
+ &casted_params->get()->destination().host_port_pair()));
}
return base_.RequestSocket(group_name, *casted_params, priority, handle,
@@ -399,9 +399,8 @@ void TransportClientSocketPool::RequestSockets(
// TODO(eroman): Split out the host and port parameters.
net_log.AddEvent(
NetLog::TYPE_TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKETS,
- make_scoped_refptr(new NetLogStringParameter(
- "host_and_port",
- casted_params->get()->destination().host_port_pair().ToString())));
+ CreateNetLogHostPortPairCallback(
+ &casted_params->get()->destination().host_port_pair()));
}
base_.RequestSockets(group_name, *casted_params, num_sockets, net_log);