summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-27 23:20:45 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-27 23:20:45 +0000
commitd13f51bc832e8e7965e92f5aa4b16b8c10c3f913 (patch)
treed5a1a413bf8716befbae7d056cd8c6194eed5a98 /net
parentf2286c23e17c0012d53800a5ef28975b6e22393a (diff)
downloadchromium_src-d13f51bc832e8e7965e92f5aa4b16b8c10c3f913.zip
chromium_src-d13f51bc832e8e7965e92f5aa4b16b8c10c3f913.tar.gz
chromium_src-d13f51bc832e8e7965e92f5aa4b16b8c10c3f913.tar.bz2
Cleanup: Address some of the todos in net_log.h
- Get rid of the AddString() and AddStringLiteral() methods. - Make EventParameters able to serialize to JSON, instead of a string. BUG=37421 Review URL: http://codereview.chromium.org/1716007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45750 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/host_resolver_impl.cc2
-rw-r--r--net/base/net_log.cc64
-rw-r--r--net/base/net_log.h66
-rw-r--r--net/base/net_log_event_type_list.h148
-rw-r--r--net/base/net_log_util.cc55
-rw-r--r--net/base/net_log_util_unittest.cc29
-rw-r--r--net/proxy/init_proxy_resolver.cc35
-rw-r--r--net/proxy/init_proxy_resolver_unittest.cc38
-rw-r--r--net/proxy/proxy_service.cc11
-rw-r--r--net/socket/client_socket_pool_base.cc31
-rw-r--r--net/socket/client_socket_pool_base_unittest.cc2
-rw-r--r--net/socket/socks5_client_socket.cc61
-rw-r--r--net/socket/tcp_client_socket_libevent.cc12
-rw-r--r--net/socket/tcp_client_socket_pool.cc10
-rw-r--r--net/socket/tcp_client_socket_win.cc15
-rw-r--r--net/socket_stream/socket_stream.cc5
-rw-r--r--net/url_request/url_request.cc8
17 files changed, 320 insertions, 272 deletions
diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc
index dcd2786..f1b57f6 100644
--- a/net/base/host_resolver_impl.cc
+++ b/net/base/host_resolver_impl.cc
@@ -167,7 +167,7 @@ class HostResolverImpl::RequestsTrace
base::TimeTicks::Now(),
NetLog::Source(),
NetLog::PHASE_NONE,
- new NetLogStringParameter(msg));
+ new NetLogStringParameter("todo", msg));
AutoLock l(lock_);
entries_.push_back(entry);
}
diff --git a/net/base/net_log.cc b/net/base/net_log.cc
index c9ef380..c46214f 100644
--- a/net/base/net_log.cc
+++ b/net/base/net_log.cc
@@ -5,6 +5,7 @@
#include "net/base/net_log.h"
#include "base/logging.h"
#include "base/string_util.h"
+#include "base/values.h"
namespace net {
@@ -63,9 +64,18 @@ void BoundNetLog::AddEventWithParameters(
}
void BoundNetLog::AddEventWithInteger(NetLog::EventType event_type,
- int integer) const {
+ const char* name,
+ int value) const {
scoped_refptr<NetLog::EventParameters> params =
- new NetLogIntegerParameter(integer);
+ new NetLogIntegerParameter(name, value);
+ AddEventWithParameters(event_type, params);
+}
+
+void BoundNetLog::AddEventWithString(NetLog::EventType event_type,
+ const char* name,
+ const std::string& value) const {
+ scoped_refptr<NetLog::EventParameters> params =
+ new NetLogStringParameter(name, value);
AddEventWithParameters(event_type, params);
}
@@ -80,16 +90,18 @@ void BoundNetLog::BeginEventWithParameters(
}
void BoundNetLog::BeginEventWithString(NetLog::EventType event_type,
- const std::string& string) const {
+ const char* name,
+ const std::string& value) const {
scoped_refptr<NetLog::EventParameters> params =
- new NetLogStringParameter(string);
+ new NetLogStringParameter(name, value);
BeginEventWithParameters(event_type, params);
}
void BoundNetLog::BeginEventWithInteger(NetLog::EventType event_type,
- int integer) const {
+ const char* name,
+ int value) const {
scoped_refptr<NetLog::EventParameters> params =
- new NetLogIntegerParameter(integer);
+ new NetLogIntegerParameter(name, value);
BeginEventWithParameters(event_type, params);
}
@@ -104,30 +116,13 @@ void BoundNetLog::EndEventWithParameters(
}
void BoundNetLog::EndEventWithInteger(NetLog::EventType event_type,
- int integer) const {
+ const char* name,
+ int value) const {
scoped_refptr<NetLog::EventParameters> params =
- new NetLogIntegerParameter(integer);
+ new NetLogIntegerParameter(name, value);
EndEventWithParameters(event_type, params);
}
-void BoundNetLog::AddString(const std::string& string) const {
- // We pass TYPE_TODO_STRING since we have no event type to associate this
- // with. (AddString() is deprecated, and should be replaced with
- // AddEventWithParameters()).
- scoped_refptr<NetLog::EventParameters> params =
- new NetLogStringParameter(string);
- AddEventWithParameters(NetLog::TYPE_TODO_STRING, params);
-}
-
-void BoundNetLog::AddStringLiteral(const char* literal) const {
- // We pass TYPE_TODO_STRING_LITERAL since we have no event type to associate
- // this with. (AddString() is deprecated, and should be replaced with
- // AddEventWithParameters()).
- scoped_refptr<NetLog::EventParameters> params =
- new NetLogStringLiteralParameter(literal);
- AddEventWithParameters(NetLog::TYPE_TODO_STRING_LITERAL, params);
-}
-
// static
BoundNetLog BoundNetLog::Make(NetLog* net_log,
NetLog::SourceType source_type) {
@@ -138,16 +133,21 @@ BoundNetLog BoundNetLog::Make(NetLog* net_log,
return BoundNetLog(source, net_log);
}
-NetLogStringParameter::NetLogStringParameter(const std::string& value)
- : value_(value) {
+NetLogStringParameter::NetLogStringParameter(const char* name,
+ const std::string& value)
+ : name_(name), value_(value) {
}
-std::string NetLogIntegerParameter::ToString() const {
- return IntToString(value_);
+Value* NetLogIntegerParameter::ToValue() const {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetInteger(ASCIIToWide(name_), value_);
+ return dict;
}
-std::string NetLogStringLiteralParameter::ToString() const {
- return std::string(value_);
+Value* NetLogStringParameter::ToValue() const {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetString(ASCIIToWide(name_), value_);
+ return dict;
}
void CapturingNetLog::AddEntry(EventType type,
diff --git a/net/base/net_log.h b/net/base/net_log.h
index cb2b3a6..c847b0e 100644
--- a/net/base/net_log.h
+++ b/net/base/net_log.h
@@ -14,6 +14,8 @@
#include "base/time.h"
#include "net/base/net_log.h"
+class Value;
+
namespace net {
// NetLog is the destination for log messages generated by the network stack.
@@ -30,11 +32,6 @@ namespace net {
// ******** The NetLog (and associated logging) is a work in progress ********
//
// TODO(eroman): Remove the 'const' qualitifer from the BoundNetLog methods.
-// TODO(eroman): Remove the AddString() and AddStringLiteral() methods.
-// These are a carry-over from old approach. Really, consumers
-// should be calling AddEventWithParameters(), and passing a
-// custom EventParameters* object that encapsulates all of the
-// interesting state.
// TODO(eroman): Remove NetLogUtil. Pretty printing should only be done from
// javascript, and should be very context-aware.
// TODO(eroman): Move Capturing*NetLog to its own file. (And eventually remove
@@ -92,9 +89,10 @@ class NetLog {
EventParameters() {}
virtual ~EventParameters() {}
- // Serializes the parameters to a string representation (this should be a
- // lossless conversion).
- virtual std::string ToString() const = 0;
+ // Serializes the parameters to a Value tree. This is intended to be a
+ // lossless conversion, which is used to serialize the parameters to JSON.
+ // The caller takes ownership of the returned Value*.
+ virtual Value* ToValue() const = 0;
private:
DISALLOW_COPY_AND_ASSIGN(EventParameters);
@@ -170,18 +168,18 @@ class BoundNetLog {
void BeginEventWithParameters(NetLog::EventType event_type,
NetLog::EventParameters* params) const;
void BeginEventWithString(NetLog::EventType event_type,
- const std::string& string) const;
- void BeginEventWithInteger(NetLog::EventType event_type, int integer) const;
- void AddEventWithInteger(NetLog::EventType event_type, int integer) const;
+ const char* name, const std::string& value) const;
+ void BeginEventWithInteger(NetLog::EventType event_type,
+ const char* name, int value) const;
+ void AddEventWithInteger(NetLog::EventType event_type,
+ const char* name, int value) const;
+ void AddEventWithString(NetLog::EventType event_type,
+ const char* name, const std::string& value) const;
void EndEvent(NetLog::EventType event_type) const;
void EndEventWithParameters(NetLog::EventType event_type,
NetLog::EventParameters* params) const;
- void EndEventWithInteger(NetLog::EventType event_type, int integer) const;
-
- // Deprecated: Don't add new dependencies that use these methods. Instead, use
- // AddEventWithParameters().
- void AddString(const std::string& string) const;
- void AddStringLiteral(const char* literal) const;
+ void EndEventWithInteger(NetLog::EventType event_type,
+ const char* name, int value) const;
// Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care
// of creating a unique source ID, and handles the case of NULL net_log.
@@ -199,53 +197,39 @@ class BoundNetLog {
// single std::string parameter.
class NetLogStringParameter : public NetLog::EventParameters {
public:
- explicit NetLogStringParameter(const std::string& value);
+ // |name| must be a string literal.
+ NetLogStringParameter(const char* name, const std::string& value);
const std::string& value() const {
return value_;
}
- virtual std::string ToString() const {
- return value_;
- }
+ virtual Value* ToValue() const;
private:
- std::string value_;
+ const char* const name_;
+ const std::string value_;
};
// NetLogIntegerParameter is a subclass of EventParameters that encapsulates a
// single integer parameter.
class NetLogIntegerParameter : public NetLog::EventParameters {
public:
- explicit NetLogIntegerParameter(int value) : value_(value) {}
+ // |name| must be a string literal.
+ NetLogIntegerParameter(const char* name, int value)
+ : name_(name), value_(value) {}
int value() const {
return value_;
}
- virtual std::string ToString() const;
+ virtual Value* ToValue() const;
private:
+ const char* name_;
const int value_;
};
-// NetLogStringLiteralParameter is a subclass of EventParameters that
-// encapsulates a single string literal parameter.
-class NetLogStringLiteralParameter : public NetLog::EventParameters {
- public:
- explicit NetLogStringLiteralParameter(const char* value) : value_(value) {}
-
- const char* const value() const {
- return value_;
- }
-
- virtual std::string ToString() const;
-
- private:
- const char* const value_;
-};
-
-
// CapturingNetLog is an implementation of NetLog that saves messages to a
// bounded buffer.
class CapturingNetLog : public NetLog {
diff --git a/net/base/net_log_event_type_list.h b/net/base/net_log_event_type_list.h
index 7e794e4..cf04de5 100644
--- a/net/base/net_log_event_type_list.h
+++ b/net/base/net_log_event_type_list.h
@@ -13,10 +13,8 @@
// log context around it.)
EVENT_TYPE(CANCELLED)
-// TODO(eroman): These are placeholders used by the deprecated
-// BoundNetLog::AddString() / BoundNetLog::AddStringLiteral().
+// TODO(eroman): remove the remaining consumers of this.
EVENT_TYPE(TODO_STRING)
-EVENT_TYPE(TODO_STRING_LITERAL)
// Marks the creation/destruction of a request (URLRequest or SocketStream).
// In the begin phase of this event, the message will contain a string which
@@ -48,12 +46,35 @@ EVENT_TYPE(INIT_PROXY_RESOLVER)
// The start/end of download of a PAC script. This could be the well-known
// WPAD URL (if testing auto-detect), or a custom PAC URL.
+//
+// The START event has the parameters:
+// {
+// "url": <URL string of script being fetched>
+// }
+//
+// If the fetch failed, then the END phase has these parameters:
+// {
+// "error_code": <Net error code integer>
+// }
EVENT_TYPE(INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)
// The start/end of the testing of a PAC script (trying to parse the fetched
// file as javascript).
+//
+// If the parsing of the script failed, the END phase will have parameters:
+// {
+// "error_code": <Net error code integer>
+// }
EVENT_TYPE(INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)
+// This event means that initialization failed because there was no
+// configured script fetcher. (This indicates a configuration error).
+EVENT_TYPE(INIT_PROXY_RESOLVER_HAS_NO_FETCHER)
+
+// This event is emitted after deciding to fall-back to the next PAC
+// script in the list.
+EVENT_TYPE(INIT_PROXY_RESOLVER_FALLING_BACK_TO_NEXT_PAC_URL)
+
// ------------------------------------------------------------------------
// ProxyService
// ------------------------------------------------------------------------
@@ -69,6 +90,18 @@ EVENT_TYPE(PROXY_SERVICE_WAITING_FOR_INIT_PAC)
// The time taken to fetch the system proxy configuration.
EVENT_TYPE(PROXY_SERVICE_POLL_CONFIG_SERVICE_FOR_CHANGES)
+// This event is emitted to show what the PAC script returned. It can contain
+// extra parameters that are either:
+// {
+// "pac_string": <List of valid proxy servers, in PAC format>
+// }
+//
+// Or if the the resolver failed:
+// {
+// "net_error": <Net error code that resolver failed with>
+// }
+EVENT_TYPE(PROXY_SERVICE_RESOLVED_PROXY_LIST)
+
// ------------------------------------------------------------------------
// Proxy Resolver
// ------------------------------------------------------------------------
@@ -105,13 +138,62 @@ EVENT_TYPE(SOCKS_CONNECT)
// The start/end of a SOCKS5 connect().
EVENT_TYPE(SOCKS5_CONNECT)
+// This event is emitted when the SOCKS connect fails because the provided
+// was longer than 255 characters.
+EVENT_TYPE(SOCKS_HOSTNAME_TOO_BIG)
+
+// These events are emitted when insufficient data was read while
+// trying to establish a connection to the SOCKS proxy server
+// (during the greeting phase or handshake phase, respectively).
+EVENT_TYPE(SOCKS_UNEXPECTEDLY_CLOSED_DURING_GREETING)
+EVENT_TYPE(SOCKS_UNEXPECTEDLY_CLOSED_DURING_HANDSHAKE)
+
+// This event indicates that a bad version number was received in the
+// proxy server's response. The extra parameters show its value:
+// {
+// "version": <Integer version number in the response>
+// }
+EVENT_TYPE(SOCKS_UNEXPECTED_VERSION)
+
+// This event indicates that the SOCKS proxy server returned an error while
+// trying to create a connection. The following parameters will be attached
+// to the event:
+// {
+// "error_code": <Integer error code returned by the server>
+// }
+EVENT_TYPE(SOCKS_SERVER_ERROR)
+
+// This event indicates that the SOCKS proxy server asked for an authentication
+// method that we don't support. The following parameters are attached to the
+// event:
+// {
+// "method": <Integer method code>
+// }
+EVENT_TYPE(SOCKS_UNEXPECTED_AUTH)
+
+// This event indicates that the SOCKS proxy server's response indicated an
+// address type which we are not prepared to handle.
+// The following parameters are attached to the event:
+// {
+// "address_type": <Integer code for the address type>
+// }
+EVENT_TYPE(SOCKS_UNKNOWN_ADDRESS_TYPE)
+
// The start/end of a SSL connect().
EVENT_TYPE(SSL_CONNECT)
// The specified number of bytes were sent on the socket.
+// The following parameters are attached:
+// {
+// "num_bytes": <Number of bytes that were just sent>
+// }
EVENT_TYPE(SOCKET_BYTES_SENT)
// The specified number of bytes were received on the socket.
+// The following parameters are attached:
+// {
+// "num_bytes": <Number of bytes that were just sent>
+// }
EVENT_TYPE(SOCKET_BYTES_RECEIVED)
// ------------------------------------------------------------------------
@@ -137,6 +219,21 @@ EVENT_TYPE(SOCKET_POOL_STALLED_MAX_SOCKETS)
// The request stalled because there are too many sockets in the group.
EVENT_TYPE(SOCKET_POOL_STALLED_MAX_SOCKETS_PER_GROUP)
+// Indicates that we reused an existing socket. Attached to the event are
+// the parameters:
+// {
+// "idle_ms": <The number of milliseconds the socket was sitting idle for>
+// }
+EVENT_TYPE(SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)
+
+// This event simply describes the host:port that were requested from the
+// socket pool. Its parameters are:
+// {
+// "host_and_port": <String encoding the host and port>
+// }
+EVENT_TYPE(TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET)
+
+
// A backup socket is created due to slow connect
EVENT_TYPE(SOCKET_BACKUP_CREATED)
@@ -147,11 +244,17 @@ EVENT_TYPE(SOCKET_BACKUP_TIMER_EXTENDED)
// is sent to the request that triggered the ConnectJob, the end event
// is sent to the request that received the connected socket. Because of
// late binding, they may not be the same. Therefore the ID for the
-// ConnectJob NetLog is sent in both events.
+// ConnectJob NetLog is sent in both events. The event parameters are:
+// {
+// "source_id": <ID of the connect job that was bound to this source>
+// }
EVENT_TYPE(SOCKET_POOL_CONNECT_JOB_ID)
// Identifies the NetLog::Source() for the Socket assigned to the pending
-// request.
+// request. The event parameters are:
+// {
+// "source_id": <ID of the socket that was bound to this source>
+// }
EVENT_TYPE(SOCKET_POOL_SOCKET_ID)
// ------------------------------------------------------------------------
@@ -161,14 +264,25 @@ EVENT_TYPE(SOCKET_POOL_SOCKET_ID)
// Measures the time between URLRequest::Start() and
// URLRequest::ResponseStarted().
//
-// For the BEGIN phase, the |extra_parameters| of the event will be of type
-// NetLogStringParameter, and will contain the URL.
+// For the BEGIN phase, the following parameters are attached:
+// {
+// "url": <String of URL being loaded>
+// }
//
-// For the END phase, the |extra_parameters| of the event will be of type
-// NetLogIntegerParameter, and will contain the net error code. Altenately,
-// the extra_parameters may be NULL indicating no error code.
+// For the END phase, if there was an error, the following parameters are
+// attached:
+// {
+// "net_error": <Net error code of the failure>
+// }
EVENT_TYPE(URL_REQUEST_START)
+// This event is sent once a URLRequest receives a redirect. The parameters
+// attached to the event are:
+// {
+// "location": <The URL that was redirected to>
+// }
+EVENT_TYPE(URL_REQUEST_REDIRECTED)
+
// ------------------------------------------------------------------------
// HttpCache
// ------------------------------------------------------------------------
@@ -260,12 +374,16 @@ EVENT_TYPE(HTTP_STREAM_PARSER_READ_HEADERS)
// Measures the time between SocketStream::Connect() and
// SocketStream::DidEstablishConnection()
//
-// For the BEGIN phase, the |extra_parameters| of the event will be of type
-// NetLogStringParameter, and will contain the URL.
+// For the BEGIN phase, the following parameters are attached:
+// {
+// "url": <String of URL being loaded>
+// }
//
-// For the END phase, the |extra_parameters| of the event will be of type
-// NetLogIntegerParameter, and will contain the net error code. Altenately,
-// the extra_parameters may be NULL indicating no error code.
+// For the END phase, if there was an error, the following parameters are
+// attached:
+// {
+// "net_error": <Net error code of the failure>
+// }
EVENT_TYPE(SOCKET_STREAM_CONNECT)
// A message sent on the SocketStream.
diff --git a/net/base/net_log_util.cc b/net/base/net_log_util.cc
index 2bcd907..b5339b9 100644
--- a/net/base/net_log_util.cc
+++ b/net/base/net_log_util.cc
@@ -5,7 +5,9 @@
#include "net/base/net_log_util.h"
#include "base/format_macros.h"
+#include "base/json/json_writer.h"
#include "base/string_util.h"
+#include "base/values.h"
#include "net/base/net_errors.h"
namespace net {
@@ -49,15 +51,6 @@ class FormatHelper {
int indentation_spaces = entries_[i].indentation * kSpacesPerIndentation;
std::string entry_str = GetEntryString(i);
- // Hack to better print known event types.
- if (entries_[i].log_entry->type == NetLog::TYPE_TODO_STRING ||
- entries_[i].log_entry->type == NetLog::TYPE_TODO_STRING_LITERAL) {
- // Don't display the TODO_STRING type.
- entry_str = StringPrintf(
- " \"%s\"",
- entries_[i].log_entry->extra_parameters->ToString().c_str());
- }
-
StringAppendF(&result, "t=%s: %s%s",
PadStringLeft(GetTimeString(i), max_time_width).c_str(),
PadStringLeft("", indentation_spaces).c_str(),
@@ -75,45 +68,19 @@ class FormatHelper {
// Append any custom parameters.
NetLog::EventParameters* extra_params =
entries_[i].log_entry->extra_parameters;
- NetLog::EventType type = entries_[i].log_entry->type;
- NetLog::EventPhase phase = entries_[i].log_entry->phase;
- if (type != NetLog::TYPE_TODO_STRING &&
- type != NetLog::TYPE_TODO_STRING_LITERAL &&
- extra_params) {
+ if (extra_params) {
std::string extra_details;
-
- // Hacks to better print known event types.
- if (type == NetLog::TYPE_URL_REQUEST_START ||
- type == NetLog::TYPE_SOCKET_STREAM_CONNECT) {
- if (phase == NetLog::PHASE_BEGIN) {
- extra_details =
- StringPrintf("url: %s", extra_params->ToString().c_str());
- } else if (phase == NetLog::PHASE_END) {
- int error_code = static_cast<NetLogIntegerParameter*>(
- extra_params)->value();
- extra_details = StringPrintf("net error: %d (%s)",
- error_code,
- ErrorToString(error_code));
- }
- } else if (type == NetLog::TYPE_SOCKET_POOL_CONNECT_JOB) {
- extra_details =
- StringPrintf("group: %s", extra_params->ToString().c_str());
- } else {
- extra_details = extra_params->ToString();
- }
-
- int indentation = max_time_width + indentation_spaces +
- kSpacesPerIndentation + 5;
-
- StringAppendF(
- &result,
- "\n%s%s",
- PadStringLeft("", indentation).c_str(),
- extra_details.c_str());
+ scoped_ptr<Value> extra_details_value(extra_params->ToValue());
+ base::JSONWriter::Write(extra_details_value.get(), true,
+ &extra_details);
+ // JSON writer uses CR LF in its pretty-printer. Normalize to newlines.
+ ReplaceSubstringsAfterOffset(&extra_details, 0, "\r\n", "\n");
+ result.append("\n");
+ result.append(extra_details);
}
- if (i + 1 != entries_.size())
+ if (!extra_params && i + 1 != entries_.size())
result += "\n";
}
diff --git a/net/base/net_log_util_unittest.cc b/net/base/net_log_util_unittest.cc
index 9306fa9..98de4bc 100644
--- a/net/base/net_log_util_unittest.cc
+++ b/net/base/net_log_util_unittest.cc
@@ -20,14 +20,6 @@ CapturingNetLog::Entry MakeEventEntry(int t,
NULL);
}
-CapturingNetLog::Entry MakeStringEntry(int t, const std::string& string) {
- return CapturingNetLog::Entry(NetLog::TYPE_TODO_STRING,
- MakeTime(t),
- NetLog::Source(),
- NetLog::PHASE_NONE,
- new NetLogStringParameter(string));
-}
-
TEST(NetLogUtilTest, Basic) {
CapturingNetLog::EntryList log;
@@ -60,19 +52,24 @@ TEST(NetLogUtilTest, Basic2) {
log.push_back(MakeEventEntry(1, NetLog::TYPE_HOST_RESOLVER_IMPL,
NetLog::PHASE_BEGIN));
- log.push_back(MakeStringEntry(12, "Sup foo"));
- log.push_back(MakeStringEntry(14, "Multiline\nString"));
+ // Attach a string parameter to a CANCELLED event.
+ CapturingNetLog::Entry e =
+ MakeEventEntry(12, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE);
+ e.extra_parameters =
+ new NetLogStringParameter("string_name", "string_value");
+ log.push_back(e);
log.push_back(MakeEventEntry(131, NetLog::TYPE_HOST_RESOLVER_IMPL,
NetLog::PHASE_END));
EXPECT_EQ(
- "t= 1: +HOST_RESOLVER_IMPL [dt=130]\n"
- "t= 12: \"Sup foo\"\n"
- "t= 14: \"Multiline\n"
- "String\"\n"
- "t=131: -HOST_RESOLVER_IMPL",
- NetLogUtil::PrettyPrintAsEventTree(log, 0));
+ "t= 1: +HOST_RESOLVER_IMPL [dt=130]\n"
+ "t= 12: CANCELLED\n"
+ "{\n"
+ " \"string_name\": \"string_value\"\n"
+ "}\n"
+ "t=131: -HOST_RESOLVER_IMPL",
+ NetLogUtil::PrettyPrintAsEventTree(log, 0));
}
TEST(NetLogUtilTest, UnmatchedOpen) {
diff --git a/net/proxy/init_proxy_resolver.cc b/net/proxy/init_proxy_resolver.cc
index 0ca39d4..e4bd51b 100644
--- a/net/proxy/init_proxy_resolver.cc
+++ b/net/proxy/init_proxy_resolver.cc
@@ -122,17 +122,15 @@ void InitProxyResolver::DoCallback(int result) {
int InitProxyResolver::DoFetchPacScript() {
DCHECK(resolver_->expects_pac_bytes());
- net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT);
-
next_state_ = STATE_FETCH_PAC_SCRIPT_COMPLETE;
const GURL& pac_url = current_pac_url();
- net_log_.AddString(pac_url.spec());
+ net_log_.BeginEventWithString(
+ NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT, "url", pac_url.spec());
if (!proxy_script_fetcher_) {
- net_log_.AddStringLiteral(
- "Can't download PAC script, because no fetcher was specified");
+ net_log_.AddEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_HAS_NO_FETCHER);
return ERR_UNEXPECTED;
}
@@ -142,15 +140,14 @@ int InitProxyResolver::DoFetchPacScript() {
int InitProxyResolver::DoFetchPacScriptComplete(int result) {
DCHECK(resolver_->expects_pac_bytes());
- net_log_.AddString(StringPrintf(
- "Completed fetch with result %s. Received %" PRIuS " bytes",
- ErrorToString(result),
- pac_bytes_.size()));
-
- net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT);
-
- if (result != OK)
+ if (result == OK) {
+ net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT);
+ } else {
+ net_log_.EndEventWithInteger(
+ NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT,
+ "net_error", result);
return TryToFallbackPacUrl(result);
+ }
next_state_ = STATE_SET_PAC_SCRIPT;
return result;
@@ -170,15 +167,12 @@ int InitProxyResolver::DoSetPacScript() {
int InitProxyResolver::DoSetPacScriptComplete(int result) {
if (result != OK) {
- net_log_.AddString(
- StringPrintf("Failed initializing the PAC script with error: %s",
- ErrorToString(result)));
- net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT);
+ net_log_.EndEventWithInteger(
+ NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT,
+ "net_error", result);
return TryToFallbackPacUrl(result);
}
- net_log_.AddStringLiteral("Successfully initialized PAC script.");
-
net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT);
return result;
}
@@ -194,7 +188,8 @@ int InitProxyResolver::TryToFallbackPacUrl(int error) {
// Advance to next URL in our list.
++current_pac_url_index_;
- net_log_.AddStringLiteral("Falling back to next PAC URL...");
+ net_log_.AddEvent(
+ NetLog::TYPE_INIT_PROXY_RESOLVER_FALLING_BACK_TO_NEXT_PAC_URL);
next_state_ = GetStartState();
diff --git a/net/proxy/init_proxy_resolver_unittest.cc b/net/proxy/init_proxy_resolver_unittest.cc
index d6ca4af..234e5b0 100644
--- a/net/proxy/init_proxy_resolver_unittest.cc
+++ b/net/proxy/init_proxy_resolver_unittest.cc
@@ -177,19 +177,19 @@ TEST(InitProxyResolverTest, CustomPacSucceeds) {
EXPECT_EQ(rule.bytes(), resolver.pac_bytes());
// Check the NetLog was filled correctly.
- EXPECT_EQ(9u, log.entries().size());
+ EXPECT_EQ(6u, log.entries().size());
EXPECT_TRUE(LogContainsBeginEvent(
log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER));
EXPECT_TRUE(LogContainsBeginEvent(
log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
EXPECT_TRUE(LogContainsEndEvent(
- log.entries(), 4, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
+ log.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
EXPECT_TRUE(LogContainsBeginEvent(
- log.entries(), 5, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
+ log.entries(), 3, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
EXPECT_TRUE(LogContainsEndEvent(
- log.entries(), 7, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
+ log.entries(), 4, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
EXPECT_TRUE(LogContainsEndEvent(
- log.entries(), 8, NetLog::TYPE_INIT_PROXY_RESOLVER));
+ log.entries(), 5, NetLog::TYPE_INIT_PROXY_RESOLVER));
}
// Fail downloading the custom PAC script.
@@ -210,15 +210,15 @@ TEST(InitProxyResolverTest, CustomPacFails1) {
EXPECT_EQ("", resolver.pac_bytes());
// Check the NetLog was filled correctly.
- EXPECT_EQ(6u, log.entries().size());
+ EXPECT_EQ(4u, log.entries().size());
EXPECT_TRUE(LogContainsBeginEvent(
log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER));
EXPECT_TRUE(LogContainsBeginEvent(
log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
EXPECT_TRUE(LogContainsEndEvent(
- log.entries(), 4, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
+ log.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
EXPECT_TRUE(LogContainsEndEvent(
- log.entries(), 5, NetLog::TYPE_INIT_PROXY_RESOLVER));
+ log.entries(), 3, NetLog::TYPE_INIT_PROXY_RESOLVER));
}
// Fail parsing the custom PAC script.
@@ -310,27 +310,31 @@ TEST(InitProxyResolverTest, AutodetectFailCustomSuccess2) {
// Check the NetLog was filled correctly.
// (Note that the Fetch and Set states are repeated since both WPAD and custom
// PAC scripts are tried).
- EXPECT_EQ(17u, log.entries().size());
+ EXPECT_EQ(11u, log.entries().size());
EXPECT_TRUE(LogContainsBeginEvent(
log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER));
EXPECT_TRUE(LogContainsBeginEvent(
log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
EXPECT_TRUE(LogContainsEndEvent(
- log.entries(), 4, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
+ log.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
EXPECT_TRUE(LogContainsBeginEvent(
- log.entries(), 5, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
+ log.entries(), 3, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
EXPECT_TRUE(LogContainsEndEvent(
- log.entries(), 7, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
+ log.entries(), 4, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
+ EXPECT_TRUE(LogContainsEvent(
+ log.entries(), 5,
+ NetLog::TYPE_INIT_PROXY_RESOLVER_FALLING_BACK_TO_NEXT_PAC_URL,
+ NetLog::PHASE_NONE));
EXPECT_TRUE(LogContainsBeginEvent(
- log.entries(), 9, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
+ log.entries(), 6, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
EXPECT_TRUE(LogContainsEndEvent(
- log.entries(), 12, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
+ log.entries(), 7, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
EXPECT_TRUE(LogContainsBeginEvent(
- log.entries(), 13, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
+ log.entries(), 8, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
EXPECT_TRUE(LogContainsEndEvent(
- log.entries(), 15, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
+ log.entries(), 9, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
EXPECT_TRUE(LogContainsEndEvent(
- log.entries(), 16, NetLog::TYPE_INIT_PROXY_RESOLVER));
+ log.entries(), 10, NetLog::TYPE_INIT_PROXY_RESOLVER));
}
// Fails at WPAD (downloading), and fails at custom PAC (downloading).
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc
index e3778b9..588b240 100644
--- a/net/proxy/proxy_service.cc
+++ b/net/proxy/proxy_service.cc
@@ -469,14 +469,15 @@ int ProxyService::DidFinishResolvingProxy(ProxyInfo* result,
if (result_code == OK) {
// When full logging is enabled, dump the proxy list.
if (net_log.HasListener()) {
- net_log.AddString(
- std::string("Resolved proxy list: ") + result->ToPacString());
+ net_log.AddEventWithString(
+ NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST,
+ "pac_string", result->ToPacString());
}
result->DeprioritizeBadProxies(proxy_retry_info_);
} else {
- net_log.AddString(StringPrintf(
- "Got an error from proxy resolver (%d), falling-back to DIRECT.",
- result_code));
+ net_log.AddEventWithInteger(
+ NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST,
+ "net_error", result_code);
// Fall-back to direct when the proxy resolver fails. This corresponds
// with a javascript runtime error in the PAC script.
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
index 532b7f2..d35372d 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -58,7 +58,7 @@ int ConnectJob::Connect() {
timer_.Start(timeout_duration_, this, &ConnectJob::OnTimeout);
net_log_.BeginEventWithString(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB,
- group_name_);
+ "group_name", group_name_);
idle_ = false;
int rv = ConnectInternal();
@@ -202,7 +202,8 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal(
request->net_log().AddEvent(NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS);
} else {
- request->net_log().AddEvent(NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS_PER_GROUP);
+ request->net_log().AddEvent(
+ NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS_PER_GROUP);
}
return ERR_IO_PENDING;
}
@@ -234,7 +235,8 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal(
BoundNetLog job_net_log = BoundNetLog::Make(
request->net_log().net_log(), NetLog::SOURCE_CONNECT_JOB);
request->net_log().BeginEventWithInteger(
- NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID, job_net_log.source().id);
+ NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID,
+ "source_id", job_net_log.source().id);
scoped_ptr<ConnectJob> connect_job(
connect_job_factory_->NewConnectJob(group_name, *request, this,
@@ -243,7 +245,8 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal(
int rv = connect_job->Connect();
if (rv == OK) {
request->net_log().EndEventWithInteger(
- NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID, job_net_log.source().id);
+ NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID,
+ "source_id", job_net_log.source().id);
HandOutSocket(connect_job->ReleaseSocket(), false /* not reused */,
handle, base::TimeDelta(), &group, request->net_log());
} else if (rv == ERR_IO_PENDING) {
@@ -264,7 +267,8 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal(
group.jobs.insert(job);
} else {
request->net_log().EndEventWithInteger(
- NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID, job_net_log.source().id);
+ NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID,
+ "source_id", job_net_log.source().id);
if (group.IsEmpty())
group_map_.erase(group_name);
}
@@ -572,7 +576,7 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete(
scoped_ptr<const Request> r(RemoveRequestFromQueue(
group.pending_requests.begin(), &group.pending_requests));
r->net_log().EndEventWithInteger(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID,
- job_log.source().id);
+ "source_id", job_log.source().id);
r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL);
HandOutSocket(
socket.release(), false /* unused socket */, r->handle(),
@@ -588,7 +592,7 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete(
scoped_ptr<const Request> r(RemoveRequestFromQueue(
group.pending_requests.begin(), &group.pending_requests));
r->net_log().EndEventWithInteger(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID,
- job_log.source().id);
+ "source_id", job_log.source().id);
r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL);
r->callback()->Run(result);
}
@@ -676,15 +680,14 @@ void ClientSocketPoolBaseHelper::HandOutSocket(
handle->set_is_reused(reused);
handle->set_idle_time(idle_time);
- if (reused)
- net_log.AddStringLiteral("Reusing socket.");
- if (idle_time != base::TimeDelta()) {
- net_log.AddString(
- StringPrintf("Socket sat idle for %" PRId64 " milliseconds",
- idle_time.InMilliseconds()));
+ if (reused) {
+ net_log.AddEventWithInteger(
+ NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET,
+ "idle_ms", static_cast<int>(idle_time.InMilliseconds()));
}
+
net_log.AddEventWithInteger(NetLog::TYPE_SOCKET_POOL_SOCKET_ID,
- socket->NetLog().source().id);
+ "source_id", socket->NetLog().source().id);
handed_out_socket_count_++;
group->active_socket_count++;
diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc
index f9e555ca..cd333ff 100644
--- a/net/socket/client_socket_pool_base_unittest.cc
+++ b/net/socket/client_socket_pool_base_unittest.cc
@@ -1396,7 +1396,7 @@ TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) {
EXPECT_EQ(OK, rv);
EXPECT_TRUE(req.handle()->is_reused());
EXPECT_TRUE(LogContainsEntryWithType(
- log.entries(), 1, NetLog::TYPE_TODO_STRING_LITERAL));
+ log.entries(), 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET));
}
// Make sure that we process all pending requests even when we're stalling
diff --git a/net/socket/socks5_client_socket.cc b/net/socket/socks5_client_socket.cc
index c960b80..2a4317e 100644
--- a/net/socket/socks5_client_socket.cc
+++ b/net/socket/socks5_client_socket.cc
@@ -17,26 +17,6 @@
namespace net {
-namespace {
-
-// Returns a string description of |socks_error|, or NULL if |socks_error| is
-// not a valid SOCKS reply.
-const char* MapSOCKSReplyToErrorString(char socks_error) {
- switch(socks_error) {
- case 1: return "(1) General SOCKS server failure";
- case 2: return "(2) Connection not allowed by ruleset";
- case 3: return "(3) Network unreachable";
- case 4: return "(4) Host unreachable";
- case 5: return "(5) Connection refused";
- case 6: return "(6) TTL expired";
- case 7: return "(7) Command not supported";
- case 8: return "(8) Address type not supported";
- default: return NULL;
- }
-}
-
-} // namespace
-
const unsigned int SOCKS5ClientSocket::kGreetReadHeaderSize = 2;
const unsigned int SOCKS5ClientSocket::kWriteHeaderSize = 10;
const unsigned int SOCKS5ClientSocket::kReadHeaderSize = 5;
@@ -236,8 +216,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_.AddStringLiteral("Failed sending request because hostname is "
- "longer than 255 characters");
+ net_log_.AddEvent(NetLog::TYPE_SOCKS_HOSTNAME_TOO_BIG);
return ERR_SOCKS_CONNECTION_FAILED;
}
@@ -284,8 +263,7 @@ int SOCKS5ClientSocket::DoGreetReadComplete(int result) {
return result;
if (result == 0) {
- net_log_.AddStringLiteral(
- "Connection unexpected closed while reading greeting.");
+ net_log_.AddEvent(NetLog::TYPE_SOCKS_UNEXPECTEDLY_CLOSED_DURING_GREETING);
return ERR_SOCKS_CONNECTION_FAILED;
}
@@ -298,15 +276,13 @@ int SOCKS5ClientSocket::DoGreetReadComplete(int result) {
// Got the greet data.
if (buffer_[0] != kSOCKS5Version) {
- net_log_.AddStringLiteral("Unexpected SOCKS version");
- net_log_.AddString(StringPrintf(
- "buffer_[0] = 0x%x", static_cast<int>(buffer_[0])));
+ net_log_.AddEventWithInteger(NetLog::TYPE_SOCKS_UNEXPECTED_VERSION,
+ "version", buffer_[0]);
return ERR_SOCKS_CONNECTION_FAILED;
}
if (buffer_[1] != 0x00) {
- net_log_.AddStringLiteral("Unexpected authentication method");
- net_log_.AddString(StringPrintf(
- "buffer_[1] = 0x%x", static_cast<int>(buffer_[1])));
+ net_log_.AddEventWithInteger(NetLog::TYPE_SOCKS_UNEXPECTED_AUTH,
+ "method", buffer_[1]);
return ERR_SOCKS_CONNECTION_FAILED;
}
@@ -397,8 +373,7 @@ int SOCKS5ClientSocket::DoHandshakeReadComplete(int result) {
// The underlying socket closed unexpectedly.
if (result == 0) {
- net_log_.AddStringLiteral(
- "Connection unexpected closed while reading handshake.");
+ net_log_.AddEvent(NetLog::TYPE_SOCKS_UNEXPECTEDLY_CLOSED_DURING_HANDSHAKE);
return ERR_SOCKS_CONNECTION_FAILED;
}
@@ -409,22 +384,13 @@ int SOCKS5ClientSocket::DoHandshakeReadComplete(int result) {
// and accordingly increase them
if (bytes_received_ == kReadHeaderSize) {
if (buffer_[0] != kSOCKS5Version || buffer_[2] != kNullByte) {
- net_log_.AddStringLiteral("Unexpected SOCKS version.");
- net_log_.AddString(StringPrintf(
- "buffer_[0] = 0x%x; buffer_[2] = 0x%x",
- static_cast<int>(buffer_[0]),
- static_cast<int>(buffer_[2])));
+ net_log_.AddEventWithInteger(NetLog::TYPE_SOCKS_UNEXPECTED_VERSION,
+ "version", buffer_[0]);
return ERR_SOCKS_CONNECTION_FAILED;
}
if (buffer_[1] != 0x00) {
- net_log_.AddStringLiteral("SOCKS server returned a failure code:");
- const char* error_string = MapSOCKSReplyToErrorString(buffer_[1]);
- if (error_string) {
- net_log_.AddStringLiteral(error_string);
- } else {
- net_log_.AddString(StringPrintf(
- "buffer_[1] = 0x%x", static_cast<int>(buffer_[1])));
- }
+ net_log_.AddEventWithInteger(NetLog::TYPE_SOCKS_SERVER_ERROR,
+ "error_code", buffer_[1]);
return ERR_SOCKS_CONNECTION_FAILED;
}
@@ -442,9 +408,8 @@ int SOCKS5ClientSocket::DoHandshakeReadComplete(int result) {
else if (address_type == kEndPointResolvedIPv6)
read_header_size += sizeof(struct in6_addr) - 1;
else {
- net_log_.AddStringLiteral("Unknown address type in response");
- net_log_.AddString(StringPrintf(
- "buffer_[3] = 0x%x", static_cast<int>(buffer_[3])));
+ net_log_.AddEventWithInteger(NetLog::TYPE_SOCKS_UNKNOWN_ADDRESS_TYPE,
+ "address_type", buffer_[3]);
return ERR_SOCKS_CONNECTION_FAILED;
}
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc
index b64523d..56cb435 100644
--- a/net/socket/tcp_client_socket_libevent.cc
+++ b/net/socket/tcp_client_socket_libevent.cc
@@ -277,7 +277,8 @@ int TCPClientSocketLibevent::Read(IOBuffer* buf,
int nread = HANDLE_EINTR(read(socket_, buf->data(), buf_len));
if (nread >= 0) {
TRACE_EVENT_END("socket.read", this, StringPrintf("%d bytes", nread));
- net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_RECEIVED, nread);
+ net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_RECEIVED,
+ "num_bytes", nread);
return nread;
}
if (errno != EAGAIN && errno != EWOULDBLOCK) {
@@ -312,7 +313,8 @@ int TCPClientSocketLibevent::Write(IOBuffer* buf,
int nwrite = HANDLE_EINTR(write(socket_, buf->data(), buf_len));
if (nwrite >= 0) {
TRACE_EVENT_END("socket.write", this, StringPrintf("%d bytes", nwrite));
- net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_SENT, nwrite);
+ net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_SENT,
+ "num_bytes", nwrite);
return nwrite;
}
if (errno != EAGAIN && errno != EWOULDBLOCK)
@@ -432,7 +434,8 @@ void TCPClientSocketLibevent::DidCompleteRead() {
TRACE_EVENT_END("socket.read", this,
StringPrintf("%d bytes", bytes_transferred));
result = bytes_transferred;
- net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_RECEIVED, result);
+ net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_RECEIVED,
+ "num_bytes", result);
} else {
result = MapPosixError(errno);
}
@@ -456,7 +459,8 @@ void TCPClientSocketLibevent::DidCompleteWrite() {
result = bytes_transferred;
TRACE_EVENT_END("socket.write", this,
StringPrintf("%d bytes", bytes_transferred));
- net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_SENT, result);
+ net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_SENT,
+ "num_bytes", result);
} else {
result = MapPosixError(errno);
}
diff --git a/net/socket/tcp_client_socket_pool.cc b/net/socket/tcp_client_socket_pool.cc
index 5cf1fa1..ed75d0e 100644
--- a/net/socket/tcp_client_socket_pool.cc
+++ b/net/socket/tcp_client_socket_pool.cc
@@ -200,9 +200,13 @@ int TCPClientSocketPool::RequestSocket(
static_cast<const TCPSocketParams*>(params);
if (net_log.HasListener()) {
- net_log.AddString(StringPrintf("Requested TCP socket to: %s [port %d]",
- casted_params->destination().hostname().c_str(),
- casted_params->destination().port()));
+ // TODO(eroman): Split out the host and port parameters.
+ net_log.AddEventWithString(
+ NetLog::TYPE_TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET,
+ "host_and_port",
+ StringPrintf("%s [port %d]",
+ casted_params->destination().hostname().c_str(),
+ casted_params->destination().port()));
}
return base_.RequestSocket(group_name, *casted_params, priority, handle,
diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc
index 24c3eca..95ec3a9 100644
--- a/net/socket/tcp_client_socket_win.cc
+++ b/net/socket/tcp_client_socket_win.cc
@@ -477,7 +477,8 @@ int TCPClientSocketWin::Read(IOBuffer* buf,
base::MemoryDebug::MarkAsInitialized(core_->read_buffer_.buf, num);
static StatsCounter read_bytes("tcp.read_bytes");
read_bytes.Add(num);
- net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_RECEIVED, num);
+ net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_RECEIVED,
+ "num_bytes", num);
return static_cast<int>(num);
}
} else {
@@ -528,7 +529,8 @@ int TCPClientSocketWin::Write(IOBuffer* buf,
TRACE_EVENT_END("socket.write", this, StringPrintf("%d bytes", rv));
static StatsCounter write_bytes("tcp.write_bytes");
write_bytes.Add(rv);
- net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_SENT, rv);
+ net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_SENT,
+ "num_bytes", rv);
return rv;
}
} else {
@@ -691,8 +693,10 @@ void TCPClientSocketWin::DidCompleteRead() {
TRACE_EVENT_END("socket.read", this, StringPrintf("%d bytes", num_bytes));
waiting_read_ = false;
core_->read_iobuffer_ = NULL;
- if (ok)
- net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_RECEIVED, num_bytes);
+ if (ok) {
+ net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_RECEIVED,
+ "num_bytes", num_bytes);
+ }
DoReadCallback(ok ? num_bytes : MapWinsockError(WSAGetLastError()));
}
@@ -718,7 +722,8 @@ void TCPClientSocketWin::DidCompleteWrite() {
<< " bytes reported.";
rv = ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES;
} else {
- net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_SENT, rv);
+ net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_SENT,
+ "num_bytes", rv);
}
}
core_->write_iobuffer_ = NULL;
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc
index 5500579..f3fb6d00 100644
--- a/net/socket_stream/socket_stream.cc
+++ b/net/socket_stream/socket_stream.cc
@@ -121,7 +121,7 @@ void SocketStream::Connect() {
// back before returning Connect().
next_state_ = STATE_RESOLVE_PROXY;
net_log_.BeginEventWithString(NetLog::TYPE_SOCKET_STREAM_CONNECT,
- url_.possibly_invalid_spec());
+ "url", url_.possibly_invalid_spec());
MessageLoop::current()->PostTask(
FROM_HERE,
NewRunnableMethod(this, &SocketStream::DoLoop, OK));
@@ -406,7 +406,8 @@ void SocketStream::DoLoop(int result) {
// close the connection.
if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) {
DCHECK_EQ(next_state_, STATE_CLOSE);
- net_log_.EndEventWithInteger(NetLog::TYPE_SOCKET_STREAM_CONNECT, result);
+ net_log_.EndEventWithInteger(NetLog::TYPE_SOCKET_STREAM_CONNECT,
+ "net_error", result);
}
} while (result != ERR_IO_PENDING);
}
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index 348fb37..589d81f 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -260,7 +260,7 @@ void URLRequest::StartJob(URLRequestJob* job) {
DCHECK(!job_);
net_log_.BeginEventWithString(net::NetLog::TYPE_URL_REQUEST_START,
- original_url().possibly_invalid_spec());
+ "url", original_url().possibly_invalid_spec());
job_ = job;
job_->SetExtraRequestHeaders(extra_request_headers_);
@@ -368,7 +368,7 @@ void URLRequest::ReceivedRedirect(const GURL& location, bool* defer_redirect) {
void URLRequest::ResponseStarted() {
if (!status_.is_success()) {
net_log_.EndEventWithInteger(net::NetLog::TYPE_URL_REQUEST_START,
- status_.os_error());
+ "net_error", status_.os_error());
} else {
net_log_.EndEvent(net::NetLog::TYPE_URL_REQUEST_START);
}
@@ -445,8 +445,8 @@ std::string URLRequest::StripPostSpecificHeaders(const std::string& headers) {
int URLRequest::Redirect(const GURL& location, int http_status_code) {
if (net_log_.HasListener()) {
- net_log_.AddString(StringPrintf("Redirected (%d) to %s",
- http_status_code, location.spec().c_str()));
+ net_log_.AddEventWithString(net::NetLog::TYPE_URL_REQUEST_REDIRECTED,
+ "location", location.possibly_invalid_spec());
}
if (redirect_limit_ <= 0) {
DLOG(INFO) << "disallowing redirect: exceeds limit";